From 4faad2cda4938806126c482c7f93b640d68b9fe8 Mon Sep 17 00:00:00 2001 From: "kali kaneko (leap communications)" Date: Fri, 12 Jun 2020 20:35:48 +0200 Subject: [refactor] rename standalone to just vpn --- pkg/bitmask/autostart.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'pkg/bitmask/autostart.go') 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 { -- cgit v1.2.3