diff --git a/src/common/ipc/ipc.ts b/src/common/ipc/ipc.ts
index 2b81345a49..fe08d0b80c 100644
--- a/src/common/ipc/ipc.ts
+++ b/src/common/ipc/ipc.ts
@@ -34,6 +34,10 @@ export async function broadcastMessage(channel: string, ...args: any[]): Promise
return requestMain(broadcastMainChannel, ...args);
}
+ if (!webContents) {
+ return;
+ }
+
const subFrames = getSubFrames();
const views = webContents.getAllWebContents();
diff --git a/src/main/ipc/window.ts b/src/main/ipc/window.ts
index b7d10e65c6..29d273fe1d 100644
--- a/src/main/ipc/window.ts
+++ b/src/main/ipc/window.ts
@@ -22,7 +22,7 @@
import { BrowserWindow, webContents } from "electron";
import { broadcastMessage } from "../../common/ipc";
-type WindowAction = "goBack" | "goForward" | "minimize" | "toggleMaximize" | "close";
+type WindowAction = "back" | "forward" | "minimize" | "toggleMaximize" | "close";
export function windowAction(action: WindowAction) {
const window = BrowserWindow.getFocusedWindow();
@@ -30,12 +30,12 @@ export function windowAction(action: WindowAction) {
if (!window) return;
switch (action) {
- case "goBack": {
+ case "back": {
window.webContents.goBack();
break;
}
- case "goForward": {
+ case "forward": {
window.webContents.goForward();
break;
}
@@ -59,18 +59,6 @@ export function windowAction(action: WindowAction) {
break;
}
}
-
- if (action === "goBack") {
- window.webContents.goBack();
- } else if (action === "goForward") {
- window.webContents.goForward();
- } else if (action === "toggleMaximize") {
- if (window.isMaximized()) {
- window.unmaximize();
- } else {
- window.maximize();
- }
- }
}
export function onLocationChange() {
diff --git a/src/renderer/components/layout/top-bar/top-bar-win-linux.test.tsx b/src/renderer/components/layout/top-bar/top-bar-win-linux.test.tsx
index e59b54cb0d..c44e53a59a 100644
--- a/src/renderer/components/layout/top-bar/top-bar-win-linux.test.tsx
+++ b/src/renderer/components/layout/top-bar/top-bar-win-linux.test.tsx
@@ -8,7 +8,7 @@ import { fireEvent } from "@testing-library/react";
import "@testing-library/jest-dom/extend-expect";
import { TopBar } from "./top-bar";
import { IpcMainWindowEvents } from "../../../../common/ipc";
-import { broadcastMessage } from "../../../../common/ipc";
+import { broadcastMessage, requestMain } from "../../../../common/ipc";
import * as vars from "../../../../common/vars";
import { getDiForUnitTesting } from "../../../getDiForUnitTesting";
import { DiRender, renderFor } from "../../test-utils/renderFor";
@@ -33,23 +33,6 @@ jest.mock("../../../../common/vars", () => {
};
});
-const mockMinimize = jest.fn();
-const mockMaximize = jest.fn();
-const mockUnmaximize = jest.fn();
-const mockClose = jest.fn();
-
-jest.mock("@electron/remote", () => {
- return {
- getCurrentWindow: () => ({
- minimize: () => mockMinimize(),
- maximize: () => mockMaximize(),
- unmaximize: () => mockUnmaximize(),
- close: () => mockClose(),
- isMaximized: () => false,
- }),
- };
-});
-
describe(" in Windows and Linux", () => {
let render: DiRender;
@@ -107,12 +90,12 @@ describe(" in Windows and Linux", () => {
expect(broadcastMessage).toHaveBeenCalledWith(IpcMainWindowEvents.OPEN_CONTEXT_MENU);
fireEvent.click(minimize);
- expect(mockMinimize).toHaveBeenCalled();
+ expect(requestMain).toHaveBeenCalledWith(IpcMainWindowEvents.WINDOW_ACTION, "minimize");
fireEvent.click(maximize);
- expect(mockMaximize).toHaveBeenCalled();
+ expect(requestMain).toHaveBeenCalledWith(IpcMainWindowEvents.WINDOW_ACTION, "toggleMaximize");
fireEvent.click(close);
- expect(mockClose).toHaveBeenCalled();
+ expect(requestMain).toHaveBeenCalledWith(IpcMainWindowEvents.WINDOW_ACTION, "close");
});
});
diff --git a/src/renderer/components/layout/top-bar/top-bar.test.tsx b/src/renderer/components/layout/top-bar/top-bar.test.tsx
index 9c55b6ec7a..c68c295636 100644
--- a/src/renderer/components/layout/top-bar/top-bar.test.tsx
+++ b/src/renderer/components/layout/top-bar/top-bar.test.tsx
@@ -12,9 +12,9 @@ import type { ConfigurableDependencyInjectionContainer } from "@ogre-tools/injec
import { DiRender, renderFor } from "../../test-utils/renderFor";
import topBarItemsInjectable from "./top-bar-items/top-bar-items.injectable";
import { computed } from "mobx";
-import directoryForUserDataInjectable
- from "../../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
+import directoryForUserDataInjectable from "../../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
import mockFs from "mock-fs";
+import { IpcMainWindowEvents } from "../../../../common/ipc";
jest.mock("../../../../common/vars", () => {
const SemVer = require("semver").SemVer;
@@ -27,6 +27,9 @@ jest.mock("../../../../common/vars", () => {
};
});
+const goBack = jest.fn();
+const goForward = jest.fn();
+
jest.mock(
"electron",
() => ({
@@ -42,6 +45,25 @@ jest.mock(
}
},
),
+ invoke: jest.fn(
+ (channel: string, action: string) => {
+ console.log("channel", channel, action);
+
+ if (channel !== IpcMainWindowEvents.WINDOW_ACTION) return;
+
+ switch(action) {
+ case "back": {
+ goBack();
+ break;
+ }
+
+ case "forward": {
+ goForward();
+ break;
+ }
+ }
+ },
+ ),
},
}),
);
@@ -50,24 +72,6 @@ jest.mock("../../+catalog", () => ({
previousActiveTab: jest.fn(),
}));
-const goBack = jest.fn();
-const goForward = jest.fn();
-
-jest.mock("@electron/remote", () => {
- return {
- webContents: {
- getAllWebContents: () => {
- return [{
- getType: () => "window",
- goBack,
- goForward,
- }];
- },
- },
- getCurrentWindow: () => jest.fn(),
- };
-});
-
describe("", () => {
let di: ConfigurableDependencyInjectionContainer;
let render: DiRender;