summaryrefslogtreecommitdiff
path: root/pkg/bitmask/autostart.go
diff options
context:
space:
mode:
authorkali kaneko (leap communications) <kali@leap.se>2020-06-12 20:35:48 +0200
committerkali kaneko (leap communications) <kali@leap.se>2020-06-12 20:35:48 +0200
commit4faad2cda4938806126c482c7f93b640d68b9fe8 (patch)
treee475b65a59ecdfac09bedc7b2ae380736de09c16 /pkg/bitmask/autostart.go
parent0ac0afaaf312a02af01d1c307ecf9b5915f40b0d (diff)
[refactor] rename standalone to just vpn
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 {