Skip to content

Commit 8b1ac16

Browse files
committed
feat: start with Windows tray option
1 parent 2d12e1d commit 8b1ac16

File tree

5 files changed

+124
-4
lines changed

5 files changed

+124
-4
lines changed

Cargo.lock

Lines changed: 56 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/wm-platform/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ path = "src/lib.rs"
88

99
[dependencies]
1010
anyhow = { workspace = true }
11+
auto-launch = "0.5.0"
1112
home = { workspace = true }
1213
tokio = { workspace = true }
1314
tracing = { workspace = true }

packages/wm-platform/src/platform.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::{
55
};
66

77
use anyhow::{bail, Context};
8+
use auto_launch::AutoLaunch;
89
use windows::{
910
core::{w, PCWSTR},
1011
Win32::{
@@ -319,6 +320,39 @@ impl Platform {
319320
Ok(())
320321
}
321322

323+
/// Gets the `AutoLaunch` instance for the GlazeWM application.
324+
fn get_auto_launch() -> anyhow::Result<AutoLaunch> {
325+
let exe_path = std::env::current_exe()?;
326+
let normalized_path = std::fs::canonicalize(exe_path)?;
327+
let quoted_exe_str = format!("\"{}\"", normalized_path.to_str().unwrap());
328+
Ok(AutoLaunch::new("GlazeWM", &quoted_exe_str, &[] as &[&str]))
329+
}
330+
331+
/// Checks if auto-launch at system startup is enabled.
332+
pub fn is_auto_launch_enabled() -> anyhow::Result<bool> {
333+
let auto_launch = Self::get_auto_launch()?;
334+
335+
match auto_launch.is_enabled() {
336+
Ok(enabled) => Ok(enabled),
337+
Err(e) => {
338+
Err(e.into())
339+
}
340+
}
341+
}
342+
343+
/// Enables or disables auto-launch at system startup.
344+
pub fn set_auto_launch_enabled(enable: bool) -> anyhow::Result<()> {
345+
let auto_launch = Self::get_auto_launch()?;
346+
347+
if enable {
348+
auto_launch.enable()?;
349+
} else {
350+
auto_launch.disable()?;
351+
}
352+
353+
Ok(())
354+
}
355+
322356
/// Opens File Explorer at the specified path.
323357
pub fn open_file_explorer(path: &PathBuf) -> anyhow::Result<()> {
324358
let normalized_path = std::fs::canonicalize(path)?;

packages/wm/src/sys_tray.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,25 @@ impl SystemTray {
4242
animations_enabled,
4343
None,
4444
);
45+
46+
let mut start_with_windows_enabled =
47+
Platform::is_auto_launch_enabled().unwrap_or(false);
4548

49+
let start_with_windows_item = CheckMenuItem::new(
50+
"Start with Windows",
51+
true,
52+
start_with_windows_enabled,
53+
None,
54+
);
55+
4656
let exit_item = MenuItem::new("Exit", true, None);
4757

4858
let tray_menu = Menu::new();
4959
tray_menu.append_items(&[
5060
&reload_config_item,
5161
&config_dir_item,
5262
&animations_item,
63+
&start_with_windows_item,
5364
&PredefinedMenuItem::separator(),
5465
&exit_item,
5566
])?;
@@ -76,6 +87,12 @@ impl SystemTray {
7687
Platform::set_window_animations_enabled(!animations_enabled);
7788

7889
animations_enabled = !animations_enabled;
90+
} else if event.id == start_with_windows_item.id() {
91+
// Toggle auto-launch on Windows startup.
92+
let _ =
93+
Platform::set_auto_launch_enabled(!start_with_windows_enabled);
94+
95+
start_with_windows_enabled = !start_with_windows_enabled;
7996
} else if event.id == exit_item.id() {
8097
exit_tx.send(())?;
8198
}

resources/wix/standalone.wxs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,5 +122,21 @@
122122
System="yes"
123123
/>
124124
</Component>
125+
126+
<!-- Remove auto-launch registry values on uninstall. -->
127+
<Component Id="Custom_RemoveAutoLaunchRegistry" Guid="B1A2C3D4-E5F6-47A8-9B0C-1234567890AB">
128+
<RemoveRegistryValue
129+
Root="HKCU"
130+
Key="SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
131+
Name="GlazeWM"
132+
Action="remove"
133+
On="uninstall" />
134+
<RemoveRegistryValue
135+
Root="HKCU"
136+
Key="SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\Run"
137+
Name="GlazeWM"
138+
Action="remove"
139+
On="uninstall" />
140+
</Component>
125141
</Package>
126142
</Wix>

0 commit comments

Comments
 (0)