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

Upgrade [email protected] #2208

Merged
merged 2 commits into from
Oct 3, 2024
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
"cheerio": "v1.0.0-rc.12",
"cross-env": "7.0.3",
"del": "3.0.0",
"electron": "32.0.1",
"electron": "32.1.2",
"electron-builder": "^24.13.2",
"electron-devtools-installer": "^3.2.0",
"electron-icon-maker": "0.0.5",
Expand Down
73 changes: 67 additions & 6 deletions spec/appMenu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { updateAlwaysOnTop } from '../src/app/window-actions';
import { zoomIn, zoomOut } from '../src/app/window-utils';
import * as envMock from '../src/common/env';
import { logger } from '../src/common/logger';
import { dialog, session, shell } from './__mocks__/electron';
import { BrowserWindow, dialog, session, shell } from './__mocks__/electron';
import { windowHandler } from '../src/app/window-handler';
import { apiName } from '../src/common/api-interface';

jest.mock('../src/app/stores', () => {
const mock = new Map<string, any>();
Expand Down Expand Up @@ -100,6 +102,7 @@ jest.mock('../src/app/window-handler', () => {
windowHandler: {
createMoreInfoWindow: jest.fn(),
getMainWindow: jest.fn(),
getMainWebContents: jest.fn(),
isMana: true,
},
};
Expand Down Expand Up @@ -373,20 +376,78 @@ describe('app menu', () => {
});

describe(`Toggle Developer Tools`, () => {
it('should call `toggleDevTools` when focusedWindow is not null', () => {
const focusedWindow = {
it('should toggle devtools on focused window - focused window is not main window', () => {
const focusedWindowMock = {
isDestroyed: jest.fn(() => false),
reload: jest.fn(),
webContents: {
toggleDevTools: jest.fn(),
},
};
const spy = jest.spyOn(focusedWindow.webContents, 'toggleDevTools');

const mainWebContentsMock = {
toggleDevTools: jest.fn(),
};

jest
.spyOn(BrowserWindow, 'getFocusedWindow')
.mockReturnValue(focusedWindowMock);
const focusedWindowDevtoolsSpy = jest.spyOn(
focusedWindowMock.webContents,
'toggleDevTools',
);
const mainWebContentsSpy = jest
.spyOn(windowHandler, 'getMainWebContents')
.mockReturnValue(mainWebContentsMock);
const mainWebContentsDevToolsSpy = jest.spyOn(
mainWebContentsMock,
'toggleDevTools',
);
const menuItem = findHelpTroubleshootingMenuItem(
'Toggle Developer Tools',
);
menuItem.click({}, focusedWindow);
expect(spy).toBeCalled();
menuItem.click({}, undefined);
expect(focusedWindowDevtoolsSpy).toBeCalled();
expect(mainWebContentsSpy).not.toBeCalled();
expect(mainWebContentsDevToolsSpy).not.toBeCalled();
});

it('should toggle devtools on focused window - focused window is main window', () => {
const focusedWindowMock = {
isDestroyed: jest.fn(() => false),
reload: jest.fn(),
webContents: {
toggleDevTools: jest.fn(),
},
winName: apiName.mainWindowName,
};

const mainWebContentsMock = {
toggleDevTools: jest.fn(),
isDestroyed: jest.fn(() => false),
};

jest
.spyOn(BrowserWindow, 'getFocusedWindow')
.mockReturnValue(focusedWindowMock);
const focusedWindowDevtoolsSpy = jest.spyOn(
focusedWindowMock.webContents,
'toggleDevTools',
);
const mainWebContentsSpy = jest
.spyOn(windowHandler, 'getMainWebContents')
.mockReturnValue(mainWebContentsMock);
const mainWebContentsDevToolsSpy = jest.spyOn(
mainWebContentsMock,
'toggleDevTools',
);
const menuItem = findHelpTroubleshootingMenuItem(
'Toggle Developer Tools',
);
menuItem.click({}, undefined);
expect(focusedWindowDevtoolsSpy).not.toBeCalled();
expect(mainWebContentsSpy).toBeCalled();
expect(mainWebContentsDevToolsSpy).toBeCalled();
});

it('should not call `electron.dialog` when focusedWindow is null', () => {
Expand Down
11 changes: 7 additions & 4 deletions src/app/app-menu.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {
app,
BaseWindow,
BrowserWindow,
Menu,
MenuItemConstructorOptions,
session,
Expand Down Expand Up @@ -650,11 +652,12 @@ export class AppMenu {
(typeof isDevToolsEnabledCC === 'boolean' &&
isDevToolsEnabledCC) ||
devToolsEnabled,
click(_item, focusedWindow) {
if (!focusedWindow || !windowExists(focusedWindow)) {
return;
}
click(_item, _window: BaseWindow | undefined) {
if (devToolsEnabled) {
const focusedWindow = BrowserWindow.getFocusedWindow();
if (!focusedWindow || !windowExists(focusedWindow)) {
return;
}
if (
(focusedWindow as ICustomBrowserWindow).winName ===
apiName.mainWindowName
Expand Down
Loading