tarkah / grout

Simple tiling window manager for Windows
MIT License
202 stars 8 forks source link

Autostart #10

Closed tarkah closed 4 years ago

tarkah commented 4 years ago

Once the system tray is added, add a flag to enable the program to autostart

gilescope commented 4 years ago

I wonder if auto-start could be abstracted away into a separate crate?

tarkah commented 4 years ago

I'd imagine you'd need autostart functionality tied pretty close to how the app is "installed" on the machine? Not sure I know enough about how this should work for windows to make a one size fits all solution.

My thought was just having the program check if autostart was enabled (a flag in the system tray menu) that gets synced to the config file, and if so, it'd make sure a copy of the executable was installed to it's %APPDATA% folder, then make the appropriate registry edit to launch it from there.

I generally want to stay away from having to bundle in an actual installer, but maybe that's best practice? This is my first program for windows so I'm totally open to ideas here.

gilescope commented 4 years ago

std::env::args().first() gets you the running command and that’s what you’d need to autostart. As a possible alternative to the registry there’s a StartUp folder in the windows menu so I guess one could just create a shortcut there (well there was a decade ago - I am assuming it’s still there!).

Sent with GitHawk

tarkah commented 4 years ago

I'm using std::env::current_exe to get path to current executabe. I added a toggle in the system tray for autostart. If this is enabled, it'll set / add the item to the config file as true, copy the executable to %APPDATA%\grout\grout.exe if it's not already being run from there, then create a registry key in HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run linking to that path.

If the option is deselected, the config file is updated accordingly and the registry key is deleted.