summaryrefslogtreecommitdiff
path: root/pkg/backend/api.go
blob: 74220eda9441aa8ec12d0be1bded88bdeedf2f71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* All the exported functions should be added here */

package backend

import (
	"C"
	"fmt"
	"log"
	"time"
	"unsafe"

	"0xacab.org/leap/bitmask-vpn/pkg/bitmask"
	"0xacab.org/leap/bitmask-vpn/pkg/pickle"
)

func SwitchOn() {
	go setStatus(starting)
	go startVPN()
}

func SwitchOff() {
	go setStatus(stopping)
	go stopVPN()
}

func Unblock() {
	//TODO -
	fmt.Println("unblock... [not implemented]")
}

func Quit() {
	if ctx.Status != off {
		go setStatus(stopping)
		ctx.cfg.SetUserStoppedVPN(true)
		stopVPN()
	}
	cleanupTempDirs()
}

func DonateAccepted() {
	donateAccepted()
}

func DonateRejected() {
	donateRejected()
}

func SubscribeToEvent(event string, f unsafe.Pointer) {
	subscribe(event, f)
}

func InitializeBitmaskContext() {
	p := bitmask.GetConfiguredProvider()

	initOnce.Do(func() { initializeContext(p.Provider, p.AppName) })
	go ctx.updateStatus()

	go func() {
		if needsDonationReminder() {
			// wait a bit before launching reminder
			timer := time.NewTimer(time.Minute * 5)
			<-timer.C
			showDonate()
		}

	}()
}

func RefreshContext() *C.char {
	c, _ := ctx.toJson()
	return C.CString(string(c))
}

func InstallHelpers() {
	pickle.InstallHelpers()
}

func MockUIInteraction() {
	log.Println("mocking ui interaction on port 8080. \nTry 'curl localhost:8080/{on|off|failed}' to toggle status.")
	go mockUI()
}