diff --git a/ElectronNET.API/App.cs b/ElectronNET.API/App.cs
index 80b3d41..e133c5c 100644
--- a/ElectronNET.API/App.cs
+++ b/ElectronNET.API/App.cs
@@ -25,6 +25,41 @@ namespace ElectronNET.API
///
public static bool SocketDebug { get; set; }
+
+ ///
+ /// Emitted when the user clicks on the dock on Mac
+ ///
+ ///
+ [SupportedOSPlatform("macos")]
+ public event Action Activate
+ {
+ add
+ {
+ if (_appActivate == null)
+ {
+ BridgeConnector.On("app-activate", () =>
+ {
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+ {
+ _appActivate();
+ }
+ });
+ }
+ _appActivate += value;
+ }
+ remove
+ {
+ _appActivate -= value;
+
+ if (_appActivate == null)
+ {
+ BridgeConnector.Off("app-activate");
+ }
+ }
+ }
+
+ private event Action _appActivate;
+
///
/// Emitted when all windows have been closed.
///
diff --git a/ElectronNET.API/WindowManager.cs b/ElectronNET.API/WindowManager.cs
index 712df60..a58764e 100644
--- a/ElectronNET.API/WindowManager.cs
+++ b/ElectronNET.API/WindowManager.cs
@@ -116,14 +116,14 @@ namespace ElectronNET.API
}
});
- if (loadUrl.ToUpper() == "HTTP://LOCALHOST")
+ if (string.Equals(loadUrl, "HTTP://LOCALHOST", StringComparison.InvariantCultureIgnoreCase))
{
loadUrl = $"{loadUrl}:{BridgeSettings.WebPort}";
}
// Workaround Windows 10 / Electron Bug
// https://github.com/electron/electron/issues/4045
- if (isWindows10())
+ if (IsWindows10())
{
options.Width = options.Width + 14;
options.Height = options.Height + 7;
@@ -140,22 +140,20 @@ namespace ElectronNET.API
{
// Workaround Windows 10 / Electron Bug
// https://github.com/electron/electron/issues/4045
- if (isWindows10())
+ if (IsWindows10())
{
options.X = options.X - 7;
}
-
-
BridgeConnector.Emit("createBrowserWindow", JObject.FromObject(options, _keepDefaultValuesSerializer), loadUrl);
}
return taskCompletionSource.Task;
}
- private bool isWindows10()
+ private bool IsWindows10()
{
- return RuntimeInformation.OSDescription.Contains("Windows 10");
+ return OperatingSystem.IsWindowsVersionAtLeast(10);
}
///
diff --git a/ElectronNET.Host/api/app.js b/ElectronNET.Host/api/app.js
index e9fb535..bec0cef 100644
--- a/ElectronNET.Host/api/app.js
+++ b/ElectronNET.Host/api/app.js
@@ -18,6 +18,13 @@ module.exports = (socket, app) => {
electronSocket.emit('app-window-all-closed' + appWindowAllClosedEventId);
}
});
+
+ app.on('activate', () => {
+ // On macOS it's common to re-create a window in the app when the
+ // dock icon is clicked and there are no other windows open.
+ electronSocket.emit('app-activate');
+ });
+
socket.on('quit-app-window-all-closed-event', (quit) => {
isQuitWindowAllClosed = quit;
});
diff --git a/ElectronNET.Host/api/app.ts b/ElectronNET.Host/api/app.ts
index 1f04f9f..e515249 100644
--- a/ElectronNET.Host/api/app.ts
+++ b/ElectronNET.Host/api/app.ts
@@ -20,6 +20,12 @@ export = (socket: Socket, app: Electron.App) => {
}
});
+ app.on('activate', () => {
+ // On macOS it's common to re-create a window in the app when the
+ // dock icon is clicked and there are no other windows open.
+ electronSocket.emit('app-activate');
+ });
+
socket.on('quit-app-window-all-closed-event', (quit) => {
isQuitWindowAllClosed = quit;
});
diff --git a/ElectronNET.Host/api/browserWindows.js b/ElectronNET.Host/api/browserWindows.js
index af3f7e6..d347e8f 100644
--- a/ElectronNET.Host/api/browserWindows.js
+++ b/ElectronNET.Host/api/browserWindows.js
@@ -4,7 +4,7 @@ const browserView_1 = require("./browserView");
const path = require('path');
const windows = (global['browserWindows'] = global['browserWindows'] || []);
let readyToShowWindowsIds = [];
-let window, lastOptions, electronSocket;
+let window, electronSocket;
let mainWindowURL;
const proxyToCredentialsMap = (global['proxyToCredentialsMap'] = global['proxyToCredentialsMap'] || []);
module.exports = (socket, app) => {
@@ -218,7 +218,6 @@ module.exports = (socket, app) => {
readyToShowWindowsIds.push(window.id);
}
});
- lastOptions = options;
window.on('closed', (sender) => {
for (let index = 0; index < windows.length; index++) {
const windowItem = windows[index];
@@ -235,13 +234,6 @@ module.exports = (socket, app) => {
}
}
});
- app.on('activate', () => {
- // On macOS it's common to re-create a window in the app when the
- // dock icon is clicked and there are no other windows open.
- if (window === null && lastOptions) {
- window = new electron_1.BrowserWindow(lastOptions);
- }
- });
if (loadUrl) {
window.loadURL(loadUrl);
}
diff --git a/ElectronNET.Host/api/browserWindows.ts b/ElectronNET.Host/api/browserWindows.ts
index 76f7ffb..b844019 100644
--- a/ElectronNET.Host/api/browserWindows.ts
+++ b/ElectronNET.Host/api/browserWindows.ts
@@ -4,7 +4,7 @@ import { browserViewMediateService } from './browserView';
const path = require('path');
const windows: Electron.BrowserWindow[] = (global['browserWindows'] = global['browserWindows'] || []) as Electron.BrowserWindow[];
let readyToShowWindowsIds: number[] = [];
-let window, lastOptions, electronSocket;
+let window, electronSocket;
let mainWindowURL;
const proxyToCredentialsMap: { [proxy: string]: string } = (global['proxyToCredentialsMap'] = global['proxyToCredentialsMap'] || []) as { [proxy: string]: string };
@@ -245,8 +245,6 @@ export = (socket: Socket, app: Electron.App) => {
}
});
- lastOptions = options;
-
window.on('closed', (sender) => {
for (let index = 0; index < windows.length; index++) {
const windowItem = windows[index];
@@ -264,14 +262,6 @@ export = (socket: Socket, app: Electron.App) => {
}
});
- app.on('activate', () => {
- // On macOS it's common to re-create a window in the app when the
- // dock icon is clicked and there are no other windows open.
- if (window === null && lastOptions) {
- window = new BrowserWindow(lastOptions);
- }
- });
-
if (loadUrl) {
window.loadURL(loadUrl);
}