Implement Electron 5.0.1 compatibility

This commit is contained in:
Gregor Biswanger
2019-05-16 03:13:35 +02:00
parent aea2c7aff5
commit 3cb92169dd
14 changed files with 59 additions and 42 deletions

View File

@@ -11,7 +11,7 @@ ElectronNET.CLI:
ElectronNET.API:
* Implement Electron 5.0.1 support
* Implement Electron 5.0.1 support, but not all new features
* Implement HostHook-API for execute own TypeScript/JavaScript code
* Fixed bug: 'X and Y options to not work on Windows 10' [\#193](https://github.com/ElectronNET/Electron.NET/issues/193)
* Merged pull request: Fix BrowserWindow::SetMenu [\#231](https://github.com/ElectronNET/Electron.NET/pull/231) thanks (thanks [CodeKenpachi](https://github.com/CodeKenpachi))

View File

@@ -1414,14 +1414,6 @@ namespace ElectronNET.API
BridgeConnector.Socket.Emit("appCommandLineAppendArgument", value);
}
/// <summary>
/// Enables mixed sandbox mode on the app. This method can only be called before app is ready.
/// </summary>
public void EnableMixedSandbox()
{
BridgeConnector.Socket.Emit("appEnableMixedSandbox");
}
/// <summary>
/// When critical is passed, the dock icon will bounce until either the application
/// becomes active or the request is canceled.When informational is passed, the

View File

@@ -185,7 +185,8 @@ namespace ElectronNET.API.Entities
/// Context' entry in the combo box at the top of the Console tab. This option is
/// currently experimental and may change or be removed in future Electron releases.
/// </summary>
public bool ContextIsolation { get; set; }
[DefaultValue(true)]
public bool ContextIsolation { get; set; } = true;
/// <summary>
/// Whether to use native window.open(). Defaults to false. This option is currently experimental.
@@ -203,6 +204,7 @@ namespace ElectronNET.API.Entities
/// <value>
/// <c>true</c> if [webview tag]; otherwise, <c>false</c>.
/// </value>
public bool WebviewTag { get; set; }
[DefaultValue(false)]
public bool WebviewTag { get; set; } = false;
}
}

View File

@@ -132,10 +132,10 @@ namespace ElectronNET.API
/// </summary>
/// <param name="url"></param>
/// <param name="options">macOS only</param>
/// <param name="action">macOS only</param>
/// <param name="errorAction">Action to get the error message.</param>
/// <returns>Whether an application was available to open the URL.
/// If callback is specified, always returns true.</returns>
public Task<bool> OpenExternalAsync(string url, OpenExternalOptions options, Action<Error> action)
public Task<bool> OpenExternalAsync(string url, OpenExternalOptions options, Action<Error> errorAction)
{
var taskCompletionSource = new TaskCompletionSource<bool>();
@@ -157,7 +157,7 @@ namespace ElectronNET.API
}
});
_openExternalCallbacks.Add(url, action);
_openExternalCallbacks.Add(url, errorAction);
BridgeConnector.Socket.Emit("shell-openExternal", url, JObject.FromObject(options, _jsonSerializer), true);

View File

@@ -215,9 +215,6 @@ module.exports = (socket, app) => {
socket.on('appCommandLineAppendArgument', (value) => {
app.commandLine.appendArgument(value);
});
socket.on('appEnableMixedSandbox', () => {
app.enableMixedSandbox();
});
socket.on('appDockBounce', (type) => {
const id = app.dock.bounce(type);
electronSocket.emit('appDockBounceCompleted', id);

File diff suppressed because one or more lines are too long

View File

@@ -268,10 +268,6 @@ export = (socket: SocketIO.Socket, app: Electron.App) => {
app.commandLine.appendArgument(value);
});
socket.on('appEnableMixedSandbox', () => {
app.enableMixedSandbox();
});
socket.on('appDockBounce', (type) => {
const id = app.dock.bounce(type);
electronSocket.emit('appDockBounceCompleted', id);

View File

@@ -155,7 +155,19 @@ module.exports = (socket, app) => {
electronSocket.emit('browserWindow-new-window-for-tab' + id);
});
});
function hasOwnChildreen(obj, ...childNames) {
for (let i = 0; i < childNames.length; i++) {
if (!obj || !obj.hasOwnProperty(childNames[i])) {
return false;
}
obj = obj[childNames[i]];
}
return true;
}
socket.on('createBrowserWindow', (options, loadUrl) => {
if (!hasOwnChildreen(options, 'webPreferences', 'nodeIntegration')) {
options = Object.assign({}, options, { webPreferences: { nodeIntegration: true } });
}
window = new electron_1.BrowserWindow(options);
lastOptions = options;
window.on('closed', (sender) => {
@@ -438,8 +450,8 @@ module.exports = (socket, app) => {
}
});
}
socket.on('browserWindowSetProgressBar', (id, progress, options) => {
getWindowById(id).setProgressBar(progress, options);
socket.on('browserWindowSetProgressBar', (id, progress) => {
getWindowById(id).setProgressBar(progress);
});
socket.on('browserWindowSetHasShadow', (id, hasShadow) => {
getWindowById(id).setHasShadow(hasShadow);

File diff suppressed because one or more lines are too long

View File

@@ -185,7 +185,22 @@ export = (socket: SocketIO.Socket, app: Electron.App) => {
});
});
function hasOwnChildreen(obj, ...childNames) {
for (let i = 0; i < childNames.length; i++) {
if (!obj || !obj.hasOwnProperty(childNames[i])) {
return false;
}
obj = obj[childNames[i]];
}
return true;
}
socket.on('createBrowserWindow', (options, loadUrl) => {
if (!hasOwnChildreen(options, 'webPreferences', 'nodeIntegration')) {
options = { ...options, webPreferences: { nodeIntegration: true } };
}
window = new BrowserWindow(options);
lastOptions = options;

View File

@@ -11,18 +11,19 @@ module.exports = (socket) => {
const success = electron_1.shell.openItem(fullPath);
electronSocket.emit('shell-openItemCompleted', success);
});
socket.on('shell-openExternal', (url, options, callback) => {
let success = false;
if (options && callback) {
success = electron_1.shell.openExternal(url, options, (error) => {
socket.on('shell-openExternal', (url, options) => {
let success = true;
if (options) {
electron_1.shell.openExternal(url, options).catch((error) => {
success = false;
electronSocket.emit('shell-openExternalCallback', [url, error]);
});
}
else if (options) {
success = electron_1.shell.openExternal(url, options);
}
else {
success = electron_1.shell.openExternal(url);
electron_1.shell.openExternal(url).catch((error) => {
success = false;
electronSocket.emit('shell-openExternalCallback', [url, error]);
});
}
electronSocket.emit('shell-openExternalCompleted', success);
});

View File

@@ -1 +1 @@
{"version":3,"file":"shell.js","sourceRoot":"","sources":["shell.ts"],"names":[],"mappings":";AAAA,uCAAiC;AACjC,IAAI,cAAc,CAAC;AAEnB,iBAAS,CAAC,MAAuB,EAAE,EAAE;IACjC,cAAc,GAAG,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,CAAC,wBAAwB,EAAE,CAAC,QAAQ,EAAE,EAAE;QAC7C,MAAM,OAAO,GAAG,gBAAK,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;QAEjD,cAAc,CAAC,IAAI,CAAC,iCAAiC,EAAE,OAAO,CAAC,CAAC;IACpE,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,E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AAwB,EAAE,CAAC,YAAY,EAAE,EAAE;QACjD,MAAM,eAAe,GAAG,gBAAK,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC;QAE7D,cAAc,CAAC,IAAI,CAAC,iCAAiC,EAAE,eAAe,CAAC,CAAC;IAC5E,CAAC,CAAC,CAAC;AACP,CAAC,CAAC"}

View File

@@ -15,17 +15,19 @@ export = (socket: SocketIO.Socket) => {
electronSocket.emit('shell-openItemCompleted', success);
});
socket.on('shell-openExternal', (url, options, callback) => {
let success = false;
socket.on('shell-openExternal', (url, options) => {
let success = true;
if (options && callback) {
success = shell.openExternal(url, options, (error) => {
if (options) {
shell.openExternal(url, options).catch((error) => {
success = false;
electronSocket.emit('shell-openExternalCallback', [url, error]);
});
} else if (options) {
success = shell.openExternal(url, options);
} else {
success = shell.openExternal(url);
shell.openExternal(url).catch((error) => {
success = false;
electronSocket.emit('shell-openExternalCallback', [url, error]);
});
}
electronSocket.emit('shell-openExternalCompleted', success);

View File

@@ -12,8 +12,8 @@
"start": "tsc -p ."
},
"dependencies": {
"electron": "^5.0.1",
"portscanner": "^2.2.0",
"electron": "^4.0.0",
"socket.io": "^2.2.0"
},
"devDependencies": {