From 7818cb2692c484e683f29eae57bed77d34f4952b Mon Sep 17 00:00:00 2001 From: Michael Wang Date: Sat, 11 Nov 2023 00:45:08 +0800 Subject: [PATCH 1/6] feat: add items to tray --- src-tauri/src/app/mod.rs | 1 + src-tauri/src/app/tray.rs | 29 +++++++++++++++++++++++++++++ src-tauri/src/main.rs | 5 +++-- 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 src-tauri/src/app/tray.rs diff --git a/src-tauri/src/app/mod.rs b/src-tauri/src/app/mod.rs index 8eb386a..179b2d8 100644 --- a/src-tauri/src/app/mod.rs +++ b/src-tauri/src/app/mod.rs @@ -2,6 +2,7 @@ pub mod cmd; pub mod conf; pub mod menu; pub mod setup; +pub mod tray; #[cfg(target_os = "macos")] pub mod mac; diff --git a/src-tauri/src/app/tray.rs b/src-tauri/src/app/tray.rs new file mode 100644 index 0000000..68b41f4 --- /dev/null +++ b/src-tauri/src/app/tray.rs @@ -0,0 +1,29 @@ +use tauri::{ + AppHandle, CustomMenuItem, SystemTray, SystemTrayEvent, SystemTrayMenu, SystemTrayMenuItem, +}; + +pub fn init() -> SystemTray { + let quit = CustomMenuItem::new("quit".to_string(), "Quit"); + let hide = CustomMenuItem::new("hide".to_string(), "Hide"); + let tray_menu = SystemTrayMenu::new() + .add_item(quit) + .add_native_item(SystemTrayMenuItem::Separator) + .add_item(hide); + + SystemTray::new().with_menu(tray_menu) +} + +pub fn handler(app: &AppHandle, event: SystemTrayEvent) { + match event { + SystemTrayEvent::MenuItemClick { id, .. } => match id.as_str() { + "quit" => { + app.exit(0); + } + "hide" => { + app.hide().unwrap(); + } + _ => {} + }, + _ => {} + } +} diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 79d566e..f9cbde8 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -4,7 +4,7 @@ mod app; mod utils; -use app::{cmd, menu, setup}; +use app::{cmd, menu, setup, tray}; #[tokio::main] async fn main() { @@ -23,7 +23,8 @@ async fn main() { .setup(setup::init) .menu(menu::init(&context)) .on_menu_event(menu::handler) - .system_tray(tauri::SystemTray::default()) + .system_tray(tray::init()) + .on_system_tray_event(tray::handler) .run(context) .expect("error while running HackDesk application"); } From 88a592a52d599b372f92e6e4b7f9920952d65587 Mon Sep 17 00:00:00 2001 From: Michael Wang Date: Sat, 11 Nov 2023 00:58:49 +0800 Subject: [PATCH 2/6] fix: remove hide item --- src-tauri/src/app/tray.rs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src-tauri/src/app/tray.rs b/src-tauri/src/app/tray.rs index 68b41f4..ee8b40d 100644 --- a/src-tauri/src/app/tray.rs +++ b/src-tauri/src/app/tray.rs @@ -1,14 +1,8 @@ -use tauri::{ - AppHandle, CustomMenuItem, SystemTray, SystemTrayEvent, SystemTrayMenu, SystemTrayMenuItem, -}; +use tauri::{AppHandle, CustomMenuItem, SystemTray, SystemTrayEvent, SystemTrayMenu}; pub fn init() -> SystemTray { let quit = CustomMenuItem::new("quit".to_string(), "Quit"); - let hide = CustomMenuItem::new("hide".to_string(), "Hide"); - let tray_menu = SystemTrayMenu::new() - .add_item(quit) - .add_native_item(SystemTrayMenuItem::Separator) - .add_item(hide); + let tray_menu = SystemTrayMenu::new().add_item(quit); SystemTray::new().with_menu(tray_menu) } @@ -19,9 +13,6 @@ pub fn handler(app: &AppHandle, event: SystemTrayEvent) { "quit" => { app.exit(0); } - "hide" => { - app.hide().unwrap(); - } _ => {} }, _ => {} From 417e3259a39abb95c017322f300668cdcdf1fbfb Mon Sep 17 00:00:00 2001 From: Michael Wang Date: Sat, 11 Nov 2023 01:19:35 +0800 Subject: [PATCH 3/6] chore: tweak allowlist --- src-tauri/tauri.conf.json | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index cca2d40..8655b76 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -19,10 +19,13 @@ "open": true }, "fs": { - "scope": ["$HOME/.hackdesk/*"] + "all": false, + "scope": ["$HOME/.hackdesk/*"], + "readFile": true, + "writeFile": true }, "globalShortcut": { - "all": true + "all": false } }, "systemTray": { From 0f8f438896bc4cd90e2a3f28b46cbb2d7391f4b0 Mon Sep 17 00:00:00 2001 From: Michael Wang Date: Sat, 11 Nov 2023 01:58:31 +0800 Subject: [PATCH 4/6] ci: add `workflow_dispatch` --- .github/workflows/build.yml | 1 + .github/workflows/deploy.yml | 2 -- README.md | 4 ++-- package.json | 4 ++++ 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 44963cc..f01e0b4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,6 +3,7 @@ name: Testing build on: pull_request: types: [labeled] + workflow_dispatch: jobs: build: diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index ecdceed..db1c26f 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -4,8 +4,6 @@ on: push: tags: - "v*" - - # Allows you to run this workflow manually from the Actions tab workflow_dispatch: # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages diff --git a/README.md b/README.md index a45da43..013d561 100644 --- a/README.md +++ b/README.md @@ -46,8 +46,8 @@ And You can also follow me on [HackMD](https://hackmd.io/@EastSun5566) 😎 ### Prerequisites -- [Rust v1.71](https://www.rust-lang.org/learn/get-started) -- [Node.js v16+](https://github.com/nvm-sh/nvm?tab=readme-ov-file#installing-and-updating) +- [Rust v1.71+](https://www.rust-lang.org/learn/get-started) +- [Node.js v18+](https://github.com/nvm-sh/nvm?tab=readme-ov-file#installing-and-updating) - [Pnpm v8+](https://pnpm.io/installation#using-corepack) ### Getting Started diff --git a/package.json b/package.json index fbd285a..08857d9 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,10 @@ "private": true, "version": "0.0.6", "type": "module", + "engines": { + "node": ">=18", + "pnpm": ">=8" + }, "scripts": { "dev": "tauri dev", "build": "tauri build", From 6aaee54b8fa46f44dba0eb6d8bd5520f27104855 Mon Sep 17 00:00:00 2001 From: Michael Wang Date: Sat, 11 Nov 2023 02:03:00 +0800 Subject: [PATCH 5/6] ci: add `synchronize` --- .github/workflows/build.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f01e0b4..e65ca64 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,7 +2,9 @@ name: Testing build on: pull_request: - types: [labeled] + types: + - labeled + - synchronize workflow_dispatch: jobs: From 23f0f9fa2f0ca98f2e79e3bd8b75aef2859d7e7b Mon Sep 17 00:00:00 2001 From: Michael Wang Date: Sat, 11 Nov 2023 02:16:00 +0800 Subject: [PATCH 6/6] ci: should trigger every time when already has build label --- .github/workflows/build.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e65ca64..ead6017 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,14 +2,11 @@ name: Testing build on: pull_request: - types: - - labeled - - synchronize workflow_dispatch: jobs: build: - if: ${{ github.event.label.name == 'build' }} + if: ${{ contains(github.event.pull_request.labels.*.name, 'build') || github.event_name == 'workflow_dispatch' }} strategy: fail-fast: false