mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-07 05:59:06 +02:00
Port VNC settings and connection-approval prompt to the Wails UI
This commit is contained in:
@@ -106,6 +106,7 @@ type WindowManager struct {
|
||||
settings *application.WebviewWindow
|
||||
browserLogin *application.WebviewWindow
|
||||
sessionExpiration *application.WebviewWindow
|
||||
approval *application.WebviewWindow
|
||||
installProgress *application.WebviewWindow
|
||||
welcome *application.WebviewWindow
|
||||
errorDialog *application.WebviewWindow
|
||||
@@ -279,6 +280,58 @@ func (s *WindowManager) CloseSessionExpiration() {
|
||||
}
|
||||
}
|
||||
|
||||
// ApprovalRequest carries the daemon-supplied metadata for an inbound-connection
|
||||
// approval prompt to the dialog window as query params. Kind, RequestID and
|
||||
// ExpiresAt are daemon-issued; the rest are remote-influenced and shown so the
|
||||
// user can vet who is connecting.
|
||||
type ApprovalRequest struct {
|
||||
RequestID string
|
||||
Kind string
|
||||
Initiator string
|
||||
PeerName string
|
||||
SourceIP string
|
||||
Username string
|
||||
PeerPubKey string
|
||||
ExpiresAt string
|
||||
}
|
||||
|
||||
// OpenApproval shows the inbound-connection approval prompt on the cursor's
|
||||
// display. Singleton, destroyed on close: a second request replaces the window,
|
||||
// and the superseded request auto-denies on the daemon's deadline.
|
||||
func (s *WindowManager) OpenApproval(req ApprovalRequest) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
startURL := approvalDialogURL(req)
|
||||
if s.approval == nil {
|
||||
opts := DialogWindowOptions("approval", s.title("window.title.approval"), startURL, s.linuxIcon)
|
||||
opts.Height = 380
|
||||
opts.Screen = s.getScreenBasedOnCursorPosition()
|
||||
opts.InitialPosition = application.WindowCentered
|
||||
s.approval = s.app.Window.NewWithOptions(opts)
|
||||
s.approval.OnWindowEvent(events.Common.WindowClosing, func(_ *application.WindowEvent) {
|
||||
s.mu.Lock()
|
||||
s.approval = nil
|
||||
s.mu.Unlock()
|
||||
})
|
||||
s.centerOnCursorScreen(s.approval)
|
||||
return
|
||||
}
|
||||
s.approval.SetURL(startURL)
|
||||
s.centerOnCursorScreen(s.approval)
|
||||
s.approval.Show()
|
||||
s.approval.Focus()
|
||||
}
|
||||
|
||||
func (s *WindowManager) CloseApproval() {
|
||||
s.mu.Lock()
|
||||
w := s.approval
|
||||
s.approval = nil
|
||||
s.mu.Unlock()
|
||||
if w != nil {
|
||||
w.Close()
|
||||
}
|
||||
}
|
||||
|
||||
// OpenInstallProgress shows the install-progress window and hides the rest for the duration
|
||||
// (restored on close). It owns its own result polling since the daemon restarts mid-install.
|
||||
func (s *WindowManager) OpenInstallProgress(version string) {
|
||||
@@ -572,5 +625,30 @@ func errorDialogURL(title, message string) string {
|
||||
return startURL
|
||||
}
|
||||
|
||||
// approvalDialogURL builds the approval window's start URL with the request
|
||||
// metadata as escaped query params. Empty fields are omitted so the dialog
|
||||
// renders only the rows it has values for.
|
||||
func approvalDialogURL(req ApprovalRequest) string {
|
||||
q := url.Values{}
|
||||
set := func(k, v string) {
|
||||
if v != "" {
|
||||
q.Set(k, v)
|
||||
}
|
||||
}
|
||||
set("request_id", req.RequestID)
|
||||
set("kind", req.Kind)
|
||||
set("initiator", req.Initiator)
|
||||
set("peer_name", req.PeerName)
|
||||
set("source_ip", req.SourceIP)
|
||||
set("username", req.Username)
|
||||
set("peer_pubkey", req.PeerPubKey)
|
||||
set("expires_at", req.ExpiresAt)
|
||||
startURL := "/#/dialog/approval"
|
||||
if enc := q.Encode(); enc != "" {
|
||||
startURL += "?" + enc
|
||||
}
|
||||
return startURL
|
||||
}
|
||||
|
||||
// u32ptr returns a pointer to v, for the optional *uint32 Wails theme fields.
|
||||
func u32ptr(v uint32) *uint32 { return &v }
|
||||
|
||||
Reference in New Issue
Block a user