diff --git a/package-lock.json b/package-lock.json index 732aa50..bf15a36 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,7 @@ "@tauri-apps/api": "^2.8.0", "@tauri-apps/cli": "^2.8.3", "@tauri-apps/plugin-opener": "^2.5.0", + "@tauri-apps/plugin-os": "^2.3.1", "@typescript-eslint/eslint-plugin": "^6.18.1", "@typescript-eslint/parser": "^6.18.1", "autoprefixer": "^10.4.16", @@ -1331,6 +1332,16 @@ "@tauri-apps/api": "^2.8.0" } }, + "node_modules/@tauri-apps/plugin-os": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/@tauri-apps/plugin-os/-/plugin-os-2.3.1.tgz", + "integrity": "sha512-ty5V8XDUIFbSnrk3zsFoP3kzN+vAufYzalJSlmrVhQTImIZa1aL1a03bOaP2vuBvfR+WDRC6NgV2xBl8G07d+w==", + "dev": true, + "license": "MIT OR Apache-2.0", + "dependencies": { + "@tauri-apps/api": "^2.8.0" + } + }, "node_modules/@types/cookie": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/@types/cookie/-/cookie-0.6.0.tgz", diff --git a/package.json b/package.json index a231a01..791d800 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "@tauri-apps/api": "^2.8.0", "@tauri-apps/cli": "^2.8.3", "@tauri-apps/plugin-opener": "^2.5.0", + "@tauri-apps/plugin-os": "^2.3.1", "@typescript-eslint/eslint-plugin": "^6.18.1", "@typescript-eslint/parser": "^6.18.1", "autoprefixer": "^10.4.16", diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index ba67284..84735d6 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1502,6 +1502,16 @@ dependencies = [ "version_check", ] +[[package]] +name = "gethostname" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc257fdb4038301ce4b9cd1b3b51704509692bb3ff716a410cbd07925d9dae55" +dependencies = [ + "rustix 1.0.8", + "windows-targets 0.52.6", +] + [[package]] name = "getopts" version = "0.2.24" @@ -2319,6 +2329,7 @@ dependencies = [ "tauri-plugin-dialog", "tauri-plugin-notification", "tauri-plugin-opener", + "tauri-plugin-os", "tauri-specta", "tokio", "url", @@ -3134,6 +3145,18 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "os_info" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0e1ac5fde8d43c34139135df8ea9ee9465394b2d8d20f032d38998f64afffc3" +dependencies = [ + "log", + "plist", + "serde", + "windows-sys 0.52.0", +] + [[package]] name = "pango" version = "0.18.3" @@ -4858,6 +4881,15 @@ dependencies = [ "syn 2.0.106", ] +[[package]] +name = "sys-locale" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8eab9a99a024a169fe8a903cf9d4a3b3601109bcc13bd9e3c6fff259138626c4" +dependencies = [ + "libc", +] + [[package]] name = "system-configuration" version = "0.5.1" @@ -5163,6 +5195,24 @@ dependencies = [ "zbus", ] +[[package]] +name = "tauri-plugin-os" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a1c77ebf6f20417ab2a74e8c310820ba52151406d0c80fbcea7df232e3f6ba" +dependencies = [ + "gethostname", + "log", + "os_info", + "serde", + "serde_json", + "serialize-to-javascript", + "sys-locale", + "tauri", + "tauri-plugin", + "thiserror 2.0.16", +] + [[package]] name = "tauri-runtime" version = "2.8.0" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 4a775db..b49b031 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -33,6 +33,7 @@ tauri-plugin-notification = "2" tauri-plugin-opener = "2" tauri-plugin-dialog = "2" dirs = "6.0.0" +tauri-plugin-os = "2" [target.'cfg(target_os = "macos")'.dependencies] macos-app-nap = "0.0" diff --git a/src-tauri/capabilities/main.json b/src-tauri/capabilities/main.json index 1882743..58c29ef 100644 --- a/src-tauri/capabilities/main.json +++ b/src-tauri/capabilities/main.json @@ -1,13 +1,16 @@ { - "$schema": "../gen/schemas/desktop-schema.json", - "identifier": "main", - "description": "main window permissions", - "local": true, - "windows": ["main"], - "permissions": [ - "core:default", - "opener:allow-open-url", - "opener:allow-default-urls", - "notification:default" - ] -} + "$schema": "../gen/schemas/desktop-schema.json", + "identifier": "main", + "description": "main window permissions", + "local": true, + "windows": [ + "main" + ], + "permissions": [ + "core:default", + "opener:allow-open-url", + "opener:allow-default-urls", + "notification:default", + "os:default" + ] +} \ No newline at end of file diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 5af5128..e85c07a 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -105,6 +105,7 @@ pub async fn run() { }; let app = tauri::Builder::default() + .plugin(tauri_plugin_os::init()) .plugin(tauri_plugin_opener::init()) .plugin(tauri_plugin_notification::init()) .invoke_handler(specta_builder.invoke_handler()) diff --git a/src/routes/menu.ts b/src/routes/menu.ts index edc39f0..16dc4b2 100644 --- a/src/routes/menu.ts +++ b/src/routes/menu.ts @@ -3,11 +3,16 @@ import { settingsOpen, viewOptions } from '$lib/data' import { Menu, Submenu, type SubmenuOptions } from '@tauri-apps/api/menu' import { openUrl } from '@tauri-apps/plugin-opener' import { show_get_started } from './+layout.svelte' +import { platform } from '@tauri-apps/plugin-os' export const menu_actions: Partial< Record<'Find' | 'Open' | 'Open Channel' | 'Archive' | 'Unarchive', () => void> > = {} +function array_if(condition: boolean, value: T): T[] | [] { + return condition ? [value] : [] +} + export async function create_menu() { const app_menu: SubmenuOptions = { text: 'Kadium', @@ -64,19 +69,19 @@ export async function create_menu() { accelerator: 'Shift+CmdOrCtrl+Backspace', action: () => menu_actions.Unarchive?.(), }, - { item: 'Separator' }, - { + ...array_if(platform() !== 'macos', { item: 'Separator' }), + ...array_if(platform() !== 'macos', { text: 'Options...', - id: 'Preferences...', - accelerator: 'cmdOrControl+,', + accelerator: 'cmdOrCtrl+,', action() { settingsOpen.set(true) }, - }, + }), { item: 'Separator' }, { item: 'CloseWindow' }, ], } + const edit_menu: SubmenuOptions = { text: 'Edit', items: [ @@ -86,8 +91,7 @@ export async function create_menu() { { item: 'Cut' }, { item: 'Copy' }, { item: 'Paste' }, - // #[cfg(not(target_os = "macos"))] - { item: 'Separator' }, + ...array_if(platform() !== 'macos', { item: 'Separator' }), { item: 'SelectAll' }, { item: 'Separator' }, {