diff --git a/app/main.js b/app/main.js index 797cca3..4ab65b1 100644 --- a/app/main.js +++ b/app/main.js @@ -99,6 +99,9 @@ app.on('window-all-closed', function() { } }); +require('electron-debug')({ + showDevTools: false +}); let mainWindow; // This method will be called when Electron has finished @@ -139,9 +142,6 @@ app.on('ready', function() { // mainWindow.loadURL('http://oleg.dev:8000/index-dev.html'); // mainWindow.loadURL('http://oleg.dev:8000/index.html'); - // 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 diff --git a/app/node_modules/electron-debug/index.js b/app/node_modules/electron-debug/index.js new file mode 100644 index 0000000..39607e0 --- /dev/null +++ b/app/node_modules/electron-debug/index.js @@ -0,0 +1,40 @@ +'use strict'; +const electron = require('electron'); +const localShortcut = require('electron-localshortcut'); +const app = electron.app; +const BrowserWindow = electron.BrowserWindow; +const isOSX = process.platform === 'darwin'; + +function devTools(win) { + win = win || BrowserWindow.getFocusedWindow(); + + if (win) { + win.toggleDevTools(); + } +} + +function refresh() { + const win = BrowserWindow.getFocusedWindow(); + + if (win) { + win.webContents.reloadIgnoringCache(); + } +} + +module.exports = opts => { + opts = opts || {}; + + app.on('browser-window-created', (e, win) => { + if (opts.showDevTools) { + devTools(win); + } + }); + + app.on('ready', () => { + localShortcut.register(isOSX ? 'Cmd+Alt+I' : 'Ctrl+Shift+I', devTools); + localShortcut.register('F12', devTools); + + localShortcut.register('CmdOrCtrl+R', refresh); + localShortcut.register('F5', refresh); + }); +}; diff --git a/app/node_modules/electron-debug/license b/app/node_modules/electron-debug/license new file mode 100644 index 0000000..654d0bf --- /dev/null +++ b/app/node_modules/electron-debug/license @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) Sindre Sorhus (sindresorhus.com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/app/node_modules/electron-debug/package.json b/app/node_modules/electron-debug/package.json new file mode 100644 index 0000000..c79c280 --- /dev/null +++ b/app/node_modules/electron-debug/package.json @@ -0,0 +1,95 @@ +{ + "_args": [ + [ + "electron-debug", + "C:\\Users\\Anatoly\\chat-client-electron\\app" + ] + ], + "_from": "electron-debug@*", + "_id": "electron-debug@0.5.1", + "_inCache": true, + "_installable": true, + "_location": "/electron-debug", + "_nodeVersion": "4.2.1", + "_npmUser": { + "email": "sindresorhus@gmail.com", + "name": "sindresorhus" + }, + "_npmVersion": "2.14.7", + "_phantomChildren": {}, + "_requested": { + "name": "electron-debug", + "raw": "electron-debug", + "rawSpec": "", + "scope": null, + "spec": "*", + "type": "range" + }, + "_requiredBy": [ + "/" + ], + "_resolved": "https://registry.npmjs.org/electron-debug/-/electron-debug-0.5.1.tgz", + "_shasum": "099446bd60f1958f80a592a975dd3a87f2888bcf", + "_shrinkwrap": null, + "_spec": "electron-debug", + "_where": "C:\\Users\\Anatoly\\chat-client-electron\\app", + "author": { + "email": "sindresorhus@gmail.com", + "name": "Sindre Sorhus", + "url": "sindresorhus.com" + }, + "bugs": { + "url": "https://github.com/sindresorhus/electron-debug/issues" + }, + "dependencies": { + "electron-localshortcut": "^0.6.0" + }, + "description": "Adds useful debug features to your Electron app", + "devDependencies": { + "electron-prebuilt": "^0.35.0", + "xo": "*" + }, + "directories": {}, + "dist": { + "shasum": "099446bd60f1958f80a592a975dd3a87f2888bcf", + "tarball": "http://registry.npmjs.org/electron-debug/-/electron-debug-0.5.1.tgz" + }, + "files": [ + "index.js" + ], + "gitHead": "f402ee8fcbd8445038fa4379b71c906db0f6595d", + "homepage": "https://github.com/sindresorhus/electron-debug", + "keywords": [ + "app", + "debug", + "dev", + "devtools", + "electron" + ], + "license": "MIT", + "maintainers": [ + { + "name": "sindresorhus", + "email": "sindresorhus@gmail.com" + } + ], + "name": "electron-debug", + "optionalDependencies": {}, + "readme": "ERROR: No README data found!", + "repository": { + "type": "git", + "url": "git+https://github.com/sindresorhus/electron-debug.git" + }, + "scripts": { + "start": "electron test.js", + "test": "xo" + }, + "version": "0.5.1", + "xo": { + "envs": [ + "browser", + "node" + ], + "esnext": true + } +} diff --git a/app/node_modules/electron-debug/readme.md b/app/node_modules/electron-debug/readme.md new file mode 100644 index 0000000..262a2eb --- /dev/null +++ b/app/node_modules/electron-debug/readme.md @@ -0,0 +1,70 @@ +# electron-debug + +> Adds useful debug features to your [Electron](http://electron.atom.io) app + +Ideas for more debug features [welcome!](https://github.com/sindresorhus/electron-debug/issues/new) + + +## Features + +### DevTools + +Toggle DevTools. + +- OS X: Cmd Alt I or F12 +- Linux: Ctrl Shift I or F12 +- Windows: Ctrl Shift I or F12 + +### Reload + +Force reload the window. + +- OS X: Cmd R or F5 +- Linux: Ctrl R or F5 +- Windows: Ctrl R or F5 + + +## Install + +``` +$ npm install --save electron-debug +``` + + +## Usage + +```js +const {app, BrowserWindow} = require('electron'); + +require('electron-debug')({ + showDevTools: true +}); + +let win; + +app.on('ready', () => { + win = new BrowserWindow({ + width: 800, + height: 600 + }); +}); +``` + +### Options + +#### showDevTools + +Type: `boolean` +Default: `false` + +Show DevTools on startup. + + +## Related + +- [debug-menu](https://github.com/parro-it/debug-menu) - Chrome-like debug context-menu for Electron + + +## License + +MIT © [Sindre Sorhus](http://sindresorhus.com) diff --git a/app/node_modules/electron-localshortcut/index.js b/app/node_modules/electron-localshortcut/index.js new file mode 100644 index 0000000..53364ed --- /dev/null +++ b/app/node_modules/electron-localshortcut/index.js @@ -0,0 +1,149 @@ +'use strict'; + +const electron = require('electron'); +const globalShortcut = electron.globalShortcut; +const BrowserWindow = electron.BrowserWindow; +const app = electron.app; +const windowsWithShortcuts = new WeakMap(); + +// a placeholder to register shortcuts +// on any window of the app. +const ANY_WINDOW = {}; + +function isAccelerator(arg) { + return typeof arg === 'string'; +} + +function unregisterAllShortcuts(win) { + const shortcuts = windowsWithShortcuts.get(win); + shortcuts.forEach( sc => + globalShortcut.unregister(sc.accelerator) + ); +} + +function registerAllShortcuts(win) { + const shortcuts = windowsWithShortcuts.get(win); + + shortcuts.forEach( sc => + globalShortcut.register(sc.accelerator, sc.callback) + ); +} + +function unregisterAll(win) { + if (win === undefined) { + // unregister shortcuts for any window in the app + unregisterAll(ANY_WINDOW); + return; + } + + if (!windowsWithShortcuts.has(win)) { + return; + } + + unregisterAllShortcuts(win); + windowsWithShortcuts.delete(win); +} + +function register(win, accelerator, callback) { + if (arguments.length === 2 && isAccelerator(win)) { + // register shortcut for any window in the app + // win = accelerator, accelerator = callback + register(ANY_WINDOW, win, accelerator); + return; + } + + if (windowsWithShortcuts.has(win)) { + const shortcuts = windowsWithShortcuts.get(win); + shortcuts.push({ + accelerator: accelerator, + callback: callback + }); + } else { + windowsWithShortcuts.set(win, [{ + accelerator: accelerator, + callback: callback + }]); + } + + const focusedWin = BrowserWindow.getFocusedWindow(); + if ((win === ANY_WINDOW && focusedWin !== null) || focusedWin === win) { + globalShortcut.register(accelerator, callback); + } +} + +function indexOfShortcut(win, accelerator) { + if (!windowsWithShortcuts.has(win)) { + return -1; + } + + const shortcuts = windowsWithShortcuts.get(win); + let shortcutToUnregisterIdx = -1; + shortcuts.some((s, idx) => { + if (s.accelerator === accelerator) { + shortcutToUnregisterIdx = idx; + return true; + } + return false; + }); + return shortcutToUnregisterIdx; +} + +function unregister(win, accelerator) { + if (arguments.length === 1 && isAccelerator(win)) { + // unregister shortcut for any window in the app + // win = accelerator + unregister(ANY_WINDOW, win); + return; + } + const shortcutToUnregisterIdx = indexOfShortcut(win, accelerator); + + if (shortcutToUnregisterIdx !== -1) { + globalShortcut.unregister(accelerator); + const shortcuts = windowsWithShortcuts.get(win); + shortcuts.splice(shortcutToUnregisterIdx); + } +} + +function isRegistered(win, accelerator) { + if (arguments.length === 1 && isAccelerator(win)) { + // check shortcut for any window in the app + // win = accelerator + return isRegistered(ANY_WINDOW, win); + } + + return indexOfShortcut(win, accelerator) !== -1; +} + + +app.on('browser-window-focus', (e, win) => { + if (windowsWithShortcuts.has(ANY_WINDOW)) { + registerAllShortcuts(ANY_WINDOW); + } + + if (!windowsWithShortcuts.has(win)) { + return; + } + + registerAllShortcuts(win); +}); + +app.on('browser-window-blur', (e, win) => { + if (windowsWithShortcuts.has(ANY_WINDOW)) { + unregisterAllShortcuts(ANY_WINDOW); + } + + if (!windowsWithShortcuts.has(win)) { + return; + } + + unregisterAllShortcuts(win); +}); + +module.exports = { + register: register, + unregister: unregister, + isRegistered: isRegistered, + unregisterAll: unregisterAll, + enableAll: registerAllShortcuts, + disableAll: unregisterAllShortcuts +}; diff --git a/app/node_modules/electron-localshortcut/license b/app/node_modules/electron-localshortcut/license new file mode 100644 index 0000000..9a12c7d --- /dev/null +++ b/app/node_modules/electron-localshortcut/license @@ -0,0 +1,22 @@ +The MIT License (MIT) +Copyright (c) 2015 Andrea Parodi + + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE +OR OTHER DEALINGS IN THE SOFTWARE. + diff --git a/app/node_modules/electron-localshortcut/package.json b/app/node_modules/electron-localshortcut/package.json new file mode 100644 index 0000000..bb2029b --- /dev/null +++ b/app/node_modules/electron-localshortcut/package.json @@ -0,0 +1,82 @@ +{ + "_args": [ + [ + "electron-localshortcut@^0.6.0", + "C:\\Users\\Anatoly\\chat-client-electron\\app\\node_modules\\electron-debug" + ] + ], + "_from": "electron-localshortcut@>=0.6.0 <0.7.0", + "_id": "electron-localshortcut@0.6.0", + "_inCache": true, + "_installable": true, + "_location": "/electron-localshortcut", + "_nodeVersion": "5.0.0", + "_npmUser": { + "email": "andrea.parodi@ebansoftware.net", + "name": "parroit" + }, + "_npmVersion": "3.3.6", + "_phantomChildren": {}, + "_requested": { + "name": "electron-localshortcut", + "raw": "electron-localshortcut@^0.6.0", + "rawSpec": "^0.6.0", + "scope": null, + "spec": ">=0.6.0 <0.7.0", + "type": "range" + }, + "_requiredBy": [ + "/electron-debug" + ], + "_resolved": "https://registry.npmjs.org/electron-localshortcut/-/electron-localshortcut-0.6.0.tgz", + "_shasum": "3d1c81833dfaa658c009c79bf74ddb56692554e6", + "_shrinkwrap": null, + "_spec": "electron-localshortcut@^0.6.0", + "_where": "C:\\Users\\Anatoly\\chat-client-electron\\app\\node_modules\\electron-debug", + "author": { + "name": "andrea@parro.it" + }, + "bugs": { + "url": "https://github.com/parro-it/electron-localshortcut/issues" + }, + "dependencies": {}, + "description": "register/unregister a keyboard shortcut locally to a BrowserWindow instance, without using a Menu", + "devDependencies": {}, + "directories": {}, + "dist": { + "shasum": "3d1c81833dfaa658c009c79bf74ddb56692554e6", + "tarball": "http://registry.npmjs.org/electron-localshortcut/-/electron-localshortcut-0.6.0.tgz" + }, + "eslintConfig": { + "extends": "eslint-config-devenv" + }, + "files": [ + "index.js" + ], + "gitHead": "ce8364ab51a94fa51187236b664a28d5d13a401d", + "homepage": "https://github.com/parro-it/electron-localshortcut#readme", + "keywords": [ + "browser-window", + "electron", + "shortcuts" + ], + "license": "MIT", + "maintainers": [ + { + "name": "parroit", + "email": "andrea.parodi@ebansoftware.net" + } + ], + "name": "electron-localshortcut", + "optionalDependencies": {}, + "readme": "ERROR: No README data found!", + "repository": { + "type": "git", + "url": "git+https://github.com/parro-it/electron-localshortcut.git" + }, + "scripts": { + "start": "electron test.js", + "test": "eslint ." + }, + "version": "0.6.0" +} diff --git a/app/node_modules/electron-localshortcut/readme.md b/app/node_modules/electron-localshortcut/readme.md new file mode 100644 index 0000000..c8a3d3b --- /dev/null +++ b/app/node_modules/electron-localshortcut/readme.md @@ -0,0 +1,134 @@ +# electron-localshortcut + +A module to register/unregister a keyboard shortcut +locally to a BrowserWindow instance, without using a Menu. + +This is built to circumvent [this Electron issue](https://github.com/atom/electron/issues/1334). + +**Note:** Since this module internally use `global-shortcut` native module, you should not use it until the `ready` event of the app module is emitted. See [electron docs](https://github.com/atom/electron/edit/master/docs/api/global-shortcut.md). + +[![Travis Build Status](https://img.shields.io/travis/parro-it/electron-localshortcut.svg)](http://travis-ci.org/parro-it/electron-localshortcut) +[![NPM module](https://img.shields.io/npm/v/electron-localshortcut.svg)](https://npmjs.org/package/electron-localshortcut) +[![NPM downloads](https://img.shields.io/npm/dt/electron-localshortcut.svg)](https://npmjs.org/package/electron-localshortcut) + + +## Installation + +```bash +npm install --save electron-localshortcut +``` + +## Usage + +```javascript + const electronLocalshortcut = require('electron-localshortcut'); + const BrowserWindow = require('electron').BrowserWindow; + + const win = new BrowserWindow(); + win.loadUrl('https://github.com'); + win.show(); + + electronLocalshortcut.register(win, 'Ctrl+A', () => { + console.log('You pressed ctrl & A'); + }); + + electronLocalshortcut.register(win, 'Ctrl+B', () => { + console.log('You pressed ctrl & B'); + }); + + console.log( + electronLocalshortcut.isRegistered(win, 'Ctrl+A') + ); // true + + electronLocalshortcut.unregister(win, 'Ctrl+A'); + electronLocalshortcut.unregisterAll(win); + + +``` + +## Methods + +The `electron-localshortcut` module has following methods: + +### `register(window, accelerator, callback)` + +* `window` BrowserWindow instance +* `accelerator` [Accelerator](https://github.com/atom/electron/blob/master/docs/api/accelerator.md) +* `callback` Function + +Registers a shortcut of `accelerator` on the `window` BrowserWindow instance. The `callback` is called when the registered shortcut is pressed by the user, only if `window` is focused. + +### `isRegistered(window, accelerator)` + +* `window` BrowserWindow instance +* `accelerator` [Accelerator](https://github.com/atom/electron/blob/master/docs/api/accelerator.md) + +Returns `true` or `false` depending on whether the shortcut `accelerator` is +registered on `window`. + +### `unregister(window, accelerator)` + +* `window` BrowserWindow instance +* `accelerator` [Accelerator](https://github.com/atom/electron/blob/master/docs/api/accelerator.md) + +Unregisters the shortcut of `accelerator` registered on the BrowserWindow instance. + +### `unregisterAll(window)` + +* `window` BrowserWindow instance + +Unregisters all of the shortcuts registered on the BrowserWindow instance. + +### `disableAll(window)` + +* `window` BrowserWindow instance + +Disable all of the shortcuts registered on the BrowserWindow instance. +Registered shortcuts no more works on the `window` instance, but the module keep a reference on them. You can reactivate them later by calling `enableAll` method on the same window instance. + +### `enableAll(window)` + +* `window` BrowserWindow instance + +Enable all of the shortcuts registered on the BrowserWindow instance that you had previously disabled calling `disableAll` method. + + +## Global shortcuts + +This set of methods allow you to manage shortcuts that work on any window of your app. They are active only when a window in the app is focused. + +They differ from native [global-shortcuts](https://github.com/atom/electron/blob/master/docs/api/global-shortcut.md) because they doesn't interfere with other apps running on the same machine. + +### `register(accelerator, callback)` + +* `accelerator` [Accelerator](https://github.com/atom/electron/blob/master/docs/api/accelerator.md) +* `callback` Function + +Registers a shortcut of `accelerator` on any focused BrowserWindow instance. The `callback` is called when the registered shortcut is pressed by the user, only if a BrowserWindow is focused. + +### `isRegistered(accelerator)` + +* `accelerator` [Accelerator](https://github.com/atom/electron/blob/master/docs/api/accelerator.md) + +Returns `true` or `false` depending on whether the shortcut `accelerator` is registered on all focused instances. If you registered the shortcut on a particular instance, this method +return false. + +### `unregister(accelerator)` + +* `accelerator` [Accelerator](https://github.com/atom/electron/blob/master/docs/api/accelerator.md) + +Unregisters the shortcut of `accelerator` registered on all focused instances. This method does not unregister any shortcut you +registered on a particular window instance. + +### `unregisterAll()` + +Unregisters all of the shortcuts registered on any focused BrowserWindow instance. This method does not unregister any shortcut you registered on a particular window instance. + +## License + +The MIT License (MIT) + +Copyright (c) 2015 Andrea Parodi + + + diff --git a/app/package.json b/app/package.json index 30df6c0..e335778 100644 --- a/app/package.json +++ b/app/package.json @@ -5,6 +5,7 @@ "author": "Algorithm LLC", "main": "main.js", "dependencies": { + "electron-debug": "^0.5.1", "electron-gh-releases": "^2.0.2" } } diff --git a/package.json b/package.json index 0c6e4d9..e1c8437 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "1.0.1", + "version": "1.0.2", "dependencies": { "grunt": "^0.4.5", "grunt-contrib-clean": "^0.7.0",