Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respectful keyboard shortcuts #5

Merged
merged 2 commits into from
Apr 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
<html lang="en">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<!--
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<!--
manifest.json provides metadata used when your web app is added to the
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!--
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Expand All @@ -21,15 +21,15 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
<title>Viz</title>
</head>

<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
<!--
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

Expand Down
38 changes: 25 additions & 13 deletions src/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const { app, BrowserWindow, globalShortcut, dialog, ipcMain } = require('electro
const fs = require('fs');
const path = require('path');

// const path = require('path');
// const url = require('url');

// Keep a global reference of the window object, if you don't, the window will
Expand Down Expand Up @@ -60,6 +59,27 @@ const openFileOrFolder = () => {
}
};

function registerShortcuts() {
// Register a 'CommandOrControl+O' shortcut listener to open a file or folder.
globalShortcut.register('CommandOrControl+O', openFileOrFolder);

// Register shortcut listeners for left and right arrow
globalShortcut.register('Left', () => {
// sending to renderer process
win.webContents.send('leftKeyPressed');
});
globalShortcut.register('Right', () => {
// sending to renderer process
win.webContents.send('rightKeyPressed');
});
}

function unregisterShortcuts() {
globalShortcut.unregister('CommandOrControl+O');
globalShortcut.unregister('Left');
globalShortcut.unregister('Right');
}

function createWindow() {
// Create the browser window.
win = new BrowserWindow({ width: 1000, height: 768 });
Expand All @@ -78,18 +98,10 @@ function createWindow() {
win = null;
});

// Register a 'CommandOrControl+O' shortcut listener to open a file or folder.
globalShortcut.register('CommandOrControl+O', openFileOrFolder);

// Register shortcut listeners for left and right arrow
globalShortcut.register('Left', () => {
// sending to renderer process
win.webContents.send('leftKeyPressed');
});
globalShortcut.register('Right', () => {
// sending to renderer process
win.webContents.send('rightKeyPressed');
});
// registering / unregistering shortcuts when necessary
registerShortcuts();
win.on('focus', registerShortcuts);
win.on('blur', unregisterShortcuts);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting, I would not have thought to do it this way ˆˆ'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, you would think there are more obvious ways, and more documented too 😄


// the "open file or folder" dialog can also be triggered from the React app
ipcMain.on('openFileOrFolder', openFileOrFolder);
Expand Down