Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show confirm exit dialog before closing desktop app #935

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 close Alby Hub? App 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
Loading