Skip to content

Commit

Permalink
Added a config for disabling the window reload
Browse files Browse the repository at this point in the history
Set the `disallowReloadKeybinding` application config to `true` if you
want to disable the browser window reload with `Ctrl/Cmd+R`.

The config does not affect the behavior of the app if it is running
in a browser environment.

Signed-off-by: Akos Kitta <[email protected]>
  • Loading branch information
Akos Kitta committed Jan 28, 2020
1 parent e1d08d0 commit f0a75e3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,11 @@ process.env.LC_NUMERIC = 'C';
const electron = require('electron');
const { join, resolve } = require('path');
const { fork } = require('child_process');
const { app, dialog, shell, BrowserWindow, ipcMain, Menu } = electron;
const { app, dialog, shell, BrowserWindow, ipcMain, Menu, globalShortcut } = electron;
const applicationName = \`${this.pck.props.frontend.config.applicationName}\`;
const isSingleInstance = ${this.pck.props.backend.config.singleInstance === true ? 'true' : 'false'};
const disallowReloadKeybinding = ${this.pck.props.frontend.config.disallowReloadKeybinding === true ? 'true' : 'false'};
if (isSingleInstance && !app.requestSingleInstanceLock()) {
// There is another instance running, exit now. The other instance will request focus.
Expand All @@ -143,6 +144,11 @@ const Storage = require('electron-store');
const electronStore = new Storage();
app.on('ready', () => {
if (disallowReloadKeybinding) {
globalShortcut.register('CmdOrCtrl+R', () => {});
}
// Explicitly set the app name to have better menu items on macOS. ("About", "Hide", and "Quit")
// See: https://github.com/electron-userland/electron-builder/issues/2468
app.setName(applicationName);
Expand Down
6 changes: 6 additions & 0 deletions dev-packages/application-package/src/application-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ export interface FrontendApplicationConfig extends ApplicationConfig {
*/
readonly applicationName: string;

/**
* If set to `true`, reloading the current browser window won't be possible with the `Ctrl/Cmd + R` keybinding.
* It is `false` by default. Has no effect if not in an electron environment.
*/
readonly disallowReloadKeybinding?: boolean;

}

/**
Expand Down

0 comments on commit f0a75e3

Please sign in to comment.