Skip to content

Commit

Permalink
fix(3357): switched to using the BrowserWindow API to get window objects
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchell-foote committed Aug 19, 2024
1 parent 6a00289 commit 285d0c6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
9 changes: 6 additions & 3 deletions public/electron/helpers/hotkeys.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const {app, globalShortcut, BrowserWindow} = require("electron");
const {windows} = require("./multiWindow");
const {clearMenubar, setMenubar} = require("./setMenubar");
const { app, globalShortcut, BrowserWindow } = require("electron");
const { clearMenubar, setMenubar } = require("./setMenubar");

module.exports = () => {
globalShortcut.register("CommandOrControl+Alt+R", function () {
// This grabs all non-server windows, as the server window doesn't have a uniqueId.
const windows = BrowserWindow.getAllWindows().filter((each) => each.uniqueId);
windows.forEach(mainWindow => {
mainWindow && mainWindow.reload();
});
Expand All @@ -14,6 +15,8 @@ module.exports = () => {
focused && focused.webContents.openDevTools();
});
globalShortcut.register("CommandOrControl+Alt+K", function () {
// This grabs all non-server windows, as the server window doesn't have a uniqueId.
const windows = BrowserWindow.getAllWindows().filter((each) => each.uniqueId);
if (windows[0] && windows[0].isKiosk()) {
windows.forEach(mainWindow => {
mainWindow.setKiosk(false);
Expand Down
20 changes: 13 additions & 7 deletions public/electron/helpers/setMenubar.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const {Menu, BrowserWindow, app} = require("electron");
const {windows, addWindow} = require("./multiWindow");
const {getLoadedUrl} = require("./loadedUrl");
const { Menu, BrowserWindow, app } = require("electron");
const { addWindow } = require("./multiWindow");
const { getLoadedUrl } = require("./loadedUrl");

function templateFunc() {
var template = [
Expand All @@ -27,13 +27,15 @@ function templateFunc() {
label: "New Window",
accelerator: "CmdOrCtrl+N",
click: function () {
addWindow({loadedUrl: getLoadedUrl()});
addWindow({ loadedUrl: getLoadedUrl() });
},
},
{
label: "Reload",
accelerator: "CmdOrCtrl+Alt+R",
click: function () {
// This grabs all non-server windows, as the server window doesn't have a uniqueId.
const windows = BrowserWindow.getAllWindows().filter((each) => each.uniqueId);
windows.forEach(mainWindow => {
if (!mainWindow.isDestroyed()) {
mainWindow.reload();
Expand All @@ -46,6 +48,8 @@ function templateFunc() {
label: "Kiosk",
accelerator: "CmdOrCtrl+Alt+K",
click: function () {
// This grabs all non-server windows, as the server window doesn't have a uniqueId.
const windows = BrowserWindow.getAllWindows().filter((each) => each.uniqueId);
if (
windows[0] &&
!windows[0].isDestroyed() &&
Expand Down Expand Up @@ -81,9 +85,9 @@ function templateFunc() {
{
label: "Edit",
submenu: [
{label: "Cut", accelerator: "CmdOrCtrl+X", selector: "cut:"},
{label: "Copy", accelerator: "CmdOrCtrl+C", selector: "copy:"},
{label: "Paste", accelerator: "CmdOrCtrl+V", selector: "paste:"},
{ 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",
Expand All @@ -98,6 +102,8 @@ function templateFunc() {
function setMenubar() {
const template = templateFunc();
Menu.setApplicationMenu(Menu.buildFromTemplate(template));
// This grabs all non-server windows, as the server window doesn't have a uniqueId.
const windows = BrowserWindow.getAllWindows().filter((each) => each.uniqueId);
windows.forEach(w => {
if (!w.isDestroyed()) {
w.setMenuBarVisibility(true);
Expand Down

0 comments on commit 285d0c6

Please sign in to comment.