summaryrefslogtreecommitdiff
path: root/pkg/backend/init.go
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/init.go
parent9b8009cfaf6707d23a20494cd5467aed9c98513b (diff)
[feat] pass initialization errors to gui
Diffstat (limited to 'pkg/backend/init.go')
-rw-r--r--pkg/backend/init.go74
1 files changed, 74 insertions, 0 deletions
diff --git a/pkg/backend/init.go b/pkg/backend/init.go
new file mode 100644
index 0000000..5abb05e
--- /dev/null
+++ b/pkg/backend/init.go
@@ -0,0 +1,74 @@
+package backend
+
+import (
+ "log"
+ "os"
+
+ "0xacab.org/leap/bitmask-vpn/pkg/bitmask"
+ "0xacab.org/leap/bitmask-vpn/pkg/config"
+ "0xacab.org/leap/bitmask-vpn/pkg/config/version"
+)
+
+// 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.
+func initializeContext(provider, appName string) {
+ var st status = off
+ ctx = &connectionCtx{
+ AppName: appName,
+ Provider: provider,
+ TosURL: config.TosURL,
+ HelpURL: config.HelpURL,
+ DonateURL: config.DonateURL,
+ AskForDonations: wantDonations(),
+ DonateDialog: false,
+ Version: version.VERSION,
+ Status: st,
+ }
+ errCh := make(chan string)
+ go trigger(OnStatusChanged)
+ 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()
+}