Skip to content

Commit

Permalink
✨ Add Extract in menu
Browse files Browse the repository at this point in the history
  • Loading branch information
ChanTsune committed Dec 14, 2023
1 parent 96aef8b commit 910e899
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
17 changes: 16 additions & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

use std::{fs, io, path::Path};

#[cfg(target_os = "macos")]
use tauri::MenuEntry;
#[cfg(not(target_os = "macos"))]
use tauri::Submenu;
use tauri::{CustomMenuItem, Menu, MenuEntry, Window};
use tauri::{CustomMenuItem, Menu, Window};

// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
#[tauri::command]
Expand Down Expand Up @@ -52,21 +54,31 @@ where
}

const MENU_UPDATE_CHECK: &str = "update check";
const MENU_EXTRACT_FILE: &str = "extract file";

fn main() {
let context = tauri::generate_context!();
let mut menu = Menu::os_default(&context.package_info().name);
let update_check = CustomMenuItem::new(MENU_UPDATE_CHECK, "Check for updates...");
let extract_file = CustomMenuItem::new(MENU_EXTRACT_FILE, "Extract");
#[cfg(target_os = "macos")]
if let MenuEntry::Submenu(sub_menu) = &mut menu.items[0] {
sub_menu
.inner
.items
.insert(1, MenuEntry::CustomItem(update_check));
}
#[cfg(target_os = "macos")]
if let MenuEntry::Submenu(sub_menu) = &mut menu.items[1] {
sub_menu
.inner
.items
.insert(0, MenuEntry::CustomItem(extract_file.accelerator("Cmd+O")));
}
#[cfg(not(target_os = "macos"))]
{
menu = menu.add_submenu(Submenu::new("Tools", Menu::new().add_item(update_check)));
menu = menu.add_item(extract_file.accelerator("Ctrl+O"));
}

tauri::Builder::default()
Expand All @@ -79,6 +91,9 @@ fn main() {
.emit_and_trigger("tauri://update", ())
.unwrap();
}
MENU_EXTRACT_FILE => {
event.window().emit("open_extract", ()).unwrap();
}
m => println!("{}", m),
};
})
Expand Down
18 changes: 10 additions & 8 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,19 @@ function App() {
extract(path);
}
});
return () => {
unlisten.then((it) => it());
};
}, []);

useEffect(() => {
const unlisten = appWindow.listen<string>("extract_processing", (e) => {
setName(e.payload);
const unlistenExtractProcessing = appWindow.listen<string>(
"extract_processing",
(e) => {
setName(e.payload);
},
);
const unlistenOpenExtract = appWindow.listen<void>("open_extract", () => {
inputRef.current?.click();
});
return () => {
unlisten.then((it) => it());
unlistenExtractProcessing.then((it) => it());
unlistenOpenExtract.then((it) => it());
};
}, []);

Expand Down

0 comments on commit 910e899

Please sign in to comment.