Skip to content

Commit

Permalink
feat: show confirm exit dialog before closing desktop app (#935)
Browse files Browse the repository at this point in the history
* feat: show confirm exit dialog before closing desktop app

* chore: update wails close confirmation message

---------

Co-authored-by: Roland <[email protected]>
  • Loading branch information
pavanjoshi914 and rolznz authored Jan 6, 2025
1 parent 2b33847 commit 36349b2
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions wails/wails_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
"github.com/wailsapp/wails/v2/pkg/options/linux"
"github.com/wailsapp/wails/v2/pkg/options/mac"
"github.com/wailsapp/wails/v2/pkg/runtime"
"gorm.io/gorm"
)

Expand All @@ -39,6 +40,21 @@ func (app *WailsApp) startup(ctx context.Context) {
app.ctx = ctx
}

func (app *WailsApp) onBeforeClose(ctx context.Context) bool {
response, err := runtime.MessageDialog(ctx, runtime.MessageDialogOptions{
Type: runtime.QuestionDialog,
Title: "Confirm Exit",
Message: "Are you sure you want to shut down Alby Hub? Alby Hub needs to stay online to send and receive transactions.",
Buttons: []string{"Yes", "No"},
DefaultButton: "No",
})
if err != nil {
logger.Logger.WithError(err).Error("failed to show confirmation dialog")
return false
}
return response != "Yes"
}

func LaunchWailsApp(app *WailsApp, assets embed.FS, appIcon []byte) {
err := wails.Run(&options.App{
Title: "Alby Hub",
Expand All @@ -52,6 +68,9 @@ func LaunchWailsApp(app *WailsApp, assets embed.FS, appIcon []byte) {

//BackgroundColour: &options.RGBA{R: 27, G: 38, B: 54, A: 1},
OnStartup: app.startup,
OnBeforeClose: func(ctx context.Context) bool {
return app.onBeforeClose(ctx)
},
Bind: []interface{}{
app,
},
Expand Down

0 comments on commit 36349b2

Please sign in to comment.