tauri开发中如果取消了默认的菜单项,复制黏贴撤销等功能也就没有了,解决办法

时间:2024-11-04 07:21:07

取消默认的菜单项:清除tauri默认的菜单项,让顶部的菜单menu不显示-****博客

就是通过配置空菜单,让菜单不显示,但是这个引发的问题就是复制黏贴撤销等功能也就没有了,解决办法:

新增加编辑下的子菜单:

// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

use tauri::{Menu, MenuItem, Submenu};

fn main() {
    let edit_menu = Submenu::new(
        "Edit",
        Menu::new()
            .add_native_item(MenuItem::Undo)
            .add_native_item(MenuItem::Redo)
            .add_native_item(MenuItem::Copy)
            .add_native_item(MenuItem::Cut)
            .add_native_item(MenuItem::Paste)
            .add_native_item(MenuItem::SelectAll)
            .add_native_item(MenuItem::CloseWindow)
            .add_native_item(MenuItem::Quit),
    );
    tauri::Builder::default()
        .menu(Menu::new().add_submenu(edit_menu))
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

然后就可以了