-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support For Standard OSX shortcuts - CMD+Q, CMD+V, CMD+X, CMD+Z, CMD+C
- Loading branch information
Artur Skowronski
committed
Sep 23, 2016
1 parent
a813748
commit 9bb1d74
Showing
6 changed files
with
61 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,102 +1,41 @@ | ||
const electron = require('electron') | ||
|
||
const menubar = require('menubar') | ||
const {Menu} = require('electron') | ||
require('electron-reload')(__dirname); | ||
var ipc = electron.ipcMain; | ||
require('electron-debug')({showDevTools: false}); | ||
|
||
// Module to control application life. | ||
const app = electron.app | ||
const globalShortcut = electron.globalShortcut | ||
// Module to create native browser window. | ||
// Module to create native browser window. | ||
const BrowserWindow = electron.BrowserWindow | ||
const menubar = require('menubar') | ||
const MenuTemplate = require('./src/clipboard.js').template | ||
const Keymap = require('./src/keymap.js') | ||
const ipc = electron.ipcMain; | ||
|
||
const mb = menubar( | ||
{ | ||
const menuBarConfiguration = { | ||
width: 400, | ||
height: 600, | ||
icon: __dirname + '/assets/keep.png', | ||
preloadWindow: true | ||
} | ||
) | ||
// console.log(menubar) | ||
// mb.window.loadURL(`https://keep.google.com/`) | ||
mb.on('ready', function ready () { | ||
// console.log(mb) | ||
} | ||
|
||
const mb = menubar(menuBarConfiguration) | ||
|
||
// your app code here | ||
}) | ||
mb.on('after-create-window', function ready () { | ||
mb.window.focus(); | ||
// your app code here | ||
}) | ||
|
||
|
||
|
||
mb.app.on('ready', () => { | ||
// Register a 'CommandOrControl+X' shortcut listener. | ||
const ret = globalShortcut.register('CommandOrControl+Alt+K', () => { | ||
mb.showWindow() | ||
}) | ||
|
||
if (!ret) { | ||
console.log('registration failed') | ||
} | ||
|
||
Menu.setApplicationMenu(Menu.buildFromTemplate(MenuTemplate(mb.app))); | ||
Keymap.initializeKeymap(electron.globalShortcut, | ||
[{shorcut: 'CommandOrControl+Alt+K', function: mb.showWindow}] | ||
) | ||
|
||
// Check whether a shortcut is registered. | ||
console.log(globalShortcut.isRegistered('CommandOrControl+X')) | ||
}) | ||
|
||
// 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 mainWindow | ||
|
||
function createWindow () { | ||
// Create the browser window. | ||
mainWindow = new BrowserWindow({width: 200, height: 600, frame: false, icon: __dirname + '/assets/icon.ico'}) | ||
|
||
// and load the index.html of the app. | ||
mainWindow.loadURL(`https://keep.google.com/`) | ||
|
||
// Open the DevTools. | ||
// mainWindow.webContents.openDevTools() | ||
|
||
// Emitted when the window is closed. | ||
mainWindow.on('closed', function () { | ||
// Dereference the window object, usually you would store windows | ||
// in an array if your app supports multi windows, this is the time | ||
// when you should delete the corresponding element. | ||
mainWindow = null | ||
|
||
}) | ||
} | ||
|
||
// This method will be called when Electron has finished | ||
// initialization and is ready to create browser windows. | ||
// Some APIs can only be used after this event occurs. | ||
// app.on('ready', createWindow) | ||
|
||
// Quit when all windows are closed. | ||
app.on('window-all-closed', function () { | ||
// On OS X it is common for applications and their menu bar | ||
// to stay active until the user quits explicitly with Cmd + Q | ||
mb.app.on('window-all-closed', function () { | ||
if (process.platform !== 'darwin') { | ||
app.quit() | ||
mb.app.quit() | ||
} | ||
}) | ||
|
||
mb.app.on('will-quit', () => { | ||
// Unregister all shortcuts. | ||
globalShortcut.unregisterAll() | ||
}) | ||
|
||
app.on('activate', function () { | ||
// On OS X it's common to re-create a window in the app when the | ||
// dock icon is clicked and there are no other windows open. | ||
if (mainWindow === null) { | ||
createWindow() | ||
} | ||
}) | ||
|
||
// In this file you can include the rest of your app's specific main process | ||
// code. You can also put them in separate files and require them here. | ||
electron.globalShortcut.unregisterAll() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
exports.template = (app) => { | ||
return [{ | ||
label: "Application", | ||
submenu: [ | ||
{ label: "About Application", selector: "orderFrontStandardAboutPanel:" }, | ||
{ type: "separator" }, | ||
{ label: "Quit", accelerator: "Command+Q", click: function() { app.quit(); }} | ||
]}, { | ||
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:" } | ||
]} | ||
]}; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
exports.initializeKeymap = (globalShortcut, keymap) => { | ||
|
||
keymap.forEach((x) => { | ||
if (!x.shorcut || !x.function) { | ||
console.log(`Keeptron: Shortcut ${x.shorcut} not registered for function ${x.function}`) | ||
return; | ||
} | ||
|
||
var ret = globalShortcut.register(x.shorcut, x.function) | ||
|
||
if (ret && globalShortcut.isRegistered('CommandOrControl+Alt+K')) { | ||
console.log(`Keeptron: Shortcut ${x.shorcut} registered properly`) | ||
} else { | ||
console.log(`Keeptron: Shortcut ${x.shorcut} not registered`) | ||
} | ||
|
||
}) | ||
} |