From a0e67fe3feb5b3a2d6d0f8e5f33ff96007955b17 Mon Sep 17 00:00:00 2001 From: "kali kaneko (leap communications)" Date: Tue, 8 Sep 2020 03:32:46 +0200 Subject: [feat] lookup the config vars at runtime - Resolves: #326 --- pkg/backend/api.go | 29 ++++++++++++----------------- pkg/backend/donate.go | 9 --------- pkg/backend/init.go | 10 +++++++--- 3 files changed, 19 insertions(+), 29 deletions(-) (limited to 'pkg/backend') 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, -- cgit v1.2.3