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

Fix timing issue with electron@8 #65

Merged
merged 3 commits into from
May 12, 2020
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 @@ -52,7 +52,7 @@
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.6.0",
"del": "^2.0.0",
"electron": "^7.1.2",
"electron": "^8.2.3",
"gulp": "^4.0.0",
"gulp-babel": "^7.0.0",
"gulp-eslint": "^3.0.1",
Expand Down
25 changes: 18 additions & 7 deletions src/injectable/electron-mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { Client } from '../ipc';
import resolveFileUrl from '../utils/resolve-file-url';
import CONSTANTS from '../constants';

const ELECTRON_VERSION = process.versions.electron && Number(process.versions.electron.split('.')[0]);

const ELECTRON_VERSION_WITH_ASYNC_LOAD_URL = 5;

const URL_QUERY_RE = /\?.*$/;
const NAVIGATION_EVENTS = ['will-navigate', 'did-navigate'];

Expand Down Expand Up @@ -54,8 +58,8 @@ function handleDialog (type, args) {
module.exports = function install (config, testPageUrl) {
ipc = new Client(config, { dialogHandler, contextMenuHandler, windowHandler });

ipc.connect();

const ipcConnectionPromise = ipc.connect();
var { Menu, dialog, app } = require('electron');

var WebContents;
Expand All @@ -82,9 +86,7 @@ module.exports = function install (config, testPageUrl) {
return url.indexOf('file:') === 0;
}

WebContents.prototype.loadURL = function (url, options) {
startLoadingTimeout(config.mainWindowUrl);

function loadUrl (webContext, url, options) {
let testUrl = stripQuery(url);

if (isFileProtocol(url))
Expand All @@ -104,10 +106,19 @@ module.exports = function install (config, testPageUrl) {
windowHandler.window = this;

if (config.openDevTools)
this.openDevTools();
webContext.openDevTools();
}

return origLoadURL.call(this, url, options);
return origLoadURL.call(webContext, url, options);
}

WebContents.prototype.loadURL = function (url, options) {
startLoadingTimeout(config.mainWindowUrl);

if (ELECTRON_VERSION >= ELECTRON_VERSION_WITH_ASYNC_LOAD_URL)
return ipcConnectionPromise.then(() => loadUrl(this, url, options));

return loadUrl(this, url, options);
};

app.getAppPath = function () {
Expand Down