summaryrefslogtreecommitdiff
path: root/pkg/backend/status.go
diff options
context:
space:
mode:
authorkali kaneko (leap communications) <kali@leap.se>2020-06-16 21:28:48 +0200
committerkali kaneko (leap communications) <kali@leap.se>2020-06-26 12:12:41 +0200
commitc17b5f6f7b6b28c890764688ff5e966ecebece63 (patch)
tree4c9931b10e7cddd9050f76aff95205dbf04d6d26 /pkg/backend/status.go
parenta18e61aa1be37aa568552c69fbd743d25498b9bb (diff)
[feat] re-implement donation reminders
first pass on giving functionality to the donation reminder
Diffstat (limited to 'pkg/backend/status.go')
-rw-r--r--pkg/backend/status.go103
1 files changed, 50 insertions, 53 deletions
diff --git a/pkg/backend/status.go b/pkg/backend/status.go
index e2d31db..7e9f211 100644
--- a/pkg/backend/status.go
+++ b/pkg/backend/status.go
@@ -6,6 +6,7 @@ import (
"log"
"0xacab.org/leap/bitmask-vpn/pkg/bitmask"
+ "0xacab.org/leap/bitmask-vpn/pkg/config"
)
const (
@@ -20,60 +21,20 @@ const (
// if we ever switch again to a provider-agnostic app, we should keep a map here.
var ctx *connectionCtx
-// the status type reflects the current VPN status. Go code is responsible for updating
-// it; the C gui just watches its changes and pulls its updates via the serialized
-// context object.
-
-type status int
-
-const (
- off status = iota
- starting
- on
- stopping
- failed
- unknown
-)
-
-func (s status) String() string {
- return [...]string{offStr, startingStr, onStr, stoppingStr, failedStr}[s]
-}
-
-func (s status) MarshalJSON() ([]byte, error) {
- b := bytes.NewBufferString(`"`)
- b.WriteString(s.String())
- b.WriteString(`"`)
- return b.Bytes(), nil
-}
-
-func (s status) fromString(st string) status {
- switch st {
- case offStr:
- return off
- case startingStr:
- return starting
- case onStr:
- return on
- case stoppingStr:
- return stopping
- case failedStr:
- return failed
- default:
- return unknown
- }
-}
-
// The connectionCtx keeps the global state that is passed around to C-land. It
// also serves as the primary way of passing requests from the frontend to the
// Go-core, by letting the UI write some of these variables and processing
// them.
type connectionCtx struct {
- AppName string `json:"appName"`
- Provider string `json:"provider"`
- Donate bool `json:"donate"`
- Status status `json:"status"`
- bm bitmask.Bitmask
+ AppName string `json:"appName"`
+ Provider string `json:"provider"`
+ AskForDonations bool `json:"askForDonations"`
+ DonateDialog bool `json:"donateDialog"`
+ DonateURL string `json:"donateURL"`
+ Status status `json:"status"`
+ bm bitmask.Bitmask
+ cfg *config.Config
}
func (c connectionCtx) toJson() ([]byte, error) {
@@ -110,11 +71,47 @@ func setStatus(st status) {
go trigger(OnStatusChanged)
}
-func toggleDonate() {
- stmut.Lock()
- defer stmut.Unlock()
- ctx.Donate = !ctx.Donate
- go trigger(OnStatusChanged)
+// the status type reflects the current VPN status. Go code is responsible for updating
+// it; the C gui just watches its changes and pulls its updates via the serialized
+// context object.
+
+type status int
+
+const (
+ off status = iota
+ starting
+ on
+ stopping
+ failed
+ unknown
+)
+
+func (s status) String() string {
+ return [...]string{offStr, startingStr, onStr, stoppingStr, failedStr}[s]
+}
+
+func (s status) MarshalJSON() ([]byte, error) {
+ b := bytes.NewBufferString(`"`)
+ b.WriteString(s.String())
+ b.WriteString(`"`)
+ return b.Bytes(), nil
+}
+
+func (s status) fromString(st string) status {
+ switch st {
+ case offStr:
+ return off
+ case startingStr:
+ return starting
+ case onStr:
+ return on
+ case stoppingStr:
+ return stopping
+ case failedStr:
+ return failed
+ default:
+ return unknown
+ }
}
func setStatusFromStr(stStr string) {