Skip to content

Commit 3176b53

Browse files
doromaraujolixmal
andauthored
[client] Add quick actions window (#4717)
* Open quick settings window if netbird-ui is already running * [client-ui] fix connection status comparison * [client-ui] modularize quick actions code * [client-ui] add netbird-disconnected logo * [client-ui] change quickactions UI It now displays the NetBird logo and a single button with a round icon * [client-ui] add hint message to quick actions screen This also updates fyne to v2.7.0 * [client-ui] remove unnecessary default clause * [client-ui] remove commented code * [client-ui] remove unused dependency * [client-ui] close quick actions on connection change * [client-ui] add function to get image from embed resources * [client] Return error when calling sendShowWindowSignal from Windows * [client-ui] Add commentary on empty OnTapped function for toggleConnectionButton * [client-ui] Fix tests * [client-ui] Add context to menuUpClick call * [client-ui] Pass serviceClient app as parameter To use its clipboard rather than the window's when showing the upload success dialog * [client-ui] Replace for select with for range chan * [client-ui] Replace settings change listener channel Settings now accept a function callback * [client-ui] Add missing iconAboutDisconnected to icons_windows.go * [client] Add quick actions signal handler for Windows with named events * [client] Run go mod tidy * [client] Remove line break * [client] Log unexpected status in separate function * [client-ui] Refactor quick actions window To address racing conditions, it also replaces usage of pause and resume channels with an atomic bool. * [client-ui] use derived context from ServiceClient * [client] Update signal_windows log message Also, format error when trying to set event on sendShowWindowSignal * go mod tidy * [client-ui] Add struct to pass fewer parameters to applyQuickActionsUiState function * [client] Add missing import --------- Co-authored-by: Viktor Liu <[email protected]>
1 parent 2795703 commit 3176b53

File tree

12 files changed

+734
-528
lines changed

12 files changed

+734
-528
lines changed
4.94 KB
Binary file not shown.
7.36 KB
Loading

client/ui/client_ui.go

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -85,21 +85,22 @@ func main() {
8585

8686
// Create the service client (this also builds the settings or networks UI if requested).
8787
client := newServiceClient(&newServiceClientArgs{
88-
addr: flags.daemonAddr,
89-
logFile: logFile,
90-
app: a,
91-
showSettings: flags.showSettings,
92-
showNetworks: flags.showNetworks,
93-
showLoginURL: flags.showLoginURL,
94-
showDebug: flags.showDebug,
95-
showProfiles: flags.showProfiles,
88+
addr: flags.daemonAddr,
89+
logFile: logFile,
90+
app: a,
91+
showSettings: flags.showSettings,
92+
showNetworks: flags.showNetworks,
93+
showLoginURL: flags.showLoginURL,
94+
showDebug: flags.showDebug,
95+
showProfiles: flags.showProfiles,
96+
showQuickActions: flags.showQuickActions,
9697
})
9798

9899
// Watch for theme/settings changes to update the icon.
99100
go watchSettingsChanges(a, client)
100101

101102
// Run in window mode if any UI flag was set.
102-
if flags.showSettings || flags.showNetworks || flags.showDebug || flags.showLoginURL || flags.showProfiles {
103+
if flags.showSettings || flags.showNetworks || flags.showDebug || flags.showLoginURL || flags.showProfiles || flags.showQuickActions {
103104
a.Run()
104105
return
105106
}
@@ -111,23 +112,29 @@ func main() {
111112
return
112113
}
113114
if running {
114-
log.Warnf("another process is running with pid %d, exiting", pid)
115+
log.Infof("another process is running with pid %d, sending signal to show window", pid)
116+
if err := sendShowWindowSignal(pid); err != nil {
117+
log.Errorf("send signal to running instance: %v", err)
118+
}
115119
return
116120
}
117121

122+
client.setupSignalHandler(client.ctx)
123+
118124
client.setDefaultFonts()
119125
systray.Run(client.onTrayReady, client.onTrayExit)
120126
}
121127

122128
type cliFlags struct {
123-
daemonAddr string
124-
showSettings bool
125-
showNetworks bool
126-
showProfiles bool
127-
showDebug bool
128-
showLoginURL bool
129-
errorMsg string
130-
saveLogsInFile bool
129+
daemonAddr string
130+
showSettings bool
131+
showNetworks bool
132+
showProfiles bool
133+
showDebug bool
134+
showLoginURL bool
135+
showQuickActions bool
136+
errorMsg string
137+
saveLogsInFile bool
131138
}
132139

133140
// parseFlags reads and returns all needed command-line flags.
@@ -143,6 +150,7 @@ func parseFlags() *cliFlags {
143150
flag.BoolVar(&flags.showNetworks, "networks", false, "run networks window")
144151
flag.BoolVar(&flags.showProfiles, "profiles", false, "run profiles window")
145152
flag.BoolVar(&flags.showDebug, "debug", false, "run debug window")
153+
flag.BoolVar(&flags.showQuickActions, "quick-actions", false, "run quick actions window")
146154
flag.StringVar(&flags.errorMsg, "error-msg", "", "displays an error message window")
147155
flag.BoolVar(&flags.saveLogsInFile, "use-log-file", false, fmt.Sprintf("save logs in a file: %s/netbird-ui-PID.log", os.TempDir()))
148156
flag.BoolVar(&flags.showLoginURL, "login-url", false, "show login URL in a popup window")
@@ -158,11 +166,9 @@ func initLogFile() (string, error) {
158166

159167
// watchSettingsChanges listens for Fyne theme/settings changes and updates the client icon.
160168
func watchSettingsChanges(a fyne.App, client *serviceClient) {
161-
settingsChangeChan := make(chan fyne.Settings)
162-
a.Settings().AddChangeListener(settingsChangeChan)
163-
for range settingsChangeChan {
169+
a.Settings().AddListener(func(settings fyne.Settings) {
164170
client.updateIcon()
165-
}
171+
})
166172
}
167173

168174
// showErrorMessage displays an error message in a simple window.
@@ -287,6 +293,7 @@ type serviceClient struct {
287293
showNetworks bool
288294
wNetworks fyne.Window
289295
wProfiles fyne.Window
296+
wQuickActions fyne.Window
290297

291298
eventManager *event.Manager
292299

@@ -306,14 +313,15 @@ type menuHandler struct {
306313
}
307314

308315
type newServiceClientArgs struct {
309-
addr string
310-
logFile string
311-
app fyne.App
312-
showSettings bool
313-
showNetworks bool
314-
showDebug bool
315-
showLoginURL bool
316-
showProfiles bool
316+
addr string
317+
logFile string
318+
app fyne.App
319+
showSettings bool
320+
showNetworks bool
321+
showDebug bool
322+
showLoginURL bool
323+
showProfiles bool
324+
showQuickActions bool
317325
}
318326

319327
// newServiceClient instance constructor
@@ -349,6 +357,8 @@ func newServiceClient(args *newServiceClientArgs) *serviceClient {
349357
s.showDebugUI()
350358
case args.showProfiles:
351359
s.showProfilesUI()
360+
case args.showQuickActions:
361+
s.showQuickActionsUI()
352362
}
353363

354364
return s

client/ui/debug.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ func (s *serviceClient) createDebugBundleFromCollection(
500500
if uploadFailureReason != "" {
501501
showUploadFailedDialog(progress.window, localPath, uploadFailureReason)
502502
} else {
503-
showUploadSuccessDialog(progress.window, localPath, uploadedKey)
503+
showUploadSuccessDialog(s.app, progress.window, localPath, uploadedKey)
504504
}
505505
} else {
506506
showBundleCreatedDialog(progress.window, localPath)
@@ -565,7 +565,7 @@ func (s *serviceClient) handleDebugCreation(
565565
if uploadFailureReason != "" {
566566
showUploadFailedDialog(w, localPath, uploadFailureReason)
567567
} else {
568-
showUploadSuccessDialog(w, localPath, uploadedKey)
568+
showUploadSuccessDialog(s.app, w, localPath, uploadedKey)
569569
}
570570
} else {
571571
showBundleCreatedDialog(w, localPath)
@@ -665,7 +665,7 @@ func showUploadFailedDialog(w fyne.Window, localPath, failureReason string) {
665665
}
666666

667667
// showUploadSuccessDialog displays a dialog when upload succeeds
668-
func showUploadSuccessDialog(w fyne.Window, localPath, uploadedKey string) {
668+
func showUploadSuccessDialog(a fyne.App, w fyne.Window, localPath, uploadedKey string) {
669669
log.Infof("Upload key: %s", uploadedKey)
670670
keyEntry := widget.NewEntry()
671671
keyEntry.SetText(uploadedKey)
@@ -683,7 +683,7 @@ func showUploadSuccessDialog(w fyne.Window, localPath, uploadedKey string) {
683683
customDialog := dialog.NewCustom("Upload Successful", "OK", content, w)
684684

685685
copyBtn := createButtonWithAction("Copy key", func() {
686-
w.Clipboard().SetContent(uploadedKey)
686+
a.Clipboard().SetContent(uploadedKey)
687687
log.Info("Upload key copied to clipboard")
688688
})
689689

client/ui/icons.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import (
99
//go:embed assets/netbird.png
1010
var iconAbout []byte
1111

12+
//go:embed assets/netbird-disconnected.png
13+
var iconAboutDisconnected []byte
14+
1215
//go:embed assets/netbird-systemtray-connected.png
1316
var iconConnected []byte
1417

client/ui/icons_windows.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import (
77
//go:embed assets/netbird.ico
88
var iconAbout []byte
99

10+
//go:embed assets/netbird-disconnected.ico
11+
var iconAboutDisconnected []byte
12+
1013
//go:embed assets/netbird-systemtray-connected.ico
1114
var iconConnected []byte
1215

0 commit comments

Comments
 (0)