diff --git a/packages/media/app/main/src/events.ts b/packages/media/app/main/src/events.ts new file mode 100644 index 0000000..ce6e875 --- /dev/null +++ b/packages/media/app/main/src/events.ts @@ -0,0 +1,17 @@ +import { app } from 'electron' + +import { refocusWindows } from './window' + +export function initEvents (): void { + app.on('activate', async () => { + await refocusWindows() + }) + + app.on('second-instance', async () => { + await refocusWindows() + }) + + app.on('window-all-closed', () => { + app.quit() + }) +} diff --git a/packages/media/app/main/src/index.ts b/packages/media/app/main/src/index.ts index 0e43291..d58d387 100644 --- a/packages/media/app/main/src/index.ts +++ b/packages/media/app/main/src/index.ts @@ -1,27 +1,21 @@ import { app } from 'electron' import { createDir } from '@library-api/core' +import { initEvents } from './events' import { initIPC } from './ipc' -import { createWindows, refocusWindows } from './window' +import { initMenu } from './menu' +import { createWindows } from './window' import { DOWNLOAD_DIR, VIDEO_DIR } from './constants' if (!app.requestSingleInstanceLock()) { app.quit() } -app.on('activate', async () => { - await refocusWindows() -}) +(async () => { + // configure app + initMenu() + initEvents() -app.on('second-instance', async () => { - await refocusWindows() -}) - -app.on('window-all-closed', () => { - app.quit() -}) - -;(async () => { // setup system files await createDir(DOWNLOAD_DIR) await createDir(VIDEO_DIR) @@ -29,5 +23,7 @@ app.on('window-all-closed', () => { // setup everything else await app.whenReady() initIPC() + + // start app await createWindows() })() diff --git a/packages/media/app/main/src/menu.ts b/packages/media/app/main/src/menu.ts new file mode 100644 index 0000000..b03a713 --- /dev/null +++ b/packages/media/app/main/src/menu.ts @@ -0,0 +1,17 @@ +import { Menu } from 'electron' +import { MenuItemConstructorOptions } from 'electron/main' + +const appName = 'Library Media' +const template: MenuItemConstructorOptions[] = [ + { + label: appName, + submenu: [ + { role: 'quit', label: `Quit ${appName}` } + ] + } +] + +export function initMenu (): void { + const menu = Menu.buildFromTemplate(template) + Menu.setApplicationMenu(menu) +}