Skip to content

Commit 7d40f10

Browse files
author
AENERV7
committed
feat: File > Open File menu item (Cmd+O), remove empty Help menu
- Replace File > Close Window with File > Open File (Cmd+O) - Open File triggers same file dialog as double-click on drop zone - Remove empty Help submenu on macOS - All three languages now use custom menu (no fallback to default) - Bump version to 0.5.2
1 parent 403e699 commit 7d40f10

5 files changed

Lines changed: 38 additions & 26 deletions

File tree

dist/index.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -982,14 +982,18 @@ <h3>${t.modal_title}</h3>
982982

983983
// ── 双击选择文件 ──
984984
const { open: openDialog } = window.__TAURI__.dialog;
985-
dropZone.addEventListener("dblclick", async () => {
985+
async function openFileDialog() {
986986
if (busy) return;
987987
const selected = await openDialog({
988988
multiple: true, directory: false
989989
});
990990
if (!selected) return;
991991
await handleFiles(Array.isArray(selected) ? selected : [selected]);
992-
});
992+
}
993+
dropZone.addEventListener("dblclick", openFileDialog);
994+
995+
// ── 菜单打开文件 ──
996+
listen("menu-open-file", openFileDialog);
993997

994998
// ── 窗口就绪后显示 ──
995999
window.__TAURI__.window.getCurrentWindow().show();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "yauz",
3-
"version": "0.5.1",
3+
"version": "0.5.2",
44
"private": true,
55
"scripts": {
66
"tauri": "tauri",

src-tauri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "yauz"
3-
version = "0.5.1"
3+
version = "0.5.2"
44
edition = "2021"
55

66
[lib]

src-tauri/src/lib.rs

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ use tauri::{State, AppHandle, Emitter};
1010
// ── macOS 菜单本地化 ──
1111

1212
#[cfg(target_os = "macos")]
13-
fn build_macos_menu(app: &tauri::AppHandle, lang: &str) -> Result<Option<tauri::menu::Menu<tauri::Wry>>, Box<dyn std::error::Error>> {
14-
use tauri::menu::{Menu, Submenu, PredefinedMenuItem, WINDOW_SUBMENU_ID, HELP_SUBMENU_ID};
13+
fn build_macos_menu(app: &tauri::AppHandle, lang: &str) -> tauri::Result<tauri::menu::Menu<tauri::Wry>> {
14+
use tauri::menu::{Menu, Submenu, MenuItem, PredefinedMenuItem, WINDOW_SUBMENU_ID};
1515

1616
struct T {
1717
file: &'static str,
18+
open_file: &'static str,
1819
edit: &'static str,
1920
view: &'static str,
2021
window: &'static str,
21-
help: &'static str,
2222
undo: &'static str,
2323
redo: &'static str,
2424
cut: &'static str,
@@ -37,7 +37,8 @@ fn build_macos_menu(app: &tauri::AppHandle, lang: &str) -> Result<Option<tauri::
3737

3838
let t = match lang {
3939
"zh-CN" => T {
40-
file: "文件", edit: "编辑", view: "显示", window: "窗口", help: "帮助",
40+
file: "文件", open_file: "打开文件...",
41+
edit: "编辑", view: "显示", window: "窗口",
4142
undo: "撤销", redo: "重做", cut: "剪切", copy: "拷贝",
4243
paste: "粘贴", select_all: "全选",
4344
minimize: "最小化", zoom: "缩放", fullscreen: "进入全屏幕",
@@ -46,15 +47,25 @@ fn build_macos_menu(app: &tauri::AppHandle, lang: &str) -> Result<Option<tauri::
4647
quit: "退出 YAUZ", services: "服务",
4748
},
4849
"zh-TW" => T {
49-
file: "檔案", edit: "編輯", view: "顯示方式", window: "視窗", help: "輔助說明",
50+
file: "檔案", open_file: "開啟檔案...",
51+
edit: "編輯", view: "顯示方式", window: "視窗",
5052
undo: "還原", redo: "重做", cut: "剪下", copy: "拷貝",
5153
paste: "貼上", select_all: "全選",
5254
minimize: "縮到最小", zoom: "縮放", fullscreen: "進入全螢幕",
5355
close: "關閉視窗",
5456
hide: "隱藏 YAUZ", hide_others: "隱藏其他",
5557
quit: "結束 YAUZ", services: "服務",
5658
},
57-
_ => return Ok(None), // English — use Tauri default menu
59+
_ => T {
60+
file: "File", open_file: "Open File...",
61+
edit: "Edit", view: "View", window: "Window",
62+
undo: "Undo", redo: "Redo", cut: "Cut", copy: "Copy",
63+
paste: "Paste", select_all: "Select All",
64+
minimize: "Minimise", zoom: "Zoom", fullscreen: "Enter Full Screen",
65+
close: "Close Window",
66+
hide: "Hide YAUZ", hide_others: "Hide Others",
67+
quit: "Quit YAUZ", services: "Services",
68+
},
5869
};
5970

6071
let pkg_info = app.package_info();
@@ -78,9 +89,10 @@ fn build_macos_menu(app: &tauri::AppHandle, lang: &str) -> Result<Option<tauri::
7889
],
7990
)?;
8091

92+
let open_item = MenuItem::with_id(app, "open_file", t.open_file, true, Some("CmdOrCtrl+O"))?;
8193
let file_submenu = Submenu::with_items(
8294
app, t.file, true,
83-
&[&PredefinedMenuItem::close_window(app, Some(t.close))?],
95+
&[&open_item],
8496
)?;
8597

8698
let edit_submenu = Submenu::with_items(
@@ -111,16 +123,10 @@ fn build_macos_menu(app: &tauri::AppHandle, lang: &str) -> Result<Option<tauri::
111123
],
112124
)?;
113125

114-
let help_submenu = Submenu::with_id_and_items(
115-
app, HELP_SUBMENU_ID, t.help, true, &[],
116-
)?;
117-
118-
let menu = Menu::with_items(
126+
Menu::with_items(
119127
app,
120-
&[&app_submenu, &file_submenu, &edit_submenu, &view_submenu, &window_submenu, &help_submenu],
121-
)?;
122-
123-
Ok(Some(menu))
128+
&[&app_submenu, &file_submenu, &edit_submenu, &view_submenu, &window_submenu],
129+
)
124130
}
125131

126132
struct AppState {
@@ -903,13 +909,15 @@ pub fn run() {
903909
.plugin(tauri_plugin_shell::init())
904910
.menu(move |app| {
905911
#[cfg(target_os = "macos")]
906-
{
907-
if let Ok(Some(m)) = build_macos_menu(app, &menu_lang) {
908-
return Ok(m);
909-
}
910-
}
912+
{ return build_macos_menu(app, &menu_lang); }
913+
#[cfg(not(target_os = "macos"))]
911914
tauri::menu::Menu::default(app)
912915
})
916+
.on_menu_event(|app, event| {
917+
if event.id().as_ref() == "open_file" {
918+
let _ = app.emit("menu-open-file", ());
919+
}
920+
})
913921
.manage(AppState {
914922
passwords: Mutex::new(passwords),
915923
seven_zip_dir: Mutex::new(seven_zip_dir),

src-tauri/tauri.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"productName": "YAUZ",
3-
"version": "0.5.1",
3+
"version": "0.5.2",
44
"identifier": "com.yauz.dev",
55
"build": {
66
"frontendDist": "../dist"

0 commit comments

Comments
 (0)