summaryrefslogtreecommitdiff
path: root/vendor/github.com/ProtonMail/go-autostart/autostart_darwin.go
diff options
context:
space:
mode:
authorKali Kaneko (leap communications) <kali@leap.se>2019-01-12 18:39:45 +0100
committerRuben Pollan <meskio@sindominio.net>2019-01-17 12:30:32 +0100
commitb1247d2d0d51108c910a73891ff3116e5f032ab1 (patch)
treee9948964f0bfb1ad2df3bc7bad02aa1f41ccfbd8 /vendor/github.com/ProtonMail/go-autostart/autostart_darwin.go
parentefcb8312e31b5c2261b1a1e95ace55b322cfcc27 (diff)
[pkg] all your deps are vendored to us
Diffstat (limited to 'vendor/github.com/ProtonMail/go-autostart/autostart_darwin.go')
-rw-r--r--vendor/github.com/ProtonMail/go-autostart/autostart_darwin.go66
1 files changed, 66 insertions, 0 deletions
diff --git a/vendor/github.com/ProtonMail/go-autostart/autostart_darwin.go b/vendor/github.com/ProtonMail/go-autostart/autostart_darwin.go
new file mode 100644
index 0000000..b2e0518
--- /dev/null
+++ b/vendor/github.com/ProtonMail/go-autostart/autostart_darwin.go
@@ -0,0 +1,66 @@
+package autostart
+
+import (
+ "os"
+ "path/filepath"
+ "text/template"
+)
+
+const jobTemplate = `<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+ <dict>
+ <key>Label</key>
+ <string>{{.Name}}</string>
+ <key>ProgramArguments</key>
+ <array>
+ {{range .Exec -}}
+ <string>{{.}}</string>
+ {{end}}
+ </array>
+ <key>RunAtLoad</key>
+ <true/>
+ </dict>
+</plist>`
+
+var launchDir string
+
+func init() {
+ launchDir = filepath.Join(os.Getenv("HOME"), "Library", "LaunchAgents")
+}
+
+func (a *App) path() string {
+ return filepath.Join(launchDir, a.Name+".plist")
+}
+
+// IsEnabled Check is app enabled startup.
+func (a *App) IsEnabled() bool {
+ _, err := os.Stat(a.path())
+ return err == nil
+}
+
+// Enable this app on startup.
+func (a *App) Enable() error {
+ t := template.Must(template.New("job").Parse(jobTemplate))
+
+ if err := os.MkdirAll(launchDir, 0777); err != nil {
+ return err
+ }
+ f, err := os.Create(a.path())
+ if err != nil {
+ return err
+ }
+ defer f.Close()
+
+ if err := t.Execute(f, a); err != nil {
+ return err
+ }
+
+ return nil
+}
+
+// Disable this app on startup.
+func (a *App) Disable() error {
+
+ return os.Remove(a.path())
+}