From c996e6f6ad42d3926adb7043375d4731f865981d Mon Sep 17 00:00:00 2001 From: Marcelo Jacobus Date: Thu, 21 Apr 2022 09:12:37 -0300 Subject: [PATCH] Add keyboard shortcuts (#65) * Add shortcut to toggle full screen * Set prettier as a linter * Remove unused vars * Add menu shortcuts for moving main windows to other screens * Bump version 1.5.0 --- package.json | 4 ++-- src/ApplicationMenu.js | 10 ++++------ src/Window.js | 9 ++++++++- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 8cc4fcf..02c28d9 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "JWPlay", "productName": "JW Play", - "version": "1.4.0", + "version": "1.5.0", "description": "My Electron application description", "main": "src/app.js", "build": { @@ -48,7 +48,7 @@ "start": "electron-forge start", "package": "electron-forge package", "make": "electron-forge make", - "lint": "echo \"No linting configured\"", + "lint": "node_modules/.bin/prettier --write src test", "start-debug": "electron . --trace-warnings > ./app-run.log 2>&1", "pack-win": "electron-builder --win", "pack-win-test": "electron-builder --dir --win", diff --git a/src/ApplicationMenu.js b/src/ApplicationMenu.js index 9bd211f..e8f9772 100644 --- a/src/ApplicationMenu.js +++ b/src/ApplicationMenu.js @@ -61,12 +61,9 @@ class ApplicationMenu { submenu: this.getMoveToItems(), }, { - label: "Fullscreen", - click: () => driver.mainWindow.fullScreen(), - }, - { - label: "Exit Fullscreen", - click: () => driver.mainWindow.unFullScreen(), + label: "Toggle Fullscreen", + accelerator: "F", + click: () => driver.mainWindow.toggleFullScreen(), }, ], }, @@ -93,6 +90,7 @@ class ApplicationMenu { return screen.getAllDisplays().map((display, index) => { return { label: `Display ${index + 1}`, + accelerator: `${index + 1}`, click: () => { this.driver.mainWindow.moveToDisplay(display); }, diff --git a/src/Window.js b/src/Window.js index 0a2cea1..9bc6d65 100644 --- a/src/Window.js +++ b/src/Window.js @@ -1,4 +1,4 @@ -const { app, BrowserWindow } = require("electron"); +const { BrowserWindow } = require("electron"); const store = require("./store"); class BaseWindow extends BrowserWindow { @@ -42,6 +42,13 @@ class BaseWindow extends BrowserWindow { this.setSize(width, height + diff); } + toggleFullScreen() { + if (this.isFullScreen()) { + return this.unFullScreen(); + } + return this.fullScreen(); + } + fullScreen() { this.keepOnTop(); this.setFullScreen(true);