@@ -9,12 +9,12 @@ import (
99 "runtime"
1010
1111 "fyne.io/fyne/v2"
12+ "github.com/emersion/go-autostart"
1213)
1314
1415const (
1516 TNFS_ROOT_PATH_KEY = "tnfsRootPath"
1617 ALLOW_BACKGROUND_KEY = "allowBackground"
17- START_AT_LOGIN_KEY = "startAtLogin"
1818)
1919
2020type Config struct {
@@ -23,6 +23,7 @@ type Config struct {
2323 Hostname string
2424 AllowBackground bool
2525 StartAtLogin bool
26+ autostartApp * autostart.App
2627}
2728
2829func (c * Config ) SetRootPath (newPath string ) {
@@ -35,9 +36,16 @@ func (c *Config) SetAllowBackground(newVal bool) {
3536 fyne .CurrentApp ().Preferences ().SetBool (ALLOW_BACKGROUND_KEY , newVal )
3637}
3738
38- func (c * Config ) SetStartAtLogin (newVal bool ) {
39- c .StartAtLogin = newVal
40- fyne .CurrentApp ().Preferences ().SetBool (START_AT_LOGIN_KEY , newVal )
39+ func (c * Config ) SetStartAtLogin (enable bool ) {
40+ var err error
41+ if enable {
42+ err = c .autostartApp .Enable ()
43+ } else {
44+ err = c .autostartApp .Disable ()
45+ }
46+ if err == nil {
47+ c .StartAtLogin = enable
48+ }
4149}
4250
4351func LoadConfig () (* Config , error ) {
@@ -47,12 +55,16 @@ func LoadConfig() (*Config, error) {
4755 }
4856
4957 prefs := fyne .CurrentApp ().Preferences ()
58+ autostartApp , _ := makeAutostartApp ()
59+
5060 cfg := & Config {
5161 ExePath : exePath ,
5262 Hostname : getHostnameOrIP (),
5363 TnfsRootPath : getRootPath (prefs ),
5464 AllowBackground : prefs .BoolWithFallback (ALLOW_BACKGROUND_KEY , false ),
55- StartAtLogin : prefs .BoolWithFallback (START_AT_LOGIN_KEY , false ),
65+ StartAtLogin : autostartApp .IsEnabled (),
66+
67+ autostartApp : autostartApp ,
5668 }
5769 return cfg , nil
5870}
@@ -89,7 +101,6 @@ func locateTnfsdExecutable() (string, error) {
89101 }
90102
91103 exePath := filepath .Join (dir , exeName )
92- exePath = "bin/tnfsd-bsd"
93104
94105 fmt .Println (currentExePath )
95106 fmt .Println (exePath )
@@ -109,3 +120,17 @@ func getRootPath(prefs fyne.Preferences) string {
109120 }
110121 return prefs .StringWithFallback (TNFS_ROOT_PATH_KEY , dirname )
111122}
123+
124+ func makeAutostartApp () (* autostart.App , error ) {
125+ a := fyne .CurrentApp ()
126+ currentExePath , err := os .Executable ()
127+ if err != nil {
128+ return nil , err
129+ }
130+ aa := & autostart.App {
131+ Name : a .Metadata ().ID ,
132+ DisplayName : a .Metadata ().Name ,
133+ Exec : []string {currentExePath , "autorun" },
134+ }
135+ return aa , nil
136+ }
0 commit comments