Files
wisp-open/internal/windows/startup.go
T
Your Name ce49f66c89 fix: Add cross-platform handling for tray, updater, and icon generation
- Add platform notes for tray startup, shortcut saving, and Linux-only settings
- Handle stat error in processRecording (missing file)
- Select correct binary name based on OS in updater
- Increase tray icon canvas size from 64 to 128 pixels
- Update frontend dist asset hash
2026-06-09 15:14:30 -07:00

101 lines
2.4 KiB
Go

//go:build windows
// ============================================================
// WINDOWS-ONLY FILE — Windows startup (autostart) management
// via the Windows Registry (HKCU\Software\Microsoft\Windows\
// CurrentVersion\Run). The Linux equivalent for autostart
// management is internal/linux/startup.go (XDG .desktop files)
// ============================================================
package windows
import (
"fmt"
"os"
"path/filepath"
"golang.org/x/sys/windows/registry"
)
// Windows Registry constants
const (
registryPath = `SOFTWARE\Microsoft\Windows\CurrentVersion\Run`
appName = "WISNative"
)
// AddToStartup adds the current executable to Windows startup.
// The application will start automatically when the user logs in.
func AddToStartup() error {
exePath, err := getExecutablePath()
if err != nil {
return fmt.Errorf("failed to get executable path: %w", err)
}
key, err := registry.OpenKey(
registry.CURRENT_USER,
registryPath,
registry.SET_VALUE,
)
if err != nil {
return fmt.Errorf("failed to open registry key: %w", err)
}
defer key.Close()
// Quote the path to handle spaces correctly and prevent execution hijacking
quotedPath := fmt.Sprintf("\"%s\"", exePath)
if err := key.SetStringValue(appName, quotedPath); err != nil {
return fmt.Errorf("failed to set registry value: %w", err)
}
return nil
}
// RemoveFromStartup removes the application from Windows startup.
func RemoveFromStartup() error {
key, err := registry.OpenKey(
registry.CURRENT_USER,
registryPath,
registry.SET_VALUE,
)
if err != nil {
return fmt.Errorf("failed to open registry key: %w", err)
}
defer key.Close()
if err := key.DeleteValue(appName); err != nil {
// Ignore error if value doesn't exist
if err != registry.ErrNotExist {
return fmt.Errorf("failed to delete registry value: %w", err)
}
}
return nil
}
// IsInStartup checks if the application is configured to start with Windows.
func IsInStartup() bool {
key, err := registry.OpenKey(
registry.CURRENT_USER,
registryPath,
registry.QUERY_VALUE,
)
if err != nil {
return false
}
defer key.Close()
_, _, err = key.GetStringValue(appName)
return err == nil
}
// getExecutablePath returns the absolute path to the current executable.
func getExecutablePath() (string, error) {
exe, err := os.Executable()
if err != nil {
return "", err
}
return filepath.Abs(exe)
}