diff options
author | kali kaneko (leap communications) <kali@leap.se> | 2020-06-12 12:40:59 +0200 |
---|---|---|
committer | kali kaneko (leap communications) <kali@leap.se> | 2020-06-12 20:03:02 +0200 |
commit | 971c28f6563de35b1d66401d6919f86787af0611 (patch) | |
tree | 81ded50db137663acf6837e05e6df74507d346da /gui/backend.go | |
parent | 57b7f111c27f57085a2c64c37c5c5a94ee1d0f02 (diff) |
[feat] working donate dialog
Signed-off-by: kali kaneko (leap communications) <kali@leap.se>
Diffstat (limited to 'gui/backend.go')
-rw-r--r-- | gui/backend.go | 60 |
1 files changed, 47 insertions, 13 deletions
diff --git a/gui/backend.go b/gui/backend.go index 43f7b67..d05ba7a 100644 --- a/gui/backend.go +++ b/gui/backend.go @@ -6,14 +6,18 @@ import ( "bytes" "encoding/json" "fmt" + "io" "log" "net/http" "os" + "path" "reflect" "sync" + //"time" "unsafe" "0xacab.org/leap/bitmask-vpn/pkg/bitmask" + "0xacab.org/leap/bitmask-vpn/pkg/config" "0xacab.org/leap/bitmask-vpn/pkg/pickle" "0xacab.org/leap/bitmask-vpn/pkg/systray2" "github.com/jmshal/go-locale" @@ -71,8 +75,6 @@ func trigger(event string) { /* connection status */ -const logFile = "systray.log" - const ( offStr = "off" startingStr = "starting" @@ -130,6 +132,7 @@ func (s status) fromString(st string) status { type connectionCtx struct { AppName string `json:"appName"` Provider string `json:"provider"` + Donate bool `json:"donate"` Status status `json:"status"` bm bitmask.Bitmask } @@ -170,8 +173,14 @@ func setStatus(st status) { go trigger(OnStatusChanged) } +func toggleDonate() { + stmut.Lock() + defer stmut.Unlock() + ctx.Donate = !ctx.Donate + go trigger(OnStatusChanged) +} + func setStatusFromStr(stStr string) { - log.Println("status:", stStr) setStatus(unknown.fromString(stStr)) } @@ -184,8 +193,18 @@ func initPrinter() *message.Printer { return message.NewPrinter(message.MatchLanguage(locale, "en")) } +const logFile = "systray.log" + +var logger io.Closer + // initializeBitmask instantiates a bitmask connection func initializeBitmask() { + _, err := config.ConfigureLogger(path.Join(config.Path, logFile)) + + if err != nil { + log.Println("Can't configure logger: ", err) + } + if ctx == nil { log.Println("error: cannot initialize bitmask, ctx is nil") os.Exit(1) @@ -223,6 +242,7 @@ func initializeContext(provider, appName string) { ctx = &connectionCtx{ AppName: appName, Provider: provider, + Donate: false, Status: st, } go trigger(OnStatusChanged) @@ -263,27 +283,32 @@ func mockUI() { //export SwitchOn func SwitchOn() { - setStatus(starting) - startVPN() + go setStatus(starting) + go startVPN() } //export SwitchOff func SwitchOff() { - setStatus(stopping) - stopVPN() + go setStatus(stopping) + go stopVPN() +} + +//export Unblock +func Unblock() { + fmt.Println("unblock... [not implemented]") } //export Quit func Quit() { if ctx.Status != off { - setStatus(stopping) + go setStatus(stopping) stopVPN() } } -//export Unblock -func Unblock() { - fmt.Println("unblock... [not implemented]") +//export ToggleDonate +func ToggleDonate() { + toggleDonate() } //export SubscribeToEvent @@ -293,12 +318,21 @@ func SubscribeToEvent(event string, f unsafe.Pointer) { //export InitializeBitmaskContext func InitializeBitmaskContext() { - provider := "black.riseup.net" - appName := "RiseupVPN" + provider := config.Provider + appName := config.ApplicationName initOnce.Do(func() { initializeContext(provider, appName) }) go ctx.updateStatus() + + /* DEBUG + timer := time.NewTimer(time.Second * 3) + go func() { + <-timer.C + fmt.Println("donate timer fired") + toggleDonate() + }() + */ } //export RefreshContext |