Skip to content

Commit

Permalink
feat(media): add custom menu, refactor events into separate module
Browse files Browse the repository at this point in the history
  • Loading branch information
BenShelton committed May 11, 2021
1 parent f69428d commit 4f73527
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 13 deletions.
17 changes: 17 additions & 0 deletions packages/media/app/main/src/events.ts
Original file line number Diff line number Diff line change
@@ -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()
})
}
22 changes: 9 additions & 13 deletions packages/media/app/main/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
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)

// setup everything else
await app.whenReady()
initIPC()

// start app
await createWindows()
})()
17 changes: 17 additions & 0 deletions packages/media/app/main/src/menu.ts
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 4f73527

Please # to comment.