Skip to content

Save in-progress game history when the app is quit mid-session#95

Merged
acrosman merged 2 commits intomainfrom
copilot/save-history-on-quit
May 1, 2026
Merged

Save in-progress game history when the app is quit mid-session#95
acrosman merged 2 commits intomainfrom
copilot/save-history-on-quit

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 1, 2026

Quitting the app mid-game silently discarded the current session's progress because the game plugin's stop() method (which persists via the score service) was never called.

Approach

Intercept before-quit in the main process, ask the renderer to flush progress via IPC, then exit once confirmed — with a 5-second force-exit fallback.

Changes

  • main.jsbefore-quit now calls event.preventDefault(), sends app:before-quit to the renderer window, and starts a QUIT_TIMEOUT_MS (5s) watchdog. A new app:quit-ready IPC handler calls app.exit(0) once the renderer signals completion.

  • app/preload.js — Exposes a new receive(channel, callback) bridge method backed by ipcRenderer.once() (allowlist: app:before-quit); adds app:quit-ready to the invoke allowlist.

  • app/interface.js — Tracks the active plugin in activePlugin. Registers an app:before-quit handler during DOMContentLoaded that awaits activePlugin.stop(), then invokes app:quit-ready. Plugin reference is set on game load and cleared on return to the main menu.

// interface.js — quit handler (simplified)
window.api.receive('app:before-quit', async () => {
  if (activePlugin && typeof activePlugin.stop === 'function') {
    await activePlugin.stop();   // persists score via scoreService
  }
  await window.api.invoke('app:quit-ready');
});
  • Testspreload.test.js covers receive() allowlist and ipcRenderer.once wiring; interface.test.js adds 5 cases for the quit handler (active game, no game, stop throws, after return-to-menu).

Copilot AI linked an issue May 1, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Save player history on application quit Save in-progress game history when the app is quit mid-session May 1, 2026
Copilot AI requested a review from acrosman May 1, 2026 01:08
@acrosman acrosman marked this pull request as ready for review May 1, 2026 02:10
@acrosman acrosman merged commit 82a68fa into main May 1, 2026
6 checks passed
@acrosman acrosman deleted the copilot/save-history-on-quit branch May 1, 2026 02:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Save history on Quit

2 participants