@@ -4,10 +4,25 @@ import (
44 "strconv"
55
66 "github.com/getlantern/systray"
7+ "github.com/hugolgst/rich-go/client"
78 "github.com/rivo/tview"
89)
910
10- var UI * tview.Application = tview .NewApplication ()
11+ var (
12+ UI * tview.Application = tview .NewApplication ()
13+ FormRPC = tview .NewForm ()
14+ )
15+
16+ func rpcButtonStart () {
17+ RPCActive = true
18+ StartRPC ()
19+ FormRPC .GetButton (0 ).SetLabel (Lang ["stop" ]).SetSelectedFunc (rpcButtonStop )
20+ }
21+ func rpcButtonStop () {
22+ RPCActive = false
23+ client .Logout ()
24+ FormRPC .GetButton (0 ).SetLabel (Lang ["start" ]).SetSelectedFunc (rpcButtonStart )
25+ }
1126
1227func LoopUI () {
1328 // UI Elements
@@ -18,7 +33,7 @@ func LoopUI() {
1833 formAddNewApp := tview .NewForm ()
1934 modalInvalidAppID := tview .NewModal ()
2035 formAppSelection := tview .NewForm ()
21- formRPC := tview .NewForm ()
36+ formRemovingApp := tview .NewForm ()
2237 formItemAppList := tview .NewDropDown ().SetFieldWidth (34 ).SetLabel (Lang ["selectApp" ])
2338
2439 // Input Infos
@@ -44,7 +59,7 @@ func LoopUI() {
4459 ConfigApps [inputAppName ] = inputAppID
4560 Config ["selectedApp" ] = inputAppName
4661 ConfigSave ()
47- formRPC .SetTitle (" " + AppName + " - " + Lang ["selectedApp" ] + Config ["selectedApp" ] + " " )
62+ FormRPC .SetTitle (" " + AppName + " - " + Lang ["selectedApp" ] + Config ["selectedApp" ] + " " )
4863 pages .SwitchToPage ("RPC" )
4964 lastPage = "RPC"
5065 }
@@ -63,7 +78,7 @@ func LoopUI() {
6378 AddInputField (Lang ["id" ], "" , 18 , tview .InputFieldMaxLength (18 ), func (text string ) {
6479 inputAppID = text
6580 }).
66- AddButton (Lang ["save " ], func () {
81+ AddButton (Lang ["add " ], func () {
6782 if len (inputAppName ) < 1 || len (inputAppID ) < 18 {
6883 return
6984 }
@@ -80,6 +95,7 @@ func LoopUI() {
8095 formItemAppList .SetOptions (options , func (text string , index int ) {
8196 inputAppName = text
8297 })
98+ formItemAppList .SetCurrentOption (- 1 )
8399 pages .SwitchToPage (lastPage )
84100 lastPage = "RPC"
85101 }
@@ -88,7 +104,7 @@ func LoopUI() {
88104 pages .SwitchToPage (lastPage )
89105 lastPage = "RPC"
90106 })
91- formAddNewApp .SetBorder (true ).SetTitle (" " + Lang [ "formAddNewAppTitle" ] + " - " + AppName + " " ).SetTitleAlign (tview .AlignLeft )
107+ formAddNewApp .SetBorder (true ).SetTitle (" " + AppName + " " ).SetTitleAlign (tview .AlignLeft )
92108 pages .AddPage ("addNewApp" , formAddNewApp , true , false )
93109
94110 // UI Page - Invalid App ID Modal
@@ -100,6 +116,32 @@ func LoopUI() {
100116 })
101117 pages .AddPage ("invalidAppID" , modalInvalidAppID , true , false )
102118
119+ // UI Page - Removing App
120+ formRemovingApp = formRemovingApp .
121+ AddFormItem (formItemAppList ).
122+ AddButton (Lang ["remove" ], func () {
123+ delete (ConfigApps , inputAppName )
124+ delete (Config , "selectedApp" )
125+ inputAppName = ""
126+ ConfigSave ()
127+ options := []string {}
128+ for k := range ConfigApps {
129+ options = append (options , k )
130+ }
131+ formItemAppList .SetOptions (options , func (text string , index int ) {
132+ inputAppName = text
133+ })
134+ formItemAppList .SetCurrentOption (- 1 )
135+ pages .SwitchToPage (lastPage )
136+ lastPage = "RPC"
137+ }).
138+ AddButton (Lang ["cancel" ], func () {
139+ pages .SwitchToPage (lastPage )
140+ lastPage = "RPC"
141+ })
142+ formRemovingApp .SetBorder (true ).SetTitle (" " + AppName + " " ).SetTitleAlign (tview .AlignLeft )
143+ pages .AddPage ("removingApp" , formRemovingApp , true , false )
144+
103145 // UI Page - App Selection
104146 formAppSelection = formAppSelection .
105147 AddFormItem (formItemAppList ).
@@ -110,16 +152,19 @@ func LoopUI() {
110152 Config ["selectedApp" ] = inputAppName
111153 ConfigSave ()
112154 if lastPage == "RPC" {
113- formRPC .SetTitle (" " + AppName + " - " + Lang ["selectedApp" ] + Config ["selectedApp" ] + " " )
155+ FormRPC .SetTitle (" " + AppName + " - " + Lang ["selectedApp" ] + Config ["selectedApp" ] + " " )
114156 }
115157 pages .SwitchToPage (lastPage )
116158 }).
117159 AddButton (Lang ["add" ], func () {
118160 lastPage = "appSelection"
119161 pages .SwitchToPage ("addNewApp" )
162+ formItemAppList .SetCurrentOption (- 1 )
120163 }).
121164 AddButton (Lang ["remove" ], func () {
122- // ...
165+ lastPage = "appSelection"
166+ pages .SwitchToPage ("removingApp" )
167+ formItemAppList .SetCurrentOption (- 1 )
123168 }).
124169 AddButton (Lang ["quit" ], func () {
125170 systray .Quit ()
@@ -128,11 +173,17 @@ func LoopUI() {
128173 pages .AddPage ("appSelection" , formAppSelection , true , false )
129174
130175 // UI Page - RPC
131- formRPC = formRPC .
132- AddInputField (Lang ["details" ], "" , 30 , nil , nil ).
133- AddInputField (Lang ["status" ], "" , 30 , nil , nil ).
134- AddButton (Lang ["start" ], nil ).
176+ FormRPC = FormRPC .
177+ AddInputField (Lang ["details" ], "" , 34 , nil , func (text string ) {
178+ RPCDetails = text
179+ }).
180+ AddInputField (Lang ["state" ], "" , 34 , nil , func (text string ) {
181+ RPCState = text
182+ }).
183+ AddButton (Lang ["start" ], rpcButtonStart ).
135184 AddButton (Lang ["changeApp" ], func () {
185+ RPCActive = false
186+ client .Logout ()
136187 options := []string {}
137188 for k := range ConfigApps {
138189 options = append (options , k )
@@ -142,16 +193,17 @@ func LoopUI() {
142193 })
143194 pages .SwitchToPage ("appSelection" )
144195 lastPage = "RPC"
196+ formItemAppList .SetCurrentOption (- 1 )
145197 }).
146198 AddButton (Lang ["quit" ], func () {
147199 systray .Quit ()
148200 })
149- formRPC .SetBorder (true ).SetTitle (" " + Lang ["selectedApp" ] + Config ["selectedApp" ] + " " ).SetTitleAlign (tview .AlignLeft )
150- pages .AddPage ("RPC" , formRPC , true , false )
201+ FormRPC .SetBorder (true ).SetTitle (" " + Lang ["selectedApp" ] + Config ["selectedApp" ] + " " ).SetTitleAlign (tview .AlignLeft )
202+ pages .AddPage ("RPC" , FormRPC , true , false )
151203
152204 // Check if there is no saved app
153205 if len (ConfigApps ) < 1 {
154- Config [ "selectedApp" ] = inputAppName
206+ delete ( Config , "selectedApp" )
155207 ConfigSave ()
156208 pages .SwitchToPage ("addFirstApp" )
157209 lastPage = "addFirstApp"
0 commit comments