summaryrefslogtreecommitdiff
path: root/pkg/bitmask
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2020-09-24 12:24:48 +0200
committerRuben Pollan <meskio@sindominio.net>2020-09-24 16:50:04 +0200
commit998b5cb54ad23be1f6df0ee8abd08af5614f38db (patch)
treeaafb1c6f11ba23da120b29170ed712d6a07d5336 /pkg/bitmask
parent3a74c28cce41fe783d9dde707ebb6de941d5cf0a (diff)
[feat] send cmd flags to the go backend
Also disable autostart if manual quit, remove custom printer that was used for i18n and disable previous autostart if -disable-autostart We didn't disable autostart after the migration to qt. - Resolves: #355 #289
Diffstat (limited to 'pkg/bitmask')
-rw-r--r--pkg/bitmask/autostart.go8
-rw-r--r--pkg/bitmask/init.go41
2 files changed, 12 insertions, 37 deletions
diff --git a/pkg/bitmask/autostart.go b/pkg/bitmask/autostart.go
index 9e37fe4..f314dbc 100644
--- a/pkg/bitmask/autostart.go
+++ b/pkg/bitmask/autostart.go
@@ -36,7 +36,7 @@ type Autostart interface {
}
// newAutostart creates a handler for the autostart of your platform
-func newAutostart(appName string, iconPath string) Autostart {
+func NewAutostart(appName string, iconPath string) Autostart {
exec := os.Args
if os.Getenv("SNAP") != "" {
re := regexp.MustCompile("/snap/([^/]*)/")
@@ -65,12 +65,12 @@ func newAutostart(appName string, iconPath string) Autostart {
}
}
-type dummyAutostart struct{}
+type DummyAutostart struct{}
-func (a *dummyAutostart) Disable() error {
+func (a *DummyAutostart) Disable() error {
return nil
}
-func (a *dummyAutostart) Enable() error {
+func (a *DummyAutostart) Enable() error {
return nil
}
diff --git a/pkg/bitmask/init.go b/pkg/bitmask/init.go
index 401f8a7..00f145e 100644
--- a/pkg/bitmask/init.go
+++ b/pkg/bitmask/init.go
@@ -17,14 +17,12 @@ package bitmask
import (
"errors"
+ "fmt"
"log"
"os"
"path"
"strconv"
- "github.com/jmshal/go-locale"
- "golang.org/x/text/message"
-
"0xacab.org/leap/bitmask-vpn/pkg/config"
"0xacab.org/leap/bitmask-vpn/pkg/vpn"
)
@@ -89,27 +87,24 @@ func InitializeLogger() {
}
}
-func initBitmask(printer *message.Printer) (Bitmask, error) {
+func initBitmask() (Bitmask, error) {
b, err := vpn.Init()
if err != nil {
log.Printf("An error ocurred starting bitmask: %v", err)
- err = errors.New(printer.Sprintf(errorMsg, err))
+ err = errors.New(fmt.Sprintf(errorMsg, err))
}
return b, err
}
-func InitializeBitmask(skipLaunch bool) (Bitmask, error) {
- if skipLaunch {
+func InitializeBitmask(conf *config.Config) (Bitmask, error) {
+ if conf.SkipLaunch {
log.Println("Initializing bitmask, but not launching it...")
}
if _, err := os.Stat(config.Path); os.IsNotExist(err) {
os.MkdirAll(config.Path, os.ModePerm)
}
- conf := config.ParseConfig()
- conf.Printer = initPrinter()
-
- b, err := initBitmask(conf.Printer)
+ b, err := initBitmask()
if err != nil {
return nil, err
}
@@ -119,39 +114,19 @@ func InitializeBitmask(skipLaunch bool) (Bitmask, error) {
return nil, err
}
- if !skipLaunch {
+ if !conf.SkipLaunch {
err := maybeStartVPN(b, conf)
if err != nil {
log.Println("Error starting VPN: ", err)
return nil, err
}
}
-
- var as Autostart
- if skipLaunch || conf.DisableAustostart {
- as = &dummyAutostart{}
- } else {
- as = newAutostart(config.ApplicationName, "")
- }
-
- err = as.Enable()
- if err != nil {
- log.Printf("Error enabling autostart: %v", err)
- }
return b, nil
}
-func initPrinter() *message.Printer {
- locale, err := go_locale.DetectLocale()
- if err != nil {
- log.Println("Error detecting the system locale: ", err)
- }
-
- return message.NewPrinter(message.MatchLanguage(locale, "en"))
-}
-
func setTransport(b Bitmask, conf *config.Config) error {
if conf.Obfs4 {
+ log.Printf("Use transport Obfs4")
err := b.UseTransport("obfs4")
if err != nil {
log.Printf("Error setting transport: %v", err)