Skip to content

Commit

Permalink
Add support for key bindings (and copy/paste)
Browse files Browse the repository at this point in the history
  • Loading branch information
bellingard committed Jun 1, 2019
1 parent b53283c commit 7fafe6e
Showing 1 changed file with 71 additions and 7 deletions.
78 changes: 71 additions & 7 deletions src/background.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
'use strict'

import { app, protocol, BrowserWindow } from 'electron'
import {
createProtocol,
installVueDevtools
} from 'vue-cli-plugin-electron-builder/lib'
import { app, protocol, BrowserWindow, Menu } from 'electron'
import { createProtocol, installVueDevtools } from 'vue-cli-plugin-electron-builder/lib'
const isDevelopment = process.env.NODE_ENV !== 'production'

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win: (BrowserWindow|null)
let win: BrowserWindow | null

// Standard scheme must be registered before the app is ready
protocol.registerStandardSchemes(['app'], { secure: true })
function createWindow () {
function createWindow() {
// Create the browser window.
win = new BrowserWindow({ width: 800, height: 600 })
win.maximize()
Expand All @@ -31,6 +28,73 @@ function createWindow () {
win.on('closed', () => {
win = null
})

createMenu()
}

function createMenu() {
const application = {
label: 'Application',
submenu: [
{
label: 'About Application',
selector: 'orderFrontStandardAboutPanel:'
},
{
type: 'separator'
},
{
label: 'Quit',
accelerator: 'Command+Q',
click: () => {
app.quit()
}
}
]
}

const edit = {
label: 'Edit',
submenu: [
{
label: 'Undo',
accelerator: 'CmdOrCtrl+Z',
selector: 'undo:'
},
{
label: 'Redo',
accelerator: 'Shift+CmdOrCtrl+Z',
selector: 'redo:'
},
{
type: 'separator'
},
{
label: 'Cut',
accelerator: 'CmdOrCtrl+X',
selector: 'cut:'
},
{
label: 'Copy',
accelerator: 'CmdOrCtrl+C',
selector: 'copy:'
},
{
label: 'Paste',
accelerator: 'CmdOrCtrl+V',
selector: 'paste:'
},
{
label: 'Select All',
accelerator: 'CmdOrCtrl+A',
selector: 'selectAll:'
}
]
}

const template: any = [application, edit]

Menu.setApplicationMenu(Menu.buildFromTemplate(template))
}

// Quit when all windows are closed.
Expand Down

0 comments on commit 7fafe6e

Please sign in to comment.