Skip to content

Commit

Permalink
feat: inter-process menu communication
Browse files Browse the repository at this point in the history
  • Loading branch information
NGPixel committed Jan 16, 2024
1 parent 6c6d3cf commit 3eb216d
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 66 deletions.
9 changes: 5 additions & 4 deletions src-electron/electron-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function createWindow () {
}
})

registerMenu()
registerMenu(mainWindow)
// mainWindow.setMenu(null)

enable(mainWindow.webContents)
Expand All @@ -79,9 +79,10 @@ function createWindow () {
// -> Load start URL
mainWindow.loadURL(process.env.APP_URL)

// if (process.env.DEBUGGING) {
// // if on DEV or Production with debug enabled
// mainWindow.webContents.openDevTools()
if (process.env.DEBUGGING) {
// if on DEV or Production with debug enabled
mainWindow.webContents.openDevTools()
}
// } else {
// // we're on production; no access to devtools pls
// mainWindow.webContents.on('devtools-opened', () => {
Expand Down
23 changes: 6 additions & 17 deletions src-electron/electron-preload.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
import { contextBridge } from 'electron'
import { BrowserWindow } from '@electron/remote'
import { contextBridge, ipcRenderer } from 'electron'

contextBridge.exposeInMainWorld('myWindowAPI', {
minimize () {
BrowserWindow.getFocusedWindow().minimize()
contextBridge.exposeInMainWorld('menuEmitter', {
emit (channel, data) {
ipcRenderer.send(channel, data)
},

toggleMaximize () {
const win = BrowserWindow.getFocusedWindow()

if (win.isMaximized()) {
win.unmaximize()
} else {
win.maximize()
}
},

close () {
BrowserWindow.getFocusedWindow().close()
subscribe (channel, callback) {
ipcRenderer.on(channel, callback)
}
})
69 changes: 24 additions & 45 deletions src-electron/menu.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,10 @@
import { globalShortcut, Menu } from 'electron'
import { Menu, shell } from 'electron'
import os from 'os'

function FileNewDraft () {

}
function FileOpen () {

}
function FileSave () {

}
function FileSaveAs () {

}
function FileMoveTo () {

}
function FilePreferences () {

}

export function registerMenu () {
export function registerMenu (mainWindow) {
const platform = process.platform || os.platform()
const isMac = platform === 'darwin'

/**
* Global Shortcuts
*/
globalShortcut.register('CommandOrControl+N', FileNewDraft)
globalShortcut.register('CommandOrControl+O', FileOpen)
globalShortcut.register('CommandOrControl+S', FileSave)
globalShortcut.register('CommandOrControl+Shift+S', FileSaveAs)

/**
* Menu Template
*/
Expand All @@ -42,13 +15,11 @@ export function registerMenu () {
submenu: [
{
label: 'New Draft...',
accelerator: 'CommandOrControl+N',
click: FileNewDraft
accelerator: 'CommandOrControl+N'
},
{
label: 'Open...',
accelerator: 'CommandOrControl+O',
click: FileOpen
accelerator: 'CommandOrControl+O'
},
{
label: 'Open Recent',
Expand All @@ -61,17 +32,14 @@ export function registerMenu () {
},
{
label: 'Save',
accelerator: 'CommandOrControl+S',
click: FileSave
accelerator: 'CommandOrControl+S'
},
{
label: 'Save As...',
accelerator: 'CommandOrControl+Shift+S',
click: FileSaveAs
accelerator: 'CommandOrControl+Shift+S'
},
{
label: 'Move To...',
click: FileMoveTo
label: 'Move To...'
},
{
label: 'Export',
Expand Down Expand Up @@ -103,8 +71,7 @@ export function registerMenu () {
type: 'separator'
},
{
label: 'Preferences',
click: FilePreferences
label: 'Preferences'
},
{
type: 'separator'
Expand Down Expand Up @@ -325,13 +292,22 @@ export function registerMenu () {
},
{ type: 'separator' },
{
label: 'Release Notes'
label: 'Release Notes',
click () {
shell.openExternal('https://github.com/ietf-tools/editor/releases')
}
},
{
label: 'Report Issue'
label: 'Report Issue',
click () {
shell.openExternal('https://github.com/ietf-tools/editor/issues')
}
},
{
label: 'View License'
label: 'View License',
click () {
shell.openExternal('https://github.com/ietf-tools/editor/blob/main/LICENSE')
}
},
{ type: 'separator' },
{
Expand All @@ -354,7 +330,10 @@ export function registerMenu () {
},
{ type: 'separator' },
{
label: 'About'
label: 'About',
click () {
mainWindow.webContents.send('menuAction', 'helpAbout')
}
}
]
}
Expand Down
17 changes: 17 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,22 @@
</template>

<script setup>
import { defineAsyncComponent } from 'vue'
import { useQuasar } from 'quasar'
const $q = useQuasar()
function helpAbout () {
$q.dialog({
component: defineAsyncComponent(() => import('components/AboutDialog.vue'))
})
}
window.menuEmitter.subscribe('menuAction', (evt, action) => {
switch (action) {
case 'helpAbout':
helpAbout()
break
}
})
</script>

0 comments on commit 3eb216d

Please sign in to comment.