From a7593feea0bd20074ce0d9951965563df62a5310 Mon Sep 17 00:00:00 2001 From: dubisdev Date: Sun, 28 Jan 2024 17:22:07 +0100 Subject: [PATCH] fix: Start hidden when run on windows start fix #6 --- src-tauri/Cargo.lock | 70 +++++++++++++++++++++++++++++++++++++-- src-tauri/Cargo.toml | 2 +- src-tauri/src/main.rs | 2 +- src-tauri/tauri.conf.json | 8 +++++ src/main.tsx | 11 +++++- 5 files changed, 88 insertions(+), 5 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 9e752e4..ade46bd 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -282,6 +282,17 @@ version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi 0.1.19", + "libc", + "winapi", +] + [[package]] name = "auto-launch" version = "0.5.0" @@ -525,6 +536,30 @@ dependencies = [ "windows-targets 0.52.0", ] +[[package]] +name = "clap" +version = "3.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" +dependencies = [ + "atty", + "bitflags 1.3.2", + "clap_lex", + "indexmap 1.9.3", + "strsim", + "termcolor", + "textwrap", +] + +[[package]] +name = "clap_lex" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +dependencies = [ + "os_str_bytes", +] + [[package]] name = "clipboard-win" version = "4.5.0" @@ -1555,6 +1590,15 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + [[package]] name = "hermit-abi" version = "0.3.4" @@ -1783,7 +1827,7 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" dependencies = [ - "hermit-abi", + "hermit-abi 0.3.4", "libc", "windows-sys 0.48.0", ] @@ -2220,7 +2264,7 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi", + "hermit-abi 0.3.4", "libc", ] @@ -2363,6 +2407,12 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "os_str_bytes" +version = "6.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" + [[package]] name = "overload" version = "0.1.1" @@ -3571,6 +3621,7 @@ dependencies = [ "anyhow", "base64 0.21.7", "bytes", + "clap", "cocoa", "dirs-next", "embed_plist", @@ -3819,6 +3870,21 @@ dependencies = [ "utf-8", ] +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "textwrap" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" + [[package]] name = "thin-slice" version = "0.1.1" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index b44551f..a55602b 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -17,7 +17,7 @@ tauri-build = { version = "1.5", features = [] } [dependencies] serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } -tauri = { version = "1.5", features = ["clipboard-write-text", "global-shortcut-all", "notification-all", "process-exit", "shell-open", "system-tray", "updater", "window-close", "window-create", "window-hide", "window-set-focus", "window-set-size", "window-show", "window-start-dragging", "window-unminimize"] } +tauri = { version = "1.5", features = [ "cli", "clipboard-write-text", "global-shortcut-all", "notification-all", "process-exit", "shell-open", "system-tray", "updater", "window-close", "window-create", "window-hide", "window-set-focus", "window-set-size", "window-show", "window-start-dragging", "window-unminimize"] } tauri-plugin-autostart = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" } tauri-plugin-single-instance = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" } diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 2a3f1d2..56b5b38 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -22,7 +22,7 @@ fn main() { tauri::Builder::default() .plugin(tauri_plugin_autostart::init( MacosLauncher::LaunchAgent, - Some(vec![""]), + Some(vec!["--hidden"]), )) .plugin(tauri_plugin_single_instance::init(|app, argv, cwd| { app.emit_all("single-instance", Payload { args: argv, cwd }) diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index f2107c9..ddb46fb 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -14,6 +14,14 @@ "systemTray": { "iconPath": "icons/app-icon.png" }, + "cli": { + "args": [ + { + "name": "hidden", + "short": "h" + } + ] + }, "allowlist": { "globalShortcut": { "all": true diff --git a/src/main.tsx b/src/main.tsx index ae23a03..f1aff06 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -1,9 +1,18 @@ import React from "react"; import ReactDOM from "react-dom/client"; import { App } from "./App"; - +import { getMatches } from "@tauri-apps/api/cli"; +import { getCurrent } from "@tauri-apps/api/window"; import "./index.css"; +// Start hidden if the arg is present (e.g. when the auto-launcher starts the app) +getMatches().then((matches) => { + const shouldHide = matches.args.hidden.value + if (shouldHide) { + getCurrent().hide() + } +}) + ReactDOM.createRoot(document.getElementById("root")!).render(