diff --git a/control/Cargo.lock b/control/Cargo.lock index 35590dc..faa7788 100644 --- a/control/Cargo.lock +++ b/control/Cargo.lock @@ -37,7 +37,7 @@ dependencies = [ [[package]] name = "dynamiclight-control" -version = "1.0.2" +version = "1.0.3" dependencies = [ "dirs", "getrandom 0.3.4", diff --git a/control/Cargo.toml b/control/Cargo.toml index 5241c60..3d547f2 100644 --- a/control/Cargo.toml +++ b/control/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dynamiclight-control" -version = "1.0.2" +version = "1.0.3" edition = "2021" license = "MIT" rust-version = "1.99" diff --git a/package.json b/package.json index a12e433..6a31037 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dynamiclight", - "version": "1.0.2", + "version": "1.0.3", "private": true, "license": "MIT", "author": "mskutin", diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 7db928f..b3d05f5 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1227,7 +1227,7 @@ checksum = "d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555" [[package]] name = "dynamiclight" -version = "1.0.2" +version = "1.0.3" dependencies = [ "cc", "chrono", @@ -1256,7 +1256,7 @@ dependencies = [ [[package]] name = "dynamiclight-control" -version = "1.0.2" +version = "1.0.3" dependencies = [ "dirs 6.0.0", "getrandom 0.3.4", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 7af058f..5a4d2fa 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dynamiclight" -version = "1.0.2" +version = "1.0.3" description = "Local USB monitor backlight controller" authors = ["mskutin"] license = "MIT" diff --git a/src-tauri/src/autostart_windows.rs b/src-tauri/src/autostart_windows.rs index 261a524..d0c7624 100644 --- a/src-tauri/src/autostart_windows.rs +++ b/src-tauri/src/autostart_windows.rs @@ -37,7 +37,10 @@ use windows::{ IsUserAnAdmin, ShellExecuteExW, SEE_MASK_NOCLOSEPROCESS, SEE_MASK_NO_CONSOLE, SHELLEXECUTEINFOW, }, - WindowsAndMessaging::{ChangeWindowMessageFilter, MSGFLT_ADD, SW_HIDE, WM_COPYDATA}, + WindowsAndMessaging::{ + ChangeWindowMessageFilter, FindWindowExW, FindWindowW, MSGFLT_ADD, SW_HIDE, + WM_COPYDATA, + }, }, }, }; @@ -319,6 +322,29 @@ pub fn elevate_and_restart() -> Result<(), String> { Ok(()) } +/// At sign-in the task starts before Explorer has created the notification area, +/// and a tray icon added earlier never shows. A start with `--autostart` waits +/// (at most a minute) until the taskbar's tray exists. +pub fn wait_for_shell() { + if !std::env::args().any(|arg| arg == "--autostart") { + return; + } + let deadline = std::time::Instant::now() + std::time::Duration::from_secs(60); + while std::time::Instant::now() < deadline { + let ready = unsafe { + FindWindowW(w!("Shell_TrayWnd"), PCWSTR::null()) + .and_then(|taskbar| { + FindWindowExW(Some(taskbar), None, w!("TrayNotifyWnd"), PCWSTR::null()) + }) + .is_ok() + }; + if ready { + break; + } + std::thread::sleep(std::time::Duration::from_millis(250)); + } +} + /// The elevated app may receive hand-overs from a normally started copy /// (single-instance uses WM_COPYDATA, which UIPI blocks from lower-integrity /// senders by default). diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 0787ace..18e1b68 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -239,6 +239,7 @@ pub fn run() { if let Some(code) = autostart_windows::startup() { std::process::exit(code); } + autostart_windows::wait_for_shell(); autostart_windows::allow_relaunch_from_unelevated(); } let app = tauri::Builder::default() diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 54bb424..dbd9423 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "$schema": "https://schema.tauri.app/config/2", "productName": "DynamicLight", - "version": "1.0.2", + "version": "1.0.3", "identifier": "com.dynamiclight.desktop", "build": { "frontendDist": "../src/ui"