Ariver
2026-06-04 cb0259e3176109d437be4ff941016fe7eb37022c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//go:build linux
 
package startup
 
import (
    "fmt"
    "os"
    "path/filepath"
)
 
const desktopEntry = `[Desktop Entry]
Type=Application
Name=PrivateVoice Dictation
Exec=%s
Hidden=false
X-GNOME-Autostart-enabled=true
`
 
func autostartPath() string {
    return autostartPathForName("privatevoice-input.desktop")
}
 
func autostartPathForName(name string) string {
    configDir, err := os.UserConfigDir()
    if err != nil {
        home, _ := os.UserHomeDir()
        configDir = filepath.Join(home, ".config")
    }
    return filepath.Join(configDir, "autostart", name)
}
 
func isEnabled() bool {
    removeLegacyAutostartFiles()
    _, err := os.Stat(autostartPath())
    return err == nil
}
 
func setEnabled(enable bool) error {
    path := autostartPath()
 
    if !enable {
        if err := removeAutostartFile(path); err != nil {
            return err
        }
        removeLegacyAutostartFiles()
        return nil
    }
 
    removeLegacyAutostartFiles()
 
    exe, err := os.Executable()
    if err != nil {
        return err
    }
 
    dir := filepath.Dir(path)
    if err := os.MkdirAll(dir, 0755); err != nil {
        return err
    }
 
    content := fmt.Sprintf(desktopEntry, exe)
    return os.WriteFile(path, []byte(content), 0644)
}
 
func removeLegacyAutostartFiles() {
    _ = removeAutostartFile(autostartPathForName("voicesnap.desktop"))
}
 
func removeAutostartFile(path string) error {
    if err := os.Remove(path); err != nil && !os.IsNotExist(err) {
        return err
    }
    return nil
}