Skip to content

[Browser]: handle before unload event properly #2939

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

Merged
merged 2 commits into from
Aug 9, 2023
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: 17 additions & 2 deletions src/backend/storeManagers/storeManagerCommon/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { access, chmod } from 'fs/promises'
import shlex from 'shlex'
import { showDialogBoxModalAuto } from '../../dialog/dialog'
import { createAbortController } from '../../utils/aborthandler/aborthandler'
import { BrowserWindow, Menu } from 'electron'
import { BrowserWindow, dialog, Menu } from 'electron'
import { gameManagerMap } from '../index'

async function getAppSettings(appName: string): Promise<GameSettings> {
Expand Down Expand Up @@ -65,7 +65,22 @@ const openNewBrowserGameWindow = async (
browserGame.close()
})

browserGame.on('close', () => {
browserGame.webContents.on('will-prevent-unload', (event) => {
const choice = dialog.showMessageBoxSync(browserGame, {
type: 'question',
buttons: ['Yes', 'No'],
title: 'Are you sure you want to quit?',
message: 'Any unsaved progress might be lost',
defaultId: 0,
cancelId: 1
})
const leave = choice === 0
if (leave) {
event.preventDefault()
}
})

browserGame.on('closed', () => {
res(true)
})
})
Expand Down