summaryrefslogtreecommitdiff
path: root/pkg/backend
diff options
context:
space:
mode:
authorkali kaneko (leap communications) <kali@leap.se>2020-06-17 21:14:35 +0200
committerkali kaneko (leap communications) <kali@leap.se>2020-06-26 12:13:44 +0200
commit20266b063c1be8818d4582bff7b59486551ee447 (patch)
tree2f7bd97624104e7defecd6d29fff8dad2446c0ce /pkg/backend
parent9b8009cfaf6707d23a20494cd5467aed9c98513b (diff)
[feat] pass initialization errors to gui
Diffstat (limited to 'pkg/backend')
-rw-r--r--pkg/backend/callbacks.go2
-rw-r--r--pkg/backend/donate.go9
-rw-r--r--pkg/backend/init.go (renamed from pkg/backend/bitmask.go)83
-rw-r--r--pkg/backend/status.go1
4 files changed, 56 insertions, 39 deletions
diff --git a/pkg/backend/callbacks.go b/pkg/backend/callbacks.go
index 5ea3b04..f3bb39f 100644
--- a/pkg/backend/callbacks.go
+++ b/pkg/backend/callbacks.go
@@ -7,7 +7,7 @@ import (
"unsafe"
)
-/* NOTE! ATCHUNG! what follow are not silly comments. Well, *this one* is, but
+/* ATCHUNG! what follow are not silly comments. Well, *this one* is, but
the lines after this are not.
Those are inline C functions, that are invoked by CGO later on.
it's also crucial that you don't any extra space between the function
diff --git a/pkg/backend/donate.go b/pkg/backend/donate.go
index d216687..608128f 100644
--- a/pkg/backend/donate.go
+++ b/pkg/backend/donate.go
@@ -3,8 +3,17 @@ package backend
import (
"log"
"time"
+
+ "0xacab.org/leap/bitmask-vpn/pkg/config"
)
+func wantDonations() bool {
+ if config.AskForDonations == "true" {
+ return true
+ }
+ return false
+}
+
func needsDonationReminder() bool {
return ctx.cfg.NeedsDonationReminder()
}
diff --git a/pkg/backend/bitmask.go b/pkg/backend/init.go
index 2b58859..5abb05e 100644
--- a/pkg/backend/bitmask.go
+++ b/pkg/backend/init.go
@@ -9,43 +9,6 @@ import (
"0xacab.org/leap/bitmask-vpn/pkg/config/version"
)
-func initializeBitmask() {
- if ctx == nil {
- log.Println("error: cannot initialize bitmask, ctx is nil")
- os.Exit(1)
- }
- bitmask.InitializeLogger()
-
- b, err := bitmask.InitializeBitmask()
- if err != nil {
- log.Println("error: cannot initialize bitmask")
- }
- ctx.bm = b
- ctx.cfg = config.ParseConfig()
-}
-
-func startVPN() {
- err := ctx.bm.StartVPN(ctx.Provider)
- if err != nil {
- log.Println(err)
- os.Exit(1)
- }
-}
-
-func stopVPN() {
- err := ctx.bm.StopVPN()
- if err != nil {
- log.Println(err)
- }
-}
-
-func wantDonations() bool {
- if config.AskForDonations == "true" {
- return true
- }
- return false
-}
-
// initializeContext initializes an empty connStatus and assigns it to the
// global ctx holder. This is expected to be called only once, so the public
// api uses the sync.Once primitive to call this.
@@ -62,6 +25,50 @@ func initializeContext(provider, appName string) {
Version: version.VERSION,
Status: st,
}
+ errCh := make(chan string)
go trigger(OnStatusChanged)
- initializeBitmask()
+ go checkErrors(errCh)
+ initializeBitmask(errCh)
+}
+
+func checkErrors(errCh chan string) {
+ for {
+ err := <-errCh
+ ctx.Errors = err
+ go trigger(OnStatusChanged)
+ }
+}
+
+func initializeBitmask(errCh chan string) {
+ if ctx == nil {
+ log.Println("bug: cannot initialize bitmask, ctx is nil!")
+ os.Exit(1)
+ }
+ bitmask.InitializeLogger()
+
+ b, err := bitmask.InitializeBitmask()
+ if err != nil {
+ log.Println("error: cannot initialize bitmask")
+ errCh <- err.Error()
+ return
+ }
+
+ helpers, privilege, err := b.VPNCheck()
+
+ if err != nil {
+ log.Println("error doing vpn check")
+ errCh <- err.Error()
+ }
+
+ if helpers == false {
+ log.Println("no helpers")
+ errCh <- "nohelpers"
+ }
+ if privilege == false {
+ log.Println("no polkit")
+ errCh <- "nopolkit"
+ }
+
+ ctx.bm = b
+ ctx.cfg = config.ParseConfig()
}
diff --git a/pkg/backend/status.go b/pkg/backend/status.go
index 84b27b7..2e9c282 100644
--- a/pkg/backend/status.go
+++ b/pkg/backend/status.go
@@ -35,6 +35,7 @@ type connectionCtx struct {
DonateDialog bool `json:"donateDialog"`
DonateURL string `json:"donateURL"`
Version string `json:"version"`
+ Errors string `json:"errors"`
Status status `json:"status"`
bm bitmask.Bitmask
cfg *config.Config