Skip to content

Commit

Permalink
Fix timing issue with electron@8 (#65)
Browse files Browse the repository at this point in the history
* Fix timing issue with electron@8

* Compatibilty with electron<5

* Lint

Co-authored-by: Andrey Belym <[email protected]>
  • Loading branch information
steveetm and AndreyBelym authored May 12, 2020
1 parent 9a3da3a commit 73eebb1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
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

0 comments on commit 73eebb1

Please sign in to comment.