summaryrefslogtreecommitdiff
path: root/pkg/backend/api.go
blob: fea38dbcaaa14df1db4d5030c643c515f950dc72 (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
/* All the exported functions should be added here */

package backend

import (
	"C"
	"fmt"
	"log"
	"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(false)
	} else {
		ctx.cfg.SetUserStoppedVPN(true)
	}
	ctx.bm.Close()
}

func DonateAccepted() {
	donateAccepted()
}

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

type InitOpts struct {
	Provider   string
	AppName    string
	SkipLaunch bool
}

func InitializeBitmaskContext(opts *InitOpts) {
	p := bitmask.GetConfiguredProvider()
	opts.Provider = p.Provider
	opts.AppName = p.AppName

	initOnce.Do(func() { initializeContext(opts) })
	runDonationReminder()
	go ctx.updateStatus()
}

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

func InstallHelpers() {
	pickle.InstallHelpers()
}

func EnableMockBackend() {
	log.Println("[+] Mocking ui interaction on port 8080. \nTry 'curl localhost:8080/{on|off|failed}' to toggle status.")
	go enableMockBackend()
}