Skip to content

Commit

Permalink
Implement Electron 5.0.1 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
GregorBiswanger committed May 16, 2019
1 parent aea2c7a commit 3cb9216
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 42 deletions.
2 changes: 1 addition & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
8 changes: 0 additions & 8 deletions ElectronNET.API/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1414,14 +1414,6 @@ public void CommandLineAppendArgument(string value)
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
Expand Down
6 changes: 4 additions & 2 deletions ElectronNET.API/Entities/WebPreferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ public class WebPreferences
/// 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.
Expand All @@ -203,6 +204,7 @@ public class WebPreferences
/// <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;
}
}
6 changes: 3 additions & 3 deletions ElectronNET.API/Shell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ public Task<bool> OpenExternalAsync(string url, OpenExternalOptions options)
/// </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>();

Expand All @@ -157,7 +157,7 @@ public Task<bool> OpenExternalAsync(string url, OpenExternalOptions options, Act
}
});

_openExternalCallbacks.Add(url, action);
_openExternalCallbacks.Add(url, errorAction);

BridgeConnector.Socket.Emit("shell-openExternal", url, JObject.FromObject(options, _jsonSerializer), true);

Expand Down
3 changes: 0 additions & 3 deletions ElectronNET.Host/api/app.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ElectronNET.Host/api/app.js.map

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions ElectronNET.Host/api/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 14 additions & 2 deletions ElectronNET.Host/api/browserWindows.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ElectronNET.Host/api/browserWindows.js.map

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions ElectronNET.Host/api/browserWindows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
17 changes: 9 additions & 8 deletions ElectronNET.Host/api/shell.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ElectronNET.Host/api/shell.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 9 additions & 7 deletions ElectronNET.Host/api/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion ElectronNET.Host/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit 3cb9216

Please sign in to comment.