-
Notifications
You must be signed in to change notification settings - Fork 97
/
main.go
111 lines (85 loc) · 2.92 KB
/
main.go
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package main
import (
"github.com/atotto/clipboard"
"github.com/getlantern/systray"
"github.com/pkg/browser"
icon "github.com/hoppscotch/proxyscotch/icons"
"github.com/hoppscotch/proxyscotch/inputbox"
"github.com/hoppscotch/proxyscotch/libproxy"
"github.com/hoppscotch/proxyscotch/notifier"
)
var (
VersionName string
VersionCode string
)
var (
mStatus *systray.MenuItem
mCopyAccessToken *systray.MenuItem
)
func main() {
systray.Run(onReady, onExit)
}
func onReady() {
systray.SetIcon(icon.Data)
systray.SetTooltip("Proxyscotch v" + VersionName + " (" + VersionCode + ") - created by NBTX")
/** Set up menu items. **/
// Status
mStatus = systray.AddMenuItem("Starting...", "")
mStatus.Disable()
mCopyAccessToken = systray.AddMenuItem("Copy Access Token...", "")
mCopyAccessToken.Disable()
systray.AddSeparator()
// Open Hoppscotch Interface
mOpenHoppscotch := systray.AddMenuItem("Open Hoppscotch", "")
systray.AddSeparator()
// View Help
mViewHelp := systray.AddMenuItem("Help...", "")
// Set Proxy Authentication Token
mSetAccessToken := systray.AddMenuItem("Set Access Token...", "")
// Check for Updates
mUpdateCheck := systray.AddMenuItem("Check for Updates...", "")
systray.AddSeparator()
// Quit Proxy
mQuit := systray.AddMenuItem("Quit Proxyscotch", "")
/** Start proxy server. **/
go runHoppscotchProxy()
/** Wait for menu input. **/
for {
select {
case <-mOpenHoppscotch.ClickedCh:
_ = browser.OpenURL("https://hoppscotch.io/")
case <-mCopyAccessToken.ClickedCh:
_ = clipboard.WriteAll(libproxy.GetAccessToken())
_ = notifier.Notify("Proxyscotch", "Proxy Access Token copied...", "The Proxy Access Token has been copied to your clipboard.", notifier.GetIcon())
case <-mViewHelp.ClickedCh:
_ = browser.OpenURL("https://github.com/hoppscotch/proxyscotch/wiki")
case <-mSetAccessToken.ClickedCh:
newAccessToken, success := inputbox.InputBox("Proxyscotch", "Please enter the new Proxy Access Token...\n(Leave this blank to disable access checks.)", "")
if success {
libproxy.SetAccessToken(newAccessToken)
if len(newAccessToken) == 0 {
_ = notifier.Notify("Proxyscotch", "Proxy Access check disabled.", "**Anyone can access your proxy server!** The Proxy Access Token check has been disabled.", notifier.GetIcon())
} else {
_ = notifier.Notify("Proxyscotch", "Proxy Access Token updated...", "The Proxy Access Token has been updated.", notifier.GetIcon())
}
}
case <-mUpdateCheck.ClickedCh:
// TODO: Add update check.
_ = browser.OpenURL("https://github.com/hoppscotch/proxyscotch")
case <-mQuit.ClickedCh:
systray.Quit()
return
}
}
}
func onExit() {
}
func runHoppscotchProxy() {
libproxy.Initialize("hoppscotch", "127.0.0.1:9159", "https://hoppscotch.io", "", "", onProxyStateChange, true, nil)
}
func onProxyStateChange(status string, isListening bool) {
mStatus.SetTitle(status)
if isListening {
mCopyAccessToken.Enable()
}
}