Adapt to Windows (#51)

* feat: remove tauri-nspanel plugin

* chore: auto formatter rust code

* feat(windows): shortcut support windows

* doc: note windows error

* feat(linux): shortcut support linux

* fix: remove open_devtools code

* wip: emit open_settings event on all os

* feat: support autostart with settings

* doc: close autostart

* wip: open settings distinguish window or other os
This commit is contained in:
tu6ge
2024-12-14 15:38:32 +08:00
committed by GitHub
parent e432f5a3d6
commit 00a9650a15
6 changed files with 248 additions and 237 deletions

View File

@@ -31,5 +31,9 @@
"unminimize",
"webviews",
"zustand"
]
],
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer",
"editor.formatOnSave": true
}
}

29
pnpm-lock.yaml generated
View File

@@ -16,7 +16,7 @@ importers:
version: 2.0.2
'@tauri-apps/plugin-autostart':
specifier: ~2
version: 2.0.0
version: 2.2.0
'@tauri-apps/plugin-global-shortcut':
specifier: ~2.0.0
version: 2.0.0
@@ -25,7 +25,7 @@ importers:
version: 2.0.1
'@tauri-apps/plugin-os':
specifier: ^2.0.0
version: 2.0.0
version: 2.2.0
'@tauri-apps/plugin-shell':
specifier: '>=2.0.0'
version: 2.0.0
@@ -533,55 +533,46 @@ packages:
resolution: {integrity: sha512-0KXvIJQMOImLCVCz9uvvdPgfyWo93aHHp8ui3FrtOP57svqrF/roSSR5pjqL2hcMp0ljeGlU4q9o/rQaAQ3AYA==}
cpu: [arm]
os: [linux]
libc: [glibc]
'@rollup/rollup-linux-arm-musleabihf@4.24.0':
resolution: {integrity: sha512-it2BW6kKFVh8xk/BnHfakEeoLPv8STIISekpoF+nBgWM4d55CZKc7T4Dx1pEbTnYm/xEKMgy1MNtYuoA8RFIWw==}
cpu: [arm]
os: [linux]
libc: [musl]
'@rollup/rollup-linux-arm64-gnu@4.24.0':
resolution: {integrity: sha512-i0xTLXjqap2eRfulFVlSnM5dEbTVque/3Pi4g2y7cxrs7+a9De42z4XxKLYJ7+OhE3IgxvfQM7vQc43bwTgPwA==}
cpu: [arm64]
os: [linux]
libc: [glibc]
'@rollup/rollup-linux-arm64-musl@4.24.0':
resolution: {integrity: sha512-9E6MKUJhDuDh604Qco5yP/3qn3y7SLXYuiC0Rpr89aMScS2UAmK1wHP2b7KAa1nSjWJc/f/Lc0Wl1L47qjiyQw==}
cpu: [arm64]
os: [linux]
libc: [musl]
'@rollup/rollup-linux-powerpc64le-gnu@4.24.0':
resolution: {integrity: sha512-2XFFPJ2XMEiF5Zi2EBf4h73oR1V/lycirxZxHZNc93SqDN/IWhYYSYj8I9381ikUFXZrz2v7r2tOVk2NBwxrWw==}
cpu: [ppc64]
os: [linux]
libc: [glibc]
'@rollup/rollup-linux-riscv64-gnu@4.24.0':
resolution: {integrity: sha512-M3Dg4hlwuntUCdzU7KjYqbbd+BLq3JMAOhCKdBE3TcMGMZbKkDdJ5ivNdehOssMCIokNHFOsv7DO4rlEOfyKpg==}
cpu: [riscv64]
os: [linux]
libc: [glibc]
'@rollup/rollup-linux-s390x-gnu@4.24.0':
resolution: {integrity: sha512-mjBaoo4ocxJppTorZVKWFpy1bfFj9FeCMJqzlMQGjpNPY9JwQi7OuS1axzNIk0nMX6jSgy6ZURDZ2w0QW6D56g==}
cpu: [s390x]
os: [linux]
libc: [glibc]
'@rollup/rollup-linux-x64-gnu@4.24.0':
resolution: {integrity: sha512-ZXFk7M72R0YYFN5q13niV0B7G8/5dcQ9JDp8keJSfr3GoZeXEoMHP/HlvqROA3OMbMdfr19IjCeNAnPUG93b6A==}
cpu: [x64]
os: [linux]
libc: [glibc]
'@rollup/rollup-linux-x64-musl@4.24.0':
resolution: {integrity: sha512-w1i+L7kAXZNdYl+vFvzSZy8Y1arS7vMgIy8wusXJzRrPyof5LAb02KGr1PD2EkRcl73kHulIID0M501lN+vobQ==}
cpu: [x64]
os: [linux]
libc: [musl]
'@rollup/rollup-win32-arm64-msvc@4.24.0':
resolution: {integrity: sha512-VXBrnPWgBpVDCVY6XF3LEW0pOU51KbaHhccHw6AS6vBWIC60eqsH19DAeeObl+g8nKAz04QFdl/Cefta0xQtUQ==}
@@ -640,28 +631,24 @@ packages:
engines: {node: '>= 10'}
cpu: [arm64]
os: [linux]
libc: [glibc]
'@tauri-apps/cli-linux-arm64-musl@2.0.3':
resolution: {integrity: sha512-I4MVD7nf6lLLRmNQPpe5beEIFM6q7Zkmh77ROA5BNu/+vHNL5kiTMD+bmd10ZL2r753A6pO7AvqkIxcBuIl0tg==}
engines: {node: '>= 10'}
cpu: [arm64]
os: [linux]
libc: [musl]
'@tauri-apps/cli-linux-x64-gnu@2.0.3':
resolution: {integrity: sha512-C6Jkx2zZGKkoi+sg5FK9GoH/0EvAaOgrZfF5azV5EALGba46g7VpWcZgp9zFUd7K2IzTi+0OOY8TQ2OVfKZgew==}
engines: {node: '>= 10'}
cpu: [x64]
os: [linux]
libc: [glibc]
'@tauri-apps/cli-linux-x64-musl@2.0.3':
resolution: {integrity: sha512-qi4ghmTfSAl+EEUDwmwI9AJUiOLNSmU1RgiGgcPRE+7A/W+Am9UnxYySAiRbB/gJgTl9sj/pqH5Y9duP1/sqHg==}
engines: {node: '>= 10'}
cpu: [x64]
os: [linux]
libc: [musl]
'@tauri-apps/cli-win32-arm64-msvc@2.0.3':
resolution: {integrity: sha512-UXxHkYmFesC97qVmZre4vY7oDxRDtC2OeKNv0bH+iSnuUp/ROxzJYGyaelnv9Ybvgl4YVqDCnxgB28qMM938TA==}
@@ -686,8 +673,8 @@ packages:
engines: {node: '>= 10'}
hasBin: true
'@tauri-apps/plugin-autostart@2.0.0':
resolution: {integrity: sha512-NEwOQWVasZ8RczXkMLNJokRDujneuMH/UFA5t84DLkbNZUmiD3G7HZWhgSd1YQ0BFU9h9w+h2B/py3y6bzWg4Q==}
'@tauri-apps/plugin-autostart@2.2.0':
resolution: {integrity: sha512-TzVcDZdOvdot0avkpstUWJKKEl4cyxLpFB9DZZRW5zH8k+Bv8IVJmO0zyYuw+7oKlGdHOINbD/7Je7GHMViw5w==}
'@tauri-apps/plugin-global-shortcut@2.0.0':
resolution: {integrity: sha512-pnB4CUwFVjg4twtBSxoLJ4uLFTYxsvOdC1zIbG581pYzhYatOl6mjB+ijD5SSXgiS/jNoqMcfkOF9PWAisurew==}
@@ -695,8 +682,8 @@ packages:
'@tauri-apps/plugin-http@2.0.1':
resolution: {integrity: sha512-j6IA3pVBybSCwPpsihpX4z8bs6PluuGtr06ahL/xy4D8HunNBTmRmadJrFOQi0gOAbaig4MkQ15nzNLBLy8R1A==}
'@tauri-apps/plugin-os@2.0.0':
resolution: {integrity: sha512-M7hG/nNyQYTJxVG/UhTKhp9mpXriwWzrs9mqDreB8mIgqA3ek5nHLdwRZJWhkKjZrnDT4v9CpA9BhYeplTlAiA==}
'@tauri-apps/plugin-os@2.2.0':
resolution: {integrity: sha512-HszbCdbisMlu5QhCNAN8YIWyz2v33abAWha6+uvV2CKX8P5VSct/y+kEe22JeyqrxCnWlQ3DRx7s49Byg7/0EA==}
'@tauri-apps/plugin-shell@2.0.0':
resolution: {integrity: sha512-OpW2+ycgJLrEoZityWeWYk+6ZWP9VyiAfbO+N/O8VfLkqyOym8kXh7odKDfINx9RAotkSGBtQM4abyKfJDkcUg==}
@@ -2706,7 +2693,7 @@ snapshots:
'@tauri-apps/cli-win32-ia32-msvc': 2.0.3
'@tauri-apps/cli-win32-x64-msvc': 2.0.3
'@tauri-apps/plugin-autostart@2.0.0':
'@tauri-apps/plugin-autostart@2.2.0':
dependencies:
'@tauri-apps/api': 2.0.2
@@ -2718,7 +2705,7 @@ snapshots:
dependencies:
'@tauri-apps/api': 2.0.2
'@tauri-apps/plugin-os@2.0.0':
'@tauri-apps/plugin-os@2.2.0':
dependencies:
'@tauri-apps/api': 2.0.2

186
src-tauri/Cargo.lock generated
View File

@@ -98,7 +98,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f012b8cc0c850f34117ec8252a44418f2e34a2cf501de89e29b241ae5f79471"
dependencies = [
"dirs 4.0.0",
"thiserror",
"thiserror 1.0.64",
"winreg 0.10.1",
]
@@ -239,7 +239,7 @@ dependencies = [
"glib",
"libc",
"once_cell",
"thiserror",
"thiserror 1.0.64",
]
[[package]]
@@ -282,7 +282,7 @@ dependencies = [
"semver",
"serde",
"serde_json",
"thiserror",
"thiserror 1.0.64",
]
[[package]]
@@ -364,7 +364,6 @@ dependencies = [
"serde_json",
"tauri",
"tauri-build",
"tauri-nspanel",
"tauri-plugin-autostart",
"tauri-plugin-global-shortcut",
"tauri-plugin-http",
@@ -563,7 +562,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331"
dependencies = [
"quote",
"syn 2.0.79",
"syn 2.0.90",
]
[[package]]
@@ -573,7 +572,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "edb49164822f3ee45b17acd4a208cfc1251410cf0cad9a833234c9890774dd9f"
dependencies = [
"quote",
"syn 2.0.79",
"syn 2.0.90",
]
[[package]]
@@ -597,7 +596,7 @@ dependencies = [
"proc-macro2",
"quote",
"strsim",
"syn 2.0.79",
"syn 2.0.90",
]
[[package]]
@@ -608,7 +607,7 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806"
dependencies = [
"darling_core",
"quote",
"syn 2.0.79",
"syn 2.0.90",
]
[[package]]
@@ -643,7 +642,7 @@ dependencies = [
"proc-macro2",
"quote",
"rustc_version",
"syn 2.0.79",
"syn 2.0.90",
]
[[package]]
@@ -723,7 +722,7 @@ checksum = "f2b99bf03862d7f545ebc28ddd33a665b50865f4dfd84031a393823879bd4c54"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.79",
"syn 2.0.90",
]
[[package]]
@@ -869,7 +868,7 @@ checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.79",
"syn 2.0.90",
]
[[package]]
@@ -937,7 +936,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.79",
"syn 2.0.90",
]
[[package]]
@@ -1131,7 +1130,7 @@ dependencies = [
"once_cell",
"pin-project-lite",
"smallvec",
"thiserror",
"thiserror 1.0.64",
]
[[package]]
@@ -1167,7 +1166,7 @@ dependencies = [
"memchr",
"once_cell",
"smallvec",
"thiserror",
"thiserror 1.0.64",
]
[[package]]
@@ -1181,7 +1180,7 @@ dependencies = [
"proc-macro-error",
"proc-macro2",
"quote",
"syn 2.0.79",
"syn 2.0.90",
]
[[package]]
@@ -1212,7 +1211,7 @@ dependencies = [
"objc2-app-kit",
"once_cell",
"serde",
"thiserror",
"thiserror 1.0.64",
"windows-sys 0.59.0",
"x11-dl",
]
@@ -1277,7 +1276,7 @@ dependencies = [
"proc-macro-error",
"proc-macro2",
"quote",
"syn 2.0.79",
"syn 2.0.90",
]
[[package]]
@@ -1628,7 +1627,7 @@ dependencies = [
"combine",
"jni-sys",
"log",
"thiserror",
"thiserror 1.0.64",
"walkdir",
"windows-sys 0.45.0",
]
@@ -1657,7 +1656,7 @@ dependencies = [
"jsonptr",
"serde",
"serde_json",
"thiserror",
"thiserror 1.0.64",
]
[[package]]
@@ -1861,7 +1860,7 @@ dependencies = [
"once_cell",
"png",
"serde",
"thiserror",
"thiserror 1.0.64",
"windows-sys 0.59.0",
]
@@ -1877,7 +1876,7 @@ dependencies = [
"ndk-sys",
"num_enum",
"raw-window-handle",
"thiserror",
"thiserror 1.0.64",
]
[[package]]
@@ -1940,7 +1939,7 @@ dependencies = [
"proc-macro-crate 2.0.2",
"proc-macro2",
"quote",
"syn 2.0.79",
"syn 2.0.90",
]
[[package]]
@@ -1952,17 +1951,6 @@ dependencies = [
"malloc_buf",
]
[[package]]
name = "objc-foundation"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9"
dependencies = [
"block",
"objc",
"objc_id",
]
[[package]]
name = "objc-sys"
version = "0.3.5"
@@ -2181,15 +2169,6 @@ dependencies = [
"objc2-foundation",
]
[[package]]
name = "objc_id"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b"
dependencies = [
"objc",
]
[[package]]
name = "object"
version = "0.36.5"
@@ -2396,7 +2375,7 @@ dependencies = [
"phf_shared 0.11.2",
"proc-macro2",
"quote",
"syn 2.0.79",
"syn 2.0.90",
]
[[package]]
@@ -2543,9 +2522,9 @@ checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068"
[[package]]
name = "proc-macro2"
version = "1.0.87"
version = "1.0.92"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a"
checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0"
dependencies = [
"unicode-ident",
]
@@ -2588,7 +2567,7 @@ dependencies = [
"rustc-hash",
"rustls",
"socket2",
"thiserror",
"thiserror 1.0.64",
"tokio",
"tracing",
]
@@ -2605,7 +2584,7 @@ dependencies = [
"rustc-hash",
"rustls",
"slab",
"thiserror",
"thiserror 1.0.64",
"tinyvec",
"tracing",
]
@@ -2736,7 +2715,7 @@ checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43"
dependencies = [
"getrandom 0.2.15",
"libredox",
"thiserror",
"thiserror 1.0.64",
]
[[package]]
@@ -2932,7 +2911,7 @@ dependencies = [
"proc-macro2",
"quote",
"serde_derive_internals",
"syn 2.0.79",
"syn 2.0.90",
]
[[package]]
@@ -2998,7 +2977,7 @@ checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.79",
"syn 2.0.90",
]
[[package]]
@@ -3009,7 +2988,7 @@ checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.79",
"syn 2.0.90",
]
[[package]]
@@ -3032,7 +3011,7 @@ checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.79",
"syn 2.0.90",
]
[[package]]
@@ -3083,7 +3062,7 @@ dependencies = [
"darling",
"proc-macro2",
"quote",
"syn 2.0.79",
"syn 2.0.90",
]
[[package]]
@@ -3315,9 +3294,9 @@ dependencies = [
[[package]]
name = "syn"
version = "2.0.79"
version = "2.0.90"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590"
checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31"
dependencies = [
"proc-macro2",
"quote",
@@ -3414,7 +3393,7 @@ checksum = "f4e16beb8b2ac17db28eab8bca40e62dbfbb34c0fcdc6d9826b11b7b5d047dfd"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.79",
"syn 2.0.90",
]
[[package]]
@@ -3463,7 +3442,7 @@ dependencies = [
"tauri-runtime",
"tauri-runtime-wry",
"tauri-utils",
"thiserror",
"thiserror 1.0.64",
"tokio",
"tray-icon",
"url",
@@ -3514,9 +3493,9 @@ dependencies = [
"serde",
"serde_json",
"sha2",
"syn 2.0.79",
"syn 2.0.90",
"tauri-utils",
"thiserror",
"thiserror 1.0.64",
"time",
"url",
"uuid",
@@ -3532,27 +3511,11 @@ dependencies = [
"heck 0.5.0",
"proc-macro2",
"quote",
"syn 2.0.79",
"syn 2.0.90",
"tauri-codegen",
"tauri-utils",
]
[[package]]
name = "tauri-nspanel"
version = "2.0.0-beta"
source = "git+https://github.com/ahkohd/tauri-nspanel?rev=005240c#005240ce43fe02108ce6d0aec6e2e436c46f46b7"
dependencies = [
"bitflags 2.6.0",
"block",
"cocoa",
"core-foundation 0.10.0",
"core-graphics",
"objc",
"objc-foundation",
"objc_id",
"tauri",
]
[[package]]
name = "tauri-plugin"
version = "2.0.1"
@@ -3572,17 +3535,16 @@ dependencies = [
[[package]]
name = "tauri-plugin-autostart"
version = "2.0.1"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bba6bb936e0fd0a58ed958b49e2e423dd40949c9d9425cc991be996959e3838e"
checksum = "a9c13f843e5e5df3eed270fc42b02923cc1a6b5c7e56b0f3ac1d858ab2c8b5fb"
dependencies = [
"auto-launch",
"log",
"serde",
"serde_json",
"tauri",
"tauri-plugin",
"thiserror",
"thiserror 2.0.6",
]
[[package]]
@@ -3601,7 +3563,7 @@ dependencies = [
"serde_repr",
"tauri",
"tauri-plugin",
"thiserror",
"thiserror 1.0.64",
"url",
"uuid",
]
@@ -3618,7 +3580,7 @@ dependencies = [
"serde_json",
"tauri",
"tauri-plugin",
"thiserror",
"thiserror 1.0.64",
]
[[package]]
@@ -3637,7 +3599,7 @@ dependencies = [
"tauri",
"tauri-plugin",
"tauri-plugin-fs",
"thiserror",
"thiserror 1.0.64",
"tokio",
"url",
"urlpattern",
@@ -3660,15 +3622,15 @@ dependencies = [
"shared_child",
"tauri",
"tauri-plugin",
"thiserror",
"thiserror 1.0.64",
"tokio",
]
[[package]]
name = "tauri-plugin-websocket"
version = "2.0.1"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2793b69e1dd494beed1e0a29865f38bd00011e7ccc35a3cfde8e3939328b790"
checksum = "14055b796521e0facf6582256dea9322453595917851082610c557293862c966"
dependencies = [
"futures-util",
"http",
@@ -3678,7 +3640,7 @@ dependencies = [
"serde_json",
"tauri",
"tauri-plugin",
"thiserror",
"thiserror 2.0.6",
"tokio",
"tokio-tungstenite",
]
@@ -3697,7 +3659,7 @@ dependencies = [
"serde",
"serde_json",
"tauri-utils",
"thiserror",
"thiserror 1.0.64",
"url",
"windows",
]
@@ -3756,7 +3718,7 @@ dependencies = [
"serde_json",
"serde_with",
"swift-rs",
"thiserror",
"thiserror 1.0.64",
"toml 0.8.2",
"url",
"urlpattern",
@@ -3797,7 +3759,16 @@ version = "1.0.64"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84"
dependencies = [
"thiserror-impl",
"thiserror-impl 1.0.64",
]
[[package]]
name = "thiserror"
version = "2.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fec2a1820ebd077e2b90c4df007bebf344cd394098a13c563957d0afc83ea47"
dependencies = [
"thiserror-impl 2.0.6",
]
[[package]]
@@ -3808,7 +3779,18 @@ checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.79",
"syn 2.0.90",
]
[[package]]
name = "thiserror-impl"
version = "2.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d65750cab40f4ff1929fb1ba509e9914eb756131cef4210da8d5d700d26f6312"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.90",
]
[[package]]
@@ -3881,7 +3863,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.79",
"syn 2.0.90",
]
[[package]]
@@ -4025,7 +4007,7 @@ dependencies = [
"once_cell",
"png",
"serde",
"thiserror",
"thiserror 1.0.64",
"windows-sys 0.59.0",
]
@@ -4051,7 +4033,7 @@ dependencies = [
"rustls",
"rustls-pki-types",
"sha1",
"thiserror",
"thiserror 1.0.64",
"utf-8",
]
@@ -4266,7 +4248,7 @@ dependencies = [
"once_cell",
"proc-macro2",
"quote",
"syn 2.0.79",
"syn 2.0.90",
"wasm-bindgen-shared",
]
@@ -4300,7 +4282,7 @@ checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.79",
"syn 2.0.90",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
@@ -4409,7 +4391,7 @@ checksum = "1d228f15bba3b9d56dde8bddbee66fa24545bd17b48d5128ccf4a8742b18e431"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.79",
"syn 2.0.90",
]
[[package]]
@@ -4418,7 +4400,7 @@ version = "0.33.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3a3e2eeb58f82361c93f9777014668eb3d07e7d174ee4c819575a9208011886"
dependencies = [
"thiserror",
"thiserror 1.0.64",
"windows",
"windows-core 0.58.0",
]
@@ -4508,7 +4490,7 @@ checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.79",
"syn 2.0.90",
]
[[package]]
@@ -4519,7 +4501,7 @@ checksum = "053c4c462dc91d3b1504c6fe5a726dd15e216ba718e84a0e46a88fbe5ded3515"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.79",
"syn 2.0.90",
]
[[package]]
@@ -4834,7 +4816,7 @@ dependencies = [
"sha2",
"soup3",
"tao-macros",
"thiserror",
"thiserror 1.0.64",
"webkit2gtk",
"webkit2gtk-sys",
"webview2-com",
@@ -4883,7 +4865,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.79",
"syn 2.0.90",
]
[[package]]

View File

@@ -24,7 +24,6 @@ serde = { version = "1", features = ["derive"] }
serde_json = "1"
tauri-plugin-http = "2"
tauri-nspanel = { git = "https://github.com/ahkohd/tauri-nspanel", rev = "005240c" }
tauri-plugin-websocket = "2"
[profile.dev]
@@ -38,5 +37,5 @@ panic = "abort" # Higher performance by disabling panic handlers.
strip = true # Ensures debug symbols are removed.
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
tauri-plugin-autostart = "2"
tauri-plugin-autostart = "^2.2"
tauri-plugin-global-shortcut = "2"

105
src-tauri/src/autostart.rs Normal file
View File

@@ -0,0 +1,105 @@
use std::{fs::create_dir, io::Read};
use tauri::{Manager, Runtime};
use tauri_plugin_autostart::ManagerExt;
/// Start or stop according to configuration
pub fn enable_autostart(app: &mut tauri::App) {
use tauri_plugin_autostart::MacosLauncher;
use tauri_plugin_autostart::ManagerExt;
app.handle()
.plugin(tauri_plugin_autostart::init(
MacosLauncher::AppleScript,
None,
))
.unwrap();
let autostart_manager = app.autolaunch();
// close autostart
// autostart_manager.disable().unwrap();
// return;
match (
autostart_manager.is_enabled(),
current_autostart(app.app_handle()),
) {
(Ok(false), Ok(true)) => match autostart_manager.enable() {
Ok(_) => println!("Autostart enabled successfully."),
Err(err) => eprintln!("Failed to enable autostart: {}", err),
},
(Ok(true), Ok(false)) => match autostart_manager.disable() {
Ok(_) => println!("Autostart disable successfully."),
Err(err) => eprintln!("Failed to disable autostart: {}", err),
},
_ => (),
}
}
fn current_autostart<R: Runtime>(app: &tauri::AppHandle<R>) -> Result<bool, String> {
use std::fs::File;
let path = app.path().app_config_dir().unwrap();
let mut old_value = true;
if path.exists() {
let file_path = path.join("autostart.txt");
if file_path.exists() {
let mut file = File::open(file_path).unwrap();
let mut data = String::new();
if let Ok(_) = file.read_to_string(&mut data) {
if data.is_empty() == false {
old_value = data.parse().unwrap_or(true)
}
}
}
};
Ok(old_value)
}
#[tauri::command]
pub fn change_autostart<R: Runtime>(app: tauri::AppHandle<R>, open: bool) -> Result<(), String> {
use std::fs::File;
use std::io::Write;
let autostart_manager = app.autolaunch();
let change = |open: bool| -> Result<(), String> {
#[allow(unused_assignments)]
let mut open_str = String::from("");
if open {
autostart_manager
.enable()
.map_err(|_| "enable autostar failed".to_owned())?;
open_str = "true".to_owned();
} else {
autostart_manager
.disable()
.map_err(|_| "disable autostar failed".to_owned())?;
open_str = "false".to_owned();
}
let path = app
.path()
.app_config_dir()
.map_err(|_| "not found app config directory".to_owned())?;
if path.exists() == false {
create_dir(&path).map_err(|_| "creating app config directory failed".to_owned())?;
}
let file_path = path.join("autostart.txt");
let mut file = File::create(file_path).unwrap();
file.write_all(open_str.as_bytes()).unwrap();
Ok(())
};
match (autostart_manager.is_enabled().unwrap(), open) {
(false, true) => change(true),
(true, false) => change(false),
_ => Err("no change".to_owned()),
}
}

View File

@@ -1,12 +1,18 @@
use std::{fs::create_dir, io::Read};
use tauri::{AppHandle, Manager, Runtime, WebviewWindow};
use tauri_nspanel::{panel_delegate, ManagerExt, WebviewWindowExt};
use tauri::{AppHandle, Emitter, Manager, Runtime, WebviewWindow};
use tauri_plugin_autostart::MacosLauncher;
use tauri_plugin_global_shortcut::{GlobalShortcutExt, Shortcut};
mod autostart;
use autostart::{change_autostart, enable_autostart};
#[cfg(target_os = "macos")]
const DEFAULT_SHORTCUT: &str = "command+shift+space";
#[cfg(any(target_os = "windows", target_os = "linux"))]
const DEFAULT_SHORTCUT: &str = "ctrl+shift+space";
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
#[tauri::command]
fn greet(name: &str) -> String {
@@ -22,64 +28,11 @@ fn change_window_height(handle: AppHandle, height: u32) {
window.set_size(size).unwrap();
}
#[tauri::command]
fn show_panel(handle: AppHandle) {
let panel = handle.get_webview_panel("main").unwrap();
panel.show();
}
#[tauri::command]
fn hide_panel(handle: AppHandle) {
let panel = handle.get_webview_panel("main").unwrap();
panel.order_out(None);
}
#[tauri::command]
fn close_panel(handle: AppHandle) {
let panel = handle.get_webview_panel("main").unwrap();
panel.released_when_closed(true);
panel.close();
}
// fn enable_autostart(app: &mut tauri::App) {
// use tauri_plugin_autostart::MacosLauncher;
// use tauri_plugin_autostart::ManagerExt;
// app.handle()
// .plugin(tauri_plugin_autostart::init(
// MacosLauncher::AppleScript,
// None,
// ))
// .unwrap();
// let autostart_manager = app.autolaunch();
// match autostart_manager.is_enabled() {
// Ok(true) => {
// println!("Autostart is already enabled.");
// }
// Ok(false) => {
// match autostart_manager.enable() {
// Ok(_) => println!("Autostart enabled successfully."),
// Err(err) => eprintln!("Failed to enable autostart: {}", err),
// }
// }
// Err(err) => {
// eprintln!("Failed to check autostart status: {}", err);
// }
// }
// }
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_http::init())
.plugin(tauri_plugin_shell::init())
.plugin(tauri_nspanel::init())
.plugin(tauri_plugin_autostart::init(
MacosLauncher::AppleScript,
None,
@@ -88,15 +41,14 @@ pub fn run() {
greet,
change_window_height,
change_shortcut,
show_panel,
hide_panel,
close_panel,
change_autostart,
])
.setup(|app| {
init(app.app_handle());
enable_shortcut(app);
enable_tray(app);
enable_autostart(app);
Ok(())
})
@@ -104,34 +56,7 @@ pub fn run() {
.expect("error while running tauri application");
}
fn init(app_handle: &AppHandle) {
let window: WebviewWindow = app_handle.get_webview_window("main").unwrap();
let panel = window.to_panel().unwrap();
let delegate = panel_delegate!(MyPanelDelegate {
window_did_become_key,
window_did_resign_key
});
let handle = app_handle.to_owned();
delegate.set_listener(Box::new(move |delegate_name: String| {
match delegate_name.as_str() {
"window_did_become_key" => {
let app_name = handle.package_info().name.to_owned();
println!("[info]: {:?} panel becomes key window!", app_name);
}
"window_did_resign_key" => {
println!("[info]: panel resigned from key window!");
}
_ => (),
}
}));
panel.set_delegate(delegate);
}
fn init(_app_handle: &AppHandle) {}
fn enable_shortcut(app: &mut tauri::App) {
use tauri_plugin_global_shortcut::{GlobalShortcutExt, Shortcut, ShortcutState};
@@ -234,6 +159,7 @@ fn current_shortcut<R: Runtime>(app: &tauri::AppHandle<R>) -> Result<Shortcut, S
Ok(short)
}
#[allow(dead_code)]
fn remove_shortcut<R: Runtime>(app: &tauri::AppHandle<R>) -> Result<(), String> {
let short = current_shortcut(app)?;
@@ -278,31 +204,12 @@ fn enable_tray(app: &mut tauri::App) {
win.set_focus().unwrap();
}
"settings" => {
println!("settings menu item was clicked");
let window = app.get_webview_window("settings");
if let Some(window) = window {
window.show().unwrap();
window.set_focus().unwrap();
} else {
let window = tauri::window::WindowBuilder::new(app, "settings")
.title("Settings Window")
.inner_size(800.0, 600.0)
.resizable(true)
.fullscreen(false)
.build()
.unwrap();
let webview_builder = WebviewBuilder::new(
"settings",
tauri::WebviewUrl::App("/ui/settings".into()),
);
let _webview = window
.add_child(
webview_builder,
tauri::LogicalPosition::new(0, 0),
window.inner_size().unwrap(),
)
.unwrap();
}
// windows failed to open second window, issue: https://github.com/tauri-apps/tauri/issues/11144
//#[cfg(windows)]
app.emit("open_settings", "");
// #[cfg(not(windows))]
// open_setting(&app);
}
"quit" => {
println!("quit menu item was clicked");
@@ -315,3 +222,30 @@ fn enable_tray(app: &mut tauri::App) {
.build(app)
.unwrap();
}
fn open_setting(app: &tauri::App) {
println!("settings menu item was clicked");
let window = app.get_webview_window("settings");
if let Some(window) = window {
window.show().unwrap();
window.set_focus().unwrap();
} else {
let window = tauri::window::WindowBuilder::new(app, "settings")
.title("Settings Window")
.inner_size(800.0, 600.0)
.resizable(true)
.fullscreen(false)
.build()
.unwrap();
let webview_builder =
WebviewBuilder::new("settings", tauri::WebviewUrl::App("/ui/settings".into()));
let _webview = window
.add_child(
webview_builder,
tauri::LogicalPosition::new(0, 0),
window.inner_size().unwrap(),
)
.unwrap();
}
}