fix: fix problem when launcher is closed
This commit is contained in:
+8
-1
@@ -3,7 +3,7 @@ import { join } from 'path'
|
||||
import { setMainWindow } from './events'
|
||||
import { IPC, type UserSettings, type PlayOptions } from '../shared/ipc'
|
||||
import { login, logout, restoreSession, getCurrent } from './auth'
|
||||
import { play, stopGame } from './play'
|
||||
import { play, stopGame, isGameRunning } from './play'
|
||||
import { getPackMetaCached } from './modpack'
|
||||
import { getSettings, setSettings } from './settings'
|
||||
import { paths } from './paths'
|
||||
@@ -35,6 +35,13 @@ function createWindow(): BrowserWindow {
|
||||
|
||||
win.on('ready-to-show', () => win.show())
|
||||
|
||||
win.on('close', (e) => {
|
||||
if (isGameRunning()) {
|
||||
e.preventDefault()
|
||||
win.hide()
|
||||
}
|
||||
})
|
||||
|
||||
// Liens externes -> navigateur système.
|
||||
win.webContents.setWindowOpenHandler(({ url }) => {
|
||||
void shell.openExternal(url)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { ChildProcess } from 'child_process'
|
||||
import { app, BrowserWindow } from 'electron'
|
||||
import { getCurrent } from './auth'
|
||||
import { fetchPackMeta } from './modpack'
|
||||
import { ensureJava } from './java'
|
||||
@@ -47,6 +48,10 @@ export async function play(opts?: PlayOptions): Promise<void> {
|
||||
gameProcess = proc
|
||||
proc.on('close', () => {
|
||||
gameProcess = null
|
||||
const allHidden = BrowserWindow.getAllWindows().every((w) => !w.isVisible())
|
||||
if (allHidden) {
|
||||
app.quit()
|
||||
}
|
||||
})
|
||||
} catch (e) {
|
||||
emit.progress({ phase: 'error', message: (e as Error).message, progress: undefined })
|
||||
@@ -60,3 +65,7 @@ export function stopGame(): boolean {
|
||||
gameProcess.kill()
|
||||
return true
|
||||
}
|
||||
|
||||
export function isGameRunning(): boolean {
|
||||
return gameProcess !== null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user