fix(desktop): hide native Edit menu bar on Linux (#6456)

This commit is contained in:
souheyl gouadria
2026-07-28 17:15:44 +01:00
committed by GitHub
parent 820bcdae55
commit 347aa2d2c5
2 changed files with 17 additions and 3 deletions
@@ -239,6 +239,13 @@ pub async fn load<R: Runtime>(app: AppHandle<R>, options: LoadOptions) -> Result
})?;
}
#[cfg(target_os = "linux")]
{
if let Err(e) = window.hide_menu() {
tracing::warn!(?e, window_label = %label, "Failed to hide menu bar");
}
}
let is_visible = window.is_visible().unwrap_or(false);
let response = LoadResponse {
success: is_visible,
@@ -169,6 +169,7 @@ pub fn run() {
#[cfg(target_os = "linux")]
{
use tauri::menu::{Menu, PredefinedMenuItem, Submenu};
use tauri::Manager;
let result = (|| -> Result<(), Box<dyn std::error::Error>> {
let handle = app.handle();
@@ -187,12 +188,18 @@ pub fn run() {
&PredefinedMenuItem::select_all(handle, None)?,
],
)?;
// NOTE: This menu bar will be visible on Linux. Removing it or hiding it
// also removes the accelerator registrations and breaks clipboard shortcuts
// (webkit2gtk requires native menu items to recognise Ctrl+C/V/X etc.).
// The menu must be registered so webkit2gtk picks up the accelerators
// (Ctrl+C/V/X etc.), but the menu bar itself should be hidden so it
// does not appear as a visible "Edit" strip the user cannot dismiss.
// See https://github.com/tauri-apps/tauri/issues/2397
let menu = Menu::with_items(handle, &[&edit_menu])?;
app.set_menu(menu)?;
for (label, window) in app.webview_windows() {
if let Err(e) = window.hide_menu() {
tracing::warn!(?e, window_label = %label, "Failed to hide menu bar");
}
}
Ok(())
})();