refactor: simplify homeDir and appConfig usage
This commit is contained in:
@@ -7,18 +7,18 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func EnsureAutostart() error {
|
||||
if isAutostartInstalled() || isTemporaryExecutable() {
|
||||
func EnsureAutostart(homeDir string) error {
|
||||
if isAutostartInstalled(homeDir) || isTemporaryExecutable() {
|
||||
return nil
|
||||
}
|
||||
|
||||
return installAutostart()
|
||||
return installAutostart(homeDir)
|
||||
}
|
||||
|
||||
func isAutostartInstalled() bool {
|
||||
func isAutostartInstalled(homeDir string) bool {
|
||||
switch runtime.GOOS {
|
||||
case "darwin":
|
||||
path := filepath.Join(os.Getenv("HOME"), "Library", "LaunchAgents", "com.godeez.watch.plist")
|
||||
path := filepath.Join(homeDir, "Library", "LaunchAgents", "com.godeez.watch.plist")
|
||||
_, err := os.Stat(path)
|
||||
|
||||
return err == nil
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func installAutostart() error {
|
||||
func installAutostart(homeDir string) error {
|
||||
exe, err := os.Executable()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -39,7 +39,7 @@ func installAutostart() error {
|
||||
</dict>
|
||||
</plist>`, exe)
|
||||
|
||||
path := filepath.Join(os.Getenv("HOME"), "Library", "LaunchAgents", "com.godeez.watch.plist")
|
||||
path := filepath.Join(homeDir, "Library", "LaunchAgents", "com.godeez.watch.plist")
|
||||
if err := os.WriteFile(path, []byte(plist), 0644); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -20,8 +20,7 @@ type Watcher struct {
|
||||
}
|
||||
|
||||
func New(appConfig *config.Config) *Watcher {
|
||||
homeDir, _ := os.UserHomeDir()
|
||||
logFile := filepath.Join(homeDir, ".godeez", "watcher.log")
|
||||
logFile := filepath.Join(appConfig.HomeDir, ".godeez", "watcher.log")
|
||||
file, err := os.OpenFile(logFile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to open log file: %v\n", err)
|
||||
|
||||
Reference in New Issue
Block a user