Skip to content

Commit

Permalink
Support For Standard OSX shortcuts - CMD+Q, CMD+V, CMD+X, CMD+Z, CMD+C
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur Skowronski committed Sep 23, 2016
1 parent a813748 commit 9bb1d74
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 83 deletions.
7 changes: 4 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<!DOCTYPE html>
<html style="margin:0;padding:0">
<head>
<script src="https://code.jquery.com/jquery-3.1.0.js" integrity="sha256-slogkvB1K3VOkzAI8QITxV3VzpOnkeNVsKvtkYLMjfk=" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.1.0.js" integrity="sha256-slogkvB1K3VOkzAI8QITxV3VzpOnkeNVsKvtkYLMjfk=" crossorigin="anonymous"></script>
<title>jQuery injection into webview preload</title>
</head>
<body style="margin:0px; padding:0px;overflow:hidden;">
<webview id="webview" preload="./manipulateGoogle.js" src="http://keep.google.com" style="position:absolute;width:100%;height:100%;"></webview>
<webview id="webview" preload="./src/injectKeep.js" src="http://keep.google.com" style="position:absolute;width:100%;height:100%;"></webview>
<script>
var webview = document.getElementById("webview")
webview.addEventListener("dom-ready", function() {
webview.addEventListener("loadcommit", function() {
webview.insertCSS(".gb_ec { background-color: red !important; }");
});
</script>
</body>
Expand Down
99 changes: 19 additions & 80 deletions main.js
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()
})
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"electron": "^1.3.4"
},
"dependencies": {
"electron-debug": "1.0.1",
"electron-reload": "1.0.2",
"menubar": "5.1.0"
}
Expand Down
19 changes: 19 additions & 0 deletions src/clipboard.js
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.
18 changes: 18 additions & 0 deletions src/keymap.js
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`)
}

})
}

0 comments on commit 9bb1d74

Please sign in to comment.