summaryrefslogtreecommitdiff
path: root/pkg/bitmask/autostart.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/bitmask/autostart.go')
-rw-r--r--pkg/bitmask/autostart.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/pkg/bitmask/autostart.go b/pkg/bitmask/autostart.go
index ebab428..1ba9162 100644
--- a/pkg/bitmask/autostart.go
+++ b/pkg/bitmask/autostart.go
@@ -1,3 +1,4 @@
+// +build !bitmaskd
// Copyright (C) 2018 LEAP
//
// This program is free software: you can redistribute it and/or modify
@@ -15,12 +16,56 @@
package bitmask
+import (
+ "fmt"
+ "log"
+ "os"
+ "path/filepath"
+ "regexp"
+
+ pmautostart "github.com/ProtonMail/go-autostart"
+)
+
+const (
+ errorMsg = `An error has ocurred initializing the VPN: %v`
+)
+
// Autostart holds the functions to enable and disable the application autostart
type Autostart interface {
Disable() error
Enable() error
}
+// newAutostart creates a handler for the autostart of your platform
+func newAutostart(appName string, iconPath string) Autostart {
+ exec := os.Args
+ if os.Getenv("SNAP") != "" {
+ re := regexp.MustCompile("/snap/([^/]*)/")
+ match := re.FindStringSubmatch(os.Args[0])
+ if len(match) > 1 {
+ snapName := match[1]
+ exec = []string{fmt.Sprintf("/snap/bin/%s.launcher", snapName)}
+ } else {
+ log.Printf("Snap binary has unknown path: %v", os.Args[0])
+ }
+ }
+
+ if exec[0][:2] == "./" || exec[0][:2] == ".\\" {
+ var err error
+ exec[0], err = filepath.Abs(exec[0])
+ if err != nil {
+ log.Printf("Error making the path absolute directory: %v", err)
+ }
+ }
+
+ return &pmautostart.App{
+ Name: appName,
+ Exec: exec,
+ DisplayName: appName,
+ Icon: iconPath,
+ }
+}
+
type dummyAutostart struct{}
func (a *dummyAutostart) Disable() error {