feat: Add 'Run on Startup' checkbox to system tray

This commit introduces a new feature that allows you to configure the application to run on startup.

- A "Run on Startup" checkbox has been added to the system tray menu.
- The application now uses a `config.json` file to store settings, including the "run on startup" state.
- On Windows, the application adds/removes itself from the startup programs by creating/deleting a key in the Windows Registry.
This commit is contained in:
google-labs-jules[bot]
2025-08-10 13:40:15 +00:00
parent 2be4f03243
commit 00bda02b37
5 changed files with 120 additions and 21 deletions

48
src/startup.py Normal file
View File

@@ -0,0 +1,48 @@
import os
import winreg
APP_NAME = "OopsWrongLang"
RUN_BAT_PATH = os.path.abspath("run.bat")
def add_to_startup():
"""
Adds the application to Windows startup.
"""
try:
key = winreg.HKEY_CURRENT_USER
sub_key = r"Software\Microsoft\Windows\CurrentVersion\Run"
with winreg.OpenKey(key, sub_key, 0, winreg.KEY_SET_VALUE) as registry_key:
winreg.SetValueEx(registry_key, APP_NAME, 0, winreg.REG_SZ, f'"{RUN_BAT_PATH}"')
except OSError as e:
print(f"Error adding to startup: {e}")
def remove_from_startup():
"""
Removes the application from Windows startup.
"""
try:
key = winreg.HKEY_CURRENT_USER
sub_key = r"Software\Microsoft\Windows\CurrentVersion\Run"
with winreg.OpenKey(key, sub_key, 0, winreg.KEY_SET_VALUE) as registry_key:
winreg.DeleteValue(registry_key, APP_NAME)
except FileNotFoundError:
# This is fine, it means the key doesn't exist
pass
except OSError as e:
print(f"Error removing from startup: {e}")
def is_in_startup():
"""
Checks if the application is in Windows startup.
"""
try:
key = winreg.HKEY_CURRENT_USER
sub_key = r"Software\Microsoft\Windows\CurrentVersion\Run"
with winreg.OpenKey(key, sub_key, 0, winreg.KEY_READ) as registry_key:
winreg.QueryValueEx(registry_key, APP_NAME)
return True
except FileNotFoundError:
return False
except OSError as e:
print(f"Error checking startup status: {e}")
return False