summaryrefslogtreecommitdiff
path: root/pkg/backend
diff options
context:
space:
mode:
authorkali kaneko (leap communications) <kali@leap.se>2020-09-08 03:32:46 +0200
committerkali kaneko (leap communications) <kali@leap.se>2020-09-08 20:09:48 +0200
commita0e67fe3feb5b3a2d6d0f8e5f33ff96007955b17 (patch)
treecda0ca1934af399385c21a67fe56b55577c7c2a5 /pkg/backend
parente591c3147e3c504611ff612e8918018125ffa2eb (diff)
[feat] lookup the config vars at runtime
- Resolves: #326
Diffstat (limited to 'pkg/backend')
-rw-r--r--pkg/backend/api.go29
-rw-r--r--pkg/backend/donate.go9
-rw-r--r--pkg/backend/init.go10
3 files changed, 19 insertions, 29 deletions
diff --git a/pkg/backend/api.go b/pkg/backend/api.go
index 59b386b..1985e6b 100644
--- a/pkg/backend/api.go
+++ b/pkg/backend/api.go
@@ -63,35 +63,30 @@ func SubscribeToEvent(event string, f unsafe.Pointer) {
}
type Providers struct {
- Default string `json:"default"`
- Data []InitOpts
+ Default string `json:"default"`
+ Data []bitmask.ProviderOpts `json:"providers"`
}
type InitOpts struct {
- Provider string `json:"name"`
- AppName string `json:"applicationName"`
- BinaryName string `json:"binaryName"`
- Auth string `json:"auth"`
- ProviderURL string `json:"providerURL"`
- TosURL string `json:"tosURL"`
- HelpURL string `json:"helpURL"`
- AskForDonations bool `json:"askForDonations"`
+ ProviderOptions *bitmask.ProviderOpts
SkipLaunch bool
}
func InitOptsFromJSON(provider, providersJSON string) *InitOpts {
- opts := InitOpts{}
- err := json.Unmarshal([]byte(providersJSON), &opts)
+ providers := Providers{}
+ err := json.Unmarshal([]byte(providersJSON), &providers)
if err != nil {
- log.Println("ERROR: %v", err)
+ log.Println("ERROR while parsing json:", err)
}
- return &opts
+ if len(providers.Data) != 1 {
+ panic("BUG: we do not support multi-provider yet")
+ }
+ providerOpts := &providers.Data[0]
+ return &InitOpts{providerOpts, false}
}
func InitializeBitmaskContext(opts *InitOpts) {
- p := bitmask.GetConfiguredProvider()
- opts.Provider = p.Provider
- opts.AppName = p.AppName
+ bitmask.ConfigureProvider(opts.ProviderOptions)
initOnce.Do(func() { initializeContext(opts) })
if ctx.bm != nil {
diff --git a/pkg/backend/donate.go b/pkg/backend/donate.go
index 20d5613..f87934a 100644
--- a/pkg/backend/donate.go
+++ b/pkg/backend/donate.go
@@ -2,8 +2,6 @@ package backend
import (
"time"
-
- "0xacab.org/leap/bitmask-vpn/pkg/config"
)
// runDonationReminder checks every hour if we need to show the reminder,
@@ -19,13 +17,6 @@ func runDonationReminder() {
}()
}
-func wantDonations() bool {
- if config.AskForDonations == "true" {
- return true
- }
- return false
-}
-
func needsDonationReminder() bool {
return ctx.cfg.NeedsDonationReminder()
}
diff --git a/pkg/backend/init.go b/pkg/backend/init.go
index be4427a..aabc720 100644
--- a/pkg/backend/init.go
+++ b/pkg/backend/init.go
@@ -14,13 +14,17 @@ import (
// api uses the sync.Once primitive to call this.
func initializeContext(opts *InitOpts) {
var st status = off
+
+ // TODO - now there's really no need to dance between opts and config anymore
+ // but this was the simplest transition. We should probably keep the multi-provider config in the backend too, and just
+ // switch the "active" here in the ctx, after the user has selected one in the combobox.
ctx = &connectionCtx{
- AppName: opts.AppName,
- Provider: opts.Provider,
+ AppName: opts.ProviderOptions.AppName,
+ Provider: opts.ProviderOptions.Provider,
TosURL: config.TosURL,
HelpURL: config.HelpURL,
DonateURL: config.DonateURL,
- AskForDonations: wantDonations(),
+ AskForDonations: config.AskForDonations,
DonateDialog: false,
Version: version.VERSION,
Status: st,