Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/kasper9n/ferrum. Music library app for Mac, Linux and Windows ferrum.kasper.space
electron linux macos music music-library music-player napi windows
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738import { ipc_renderer } from './window'
let unfinished_tasks = 0export function not_ready() { unfinished_tasks++}export function ready() { unfinished_tasks-- try_to_quit()}
type Callback = () => void | Promise<void>interface Handlers { [key: string]: Callback}const handlers: Handlers = {}function set_handler(name: string, callback: Callback) { handlers[name] = callback}
export default { not_ready, ready, set_handler }
function try_to_quit() { if (unfinished_tasks === 0) { ipc_renderer.send('readyToQuit') }}
not_ready()ipc_renderer.on('gonnaQuit', async function () { for (const key of Object.keys(handlers)) { const handler = handlers[key] const async_handler = await Promise.resolve(handler) await async_handler() } ready()})