Skip to content
18 changes: 17 additions & 1 deletion src/backend/storeManagers/storeManagerCommon/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
app,
BrowserWindow,
BrowserWindowConstructorOptions,
session,
WindowOpenHandlerResponse
} from 'electron'
import { gameManagerMap } from '../index'
Expand Down Expand Up @@ -145,14 +146,16 @@ const openNewBrowserGameWindow = async (
const hpOverlay = await getHpOverlay()

return new Promise((res) => {
const partition = `persist:${appName}`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

const browserGame = new BrowserWindow({
icon: icon,
fullscreen: true,
webPreferences: {
webviewTag: true,
contextIsolation: true,
nodeIntegration: true,
preload: path.join(__dirname, '../preload/preload.js')
preload: path.join(__dirname, '../preload/preload.js'),
partition
},
show: false
})
Expand Down Expand Up @@ -215,6 +218,19 @@ const openNewBrowserGameWindow = async (
}
app.on('web-contents-created', interceptFullscreenKeyInput)

// Clear cache on launch to avoid issues with game updates
const gameSession = session.fromPartition(partition)
gameSession.clearCache()
gameSession.clearStorageData({
storages: ['filesystem', 'shadercache', 'cachestorage'],
quotas: ['temporary', 'syncable']
})

// Open DevTools
if (!app.isPackaged || process.env.HP_ENABLE_DEVTOOLS === 'true') {
browserGame.webContents.openDevTools()
}

browserGame.loadURL(url)
// this is electron's suggested way to prevent visual flash
// https://github.com/electron/electron/blob/main/docs/api/browser-window.md#using-the-ready-to-show-event
Expand Down
Loading