Skip to content

Commit

Permalink
[Browser]: handle before unload event properly (#2939)
Browse files Browse the repository at this point in the history
* fix: handle before unload event properly

* add translations
  • Loading branch information
imLinguin committed Aug 9, 2023
1 parent 86e2e11 commit f11ecef
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
6 changes: 6 additions & 0 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@
"install": "Epic Servers are having major outage right now, the game cannot be installed!",
"update": "Epic Servers are having major outage right now, the game cannot be updated!"
},
"sideload": {
"confirmExit": {
"message": "Any unsaved progress might be lost",
"title": "Are you sure you want to quit?"
}
},
"title": "Warning",
"wine-change": {
"message": "We could not find the selected wine version to launch this title ({{selectedWine}}). {{newline}} We found another one, do you want to continue launching using {{foundWine}} ?",
Expand Down
25 changes: 23 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,28 @@ 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: i18next.t(
'box.warning.sideload.confirmExit.title',
'Are you sure you want to quit?'
),
message: i18next.t(
'box.warning.sideload.confirmExit.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

0 comments on commit f11ecef

Please sign in to comment.