Skip to content

Commit

Permalink
fix: focus the window when loading fiddle with protocol (#1018)
Browse files Browse the repository at this point in the history
* fix: getting the mainWindow from foreground

* Added test for regression

* chore: tweak test

* chore: tweak order of imports

Co-authored-by: David Sanders <dsanders11@ucsbalum.com>
  • Loading branch information
akgupta0777 and dsanders11 authored Mar 25, 2022
1 parent f6ff9ea commit 50b6656
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as nodeUrl from 'url';
import { IpcEvents } from '../ipc-events';
import { isDevMode } from '../utils/devmode';
import { ipcMainManager } from './ipc';
import { getOrCreateMainWindow } from './windows';

const PROTOCOL = 'electron-fiddle';
const squirrelPath = path.resolve(
Expand Down Expand Up @@ -66,6 +67,7 @@ const handlePotentialProtocolLaunch = (url: string) => {
default:
return;
}
getOrCreateMainWindow().focus();
};

const isProtocolString = (arg: string) => arg.startsWith(`${PROTOCOL}://`);
Expand Down
12 changes: 12 additions & 0 deletions tests/main/protocol-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
listenForProtocolHandler,
setupProtocolHandler,
} from '../../src/main/protocol';
import { getOrCreateMainWindow } from '../../src/main/windows';
import { overridePlatform, resetPlatform } from '../utils';

jest.mock('fs');
Expand Down Expand Up @@ -176,5 +177,16 @@ describe('protocol', () => {

expect(ipcMainManager.send).toHaveBeenCalledTimes(0);
});

it('focuses window when loading a fiddle', () => {
listenForProtocolHandler();

const mainWindow = getOrCreateMainWindow();
const handler = (app.on as any).mock.calls[0][1];

handler({}, 'electron-fiddle://electron/4.0.0/test/path');

expect(mainWindow.focus).toHaveBeenCalled();
});
});
});

0 comments on commit 50b6656

Please sign in to comment.