feat: basic app menu (#1207)
This commit is contained in:
36
apps/desktop/src-tauri/Cargo.lock
generated
36
apps/desktop/src-tauri/Cargo.lock
generated
@@ -2115,6 +2115,30 @@ dependencies = [
|
|||||||
"thiserror",
|
"thiserror",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libappindicator"
|
||||||
|
version = "0.7.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "db2d3cb96d092b4824cb306c9e544c856a4cb6210c1081945187f7f1924b47e8"
|
||||||
|
dependencies = [
|
||||||
|
"glib",
|
||||||
|
"gtk",
|
||||||
|
"gtk-sys",
|
||||||
|
"libappindicator-sys",
|
||||||
|
"log",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libappindicator-sys"
|
||||||
|
version = "0.7.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f1b3b6681973cea8cc3bce7391e6d7d5502720b80a581c9a95c9cbaf592826aa"
|
||||||
|
dependencies = [
|
||||||
|
"gtk-sys",
|
||||||
|
"libloading",
|
||||||
|
"once_cell",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.138"
|
version = "0.2.138"
|
||||||
@@ -2130,6 +2154,16 @@ dependencies = [
|
|||||||
"pkg-config",
|
"pkg-config",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libloading"
|
||||||
|
version = "0.7.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libsqlite3-sys"
|
name = "libsqlite3-sys"
|
||||||
version = "0.24.2"
|
version = "0.24.2"
|
||||||
@@ -4430,6 +4464,7 @@ dependencies = [
|
|||||||
"core-foundation",
|
"core-foundation",
|
||||||
"core-graphics",
|
"core-graphics",
|
||||||
"crossbeam-channel",
|
"crossbeam-channel",
|
||||||
|
"dirs-next",
|
||||||
"dispatch",
|
"dispatch",
|
||||||
"gdk",
|
"gdk",
|
||||||
"gdk-pixbuf",
|
"gdk-pixbuf",
|
||||||
@@ -4443,6 +4478,7 @@ dependencies = [
|
|||||||
"instant",
|
"instant",
|
||||||
"jni",
|
"jni",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
|
"libappindicator",
|
||||||
"libc",
|
"libc",
|
||||||
"log",
|
"log",
|
||||||
"ndk",
|
"ndk",
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ schemars = "0.8.3"
|
|||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
dotenvy = "0.15.6"
|
dotenvy = "0.15.6"
|
||||||
tauri = { version = "1.2", features = ["api-all", "devtools"] }
|
tauri = { version = "1.2", features = ["api-all", "devtools", "system-tray"] }
|
||||||
tokio = { version = "1.23.0", features = ["rt", "macros"] }
|
tokio = { version = "1.23.0", features = ["rt", "macros"] }
|
||||||
lib0 = "0.12.0"
|
lib0 = "0.12.0"
|
||||||
moka = { version = "0.9.6", features = ["future"] }
|
moka = { version = "0.9.6", features = ["future"] }
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
mod commands;
|
mod commands;
|
||||||
mod state;
|
mod state;
|
||||||
|
mod menu;
|
||||||
use dotenvy::dotenv;
|
use dotenvy::dotenv;
|
||||||
use state::AppState;
|
use state::AppState;
|
||||||
use std::env;
|
use std::env;
|
||||||
@@ -47,6 +48,8 @@ async fn main() {
|
|||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
.invoke_handler(commands::invoke_handler())
|
.invoke_handler(commands::invoke_handler())
|
||||||
|
.menu(menu::init())
|
||||||
|
.on_menu_event(menu::menu_handler)
|
||||||
.run(tauri::generate_context!())
|
.run(tauri::generate_context!())
|
||||||
.expect("error while running tauri application");
|
.expect("error while running tauri application");
|
||||||
}
|
}
|
||||||
|
|||||||
108
apps/desktop/src-tauri/src/menu.rs
Normal file
108
apps/desktop/src-tauri/src/menu.rs
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
use tauri::{CustomMenuItem, Manager, Menu, MenuItem, Submenu, WindowMenuEvent};
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
use tauri::AboutMetadata;
|
||||||
|
|
||||||
|
// --- Menu
|
||||||
|
pub fn init() -> Menu {
|
||||||
|
let name = "AFFiNE";
|
||||||
|
let app_menu = Submenu::new(
|
||||||
|
name,
|
||||||
|
Menu::with_items([
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
MenuItem::About(name.into(), AboutMetadata::default()).into(),
|
||||||
|
MenuItem::Services.into(),
|
||||||
|
MenuItem::Hide.into(),
|
||||||
|
MenuItem::HideOthers.into(),
|
||||||
|
MenuItem::ShowAll.into(),
|
||||||
|
MenuItem::Separator.into(),
|
||||||
|
MenuItem::Quit.into(),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
|
||||||
|
let edit_menu = Submenu::new(
|
||||||
|
"Edit",
|
||||||
|
Menu::new()
|
||||||
|
.add_native_item(MenuItem::Undo)
|
||||||
|
.add_native_item(MenuItem::Redo)
|
||||||
|
.add_native_item(MenuItem::Separator)
|
||||||
|
.add_native_item(MenuItem::Cut)
|
||||||
|
.add_native_item(MenuItem::Copy)
|
||||||
|
.add_native_item(MenuItem::Paste)
|
||||||
|
.add_native_item(MenuItem::SelectAll),
|
||||||
|
);
|
||||||
|
|
||||||
|
let view_menu = Submenu::new(
|
||||||
|
"View",
|
||||||
|
Menu::new()
|
||||||
|
.add_item(CustomMenuItem::new("go_back".to_string(), "Go Back").accelerator("CmdOrCtrl+["))
|
||||||
|
.add_item(
|
||||||
|
CustomMenuItem::new("go_forward".to_string(), "Go Forward").accelerator("CmdOrCtrl+]"),
|
||||||
|
)
|
||||||
|
.add_native_item(MenuItem::Separator)
|
||||||
|
.add_item(
|
||||||
|
CustomMenuItem::new("zoom_0".to_string(), "Zoom to Actual Size").accelerator("CmdOrCtrl+0"),
|
||||||
|
)
|
||||||
|
.add_item(CustomMenuItem::new("zoom_out".to_string(), "Zoom Out").accelerator("CmdOrCtrl+-"))
|
||||||
|
.add_item(CustomMenuItem::new("zoom_in".to_string(), "Zoom In").accelerator("CmdOrCtrl+Plus"))
|
||||||
|
.add_native_item(MenuItem::Separator)
|
||||||
|
.add_item(
|
||||||
|
CustomMenuItem::new("reload".to_string(), "Refresh the Screen").accelerator("CmdOrCtrl+R"),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
let window_menu = Submenu::new(
|
||||||
|
"Window",
|
||||||
|
Menu::new()
|
||||||
|
.add_item(CustomMenuItem::new(
|
||||||
|
"official_website".to_string(),
|
||||||
|
"About AFFiNE",
|
||||||
|
))
|
||||||
|
.add_native_item(MenuItem::Separator)
|
||||||
|
.add_native_item(MenuItem::Minimize)
|
||||||
|
.add_native_item(MenuItem::Zoom),
|
||||||
|
);
|
||||||
|
|
||||||
|
let help_menu = Submenu::new(
|
||||||
|
"Help",
|
||||||
|
Menu::new()
|
||||||
|
.add_item(CustomMenuItem::new("update_log".to_string(), "Update Log"))
|
||||||
|
.add_item(CustomMenuItem::new("report_bug".to_string(), "Report Bug"))
|
||||||
|
.add_item(
|
||||||
|
CustomMenuItem::new("dev_tools".to_string(), "Toggle Developer Tools")
|
||||||
|
.accelerator("CmdOrCtrl+Shift+I"),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
Menu::new()
|
||||||
|
.add_submenu(app_menu)
|
||||||
|
.add_submenu(window_menu)
|
||||||
|
.add_submenu(edit_menu)
|
||||||
|
.add_submenu(view_menu)
|
||||||
|
.add_submenu(help_menu)
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Menu Event
|
||||||
|
pub fn menu_handler(event: WindowMenuEvent<tauri::Wry>) {
|
||||||
|
let win = Some(event.window()).unwrap();
|
||||||
|
let app = win.app_handle();
|
||||||
|
let menu_id = event.menu_item_id();
|
||||||
|
|
||||||
|
match menu_id {
|
||||||
|
// App
|
||||||
|
"restart" => tauri::api::process::restart(&app.env()),
|
||||||
|
// Window
|
||||||
|
// View
|
||||||
|
"zoom_0" => win.eval("window.__zoom0 && window.__zoom0()").unwrap(),
|
||||||
|
"zoom_out" => win.eval("window.__zoomOut && window.__zoomOut()").unwrap(),
|
||||||
|
"zoom_in" => win.eval("window.__zoomIn && window.__zoomIn()").unwrap(),
|
||||||
|
"reload" => win.eval("window.location.reload()").unwrap(),
|
||||||
|
"go_back" => win.eval("window.history.go(-1)").unwrap(),
|
||||||
|
"go_forward" => win.eval("window.history.go(1)").unwrap(),
|
||||||
|
"dev_tools" => {
|
||||||
|
win.open_devtools();
|
||||||
|
win.close_devtools();
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,6 +18,11 @@
|
|||||||
"scope": ["$RESOURCE", "$RESOURCE/*", "$APP/*"]
|
"scope": ["$RESOURCE", "$RESOURCE/*", "$APP/*"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"systemTray": {
|
||||||
|
"iconPath": "icons/128x128@2x.png",
|
||||||
|
"iconAsTemplate": true,
|
||||||
|
"menuOnLeftClick": false
|
||||||
|
},
|
||||||
"bundle": {
|
"bundle": {
|
||||||
"active": true,
|
"active": true,
|
||||||
"category": "DeveloperTool",
|
"category": "DeveloperTool",
|
||||||
|
|||||||
@@ -1,9 +1,3 @@
|
|||||||
declare global {
|
|
||||||
interface Window {
|
|
||||||
__TAURI_ISOLATION_HOOK_: (payload: any) => any;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// tauri preload script can't have `export {}`
|
// tauri preload script can't have `export {}`
|
||||||
// @ts-ignore 'index.ts' cannot be compiled under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement to make it a module.ts(1208)
|
// @ts-ignore 'index.ts' cannot be compiled under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement to make it a module.ts(1208)
|
||||||
window.__TAURI_ISOLATION_HOOK__ = payload => {
|
window.__TAURI_ISOLATION_HOOK__ = payload => {
|
||||||
@@ -20,5 +14,3 @@ function setEnvironmentVariables() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setEnvironmentVariables();
|
setEnvironmentVariables();
|
||||||
|
|
||||||
export {};
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ declare global {
|
|||||||
|
|
||||||
interface Window {
|
interface Window {
|
||||||
CLIENT_APP?: boolean;
|
CLIENT_APP?: boolean;
|
||||||
|
__TAURI_ISOLATION_HOOK_: (payload: any) => any;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user