Skip to content

Commit

Permalink
Add a confirmation screen when logging out
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Jan 12, 2024
1 parent 55ee4d9 commit 618d413
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
47 changes: 46 additions & 1 deletion internal/ui/menu.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package ui

import (
"fmt"
"image/color"
"os"
"sort"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
deskDriver "fyne.io/fyne/v2/driver/desktop"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"

Expand Down Expand Up @@ -49,6 +53,47 @@ func (w *widgetPanel) appendAppCategories(acc *widget.Accordion, win fyne.Window
acc.Refresh()
}

func (w *widgetPanel) askLogout() {
win := fyne.CurrentApp().Driver().(deskDriver.Driver).CreateSplashWindow()
logout := widget.NewButtonWithIcon("Logout", theme.LogoutIcon(), func() {
win.Close()
w.desk.WindowManager().Close()
})
logout.Importance = widget.DangerImportance
cancel := widget.NewButton("Cancel", func() {
win.Close()
})

header := widget.NewRichTextFromMarkdown(fmt.Sprintf("### Log out"))

Check failure on line 67 in internal/ui/menu.go

View workflow job for this annotation

GitHub Actions / checks

unnecessary use of fmt.Sprintf (S1039)
header.Truncation = fyne.TextTruncateEllipsis
bottomPad := canvas.NewRectangle(color.Transparent)
bottomPad.SetMinSize(fyne.NewSquareSize(10))
content := container.NewBorder(
header,
container.NewVBox(
container.NewHBox(layout.NewSpacer(),
container.NewGridWithColumns(2, cancel, logout),
layout.NewSpacer()), bottomPad),
nil, nil,
widget.NewLabel("Are you sure you want to log out?"))

r, g, b, _ := theme.OverlayBackgroundColor().RGBA()
bgCol := &color.NRGBA{R: uint8(r), G: uint8(g), B: uint8(b), A: 230}

bg := canvas.NewRectangle(bgCol)
icon := canvas.NewImageFromResource(theme.LogoutIcon())
iconBox := container.NewWithoutLayout(icon)
icon.Resize(fyne.NewSize(92, 92))
icon.Move(fyne.NewPos(280-92-theme.Padding(), theme.Padding()))
win.SetContent(container.NewStack(
iconBox, bg,
container.NewPadded(content)))

win.Resize(fyne.NewSize(280, 150))
win.CenterOnScreen()
win.Show()
}

func (w *widgetPanel) showAccountMenu(_ fyne.CanvasObject) {
w2 := fyne.CurrentApp().Driver().(deskDriver.Driver).CreateSplashWindow()
w2.Canvas().SetOnTypedKey(func(k *fyne.KeyEvent) {
Expand All @@ -58,8 +103,8 @@ func (w *widgetPanel) showAccountMenu(_ fyne.CanvasObject) {
})
items1 := []fyne.CanvasObject{
&widget.Button{Icon: theme.LogoutIcon(), Importance: widget.DangerImportance, OnTapped: func() {
w.askLogout()
w2.Close()
w.desk.WindowManager().Close()
}}}
isEmbed := w.desk.(*desktop).root.Title() != RootWindowName
if !isEmbed {
Expand Down
6 changes: 4 additions & 2 deletions internal/x11/wm/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,10 @@ func (x *x11WM) handleMouseEnter(ev xproto.EnterNotifyEvent) {
func (x *x11WM) handleMouseLeave(ev xproto.LeaveNotifyEvent) {
if ev.Event == x.menuID { // dismiss overlay menus on mouse out
x.menuID = 0
x.menuWin.Close()
x.menuWin = nil
if x.menuWin != nil {
x.menuWin.Close()
x.menuWin = nil
}
}

for _, c := range x.clients {
Expand Down

0 comments on commit 618d413

Please sign in to comment.