Skip to content
This repository has been archived by the owner on Sep 7, 2024. It is now read-only.

feat: startup with system #30

Merged
merged 3 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

### ✨ 新功能

* 新增開機時自動啟動的設定 (https://github.com/ExpTechTW/TREM-tauri/pull/30)
* 新增最小化至系統匣的設定 (https://github.com/ExpTechTW/TREM-tauri/pull/30)
* 新增啟動參數 `--quiet` 在開啟程式時隱藏視窗 (https://github.com/ExpTechTW/TREM-tauri/pull/30)

**完整變更紀錄**: https://github.com/ExpTechTW/TREM-tauri/compare/v0.0.0-alpha.2...v0.0.0-alpha.3


Expand Down
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"jszip": "^3.10.1",
"maplibre-gl": "^4.0.0",
"material-symbols": "^0.14.6",
"tauri-plugin-autostart-api": "github:tauri-apps/tauri-plugin-autostart#v1",
"tauri-settings": "^0.3.4",
"vue": "^3.3.4",
"ws": "^8.16.0"
Expand Down
122 changes: 121 additions & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 13 additions & 10 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,28 @@ edition = "2021"
tauri-build = { version = "1.5", features = [] }

[dependencies]
tauri = { version = "1.5", features = [
tauri = { version = "1.5", features = [ "cli",
"clipboard-write-text",
"http-request",
"window-set-always-on-top",
"window-request-user-attention",
"window-set-focus",
"window-set-skip-taskbar",
"window-show",
"window-set-title",
"system-tray",
"fs-write-file",
"fs-read-file",
"fs-create-dir",
"fs-read-dir",
"fs-read-file",
"fs-write-file",
"path-all",
"shell-open",
"system-tray",
"window-close",
"window-hide",
"window-request-user-attention",
"window-set-always-on-top",
"window-set-focus",
"window-set-skip-taskbar",
"window-set-title",
"window-show",
] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tauri-plugin-autostart = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }

[features]
# this feature is used for production builds or when `devPath` points to the filesystem
Expand Down
29 changes: 21 additions & 8 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use tauri::{
CustomMenuItem, Manager, SystemTray, SystemTrayEvent, SystemTrayMenu, SystemTrayMenuItem,
};
use tauri_plugin_autostart::MacosLauncher;

fn main() {
let tray_menu = SystemTrayMenu::new()
Expand All @@ -17,9 +18,28 @@ fn main() {
.add_native_item(SystemTrayMenuItem::Separator)
.add_item(CustomMenuItem::new("quit".to_string(), "關閉"));

let system_tray = SystemTray::new().with_menu(tray_menu).with_tooltip("TREM Tauri | 臺灣即時地震監測");
let system_tray = SystemTray::new()
.with_menu(tray_menu)
.with_tooltip("TREM Tauri | 臺灣即時地震監測");

tauri::Builder::default()
.setup(|app| {
match app.get_cli_matches() {
Ok(matches) => match matches.args["quiet"].value.as_bool() {
Some(true) => {}
_ => {
let window = app.get_window("main").unwrap();
window.show().unwrap();
}
},
Err(_) => {}
}
Ok(())
})
.plugin(tauri_plugin_autostart::init(
MacosLauncher::LaunchAgent,
Some(vec!["--quiet"]),
))
.system_tray(system_tray)
.on_system_tray_event(|app, event| match event {
SystemTrayEvent::LeftClick {
Expand All @@ -38,13 +58,6 @@ fn main() {
},
_ => {}
})
.on_window_event(|event| match event.event() {
tauri::WindowEvent::CloseRequested { api, .. } => {
event.window().hide().unwrap();
api.prevent_close();
}
_ => {}
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
11 changes: 11 additions & 0 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
},
"window": {
"all": false,
"close": true,
"hide": true,
"requestUserAttention": true,
"setAlwaysOnTop": true,
"setFocus": true,
Expand Down Expand Up @@ -64,13 +66,22 @@
}
}
},
"cli":{
"args": [
{
"name": "quiet",
"short": "q"
}
]
},
"security": {
"csp": null
},
"windows": [
{
"fullscreen": false,
"resizable": true,
"visible": false,
"title": "TREM Tauri | 臺灣即時地震監測",
"width": 1200,
"height": 720
Expand Down
Loading
Loading