summaryrefslogtreecommitdiff
path: root/vendor/github.com/ProtonMail/go-autostart
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
parentefcb8312e31b5c2261b1a1e95ace55b322cfcc27 (diff)
[pkg] all your deps are vendored to us
Diffstat (limited to 'vendor/github.com/ProtonMail/go-autostart')
-rw-r--r--vendor/github.com/ProtonMail/go-autostart/LICENSE21
-rw-r--r--vendor/github.com/ProtonMail/go-autostart/README.md51
-rw-r--r--vendor/github.com/ProtonMail/go-autostart/autostart.go13
-rw-r--r--vendor/github.com/ProtonMail/go-autostart/autostart_darwin.go66
-rw-r--r--vendor/github.com/ProtonMail/go-autostart/autostart_windows.c51
-rw-r--r--vendor/github.com/ProtonMail/go-autostart/autostart_windows.go52
-rw-r--r--vendor/github.com/ProtonMail/go-autostart/autostart_xdg.go69
-rw-r--r--vendor/github.com/ProtonMail/go-autostart/quote.go16
8 files changed, 339 insertions, 0 deletions
diff --git a/vendor/github.com/ProtonMail/go-autostart/LICENSE b/vendor/github.com/ProtonMail/go-autostart/LICENSE
new file mode 100644
index 0000000..f9e1447
--- /dev/null
+++ b/vendor/github.com/ProtonMail/go-autostart/LICENSE
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2016 ProtonMail
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/vendor/github.com/ProtonMail/go-autostart/README.md b/vendor/github.com/ProtonMail/go-autostart/README.md
new file mode 100644
index 0000000..580862f
--- /dev/null
+++ b/vendor/github.com/ProtonMail/go-autostart/README.md
@@ -0,0 +1,51 @@
+# go-autostart
+
+[![GoDoc](https://godoc.org/github.com/ProtonMail/go-autostart?status.svg)](https://godoc.org/github.com/ProtonMail/go-autostart)
+
+A Go library to run a command after login.
+
+## Usage
+
+```go
+package main
+
+import (
+ "log"
+ "github.com/ProtonMail/go-autostart"
+)
+
+func main() {
+ app := &autostart.App{
+ Name: "test",
+ DisplayName: "Just a Test App",
+ Exec: []string{"bash", "-c", "echo autostart >> ~/autostart.txt"},
+ }
+
+ if app.IsEnabled() {
+ log.Println("App is already enabled, removing it...")
+
+ if err := app.Disable(); err != nil {
+ log.Fatal(err)
+ }
+ } else {
+ log.Println("Enabling app...")
+
+ if err := app.Enable(); err != nil {
+ log.Fatal(err)
+ }
+ }
+
+ log.Println("Done!")
+}
+```
+
+## Behavior
+
+* On Linux and BSD, it creates a `.desktop` file in `$XDG_CONFIG_HOME/autostart`
+ (i.e. `$HOME/.config/autostart`). See http://askubuntu.com/questions/48321/how-do-i-start-applications-automatically-on-login
+* On macOS, it creates a `launchd` job. See http://blog.gordn.org/2015/03/implementing-run-on-login-for-your-node.html
+* On Windows, it creates a link to the program in `%USERPROFILE%\Start Menu\Programs\Startup`
+
+## License
+
+MIT
diff --git a/vendor/github.com/ProtonMail/go-autostart/autostart.go b/vendor/github.com/ProtonMail/go-autostart/autostart.go
new file mode 100644
index 0000000..7b7d6de
--- /dev/null
+++ b/vendor/github.com/ProtonMail/go-autostart/autostart.go
@@ -0,0 +1,13 @@
+package autostart
+
+// An application that will be started when the user logs in.
+type App struct {
+ // Unique identifier for the app.
+ Name string
+ // The command to execute, followed by its arguments.
+ Exec []string
+ // The app name.
+ DisplayName string
+ // The app icon.
+ Icon string
+}
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())
+}
diff --git a/vendor/github.com/ProtonMail/go-autostart/autostart_windows.c b/vendor/github.com/ProtonMail/go-autostart/autostart_windows.c
new file mode 100644
index 0000000..a61618c
--- /dev/null
+++ b/vendor/github.com/ProtonMail/go-autostart/autostart_windows.c
@@ -0,0 +1,51 @@
+#include <windows.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <objbase.h>
+#include <shlobj.h>
+
+uint64_t CreateShortcut(char *shortcutA, char *path, char *args) {
+ IShellLink* pISL;
+ IPersistFile* pIPF;
+ HRESULT hr;
+
+ CoInitializeEx(NULL, COINIT_MULTITHREADED);
+
+ // Shortcut filename: convert ANSI to unicode
+ WORD shortcutW[MAX_PATH];
+ int nChar = MultiByteToWideChar(CP_ACP, 0, shortcutA, -1, shortcutW, MAX_PATH);
+
+ hr = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLink, (LPVOID*)&pISL);
+ if (!SUCCEEDED(hr)) {
+ return hr+0x01000000;
+ }
+
+ // See https://msdn.microsoft.com/en-us/library/windows/desktop/bb774950(v=vs.85).aspx
+ hr = pISL->lpVtbl->SetPath(pISL, path);
+ if (!SUCCEEDED(hr)) {
+ return hr+0x02000000;
+ }
+
+ hr = pISL->lpVtbl->SetArguments(pISL, args);
+ if (!SUCCEEDED(hr)) {
+ return hr+0x03000000;
+ }
+
+ // Save the shortcut
+ hr = pISL->lpVtbl->QueryInterface(pISL, &IID_IPersistFile, (void**)&pIPF);
+ if (!SUCCEEDED(hr)) {
+ return hr+0x04000000;
+ }
+
+ hr = pIPF->lpVtbl->Save(pIPF, shortcutW, FALSE);
+ if (!SUCCEEDED(hr)) {
+ return hr+0x05000000;
+ }
+
+ pIPF->lpVtbl->Release(pIPF);
+ pISL->lpVtbl->Release(pISL);
+
+ return 0x0;
+}
diff --git a/vendor/github.com/ProtonMail/go-autostart/autostart_windows.go b/vendor/github.com/ProtonMail/go-autostart/autostart_windows.go
new file mode 100644
index 0000000..3c14609
--- /dev/null
+++ b/vendor/github.com/ProtonMail/go-autostart/autostart_windows.go
@@ -0,0 +1,52 @@
+package autostart
+
+// #cgo LDFLAGS: -lole32 -luuid
+/*
+#define WIN32_LEAN_AND_MEAN
+#include <stdint.h>
+#include <windows.h>
+
+uint64_t CreateShortcut(char *shortcutA, char *path, char *args);
+*/
+import "C"
+
+import (
+ "errors"
+ "fmt"
+ "os"
+ "path/filepath"
+ "strings"
+)
+
+var startupDir string
+
+func init() {
+ startupDir = filepath.Join(os.Getenv("USERPROFILE"), "AppData", "Roaming", "Microsoft", "Windows", "Start Menu", "Programs", "Startup")
+}
+
+func (a *App) path() string {
+ return filepath.Join(startupDir, a.Name+".lnk")
+}
+
+func (a *App) IsEnabled() bool {
+ _, err := os.Stat(a.path())
+ return err == nil
+}
+
+func (a *App) Enable() error {
+ path := a.Exec[0]
+ args := strings.Join(a.Exec[1:], " ")
+
+ if err := os.MkdirAll(startupDir, 0777); err != nil {
+ return err
+ }
+ res := C.CreateShortcut(C.CString(a.path()), C.CString(path), C.CString(args))
+ if res != 0 {
+ return errors.New(fmt.Sprintf("autostart: cannot create shortcut '%s' error code: 0x%.8x", a.path(), res))
+ }
+ return nil
+}
+
+func (a *App) Disable() error {
+ return os.Remove(a.path())
+}
diff --git a/vendor/github.com/ProtonMail/go-autostart/autostart_xdg.go b/vendor/github.com/ProtonMail/go-autostart/autostart_xdg.go
new file mode 100644
index 0000000..39306a5
--- /dev/null
+++ b/vendor/github.com/ProtonMail/go-autostart/autostart_xdg.go
@@ -0,0 +1,69 @@
+// +build !windows,!darwin
+
+package autostart
+
+import (
+ "os"
+ "path/filepath"
+ "text/template"
+)
+
+const desktopTemplate = `[Desktop Entry]
+Type=Application
+Name={{.DisplayName}}
+Exec={{.Exec}}
+{{- if .Icon}}
+Icon={{.Icon}}{{end}}
+X-GNOME-Autostart-enabled=true
+`
+
+var autostartDir string
+
+func init() {
+ if os.Getenv("XDG_CONFIG_HOME") != "" {
+ autostartDir = os.Getenv("XDG_CONFIG_HOME")
+ } else {
+ autostartDir = filepath.Join(os.Getenv("HOME"), ".config")
+ }
+ autostartDir = filepath.Join(autostartDir, "autostart")
+}
+
+func (a *App) path() string {
+ return filepath.Join(autostartDir, a.Name+".desktop")
+}
+
+// Check if the app is enabled on startup.
+func (a *App) IsEnabled() bool {
+ _, err := os.Stat(a.path())
+ return err == nil
+}
+
+type app struct {
+ *App
+}
+
+// Override App.Exec to return a string.
+func (a *app) Exec() string {
+ return quote(a.App.Exec)
+}
+
+// Enable this app on startup.
+func (a *App) Enable() error {
+ t := template.Must(template.New("desktop").Parse(desktopTemplate))
+
+ if err := os.MkdirAll(autostartDir, 0777); err != nil {
+ return err
+ }
+ f, err := os.Create(a.path())
+ if err != nil {
+ return err
+ }
+ defer f.Close()
+
+ return t.Execute(f, &app{a})
+}
+
+// Disable this app on startup.
+func (a *App) Disable() error {
+ return os.Remove(a.path())
+}
diff --git a/vendor/github.com/ProtonMail/go-autostart/quote.go b/vendor/github.com/ProtonMail/go-autostart/quote.go
new file mode 100644
index 0000000..b906eed
--- /dev/null
+++ b/vendor/github.com/ProtonMail/go-autostart/quote.go
@@ -0,0 +1,16 @@
+// +build !darwin
+
+package autostart
+
+import (
+ "strconv"
+ "strings"
+)
+
+func quote(args []string) string {
+ for i, v := range args {
+ args[i] = strconv.Quote(v)
+ }
+
+ return strings.Join(args, " ")
+}