add tray & creating shortcuts
This commit is contained in:
parent
81f5eadc76
commit
1097a1f441
11 changed files with 452 additions and 22 deletions
|
|
@ -18,9 +18,15 @@ function sendToWindow(win, channel, data) {
|
|||
}
|
||||
|
||||
// Game-process state: id -> pid (or null while the process is starting).
|
||||
function createGamesService({ getWindow }) {
|
||||
// onGamesChanged fires in the MAIN process whenever the running-games set
|
||||
// changes (the tray menu rebuilds itself from it).
|
||||
function createGamesService({ getWindow, onGamesChanged }) {
|
||||
const running = new Map()
|
||||
const killRequests = new Set()
|
||||
let onGameExit = null
|
||||
const notifyChanged = () => {
|
||||
if (typeof onGamesChanged === 'function') onGamesChanged()
|
||||
}
|
||||
|
||||
const isRunning = id => running.has(id)
|
||||
const listRunning = () => [...running.keys()]
|
||||
|
|
@ -35,6 +41,8 @@ function createGamesService({ getWindow }) {
|
|||
function handleExit(id) {
|
||||
running.delete(id)
|
||||
sendToWindow(getWindow(), 'games:changed')
|
||||
notifyChanged()
|
||||
if (onGameExit) onGameExit(id)
|
||||
}
|
||||
|
||||
async function start(win, id) {
|
||||
|
|
@ -58,7 +66,8 @@ function createGamesService({ getWindow }) {
|
|||
if (res.pid) killProcessGroup(res.pid)
|
||||
}
|
||||
sendToWindow(win, 'games:changed')
|
||||
return { ok: true }
|
||||
notifyChanged()
|
||||
return { ok: true, pid: res.pid || null, logFile: res.logFile || null }
|
||||
} catch (err) {
|
||||
running.delete(id)
|
||||
return { ok: false, error: String((err && err.message) || err) }
|
||||
|
|
@ -71,6 +80,7 @@ function createGamesService({ getWindow }) {
|
|||
killProcessGroup(pid)
|
||||
running.delete(id)
|
||||
sendToWindow(getWindow(), 'games:changed')
|
||||
notifyChanged()
|
||||
} else if (running.has(id)) {
|
||||
killRequests.add(id)
|
||||
}
|
||||
|
|
@ -94,11 +104,17 @@ function createGamesService({ getWindow }) {
|
|||
}
|
||||
}
|
||||
|
||||
// subscribe to game exits (used by the tray/headless mode to e.g. quit when
|
||||
// the game that auto-started the launcher has finished)
|
||||
function setOnGameExit(fn) {
|
||||
onGameExit = typeof fn === 'function' ? fn : null
|
||||
}
|
||||
|
||||
async function importTo(win, srcDir, mode) {
|
||||
return importGame(srcDir, mode, data => sendToWindow(win, 'import:progress', data))
|
||||
}
|
||||
|
||||
return { isRunning, listRunning, start, kill, runToolFor, import: importTo }
|
||||
return { isRunning, listRunning, start, kill, runToolFor, import: importTo, setOnGameExit }
|
||||
}
|
||||
|
||||
module.exports = { createGamesService, killProcessGroup, sendToWindow }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue