[READ-ONLY] Mirror of https://github.com/probablykasper/ferrum. Music library app for Mac, Linux and Windows ferrum.kasper.space
electron linux macos music music-library music-player napi windows
0

Configure Feed

Select the types of activity you want to include in your feed.

Fix graceful shutdown

Kasper (Sep 18, 2024, 9:48 AM +0200) 98ce2d4c c92e93fb

+20 -6
+7 -1
src/App.svelte
··· 30 30 import Route from './lib/Route.svelte' 31 31 import { navigate_back, navigate_forward } from './lib/router' 32 32 33 - ipc_renderer.emit('appLoaded') 33 + ipc_renderer.invoke('app_loaded').catch(() => { 34 + ipc_renderer.invoke('showMessageBox', false, { 35 + type: 'error', 36 + message: 'Failed to signal app loading', 37 + detail: 'Graceful shutdown will not be possible.', 38 + }) 39 + }) 34 40 35 41 async function open_import_dialog() { 36 42 if ($modal_count !== 0) {
+11 -4
src/electron/main.ts
··· 9 9 import('./ipc') 10 10 import path from 'path' 11 11 import url from 'url' 12 + import { ipc_main } from './typed_ipc' 12 13 13 14 async function err_handler(msg: string, error: Error) { 14 15 app.whenReady().then(() => { ··· 142 143 main_window.on('closed', () => { 143 144 main_window = null 144 145 }) 145 - ipcMain.once('appLoaded', () => { 146 + ipc_main.handle('app_loaded', () => { 146 147 app_loaded = true 147 148 }) 148 149 149 - // doesn't fire on Windows :( 150 - app.on('before-quit', () => { 151 - if (app_loaded) { 150 + // doesn't always fire on Windows :( 151 + app.on('before-quit', (e) => { 152 + if (quitting) { 153 + return 154 + } else if (app_loaded) { 155 + console.log('Preparing to quit') 156 + e.preventDefault() 152 157 main_window?.webContents.send('gonnaQuit') 153 158 ipcMain.once('readyToQuit', () => { 159 + console.log('Quitting gracefully') 154 160 quitting = true 155 161 main_window?.close() 156 162 }) 157 163 } else { 164 + console.log('Quitting immediately') 158 165 quitting = true 159 166 main_window?.close() 160 167 }
+1
src/electron/typed_ipc.ts
··· 145 145 } 146 146 147 147 type Commands = { 148 + app_loaded: () => void 148 149 showMessageBox: ( 149 150 attached: boolean, 150 151 options: Parameters<typeof dialog.showMessageBox>[0],
+1 -1
vite.config.mjs
··· 26 26 entry: ['./src/electron/main.ts', './src/electron/preload.ts'], 27 27 onstart({ startup }) { 28 28 if (process.electronApp) { 29 - console.log('\x1b[33mNot restarting\x1b[0m') 29 + process.kill(process.electronApp.pid, 'SIGTERM') 30 30 } else { 31 31 startup() 32 32 }