diff --git a/ElectronNET.API/App.cs b/ElectronNET.API/App.cs
index 69d8722c..274786c5 100644
--- a/ElectronNET.API/App.cs
+++ b/ElectronNET.API/App.cs
@@ -15,6 +15,11 @@ namespace ElectronNET.API
///
public sealed class App
{
+ ///
+ /// Print every message sent to the socket
+ ///
+ public static bool SocketDebug { get; set; }
+
///
/// Emitted when all windows have been closed.
///
@@ -30,7 +35,7 @@ public event Action WindowAllClosed
{
if (_windowAllClosed == null)
{
- BridgeConnector.Socket.On("app-window-all-closed" + GetHashCode(), () =>
+ BridgeConnector.On("app-window-all-closed" + GetHashCode(), () =>
{
if (!Electron.WindowManager.IsQuitOnWindowAllClosed || RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
@@ -38,7 +43,7 @@ public event Action WindowAllClosed
}
});
- BridgeConnector.Socket.Emit("register-app-window-all-closed-event", GetHashCode());
+ BridgeConnector.Emit("register-app-window-all-closed-event", GetHashCode());
}
_windowAllClosed += value;
}
@@ -47,7 +52,7 @@ public event Action WindowAllClosed
_windowAllClosed -= value;
if(_windowAllClosed == null)
- BridgeConnector.Socket.Off("app-window-all-closed" + GetHashCode());
+ BridgeConnector.Off("app-window-all-closed" + GetHashCode());
}
}
@@ -67,7 +72,7 @@ public event Func BeforeQuit
{
if (_beforeQuit == null)
{
- BridgeConnector.Socket.On("app-before-quit" + GetHashCode(), async () =>
+ BridgeConnector.On("app-before-quit" + GetHashCode(), async () =>
{
await _beforeQuit(new QuitEventArgs());
@@ -110,7 +115,7 @@ public event Func BeforeQuit
}
});
- BridgeConnector.Socket.Emit("register-app-before-quit-event", GetHashCode());
+ BridgeConnector.Emit("register-app-before-quit-event", GetHashCode());
}
_beforeQuit += value;
}
@@ -119,7 +124,7 @@ public event Func BeforeQuit
_beforeQuit -= value;
if (_beforeQuit == null)
- BridgeConnector.Socket.Off("app-before-quit" + GetHashCode());
+ BridgeConnector.Off("app-before-quit" + GetHashCode());
}
}
@@ -139,7 +144,7 @@ public event Func WillQuit
{
if (_willQuit == null)
{
- BridgeConnector.Socket.On("app-will-quit" + GetHashCode(), async () =>
+ BridgeConnector.On("app-will-quit" + GetHashCode(), async () =>
{
await _willQuit(new QuitEventArgs());
@@ -161,7 +166,7 @@ public event Func WillQuit
}
});
- BridgeConnector.Socket.Emit("register-app-will-quit-event", GetHashCode());
+ BridgeConnector.Emit("register-app-will-quit-event", GetHashCode());
}
_willQuit += value;
}
@@ -170,7 +175,7 @@ public event Func WillQuit
_willQuit -= value;
if (_willQuit == null)
- BridgeConnector.Socket.Off("app-will-quit" + GetHashCode());
+ BridgeConnector.Off("app-will-quit" + GetHashCode());
}
}
@@ -187,7 +192,7 @@ public event Func Quitting
{
if (_quitting == null)
{
- BridgeConnector.Socket.On("app-will-quit" + GetHashCode() + "quitting", async () =>
+ BridgeConnector.On("app-will-quit" + GetHashCode() + "quitting", async () =>
{
if(_willQuit == null)
{
@@ -196,7 +201,7 @@ public event Func Quitting
}
});
- BridgeConnector.Socket.Emit("register-app-will-quit-event", GetHashCode() + "quitting");
+ BridgeConnector.Emit("register-app-will-quit-event", GetHashCode() + "quitting");
}
_quitting += value;
}
@@ -205,7 +210,7 @@ public event Func Quitting
_quitting -= value;
if (_quitting == null)
- BridgeConnector.Socket.Off("app-will-quit" + GetHashCode() + "quitting");
+ BridgeConnector.Off("app-will-quit" + GetHashCode() + "quitting");
}
}
@@ -220,12 +225,12 @@ public event Action BrowserWindowBlur
{
if (_browserWindowBlur == null)
{
- BridgeConnector.Socket.On("app-browser-window-blur" + GetHashCode(), () =>
+ BridgeConnector.On("app-browser-window-blur" + GetHashCode(), () =>
{
_browserWindowBlur();
});
- BridgeConnector.Socket.Emit("register-app-browser-window-blur-event", GetHashCode());
+ BridgeConnector.Emit("register-app-browser-window-blur-event", GetHashCode());
}
_browserWindowBlur += value;
}
@@ -234,7 +239,7 @@ public event Action BrowserWindowBlur
_browserWindowBlur -= value;
if (_browserWindowBlur == null)
- BridgeConnector.Socket.Off("app-browser-window-blur" + GetHashCode());
+ BridgeConnector.Off("app-browser-window-blur" + GetHashCode());
}
}
@@ -249,12 +254,12 @@ public event Action BrowserWindowFocus
{
if (_browserWindowFocus == null)
{
- BridgeConnector.Socket.On("app-browser-window-focus" + GetHashCode(), () =>
+ BridgeConnector.On("app-browser-window-focus" + GetHashCode(), () =>
{
_browserWindowFocus();
});
- BridgeConnector.Socket.Emit("register-app-browser-window-focus-event", GetHashCode());
+ BridgeConnector.Emit("register-app-browser-window-focus-event", GetHashCode());
}
_browserWindowFocus += value;
}
@@ -263,7 +268,7 @@ public event Action BrowserWindowFocus
_browserWindowFocus -= value;
if (_browserWindowFocus == null)
- BridgeConnector.Socket.Off("app-browser-window-focus" + GetHashCode());
+ BridgeConnector.Off("app-browser-window-focus" + GetHashCode());
}
}
@@ -278,12 +283,12 @@ public event Action BrowserWindowCreated
{
if (_browserWindowCreated == null)
{
- BridgeConnector.Socket.On("app-browser-window-created" + GetHashCode(), () =>
+ BridgeConnector.On("app-browser-window-created" + GetHashCode(), () =>
{
_browserWindowCreated();
});
- BridgeConnector.Socket.Emit("register-app-browser-window-created-event", GetHashCode());
+ BridgeConnector.Emit("register-app-browser-window-created-event", GetHashCode());
}
_browserWindowCreated += value;
}
@@ -292,7 +297,7 @@ public event Action BrowserWindowCreated
_browserWindowCreated -= value;
if (_browserWindowCreated == null)
- BridgeConnector.Socket.Off("app-browser-window-created" + GetHashCode());
+ BridgeConnector.Off("app-browser-window-created" + GetHashCode());
}
}
@@ -307,12 +312,12 @@ public event Action WebContentsCreated
{
if (_webContentsCreated == null)
{
- BridgeConnector.Socket.On("app-web-contents-created" + GetHashCode(), () =>
+ BridgeConnector.On("app-web-contents-created" + GetHashCode(), () =>
{
_webContentsCreated();
});
- BridgeConnector.Socket.Emit("register-app-web-contents-created-event", GetHashCode());
+ BridgeConnector.Emit("register-app-web-contents-created-event", GetHashCode());
}
_webContentsCreated += value;
}
@@ -321,7 +326,7 @@ public event Action WebContentsCreated
_webContentsCreated -= value;
if (_webContentsCreated == null)
- BridgeConnector.Socket.Off("app-web-contents-created" + GetHashCode());
+ BridgeConnector.Off("app-web-contents-created" + GetHashCode());
}
}
@@ -338,12 +343,12 @@ public event Action AccessibilitySupportChanged
{
if (_accessibilitySupportChanged == null)
{
- BridgeConnector.Socket.On("app-accessibility-support-changed" + GetHashCode(), (state) =>
+ BridgeConnector.On("app-accessibility-support-changed" + GetHashCode(), (state) =>
{
- _accessibilitySupportChanged((bool)state);
+ _accessibilitySupportChanged(state);
});
- BridgeConnector.Socket.Emit("register-app-accessibility-support-changed-event", GetHashCode());
+ BridgeConnector.Emit("register-app-accessibility-support-changed-event", GetHashCode());
}
_accessibilitySupportChanged += value;
}
@@ -352,7 +357,7 @@ public event Action AccessibilitySupportChanged
_accessibilitySupportChanged -= value;
if (_accessibilitySupportChanged == null)
- BridgeConnector.Socket.Off("app-accessibility-support-changed" + GetHashCode());
+ BridgeConnector.Off("app-accessibility-support-changed" + GetHashCode());
}
}
@@ -396,6 +401,7 @@ internal set
}
}
}
+
private bool _isReady = false;
///
@@ -411,12 +417,12 @@ public event Action OpenFile
{
if (_openFile == null)
{
- BridgeConnector.Socket.On("app-open-file" + GetHashCode(), (file) =>
+ BridgeConnector.On("app-open-file" + GetHashCode(), (file) =>
{
- _openFile(file.ToString());
+ _openFile(file);
});
- BridgeConnector.Socket.Emit("register-app-open-file-event", GetHashCode());
+ BridgeConnector.Emit("register-app-open-file-event", GetHashCode());
}
_openFile += value;
}
@@ -425,7 +431,7 @@ public event Action OpenFile
_openFile -= value;
if (_openFile == null)
- BridgeConnector.Socket.Off("app-open-file" + GetHashCode());
+ BridgeConnector.Off("app-open-file" + GetHashCode());
}
}
@@ -442,12 +448,12 @@ public event Action OpenUrl
{
if (_openUrl == null)
{
- BridgeConnector.Socket.On("app-open-url" + GetHashCode(), (url) =>
+ BridgeConnector.On("app-open-url" + GetHashCode(), (url) =>
{
- _openUrl(url.ToString());
+ _openUrl(url);
});
- BridgeConnector.Socket.Emit("register-app-open-url-event", GetHashCode());
+ BridgeConnector.Emit("register-app-open-url-event", GetHashCode());
}
_openUrl += value;
}
@@ -456,7 +462,7 @@ public event Action OpenUrl
_openUrl -= value;
if (_openUrl == null)
- BridgeConnector.Socket.Off("app-open-url" + GetHashCode());
+ BridgeConnector.Off("app-open-url" + GetHashCode());
}
}
@@ -472,14 +478,9 @@ public event Action OpenUrl
///
public string Name
{
- [Obsolete("Use the asynchronous version NameAsync instead")]
- get
- {
- return NameAsync.Result;
- }
set
{
- BridgeConnector.Socket.Emit("appSetName", value);
+ BridgeConnector.Emit("appSetName", value);
}
}
@@ -491,26 +492,7 @@ public string Name
/// should usually also specify a productName field, which is your application's full capitalized name, and
/// which will be preferred over name by Electron.
///
- public Task NameAsync
- {
- get
- {
- return Task.Run(() =>
- {
- var taskCompletionSource = new TaskCompletionSource();
-
- BridgeConnector.Socket.On("appGetNameCompleted", (result) =>
- {
- BridgeConnector.Socket.Off("appGetNameCompleted");
- taskCompletionSource.SetResult((string)result);
- });
-
- BridgeConnector.Socket.Emit("appGetName");
-
- return taskCompletionSource.Task;
- });
- }
- }
+ public Task GetNameAsync() => BridgeConnector.OnResult("appGetName", "appGetNameCompleted");
internal App()
@@ -537,14 +519,17 @@ internal static App Instance
}
}
+ ///
+ /// Manually set that the app is ready instead of using the UseElectron extension method
+ ///
+ public static void ManuallySetIsReady()
+ {
+ Instance.IsReady = true;
+ }
+
private static App _app;
private static object _syncRoot = new object();
- private readonly JsonSerializer _jsonSerializer = new JsonSerializer()
- {
- ContractResolver = new CamelCasePropertyNamesContractResolver()
- };
-
///
/// Try to close all windows. The event will be emitted first. If all windows are successfully
/// closed, the event will be emitted and by default the application will terminate. This method
@@ -553,7 +538,7 @@ internal static App Instance
///
public void Quit()
{
- BridgeConnector.Socket.Emit("appQuit");
+ BridgeConnector.EmitSync("appQuit");
}
///
@@ -563,7 +548,7 @@ public void Quit()
/// Exits immediately with exitCode. exitCode defaults to 0.
public void Exit(int exitCode = 0)
{
- BridgeConnector.Socket.Emit("appExit", exitCode);
+ BridgeConnector.EmitSync("appExit", exitCode);
}
///
@@ -578,7 +563,7 @@ public void Exit(int exitCode = 0)
///
public void Relaunch()
{
- BridgeConnector.Socket.Emit("appRelaunch");
+ BridgeConnector.EmitSync("appRelaunch");
}
///
@@ -596,7 +581,7 @@ public void Relaunch()
/// Options for the relaunch.
public void Relaunch(RelaunchOptions relaunchOptions)
{
- BridgeConnector.Socket.Emit("appRelaunch", JObject.FromObject(relaunchOptions, _jsonSerializer));
+ BridgeConnector.EmitSync("appRelaunch", JObject.FromObject(relaunchOptions, _jsonSerializer));
}
///
@@ -605,7 +590,7 @@ public void Relaunch(RelaunchOptions relaunchOptions)
///
public void Focus()
{
- BridgeConnector.Socket.Emit("appFocus");
+ BridgeConnector.Emit("appFocus");
}
///
@@ -616,7 +601,7 @@ public void Focus()
///
public void Focus(FocusOptions focusOptions)
{
- BridgeConnector.Socket.Emit("appFocus", JObject.FromObject(focusOptions, _jsonSerializer));
+ BridgeConnector.Emit("appFocus", JObject.FromObject(focusOptions, _jsonSerializer));
}
///
@@ -624,7 +609,7 @@ public void Focus(FocusOptions focusOptions)
///
public void Hide()
{
- BridgeConnector.Socket.Emit("appHide");
+ BridgeConnector.Emit("appHide");
}
///
@@ -632,31 +617,13 @@ public void Hide()
///
public void Show()
{
- BridgeConnector.Socket.Emit("appShow");
+ BridgeConnector.Emit("appShow");
}
///
/// The current application directory.
///
- public async Task GetAppPathAsync(CancellationToken cancellationToken = default)
- {
- cancellationToken.ThrowIfCancellationRequested();
-
- var taskCompletionSource = new TaskCompletionSource();
- using(cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
- {
- BridgeConnector.Socket.On("appGetAppPathCompleted", (path) =>
- {
- BridgeConnector.Socket.Off("appGetAppPathCompleted");
- taskCompletionSource.SetResult(path.ToString());
- });
-
- BridgeConnector.Socket.Emit("appGetAppPath");
-
- return await taskCompletionSource.Task
- .ConfigureAwait(false);
- }
- }
+ public Task GetAppPathAsync(CancellationToken cancellationToken = default) => BridgeConnector.OnResult("appGetAppPath", "appGetAppPathCompleted", cancellationToken);
///
/// Sets or creates a directory your app's logs which can then be manipulated with
@@ -668,7 +635,7 @@ public async Task GetAppPathAsync(CancellationToken cancellationToken =
/// A custom path for your logs. Must be absolute.
public void SetAppLogsPath(string path)
{
- BridgeConnector.Socket.Emit("appSetAppLogsPath", path);
+ BridgeConnector.Emit("appSetAppLogsPath", path);
}
///
@@ -679,26 +646,8 @@ public void SetAppLogsPath(string path)
/// Special directory.
/// The cancellation token.
/// A path to a special directory or file associated with name.
- public async Task GetPathAsync(PathName pathName, CancellationToken cancellationToken = default)
- {
- cancellationToken.ThrowIfCancellationRequested();
-
- var taskCompletionSource = new TaskCompletionSource();
- using(cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
- {
- BridgeConnector.Socket.On("appGetPathCompleted", (path) =>
- {
- BridgeConnector.Socket.Off("appGetPathCompleted");
-
- taskCompletionSource.SetResult(path.ToString());
- });
+ public Task GetPathAsync(PathName pathName, CancellationToken cancellationToken = default) => BridgeConnector.OnResult("appGetPath", "appGetPathCompleted", cancellationToken, pathName.GetDescription());
- BridgeConnector.Socket.Emit("appGetPath", pathName.GetDescription());
-
- return await taskCompletionSource.Task
- .ConfigureAwait(false);
- }
- }
///
/// Overrides the path to a special directory or file associated with name. If the path specifies a directory
@@ -714,7 +663,7 @@ public async Task GetPathAsync(PathName pathName, CancellationToken canc
///
public void SetPath(PathName name, string path)
{
- BridgeConnector.Socket.Emit("appSetPath", name.GetDescription(), path);
+ BridgeConnector.Emit("appSetPath", name.GetDescription(), path);
}
///
@@ -722,25 +671,7 @@ public void SetPath(PathName name, string path)
/// the version of the current bundle or executable is returned.
///
/// The version of the loaded application.
- public async Task GetVersionAsync(CancellationToken cancellationToken = default)
- {
- cancellationToken.ThrowIfCancellationRequested();
-
- var taskCompletionSource = new TaskCompletionSource();
- using(cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
- {
- BridgeConnector.Socket.On("appGetVersionCompleted", (version) =>
- {
- BridgeConnector.Socket.Off("appGetVersionCompleted");
- taskCompletionSource.SetResult(version.ToString());
- });
-
- BridgeConnector.Socket.Emit("appGetVersion");
-
- return await taskCompletionSource.Task
- .ConfigureAwait(false);
- }
- }
+ public Task GetVersionAsync(CancellationToken cancellationToken = default) => BridgeConnector.OnResult("appGetVersion", "appGetVersionCompleted", cancellationToken);
///
/// The current application locale. Possible return values are documented here.
@@ -750,25 +681,7 @@ public async Task GetVersionAsync(CancellationToken cancellationToken =
/// Note: On Windows, you have to call it after the events gets emitted.
///
/// The current application locale.
- public async Task GetLocaleAsync(CancellationToken cancellationToken = default)
- {
- cancellationToken.ThrowIfCancellationRequested();
-
- var taskCompletionSource = new TaskCompletionSource();
- using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
- {
- BridgeConnector.Socket.On("appGetLocaleCompleted", (local) =>
- {
- BridgeConnector.Socket.Off("appGetLocaleCompleted");
- taskCompletionSource.SetResult(local.ToString());
- });
-
- BridgeConnector.Socket.Emit("appGetLocale");
-
- return await taskCompletionSource.Task
- .ConfigureAwait(false);
- }
- }
+ public Task GetLocaleAsync(CancellationToken cancellationToken = default) => BridgeConnector.OnResult("appGetLocale", "appGetLocaleCompleted", cancellationToken);
///
/// Adds path to the recent documents list. This list is managed by the OS. On Windows you can visit the
@@ -777,7 +690,7 @@ public async Task GetLocaleAsync(CancellationToken cancellationToken = d
/// Path to add.
public void AddRecentDocument(string path)
{
- BridgeConnector.Socket.Emit("appAddRecentDocument", path);
+ BridgeConnector.Emit("appAddRecentDocument", path);
}
///
@@ -785,7 +698,7 @@ public void AddRecentDocument(string path)
///
public void ClearRecentDocuments()
{
- BridgeConnector.Socket.Emit("appClearRecentDocuments");
+ BridgeConnector.Emit("appClearRecentDocuments");
}
///
@@ -876,25 +789,7 @@ public async Task SetAsDefaultProtocolClientAsync(string protocol, string
/// Arguments passed to the executable. Defaults to an empty array.
/// The cancellation token.
/// Whether the call succeeded.
- public async Task SetAsDefaultProtocolClientAsync(string protocol, string path, string[] args, CancellationToken cancellationToken = default)
- {
- cancellationToken.ThrowIfCancellationRequested();
-
- var taskCompletionSource = new TaskCompletionSource();
- using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
- {
- BridgeConnector.Socket.On("appSetAsDefaultProtocolClientCompleted", (success) =>
- {
- BridgeConnector.Socket.Off("appSetAsDefaultProtocolClientCompleted");
- taskCompletionSource.SetResult((bool) success);
- });
-
- BridgeConnector.Socket.Emit("appSetAsDefaultProtocolClient", protocol, path, args);
-
- return await taskCompletionSource.Task
- .ConfigureAwait(false);
- }
- }
+ public Task SetAsDefaultProtocolClientAsync(string protocol, string path, string[] args, CancellationToken cancellationToken = default) => BridgeConnector.OnResult("appSetAsDefaultProtocolClient", "appSetAsDefaultProtocolClientCompleted", cancellationToken, protocol, path, args);
///
/// This method checks if the current executable as the default handler for a protocol (aka URI scheme).
@@ -930,25 +825,8 @@ public async Task RemoveAsDefaultProtocolClientAsync(string protocol, stri
/// Defaults to an empty array.
/// The cancellation token.
/// Whether the call succeeded.
- public async Task RemoveAsDefaultProtocolClientAsync(string protocol, string path, string[] args, CancellationToken cancellationToken = default)
- {
- cancellationToken.ThrowIfCancellationRequested();
+ public Task RemoveAsDefaultProtocolClientAsync(string protocol, string path, string[] args, CancellationToken cancellationToken = default) => BridgeConnector.OnResult("appRemoveAsDefaultProtocolClient", "appRemoveAsDefaultProtocolClientCompleted", cancellationToken, protocol, path, args);
- var taskCompletionSource = new TaskCompletionSource();
- using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
- {
- BridgeConnector.Socket.On("appRemoveAsDefaultProtocolClientCompleted", (success) =>
- {
- BridgeConnector.Socket.Off("appRemoveAsDefaultProtocolClientCompleted");
- taskCompletionSource.SetResult((bool) success);
- });
-
- BridgeConnector.Socket.Emit("appRemoveAsDefaultProtocolClient", protocol, path, args);
-
- return await taskCompletionSource.Task
- .ConfigureAwait(false);
- }
- }
///
/// This method checks if the current executable is the default handler for a protocol (aka URI scheme).
@@ -1002,25 +880,8 @@ public async Task IsDefaultProtocolClientAsync(string protocol, string pat
/// Defaults to an empty array.
/// The cancellation token.
/// Whether the current executable is the default handler for a protocol (aka URI scheme).
- public async Task IsDefaultProtocolClientAsync(string protocol, string path, string[] args, CancellationToken cancellationToken = default)
- {
- cancellationToken.ThrowIfCancellationRequested();
+ public Task IsDefaultProtocolClientAsync(string protocol, string path, string[] args, CancellationToken cancellationToken = default) => BridgeConnector.OnResult("appIsDefaultProtocolClient", "appIsDefaultProtocolClientCompleted", cancellationToken, protocol, path, args);
- var taskCompletionSource = new TaskCompletionSource();
- using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
- {
- BridgeConnector.Socket.On("appIsDefaultProtocolClientCompleted", (success) =>
- {
- BridgeConnector.Socket.Off("appIsDefaultProtocolClientCompleted");
- taskCompletionSource.SetResult((bool) success);
- });
-
- BridgeConnector.Socket.Emit("appIsDefaultProtocolClient", protocol, path, args);
-
- return await taskCompletionSource.Task
- .ConfigureAwait(false);
- }
- }
///
/// Adds tasks to the category of the JumpList on Windows.
@@ -1030,50 +891,14 @@ public async Task IsDefaultProtocolClientAsync(string protocol, string pat
/// Array of objects.
/// The cancellation token.
/// Whether the call succeeded.
- public async Task SetUserTasksAsync(UserTask[] userTasks, CancellationToken cancellationToken = default)
- {
- cancellationToken.ThrowIfCancellationRequested();
-
- var taskCompletionSource = new TaskCompletionSource();
- using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
- {
- BridgeConnector.Socket.On("appSetUserTasksCompleted", (success) =>
- {
- BridgeConnector.Socket.Off("appSetUserTasksCompleted");
- taskCompletionSource.SetResult((bool) success);
- });
-
- BridgeConnector.Socket.Emit("appSetUserTasks", JArray.FromObject(userTasks, _jsonSerializer));
-
- return await taskCompletionSource.Task
- .ConfigureAwait(false);
- }
- }
+ public Task SetUserTasksAsync(UserTask[] userTasks, CancellationToken cancellationToken = default) => BridgeConnector.OnResult("appSetUserTasks", "appSetUserTasksCompleted", cancellationToken, JArray.FromObject(userTasks, _jsonSerializer));
///
/// Jump List settings for the application.
///
/// The cancellation token.
/// Jump List settings.
- public async Task GetJumpListSettingsAsync(CancellationToken cancellationToken = default)
- {
- cancellationToken.ThrowIfCancellationRequested();
-
- var taskCompletionSource = new TaskCompletionSource();
- using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
- {
- BridgeConnector.Socket.On("appGetJumpListSettingsCompleted", (jumpListSettings) =>
- {
- BridgeConnector.Socket.Off("appGetJumpListSettingsCompleted");
- taskCompletionSource.SetResult(JObject.Parse(jumpListSettings.ToString()).ToObject());
- });
-
- BridgeConnector.Socket.Emit("appGetJumpListSettings");
-
- return await taskCompletionSource.Task
- .ConfigureAwait(false);
- }
- }
+ public Task GetJumpListSettingsAsync(CancellationToken cancellationToken = default) => BridgeConnector.OnResult("appGetJumpListSettings", "appGetJumpListSettingsCompleted", cancellationToken);
///
/// Sets or removes a custom Jump List for the application. If categories is null the previously set custom
@@ -1093,7 +918,7 @@ public async Task GetJumpListSettingsAsync(CancellationToken c
/// Array of objects.
public void SetJumpList(JumpListCategory[] categories)
{
- BridgeConnector.Socket.Emit("appSetJumpList", JArray.FromObject(categories, _jsonSerializer));
+ BridgeConnector.Emit("appSetJumpList", JArray.FromObject(categories, _jsonSerializer));
}
///
@@ -1117,33 +942,28 @@ public void SetJumpList(JumpListCategory[] categories)
/// should continue loading. And returns true if your process has sent its parameters to another instance, and
/// you should immediately quit.
///
- public async Task RequestSingleInstanceLockAsync(Action newInstanceOpened, CancellationToken cancellationToken = default)
+ public async Task RequestSingleInstanceLockAsync(Action newInstanceOpened, CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
- var taskCompletionSource = new TaskCompletionSource();
+ var taskCompletionSource = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
{
- BridgeConnector.Socket.On("appRequestSingleInstanceLockCompleted", (success) =>
+ BridgeConnector.On("appRequestSingleInstanceLockCompleted", (success) =>
{
- BridgeConnector.Socket.Off("appRequestSingleInstanceLockCompleted");
- taskCompletionSource.SetResult((bool)success);
+ BridgeConnector.Off("appRequestSingleInstanceLockCompleted");
+ taskCompletionSource.SetResult(success);
});
- BridgeConnector.Socket.Off("secondInstance");
- BridgeConnector.Socket.On("secondInstance", (result) =>
+ BridgeConnector.Off("secondInstance");
+ BridgeConnector.On("secondInstance", (result) =>
{
- JArray results = (JArray)result;
- string[] args = results.First.ToObject();
- string workingDirectory = results.Last.ToObject();
-
- newInstanceOpened(args, workingDirectory);
+ newInstanceOpened(result.args, result.workingDirectory);
});
- BridgeConnector.Socket.Emit("appRequestSingleInstanceLock");
+ BridgeConnector.Emit("appRequestSingleInstanceLock");
- return await taskCompletionSource.Task
- .ConfigureAwait(false);
+ return await taskCompletionSource.Task.ConfigureAwait(false);
}
}
@@ -1153,7 +973,7 @@ public async Task RequestSingleInstanceLockAsync(Action
///
public void ReleaseSingleInstanceLock()
{
- BridgeConnector.Socket.Emit("appReleaseSingleInstanceLock");
+ BridgeConnector.Emit("appReleaseSingleInstanceLock");
}
///
@@ -1162,25 +982,7 @@ public void ReleaseSingleInstanceLock()
/// .
///
/// The cancellation token.
- public async Task HasSingleInstanceLockAsync(CancellationToken cancellationToken = default)
- {
- cancellationToken.ThrowIfCancellationRequested();
-
- var taskCompletionSource = new TaskCompletionSource();
- using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
- {
- BridgeConnector.Socket.On("appHasSingleInstanceLockCompleted", (hasLock) =>
- {
- BridgeConnector.Socket.Off("appHasSingleInstanceLockCompleted");
- taskCompletionSource.SetResult((bool) hasLock);
- });
-
- BridgeConnector.Socket.Emit("appHasSingleInstanceLock");
-
- return await taskCompletionSource.Task
- .ConfigureAwait(false);
- }
- }
+ public Task HasSingleInstanceLockAsync(CancellationToken cancellationToken = default) => BridgeConnector.OnResult("appHasSingleInstanceLock", "appHasSingleInstanceLockCompleted", cancellationToken);
///
/// Creates an NSUserActivity and sets it as the current activity. The activity is
@@ -1208,39 +1010,22 @@ public void SetUserActivity(string type, object userInfo)
///
public void SetUserActivity(string type, object userInfo, string webpageUrl)
{
- BridgeConnector.Socket.Emit("appSetUserActivity", type, userInfo, webpageUrl);
+ BridgeConnector.Emit("appSetUserActivity", type, userInfo, webpageUrl);
}
///
/// The type of the currently running activity.
///
/// The cancellation token.
- public async Task GetCurrentActivityTypeAsync(CancellationToken cancellationToken = default)
- {
- cancellationToken.ThrowIfCancellationRequested();
-
- var taskCompletionSource = new TaskCompletionSource();
- using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
- {
- BridgeConnector.Socket.On("appGetCurrentActivityTypeCompleted", (activityType) =>
- {
- BridgeConnector.Socket.Off("appGetCurrentActivityTypeCompleted");
- taskCompletionSource.SetResult(activityType.ToString());
- });
+ public Task GetCurrentActivityTypeAsync(CancellationToken cancellationToken = default) => BridgeConnector.OnResult("appGetCurrentActivityType", "appGetCurrentActivityTypeCompleted", cancellationToken);
- BridgeConnector.Socket.Emit("appGetCurrentActivityType");
-
- return await taskCompletionSource.Task
- .ConfigureAwait(false);
- }
- }
///
/// Invalidates the current Handoff user activity.
///
public void InvalidateCurrentActivity()
{
- BridgeConnector.Socket.Emit("appInvalidateCurrentActivity");
+ BridgeConnector.Emit("appInvalidateCurrentActivity");
}
///
@@ -1248,7 +1033,7 @@ public void InvalidateCurrentActivity()
///
public void ResignCurrentActivity()
{
- BridgeConnector.Socket.Emit("appResignCurrentActivity");
+ BridgeConnector.Emit("appResignCurrentActivity");
}
///
@@ -1257,7 +1042,7 @@ public void ResignCurrentActivity()
/// Model Id.
public void SetAppUserModelId(string id)
{
- BridgeConnector.Socket.Emit("appSetAppUserModelId", id);
+ BridgeConnector.Emit("appSetAppUserModelId", id);
}
/// TODO: Check new parameter which is a function [App.ImportCertificate]
@@ -1269,25 +1054,7 @@ public void SetAppUserModelId(string id)
///
/// The cancellation token.
/// Result of import. Value of 0 indicates success.
- public async Task ImportCertificateAsync(ImportCertificateOptions options, CancellationToken cancellationToken = default)
- {
- cancellationToken.ThrowIfCancellationRequested();
-
- var taskCompletionSource = new TaskCompletionSource();
- using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
- {
- BridgeConnector.Socket.On("appImportCertificateCompleted", (result) =>
- {
- BridgeConnector.Socket.Off("appImportCertificateCompleted");
- taskCompletionSource.SetResult((int) result);
- });
-
- BridgeConnector.Socket.Emit("appImportCertificate", JObject.FromObject(options, _jsonSerializer));
-
- return await taskCompletionSource.Task
- .ConfigureAwait(false);
- }
- }
+ public Task ImportCertificateAsync(ImportCertificateOptions options, CancellationToken cancellationToken = default) => BridgeConnector.OnResult("appImportCertificate", "appImportCertificateCompleted", cancellationToken, JObject.FromObject(options, _jsonSerializer));
///
/// Memory and cpu usage statistics of all the processes associated with the app.
@@ -1297,27 +1064,7 @@ public async Task ImportCertificateAsync(ImportCertificateOptions options,
/// statistics of all the processes associated with the app.
/// The cancellation token.
///
- public async Task GetAppMetricsAsync(CancellationToken cancellationToken = default)
- {
- cancellationToken.ThrowIfCancellationRequested();
-
- var taskCompletionSource = new TaskCompletionSource();
- using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
- {
- BridgeConnector.Socket.On("appGetAppMetricsCompleted", (result) =>
- {
- BridgeConnector.Socket.Off("appGetAppMetricsCompleted");
- var processMetrics = ((JArray)result).ToObject();
-
- taskCompletionSource.SetResult(processMetrics);
- });
-
- BridgeConnector.Socket.Emit("appGetAppMetrics");
-
- return await taskCompletionSource.Task
- .ConfigureAwait(false);
- }
- }
+ public Task GetAppMetricsAsync(CancellationToken cancellationToken = default) => BridgeConnector.OnResult("appGetAppMetrics", "appGetAppMetricsCompleted", cancellationToken);
///
/// The Graphics Feature Status from chrome://gpu/.
@@ -1325,27 +1072,7 @@ public async Task GetAppMetricsAsync(CancellationToken cancella
/// Note: This information is only usable after the gpu-info-update event is emitted.
/// The cancellation token.
///
- public async Task GetGpuFeatureStatusAsync(CancellationToken cancellationToken = default)
- {
- cancellationToken.ThrowIfCancellationRequested();
-
- var taskCompletionSource = new TaskCompletionSource();
- using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
- {
- BridgeConnector.Socket.On("appGetGpuFeatureStatusCompleted", (result) =>
- {
- BridgeConnector.Socket.Off("appGetGpuFeatureStatusCompleted");
- var gpuFeatureStatus = ((JObject)result).ToObject();
-
- taskCompletionSource.SetResult(gpuFeatureStatus);
- });
-
- BridgeConnector.Socket.Emit("appGetGpuFeatureStatus");
-
- return await taskCompletionSource.Task
- .ConfigureAwait(false);
- }
- }
+ public Task GetGpuFeatureStatusAsync(CancellationToken cancellationToken = default) => BridgeConnector.OnResult("appGetGpuFeatureStatus", "appGetGpuFeatureStatusCompleted", cancellationToken);
///
/// Sets the counter badge for current app. Setting the count to 0 will hide the badge.
@@ -1357,49 +1084,13 @@ public async Task GetGpuFeatureStatusAsync(CancellationToken c
/// Counter badge.
/// The cancellation token.
/// Whether the call succeeded.
- public async Task SetBadgeCountAsync(int count, CancellationToken cancellationToken = default)
- {
- cancellationToken.ThrowIfCancellationRequested();
-
- var taskCompletionSource = new TaskCompletionSource();
- using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
- {
- BridgeConnector.Socket.On("appSetBadgeCountCompleted", (success) =>
- {
- BridgeConnector.Socket.Off("appSetBadgeCountCompleted");
- taskCompletionSource.SetResult((bool) success);
- });
-
- BridgeConnector.Socket.Emit("appSetBadgeCount", count);
-
- return await taskCompletionSource.Task
- .ConfigureAwait(false);
- }
- }
+ public Task SetBadgeCountAsync(int count, CancellationToken cancellationToken = default) => BridgeConnector.OnResult("appSetBadgeCount", "appSetBadgeCountCompleted", cancellationToken, count);
///
/// The current value displayed in the counter badge.
///
/// The cancellation token.
- public async Task GetBadgeCountAsync(CancellationToken cancellationToken = default)
- {
- cancellationToken.ThrowIfCancellationRequested();
-
- var taskCompletionSource = new TaskCompletionSource();
- using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
- {
- BridgeConnector.Socket.On("appGetBadgeCountCompleted", (count) =>
- {
- BridgeConnector.Socket.Off("appGetBadgeCountCompleted");
- taskCompletionSource.SetResult((int)count);
- });
-
- BridgeConnector.Socket.Emit("appGetBadgeCount");
-
- return await taskCompletionSource.Task
- .ConfigureAwait(false);
- }
- }
+ public Task GetBadgeCountAsync(CancellationToken cancellationToken = default) => BridgeConnector.OnResult("appGetBadgeCount", "appGetBadgeCountCompleted", cancellationToken);
///
/// A object that allows you to read and manipulate the command line arguments that Chromium uses.
@@ -1410,25 +1101,7 @@ public async Task GetBadgeCountAsync(CancellationToken cancellationToken =
/// Whether the current desktop environment is Unity launcher.
///
/// The cancellation token.
- public async Task IsUnityRunningAsync(CancellationToken cancellationToken = default)
- {
- cancellationToken.ThrowIfCancellationRequested();
-
- var taskCompletionSource = new TaskCompletionSource();
- using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
- {
- BridgeConnector.Socket.On("appIsUnityRunningCompleted", (isUnityRunning) =>
- {
- BridgeConnector.Socket.Off("appIsUnityRunningCompleted");
- taskCompletionSource.SetResult((bool)isUnityRunning);
- });
-
- BridgeConnector.Socket.Emit("appIsUnityRunning");
-
- return await taskCompletionSource.Task
- .ConfigureAwait(false);
- }
- }
+ public Task IsUnityRunningAsync(CancellationToken cancellationToken = default) => BridgeConnector.OnResult("appIsUnityRunning", "appIsUnityRunningCompleted", cancellationToken);
///
/// If you provided path and args options to then you need to pass the same
@@ -1445,35 +1118,9 @@ public async Task GetLoginItemSettingsAsync(CancellationToken
///
///
/// The cancellation token.
- public async Task GetLoginItemSettingsAsync(LoginItemSettingsOptions options, CancellationToken cancellationToken = default)
- {
- cancellationToken.ThrowIfCancellationRequested();
-
- var taskCompletionSource = new TaskCompletionSource();
- using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
- {
- BridgeConnector.Socket.On("appGetLoginItemSettingsCompleted", (loginItemSettings) =>
- {
- BridgeConnector.Socket.Off("appGetLoginItemSettingsCompleted");
-
- var result = ((JObject) loginItemSettings).ToObject();
-
- taskCompletionSource.SetResult(result);
- });
-
- if (options == null)
- {
- BridgeConnector.Socket.Emit("appGetLoginItemSettings");
- }
- else
- {
- BridgeConnector.Socket.Emit("appGetLoginItemSettings", JObject.FromObject(options, _jsonSerializer));
- }
-
- return await taskCompletionSource.Task
- .ConfigureAwait(false);
- }
- }
+ public Task GetLoginItemSettingsAsync(LoginItemSettingsOptions options, CancellationToken cancellationToken = default) =>
+ options is null ? BridgeConnector.OnResult("appGetLoginItemSettings", "appGetLoginItemSettingsCompleted", cancellationToken)
+ : BridgeConnector.OnResult("appGetLoginItemSettings", "appGetLoginItemSettingsCompleted", cancellationToken, JObject.FromObject(options, _jsonSerializer));
///
/// Set the app's login item settings.
@@ -1483,7 +1130,7 @@ public async Task GetLoginItemSettingsAsync(LoginItemSettings
///
public void SetLoginItemSettings(LoginSettings loginSettings)
{
- BridgeConnector.Socket.Emit("appSetLoginItemSettings", JObject.FromObject(loginSettings, _jsonSerializer));
+ BridgeConnector.Emit("appSetLoginItemSettings", JObject.FromObject(loginSettings, _jsonSerializer));
}
///
@@ -1492,25 +1139,8 @@ public void SetLoginItemSettings(LoginSettings loginSettings)
/// See Chromium's accessibility docs for more details.
///
/// if Chrome’s accessibility support is enabled, otherwise.
- public async Task IsAccessibilitySupportEnabledAsync(CancellationToken cancellationToken = default)
- {
- cancellationToken.ThrowIfCancellationRequested();
-
- var taskCompletionSource = new TaskCompletionSource();
- using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
- {
- BridgeConnector.Socket.On("appIsAccessibilitySupportEnabledCompleted", (isAccessibilitySupportEnabled) =>
- {
- BridgeConnector.Socket.Off("appIsAccessibilitySupportEnabledCompleted");
- taskCompletionSource.SetResult((bool)isAccessibilitySupportEnabled);
- });
+ public Task IsAccessibilitySupportEnabledAsync(CancellationToken cancellationToken = default) => BridgeConnector.OnResult("appIsAccessibilitySupportEnabled", "appIsAccessibilitySupportEnabledCompleted", cancellationToken);
- BridgeConnector.Socket.Emit("appIsAccessibilitySupportEnabled");
-
- return await taskCompletionSource.Task
- .ConfigureAwait(false);
- }
- }
///
/// Manually enables Chrome's accessibility support, allowing to expose accessibility switch to users in application settings.
@@ -1524,7 +1154,7 @@ public async Task IsAccessibilitySupportEnabledAsync(CancellationToken can
/// Enable or disable accessibility tree rendering.
public void SetAccessibilitySupportEnabled(bool enabled)
{
- BridgeConnector.Socket.Emit("appSetAboutPanelOptions", enabled);
+ BridgeConnector.Emit("appSetAboutPanelOptions", enabled);
}
///
@@ -1533,7 +1163,7 @@ public void SetAccessibilitySupportEnabled(bool enabled)
///
public void ShowAboutPanel()
{
- BridgeConnector.Socket.Emit("appShowAboutPanel");
+ BridgeConnector.Emit("appShowAboutPanel");
}
///
@@ -1549,7 +1179,7 @@ public void ShowAboutPanel()
/// About panel options.
public void SetAboutPanelOptions(AboutPanelOptions options)
{
- BridgeConnector.Socket.Emit("appSetAboutPanelOptions", JObject.FromObject(options, _jsonSerializer));
+ BridgeConnector.Emit("appSetAboutPanelOptions", JObject.FromObject(options, _jsonSerializer));
}
///
@@ -1562,14 +1192,9 @@ public void SetAboutPanelOptions(AboutPanelOptions options)
///
public string UserAgentFallback
{
- [Obsolete("Use the asynchronous version UserAgentFallbackAsync instead")]
- get
- {
- return UserAgentFallbackAsync.Result;
- }
set
{
- BridgeConnector.Socket.Emit("appSetUserAgentFallback", value);
+ BridgeConnector.Emit("appSetUserAgentFallback", value);
}
}
@@ -1581,26 +1206,7 @@ public string UserAgentFallback
/// custom value as early as possible in your app's initialization to ensure that your overridden value
/// is used.
///
- public Task UserAgentFallbackAsync
- {
- get
- {
- return Task.Run(() =>
- {
- var taskCompletionSource = new TaskCompletionSource();
-
- BridgeConnector.Socket.On("appGetUserAgentFallbackCompleted", (result) =>
- {
- BridgeConnector.Socket.Off("appGetUserAgentFallbackCompleted");
- taskCompletionSource.SetResult((string)result);
- });
-
- BridgeConnector.Socket.Emit("appGetUserAgentFallback");
-
- return taskCompletionSource.Task;
- });
- }
- }
+ public Task GetUserAgentFallbackAsync() => BridgeConnector.OnResult("appGetUserAgentFallback", "appGetUserAgentFallbackCompleted");
internal void PreventQuit()
{
@@ -1615,28 +1221,32 @@ internal void PreventQuit()
///
/// The event name
/// The handler
- public void On(string eventName, Action fn)
- => Events.Instance.On(ModuleName, eventName, fn);
+ public void On(string eventName, Action fn) => Events.Instance.On(ModuleName, eventName, fn);
+
///
/// Subscribe to an unmapped event on the module.
///
/// The event name
/// The handler
- public void On(string eventName, Action
public bool AutoInstallOnAppQuit
{
- get
- {
- return Task.Run(() =>
- {
- var taskCompletionSource = new TaskCompletionSource();
-
- BridgeConnector.Socket.On("autoUpdater-autoInstallOnAppQuit-get-reply", (result) =>
- {
- BridgeConnector.Socket.Off("autoUpdater-autoInstallOnAppQuit-get-reply");
- taskCompletionSource.SetResult((bool)result);
- });
-
- BridgeConnector.Socket.Emit("autoUpdater-autoInstallOnAppQuit-get");
-
- return taskCompletionSource.Task;
- }).Result;
- }
set
{
- BridgeConnector.Socket.Emit("autoUpdater-autoInstallOnAppQuit-set", value);
+ BridgeConnector.Emit("autoUpdater-autoInstallOnAppQuit-set", value);
}
}
@@ -79,26 +74,9 @@ public bool AutoInstallOnAppQuit
///
public bool AllowPrerelease
{
- get
- {
- return Task.Run(() =>
- {
- var taskCompletionSource = new TaskCompletionSource();
-
- BridgeConnector.Socket.On("autoUpdater-allowPrerelease-get-reply", (result) =>
- {
- BridgeConnector.Socket.Off("autoUpdater-allowPrerelease-get-reply");
- taskCompletionSource.SetResult((bool)result);
- });
-
- BridgeConnector.Socket.Emit("autoUpdater-allowPrerelease-get");
-
- return taskCompletionSource.Task;
- }).Result;
- }
set
{
- BridgeConnector.Socket.Emit("autoUpdater-allowPrerelease-set", value);
+ BridgeConnector.Emit("autoUpdater-allowPrerelease-set", value);
}
}
@@ -108,26 +86,9 @@ public bool AllowPrerelease
///
public bool FullChangelog
{
- get
- {
- return Task.Run(() =>
- {
- var taskCompletionSource = new TaskCompletionSource();
-
- BridgeConnector.Socket.On("autoUpdater-fullChangelog-get-reply", (result) =>
- {
- BridgeConnector.Socket.Off("autoUpdater-fullChangelog-get-reply");
- taskCompletionSource.SetResult((bool)result);
- });
-
- BridgeConnector.Socket.Emit("autoUpdater-fullChangelog-get");
-
- return taskCompletionSource.Task;
- }).Result;
- }
set
{
- BridgeConnector.Socket.Emit("autoUpdater-fullChangelog-set", value);
+ BridgeConnector.Emit("autoUpdater-fullChangelog-set", value);
}
}
@@ -138,137 +99,32 @@ public bool FullChangelog
///
public bool AllowDowngrade
{
- get
- {
- return Task.Run(() =>
- {
- var taskCompletionSource = new TaskCompletionSource();
-
- BridgeConnector.Socket.On("autoUpdater-allowDowngrade-get-reply", (result) =>
- {
- BridgeConnector.Socket.Off("autoUpdater-allowDowngrade-get-reply");
- taskCompletionSource.SetResult((bool)result);
- });
-
- BridgeConnector.Socket.Emit("autoUpdater-allowDowngrade-get");
-
- return taskCompletionSource.Task;
- }).Result;
- }
set
{
- BridgeConnector.Socket.Emit("autoUpdater-allowDowngrade-set", value);
+ BridgeConnector.Emit("autoUpdater-allowDowngrade-set", value);
}
}
///
/// For test only.
///
- public string UpdateConfigPath
- {
- get
- {
- return Task.Run(() =>
- {
- var taskCompletionSource = new TaskCompletionSource();
-
- BridgeConnector.Socket.On("autoUpdater-updateConfigPath-get-reply", (result) =>
- {
- BridgeConnector.Socket.Off("autoUpdater-updateConfigPath-get-reply");
- taskCompletionSource.SetResult(result.ToString());
- });
-
- BridgeConnector.Socket.Emit("autoUpdater-updateConfigPath-get");
-
- return taskCompletionSource.Task;
- }).Result;
- }
- }
+ public Task GetUpdateConfigPathAsync() => BridgeConnector.OnResult("autoUpdater-updateConfigPath-get", "autoUpdater-updateConfigPath-get-reply");
///
/// The current application version
///
- public Task CurrentVersionAsync
- {
- get
- {
- return Task.Run(() =>
- {
- var taskCompletionSource = new TaskCompletionSource();
-
- BridgeConnector.Socket.On("autoUpdater-currentVersion-get-reply", (result) =>
- {
- BridgeConnector.Socket.Off("autoUpdater-currentVersion-get-reply");
- SemVer version = ((JObject)result).ToObject();
- taskCompletionSource.SetResult(version);
- });
- BridgeConnector.Socket.Emit("autoUpdater-currentVersion-get");
-
- return taskCompletionSource.Task;
- });
- }
- }
+ public Task GetCurrentVersionAsync() => BridgeConnector.OnResult("autoUpdater-updateConcurrentVersionfigPath-get", "autoUpdater-currentVersion-get-reply");
///
/// Get the update channel. Not applicable for GitHub.
/// Doesn’t return channel from the update configuration, only if was previously set.
///
- [Obsolete("Use the asynchronous version ChannelAsync instead")]
- public string Channel
- {
- get
- {
- return ChannelAsync.Result;
- }
- }
-
- ///
- /// Get the update channel. Not applicable for GitHub.
- /// Doesn’t return channel from the update configuration, only if was previously set.
- ///
- public Task ChannelAsync
- {
- get
- {
- return Task.Run(() =>
- {
- var taskCompletionSource = new TaskCompletionSource();
-
- BridgeConnector.Socket.On("autoUpdater-channel-get-reply", (result) =>
- {
- BridgeConnector.Socket.Off("autoUpdater-channel-get-reply");
- taskCompletionSource.SetResult(result.ToString());
- });
- BridgeConnector.Socket.Emit("autoUpdater-channel-get");
-
- return taskCompletionSource.Task;
- });
- }
- }
-
-
+ public Task GetChannelAsync() => BridgeConnector.OnResult("autoUpdater-channel-get", "autoUpdater-channel-get-reply");
///
/// The request headers.
///
- public Task> RequestHeadersAsync
- {
- get
- {
- return Task.Run(() =>
- {
- var taskCompletionSource = new TaskCompletionSource>();
- BridgeConnector.Socket.On("autoUpdater-requestHeaders-get-reply", (headers) =>
- {
- BridgeConnector.Socket.Off("autoUpdater-requestHeaders-get-reply");
- Dictionary result = ((JObject)headers).ToObject>();
- taskCompletionSource.SetResult(result);
- });
- BridgeConnector.Socket.Emit("autoUpdater-requestHeaders-get");
- return taskCompletionSource.Task;
- });
- }
- }
+ public Task> GetRequestHeadersAsync() => BridgeConnector.OnResult>("autoUpdater-requestHeaders-get", "autoUpdater-requestHeaders-get-reply");
///
/// The request headers.
@@ -277,7 +133,7 @@ public Dictionary RequestHeaders
{
set
{
- BridgeConnector.Socket.Emit("autoUpdater-requestHeaders-set", JObject.FromObject(value, _jsonSerializer));
+ BridgeConnector.Emit("autoUpdater-requestHeaders-set", value);
}
}
@@ -290,12 +146,12 @@ public event Action OnError
{
if (_error == null)
{
- BridgeConnector.Socket.On("autoUpdater-error" + GetHashCode(), (message) =>
+ BridgeConnector.On("autoUpdater-error" + GetHashCode(), (message) =>
{
_error(message.ToString());
});
- BridgeConnector.Socket.Emit("register-autoUpdater-error-event", GetHashCode());
+ BridgeConnector.Emit("register-autoUpdater-error-event", GetHashCode());
}
_error += value;
}
@@ -304,7 +160,7 @@ public event Action OnError
_error -= value;
if (_error == null)
- BridgeConnector.Socket.Off("autoUpdater-error" + GetHashCode());
+ BridgeConnector.Off("autoUpdater-error" + GetHashCode());
}
}
@@ -319,12 +175,12 @@ public event Action OnCheckingForUpdate
{
if (_checkingForUpdate == null)
{
- BridgeConnector.Socket.On("autoUpdater-checking-for-update" + GetHashCode(), () =>
+ BridgeConnector.On("autoUpdater-checking-for-update" + GetHashCode(), () =>
{
_checkingForUpdate();
});
- BridgeConnector.Socket.Emit("register-autoUpdater-checking-for-update-event", GetHashCode());
+ BridgeConnector.Emit("register-autoUpdater-checking-for-update-event", GetHashCode());
}
_checkingForUpdate += value;
}
@@ -333,7 +189,7 @@ public event Action OnCheckingForUpdate
_checkingForUpdate -= value;
if (_checkingForUpdate == null)
- BridgeConnector.Socket.Off("autoUpdater-checking-for-update" + GetHashCode());
+ BridgeConnector.Off("autoUpdater-checking-for-update" + GetHashCode());
}
}
@@ -349,12 +205,12 @@ public event Action OnUpdateAvailable
{
if (_updateAvailable == null)
{
- BridgeConnector.Socket.On("autoUpdater-update-available" + GetHashCode(), (updateInfo) =>
+ BridgeConnector.On("autoUpdater-update-available" + GetHashCode(), (updateInfo) =>
{
- _updateAvailable(JObject.Parse(updateInfo.ToString()).ToObject());
+ _updateAvailable(updateInfo);
});
- BridgeConnector.Socket.Emit("register-autoUpdater-update-available-event", GetHashCode());
+ BridgeConnector.Emit("register-autoUpdater-update-available-event", GetHashCode());
}
_updateAvailable += value;
}
@@ -363,7 +219,7 @@ public event Action OnUpdateAvailable
_updateAvailable -= value;
if (_updateAvailable == null)
- BridgeConnector.Socket.Off("autoUpdater-update-available" + GetHashCode());
+ BridgeConnector.Off("autoUpdater-update-available" + GetHashCode());
}
}
@@ -378,12 +234,12 @@ public event Action OnUpdateNotAvailable
{
if (_updateNotAvailable == null)
{
- BridgeConnector.Socket.On("autoUpdater-update-not-available" + GetHashCode(), (updateInfo) =>
+ BridgeConnector.On("autoUpdater-update-not-available" + GetHashCode(), (updateInfo) =>
{
- _updateNotAvailable(JObject.Parse(updateInfo.ToString()).ToObject());
+ _updateNotAvailable(updateInfo);
});
- BridgeConnector.Socket.Emit("register-autoUpdater-update-not-available-event", GetHashCode());
+ BridgeConnector.Emit("register-autoUpdater-update-not-available-event", GetHashCode());
}
_updateNotAvailable += value;
}
@@ -392,7 +248,7 @@ public event Action OnUpdateNotAvailable
_updateNotAvailable -= value;
if (_updateNotAvailable == null)
- BridgeConnector.Socket.Off("autoUpdater-update-not-available" + GetHashCode());
+ BridgeConnector.Off("autoUpdater-update-not-available" + GetHashCode());
}
}
@@ -407,12 +263,12 @@ public event Action OnDownloadProgress
{
if (_downloadProgress == null)
{
- BridgeConnector.Socket.On("autoUpdater-download-progress" + GetHashCode(), (progressInfo) =>
+ BridgeConnector.On("autoUpdater-download-progress" + GetHashCode(), (progressInfo) =>
{
- _downloadProgress(JObject.Parse(progressInfo.ToString()).ToObject());
+ _downloadProgress(progressInfo);
});
- BridgeConnector.Socket.Emit("register-autoUpdater-download-progress-event", GetHashCode());
+ BridgeConnector.Emit("register-autoUpdater-download-progress-event", GetHashCode());
}
_downloadProgress += value;
}
@@ -421,7 +277,7 @@ public event Action OnDownloadProgress
_downloadProgress -= value;
if (_downloadProgress == null)
- BridgeConnector.Socket.Off("autoUpdater-download-progress" + GetHashCode());
+ BridgeConnector.Off("autoUpdater-download-progress" + GetHashCode());
}
}
@@ -436,12 +292,12 @@ public event Action OnUpdateDownloaded
{
if (_updateDownloaded == null)
{
- BridgeConnector.Socket.On("autoUpdater-update-downloaded" + GetHashCode(), (updateInfo) =>
+ BridgeConnector.On("autoUpdater-update-downloaded" + GetHashCode(), (updateInfo) =>
{
- _updateDownloaded(JObject.Parse(updateInfo.ToString()).ToObject());
+ _updateDownloaded(updateInfo);
});
- BridgeConnector.Socket.Emit("register-autoUpdater-update-downloaded-event", GetHashCode());
+ BridgeConnector.Emit("register-autoUpdater-update-downloaded-event", GetHashCode());
}
_updateDownloaded += value;
}
@@ -450,7 +306,7 @@ public event Action OnUpdateDownloaded
_updateDownloaded -= value;
if (_updateDownloaded == null)
- BridgeConnector.Socket.Off("autoUpdater-update-downloaded" + GetHashCode());
+ BridgeConnector.Off("autoUpdater-update-downloaded" + GetHashCode());
}
}
@@ -486,33 +342,33 @@ internal static AutoUpdater Instance
///
public Task CheckForUpdatesAsync()
{
- var taskCompletionSource = new TaskCompletionSource();
+ var taskCompletionSource = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
string guid = Guid.NewGuid().ToString();
- BridgeConnector.Socket.On("autoUpdaterCheckForUpdatesComplete" + guid, (updateCheckResult) =>
+ BridgeConnector.On("autoUpdaterCheckForUpdatesComplete" + guid, (updateCheckResult) =>
{
try
{
- BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesComplete" + guid);
- BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesError" + guid);
- taskCompletionSource.SetResult(JObject.Parse(updateCheckResult.ToString()).ToObject());
+ BridgeConnector.Off("autoUpdaterCheckForUpdatesComplete" + guid);
+ BridgeConnector.Off("autoUpdaterCheckForUpdatesError" + guid);
+ taskCompletionSource.SetResult(updateCheckResult);
}
catch (Exception ex)
{
taskCompletionSource.SetException(ex);
}
});
- BridgeConnector.Socket.On("autoUpdaterCheckForUpdatesError" + guid, (error) =>
+ BridgeConnector.On("autoUpdaterCheckForUpdatesError" + guid, (error) =>
{
- BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesComplete" + guid);
- BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesError" + guid);
+ BridgeConnector.Off("autoUpdaterCheckForUpdatesComplete" + guid);
+ BridgeConnector.Off("autoUpdaterCheckForUpdatesError" + guid);
string message = "An error occurred in CheckForUpdatesAsync";
if (error != null && !string.IsNullOrEmpty(error.ToString()))
message = JsonConvert.SerializeObject(error);
taskCompletionSource.SetException(new Exception(message));
});
- BridgeConnector.Socket.Emit("autoUpdaterCheckForUpdates", guid);
+ BridgeConnector.Emit("autoUpdaterCheckForUpdates", guid);
return taskCompletionSource.Task;
}
@@ -525,36 +381,36 @@ public Task CheckForUpdatesAsync()
///
public Task CheckForUpdatesAndNotifyAsync()
{
- var taskCompletionSource = new TaskCompletionSource();
+ var taskCompletionSource = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
string guid = Guid.NewGuid().ToString();
- BridgeConnector.Socket.On("autoUpdaterCheckForUpdatesAndNotifyComplete" + guid, (updateCheckResult) =>
+ BridgeConnector.On("autoUpdaterCheckForUpdatesAndNotifyComplete" + guid, (updateCheckResult) =>
{
try
{
- BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesAndNotifyComplete" + guid);
- BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesAndNotifyError" + guid);
+ BridgeConnector.Off("autoUpdaterCheckForUpdatesAndNotifyComplete" + guid);
+ BridgeConnector.Off("autoUpdaterCheckForUpdatesAndNotifyError" + guid);
if (updateCheckResult == null)
taskCompletionSource.SetResult(null);
else
- taskCompletionSource.SetResult(JObject.Parse(updateCheckResult.ToString()).ToObject());
+ taskCompletionSource.SetResult(updateCheckResult);
}
catch (Exception ex)
{
taskCompletionSource.SetException(ex);
}
});
- BridgeConnector.Socket.On("autoUpdaterCheckForUpdatesAndNotifyError" + guid, (error) =>
+ BridgeConnector.On("autoUpdaterCheckForUpdatesAndNotifyError" + guid, (error) =>
{
- BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesAndNotifyComplete" + guid);
- BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesAndNotifyError" + guid);
+ BridgeConnector.Off("autoUpdaterCheckForUpdatesAndNotifyComplete" + guid);
+ BridgeConnector.Off("autoUpdaterCheckForUpdatesAndNotifyError" + guid);
string message = "An error occurred in autoUpdaterCheckForUpdatesAndNotify";
if (error != null)
message = JsonConvert.SerializeObject(error);
taskCompletionSource.SetException(new Exception(message));
});
- BridgeConnector.Socket.Emit("autoUpdaterCheckForUpdatesAndNotify", guid);
+ BridgeConnector.Emit("autoUpdaterCheckForUpdatesAndNotify", guid);
return taskCompletionSource.Task;
}
@@ -570,7 +426,7 @@ public Task CheckForUpdatesAndNotifyAsync()
/// Run the app after finish even on silent install. Not applicable for macOS. Ignored if `isSilent` is set to `false`.
public void QuitAndInstall(bool isSilent = false, bool isForceRunAfter = false)
{
- BridgeConnector.Socket.Emit("autoUpdaterQuitAndInstall", isSilent, isForceRunAfter);
+ BridgeConnector.EmitSync("autoUpdaterQuitAndInstall", isSilent, isForceRunAfter);
}
///
@@ -579,16 +435,16 @@ public void QuitAndInstall(bool isSilent = false, bool isForceRunAfter = false)
/// Path to downloaded file.
public Task DownloadUpdateAsync()
{
- var taskCompletionSource = new TaskCompletionSource();
+ var taskCompletionSource = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
string guid = Guid.NewGuid().ToString();
- BridgeConnector.Socket.On("autoUpdaterDownloadUpdateComplete" + guid, (downloadedPath) =>
+ BridgeConnector.On("autoUpdaterDownloadUpdateComplete" + guid, (downloadedPath) =>
{
- BridgeConnector.Socket.Off("autoUpdaterDownloadUpdateComplete" + guid);
+ BridgeConnector.Off("autoUpdaterDownloadUpdateComplete" + guid);
taskCompletionSource.SetResult(downloadedPath.ToString());
});
- BridgeConnector.Socket.Emit("autoUpdaterDownloadUpdate", guid);
+ BridgeConnector.Emit("autoUpdaterDownloadUpdate", guid);
return taskCompletionSource.Task;
}
@@ -599,23 +455,18 @@ public Task DownloadUpdateAsync()
/// Feed URL.
public Task GetFeedURLAsync()
{
- var taskCompletionSource = new TaskCompletionSource();
+ var taskCompletionSource = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
string guid = Guid.NewGuid().ToString();
- BridgeConnector.Socket.On("autoUpdaterGetFeedURLComplete" + guid, (downloadedPath) =>
+ BridgeConnector.On("autoUpdaterGetFeedURLComplete" + guid, (downloadedPath) =>
{
- BridgeConnector.Socket.Off("autoUpdaterGetFeedURLComplete" + guid);
+ BridgeConnector.Off("autoUpdaterGetFeedURLComplete" + guid);
taskCompletionSource.SetResult(downloadedPath.ToString());
});
- BridgeConnector.Socket.Emit("autoUpdaterGetFeedURL", guid);
+ BridgeConnector.Emit("autoUpdaterGetFeedURL", guid);
return taskCompletionSource.Task;
}
-
- private readonly JsonSerializer _jsonSerializer = new JsonSerializer()
- {
- ContractResolver = new CamelCasePropertyNamesContractResolver()
- };
}
}
diff --git a/ElectronNET.API/BridgeConnector.cs b/ElectronNET.API/BridgeConnector.cs
index 08a84745..1088f9e1 100644
--- a/ElectronNET.API/BridgeConnector.cs
+++ b/ElectronNET.API/BridgeConnector.cs
@@ -1,44 +1,318 @@
-using Quobject.SocketIoClientDotNet.Client;
-using System;
+using System;
+using System.Collections.Concurrent;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading;
+using System.Threading.Tasks;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Serialization;
+using SocketIOClient;
+using SocketIOClient.JsonSerializer;
+using SocketIOClient.Newtonsoft.Json;
namespace ElectronNET.API
{
internal static class BridgeConnector
{
- private static Socket _socket;
+ internal static class EventTasks
+ {
+ //Although SocketIO already manage event handlers, we need to manage this here as well for the OnResult calls,
+ //because SocketIO will simply replace the existing event handler on every call to On(key, ...) , which means there is
+ //a race condition between On / Off calls that can lead to tasks deadlocking forever without ever triggering their On handler
+
+ private static readonly Dictionary> _taskCompletionSources = new();
+ private static readonly Dictionary _eventKeys = new();
+ private static readonly object _lock = new();
+
+ ///
+ /// Get or add a new TaskCompletionSource for a given event key
+ ///
+ ///
+ ///
+ ///
+ ///
+ /// Returns true if a new TaskCompletionSource was added to the dictionary
+ internal static bool TryGetOrAdd(string key, string eventKey, out TaskCompletionSource taskCompletionSource, out Task waitThisFirstAndThenTryAgain)
+ {
+ lock (_lock)
+ {
+ if (!_taskCompletionSources.TryGetValue(key, out taskCompletionSource))
+ {
+ taskCompletionSource = new(TaskCreationOptions.RunContinuationsAsynchronously);
+ _taskCompletionSources[key] = taskCompletionSource;
+ _eventKeys[key] = eventKey;
+ waitThisFirstAndThenTryAgain = null;
+ return true; //Was added, so we need to also register the socket events
+ }
+
+ if(_eventKeys.TryGetValue(key, out var existingEventKey) && existingEventKey == eventKey)
+ {
+ waitThisFirstAndThenTryAgain = null;
+ return false; //No need to register the socket events twice
+ }
+
+ waitThisFirstAndThenTryAgain = taskCompletionSource.Task; //Will need to try again after the previous existing one is done
+
+ taskCompletionSource = null;
+
+ return true; //Need to register the socket events, but must first await the previous task to complete
+ }
+ }
+
+ ///
+ /// Clean up the TaskCompletionSource from the dictionary if and only if it is the same as the passed argument
+ ///
+ ///
+ ///
+ ///
+ internal static void DoneWith(string key, string eventKey, TaskCompletionSource taskCompletionSource)
+ {
+ lock (_lock)
+ {
+ if (_taskCompletionSources.TryGetValue(key, out var existingTaskCompletionSource)
+ && ReferenceEquals(existingTaskCompletionSource, taskCompletionSource))
+ {
+ _taskCompletionSources.Remove(key);
+ }
+
+ if (_eventKeys.TryGetValue(key, out var existingEventKey) && existingEventKey == eventKey)
+ {
+ _eventKeys.Remove(key);
+ }
+ }
+ }
+ }
+
+ private static SocketIO _socket;
+
private static object _syncRoot = new object();
- public static Socket Socket
+ public static void Emit(string eventString, params object[] args)
{
- get
+ //We don't care about waiting for the event to be emitted, so this doesn't need to be async
+
+ Task.Run(async () =>
+ {
+ if (App.SocketDebug)
+ {
+ Console.WriteLine($"Sending event {eventString}");
+ }
+
+ await Socket.EmitAsync(eventString, args);
+
+ if (App.SocketDebug)
+ {
+ Console.WriteLine($"Sent event {eventString}");
+ }
+ });
+ }
+
+ ///
+ /// This method is only used on places where we need to be sure the event was sent on the socket, such as Quit, Exit, Relaunch and QuitAndInstall methods
+ ///
+ ///
+ ///
+ internal static void EmitSync(string eventString, params object[] args)
+ {
+ if (App.SocketDebug)
+ {
+ Console.WriteLine($"Sending event {eventString}");
+ }
+
+ Socket.EmitAsync(eventString, args).Wait();
+
+ if (App.SocketDebug)
+ {
+ Console.WriteLine($"Sent event {eventString}");
+ }
+ }
+
+ public static void Off(string eventString)
+ {
+ Socket.Off(eventString);
+ }
+
+ public static void On(string eventString, Action fn)
+ {
+ Socket.On(eventString, _ => fn());
+ }
+
+ public static void On(string eventString, Action fn)
+ {
+ Socket.On(eventString, (o) => fn(o.GetValue(0)));
+ }
+
+ public static void Once(string eventString, Action fn)
+ {
+ On(eventString, (o) =>
+ {
+ Off(eventString);
+ fn(o);
+ });
+ }
+
+ public static async Task OnResult(string triggerEvent, string completedEvent, params object[] args)
+ {
+ string eventKey = completedEvent;
+
+ if (args is object && args.Length > 0) // If there are arguments passed, we generate a unique event key with the arguments
+ // this allow us to wait for previous events first before registering new ones
+ {
+ var hash = new HashCode();
+ foreach(var obj in args)
+ {
+ hash.Add(obj);
+ }
+ eventKey = $"{eventKey}-{(uint)hash.ToHashCode()}";
+ }
+
+ if (EventTasks.TryGetOrAdd(completedEvent, eventKey, out var taskCompletionSource, out var waitThisFirstAndThenTryAgain))
+ {
+ if (waitThisFirstAndThenTryAgain is object)
+ {
+ //There was a pending call with different parameters, so we need to wait that first and then call here again
+ try
+ {
+ await waitThisFirstAndThenTryAgain;
+ }
+ catch
+ {
+ //Ignore any exceptions here so we can set a new event below
+ //The exception will also be visible to the original first caller due to taskCompletionSource.Task
+ }
+
+ //Try again to set the event
+ return await OnResult(triggerEvent, completedEvent, args);
+ }
+ else
+ {
+ //A new TaskCompletionSource was added, so we need to register the completed event here
+
+ On(completedEvent, (result) =>
+ {
+ Off(completedEvent);
+ taskCompletionSource.SetResult(result);
+ EventTasks.DoneWith(completedEvent, eventKey, taskCompletionSource);
+ });
+
+ Emit(triggerEvent, args);
+ }
+ }
+
+ return await taskCompletionSource.Task;
+ }
+
+
+ public static async Task OnResult(string triggerEvent, string completedEvent, CancellationToken cancellationToken, params object[] args)
+ {
+ string eventKey = completedEvent;
+
+ if (args is object && args.Length > 0) // If there are arguments passed, we generate a unique event key with the arguments
+ // this allow us to wait for previous events first before registering new ones
{
- if(_socket == null && HybridSupport.IsElectronActive)
+ var hash = new HashCode();
+ foreach (var obj in args)
+ {
+ hash.Add(obj);
+ }
+ eventKey = $"{eventKey}-{(uint)hash.ToHashCode()}";
+ }
+
+ if (EventTasks.TryGetOrAdd(completedEvent, eventKey, out var taskCompletionSource, out var waitThisFirstAndThenTryAgain))
+ {
+ if (waitThisFirstAndThenTryAgain is object)
+ {
+ //There was a pending call with different parameters, so we need to wait that first and then call here again
+ try
+ {
+ await Task.Run(() => waitThisFirstAndThenTryAgain, cancellationToken);
+ }
+ catch
+ {
+ //Ignore any exceptions here so we can set a new event below
+ //The exception will also be visible to the original first caller due to taskCompletionSource.Task
+ }
+
+ //Try again to set the event
+ return await OnResult(triggerEvent, completedEvent, cancellationToken, args);
+ }
+ else
{
- lock (_syncRoot)
+ using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
{
- if (_socket == null && HybridSupport.IsElectronActive)
+ //A new TaskCompletionSource was added, so we need to register the completed event here
+
+ On(completedEvent, (result) =>
{
- _socket = IO.Socket("http://localhost:" + BridgeSettings.SocketPort);
- _socket.On(Socket.EVENT_CONNECT, () =>
- {
- Console.WriteLine("BridgeConnector connected!");
- });
- }
+ Off(completedEvent);
+ taskCompletionSource.SetResult(result);
+ EventTasks.DoneWith(completedEvent, eventKey, taskCompletionSource);
+ });
+
+ Emit(triggerEvent, args);
}
}
- else if(_socket == null && !HybridSupport.IsElectronActive)
+ }
+
+ return await taskCompletionSource.Task;
+ }
+ private static SocketIO Socket
+ {
+ get
+ {
+ if (_socket is null)
{
- lock (_syncRoot)
+ if (HybridSupport.IsElectronActive)
{
- if (_socket == null && !HybridSupport.IsElectronActive)
+
+ lock (_syncRoot)
{
- _socket = IO.Socket(new Uri("http://localhost"), new IO.Options { AutoConnect = false });
+ if (_socket is null && HybridSupport.IsElectronActive)
+ {
+ var socket = new SocketIO($"http://localhost:{BridgeSettings.SocketPort}", new SocketIOOptions()
+ {
+ EIO = 3
+ });
+
+ socket.JsonSerializer = new CamelCaseNewtonsoftJsonSerializer(socket.Options.EIO);
+
+
+ socket.OnConnected += (_, __) =>
+ {
+ Console.WriteLine("BridgeConnector connected!");
+ };
+
+ socket.ConnectAsync().Wait();
+
+ _socket = socket;
+ }
}
}
+ else
+ {
+ throw new Exception("Missing Socket Port");
+ }
}
return _socket;
}
}
+
+ private class CamelCaseNewtonsoftJsonSerializer : NewtonsoftJsonSerializer
+ {
+ public CamelCaseNewtonsoftJsonSerializer(int eio) : base(eio)
+ {
+ }
+
+ public override JsonSerializerSettings CreateOptions()
+ {
+ return new JsonSerializerSettings()
+ {
+ ContractResolver = new CamelCasePropertyNamesContractResolver(),
+ NullValueHandling = NullValueHandling.Ignore,
+ DefaultValueHandling = DefaultValueHandling.Ignore
+ };
+ }
+ }
}
}
diff --git a/ElectronNET.API/BridgeSettings.cs b/ElectronNET.API/BridgeSettings.cs
index 96a2653a..daa230a1 100644
--- a/ElectronNET.API/BridgeSettings.cs
+++ b/ElectronNET.API/BridgeSettings.cs
@@ -20,5 +20,16 @@ public static class BridgeSettings
/// The web port.
///
public static string WebPort { get; internal set; }
+
+ ///
+ /// Manually set the port values instead of using the UseElectron extension method
+ ///
+ ///
+ ///
+ public static void InitializePorts(int socketPort, int webPort)
+ {
+ SocketPort = socketPort.ToString();
+ WebPort = webPort.ToString();
+ }
}
}
diff --git a/ElectronNET.API/BrowserView.cs b/ElectronNET.API/BrowserView.cs
index 96bddd7f..09a44cbd 100644
--- a/ElectronNET.API/BrowserView.cs
+++ b/ElectronNET.API/BrowserView.cs
@@ -31,29 +31,11 @@ public class BrowserView
///
/// (experimental)
///
- public Rectangle Bounds
- {
- get
- {
- return Task.Run(() =>
- {
- var taskCompletionSource = new TaskCompletionSource();
-
- BridgeConnector.Socket.On("browserView-getBounds-reply", (result) =>
- {
- BridgeConnector.Socket.Off("browserView-getBounds-reply");
- taskCompletionSource.SetResult((Rectangle)result);
- });
-
- BridgeConnector.Socket.Emit("browserView-getBounds", Id);
+ public Task GetBoundsAsync() => BridgeConnector.OnResult("browserView-getBounds", "browserView-getBounds-reply" + Id, Id);
- return taskCompletionSource.Task;
- }).Result;
- }
- set
- {
- BridgeConnector.Socket.Emit("browserView-setBounds", Id, JObject.FromObject(value, _jsonSerializer));
- }
+ public void SetBounds(Rectangle value)
+ {
+ BridgeConnector.Emit("browserView-setBounds", Id, value);
}
///
@@ -74,7 +56,7 @@ internal BrowserView(int id)
///
public void SetAutoResize(AutoResizeOptions options)
{
- BridgeConnector.Socket.Emit("browserView-setAutoResize", Id, JObject.FromObject(options, _jsonSerializer));
+ BridgeConnector.Emit("browserView-setAutoResize", Id, options);
}
///
@@ -85,13 +67,7 @@ public void SetAutoResize(AutoResizeOptions options)
/// Color in #aarrggbb or #argb form. The alpha channel is optional.
public void SetBackgroundColor(string color)
{
- BridgeConnector.Socket.Emit("browserView-setBackgroundColor", Id, color);
+ BridgeConnector.Emit("browserView-setBackgroundColor", Id, color);
}
-
- private JsonSerializer _jsonSerializer = new JsonSerializer()
- {
- ContractResolver = new CamelCasePropertyNamesContractResolver(),
- NullValueHandling = NullValueHandling.Ignore
- };
}
}
diff --git a/ElectronNET.API/BrowserWindow.cs b/ElectronNET.API/BrowserWindow.cs
index 2c4590ac..0b8222c5 100644
--- a/ElectronNET.API/BrowserWindow.cs
+++ b/ElectronNET.API/BrowserWindow.cs
@@ -34,12 +34,12 @@ public event Action OnReadyToShow
{
if (_readyToShow == null)
{
- BridgeConnector.Socket.On("browserWindow-ready-to-show" + Id, () =>
+ BridgeConnector.On("browserWindow-ready-to-show" + Id, () =>
{
_readyToShow();
});
- BridgeConnector.Socket.Emit("register-browserWindow-ready-to-show", Id);
+ BridgeConnector.Emit("register-browserWindow-ready-to-show", Id);
}
_readyToShow += value;
}
@@ -48,7 +48,7 @@ public event Action OnReadyToShow
_readyToShow -= value;
if (_readyToShow == null)
- BridgeConnector.Socket.Off("browserWindow-ready-to-show" + Id);
+ BridgeConnector.Off("browserWindow-ready-to-show" + Id);
}
}
@@ -63,12 +63,12 @@ public event Action OnPageTitleUpdated
{
if (_pageTitleUpdated == null)
{
- BridgeConnector.Socket.On("browserWindow-page-title-updated" + Id, (title) =>
+ BridgeConnector.On("browserWindow-page-title-updated" + Id, (title) =>
{
- _pageTitleUpdated(title.ToString());
+ _pageTitleUpdated(title);
});
- BridgeConnector.Socket.Emit("register-browserWindow-page-title-updated", Id);
+ BridgeConnector.Emit("register-browserWindow-page-title-updated", Id);
}
_pageTitleUpdated += value;
}
@@ -77,7 +77,7 @@ public event Action OnPageTitleUpdated
_pageTitleUpdated -= value;
if (_pageTitleUpdated == null)
- BridgeConnector.Socket.Off("browserWindow-page-title-updated" + Id);
+ BridgeConnector.Off("browserWindow-page-title-updated" + Id);
}
}
@@ -92,12 +92,12 @@ public event Action OnClose
{
if (_close == null)
{
- BridgeConnector.Socket.On("browserWindow-close" + Id, () =>
+ BridgeConnector.On("browserWindow-close" + Id, () =>
{
_close();
});
- BridgeConnector.Socket.Emit("register-browserWindow-close", Id);
+ BridgeConnector.Emit("register-browserWindow-close", Id);
}
_close += value;
}
@@ -106,7 +106,7 @@ public event Action OnClose
_close -= value;
if (_close == null)
- BridgeConnector.Socket.Off("browserWindow-close" + Id);
+ BridgeConnector.Off("browserWindow-close" + Id);
}
}
@@ -123,12 +123,12 @@ public event Action OnClosed
{
if (_closed == null)
{
- BridgeConnector.Socket.On("browserWindow-closed" + Id, () =>
+ BridgeConnector.On("browserWindow-closed" + Id, () =>
{
_closed();
});
- BridgeConnector.Socket.Emit("register-browserWindow-closed", Id);
+ BridgeConnector.Emit("register-browserWindow-closed", Id);
}
_closed += value;
}
@@ -137,7 +137,7 @@ public event Action OnClosed
_closed -= value;
if (_closed == null)
- BridgeConnector.Socket.Off("browserWindow-closed" + Id);
+ BridgeConnector.Off("browserWindow-closed" + Id);
}
}
@@ -152,12 +152,12 @@ public event Action OnSessionEnd
{
if (_sessionEnd == null)
{
- BridgeConnector.Socket.On("browserWindow-session-end" + Id, () =>
+ BridgeConnector.On("browserWindow-session-end" + Id, () =>
{
_sessionEnd();
});
- BridgeConnector.Socket.Emit("register-browserWindow-session-end", Id);
+ BridgeConnector.Emit("register-browserWindow-session-end", Id);
}
_sessionEnd += value;
}
@@ -166,7 +166,7 @@ public event Action OnSessionEnd
_sessionEnd -= value;
if (_sessionEnd == null)
- BridgeConnector.Socket.Off("browserWindow-session-end" + Id);
+ BridgeConnector.Off("browserWindow-session-end" + Id);
}
}
@@ -181,12 +181,12 @@ public event Action OnUnresponsive
{
if (_unresponsive == null)
{
- BridgeConnector.Socket.On("browserWindow-unresponsive" + Id, () =>
+ BridgeConnector.On("browserWindow-unresponsive" + Id, () =>
{
_unresponsive();
});
- BridgeConnector.Socket.Emit("register-browserWindow-unresponsive", Id);
+ BridgeConnector.Emit("register-browserWindow-unresponsive", Id);
}
_unresponsive += value;
}
@@ -195,7 +195,7 @@ public event Action OnUnresponsive
_unresponsive -= value;
if (_unresponsive == null)
- BridgeConnector.Socket.Off("browserWindow-unresponsive" + Id);
+ BridgeConnector.Off("browserWindow-unresponsive" + Id);
}
}
@@ -210,12 +210,12 @@ public event Action OnResponsive
{
if (_responsive == null)
{
- BridgeConnector.Socket.On("browserWindow-responsive" + Id, () =>
+ BridgeConnector.On("browserWindow-responsive" + Id, () =>
{
_responsive();
});
- BridgeConnector.Socket.Emit("register-browserWindow-responsive", Id);
+ BridgeConnector.Emit("register-browserWindow-responsive", Id);
}
_responsive += value;
}
@@ -224,7 +224,7 @@ public event Action OnResponsive
_responsive -= value;
if (_responsive == null)
- BridgeConnector.Socket.Off("browserWindow-responsive" + Id);
+ BridgeConnector.Off("browserWindow-responsive" + Id);
}
}
@@ -239,12 +239,12 @@ public event Action OnBlur
{
if (_blur == null)
{
- BridgeConnector.Socket.On("browserWindow-blur" + Id, () =>
+ BridgeConnector.On("browserWindow-blur" + Id, () =>
{
_blur();
});
- BridgeConnector.Socket.Emit("register-browserWindow-blur", Id);
+ BridgeConnector.Emit("register-browserWindow-blur", Id);
}
_blur += value;
}
@@ -253,7 +253,7 @@ public event Action OnBlur
_blur -= value;
if (_blur == null)
- BridgeConnector.Socket.Off("browserWindow-blur" + Id);
+ BridgeConnector.Off("browserWindow-blur" + Id);
}
}
@@ -268,12 +268,12 @@ public event Action OnFocus
{
if (_focus == null)
{
- BridgeConnector.Socket.On("browserWindow-focus" + Id, () =>
+ BridgeConnector.On("browserWindow-focus" + Id, () =>
{
_focus();
});
- BridgeConnector.Socket.Emit("register-browserWindow-focus", Id);
+ BridgeConnector.Emit("register-browserWindow-focus", Id);
}
_focus += value;
}
@@ -282,7 +282,7 @@ public event Action OnFocus
_focus -= value;
if (_focus == null)
- BridgeConnector.Socket.Off("browserWindow-focus" + Id);
+ BridgeConnector.Off("browserWindow-focus" + Id);
}
}
@@ -297,12 +297,12 @@ public event Action OnShow
{
if (_show == null)
{
- BridgeConnector.Socket.On("browserWindow-show" + Id, () =>
+ BridgeConnector.On("browserWindow-show" + Id, () =>
{
_show();
});
- BridgeConnector.Socket.Emit("register-browserWindow-show", Id);
+ BridgeConnector.Emit("register-browserWindow-show", Id);
}
_show += value;
}
@@ -311,7 +311,7 @@ public event Action OnShow
_show -= value;
if (_show == null)
- BridgeConnector.Socket.Off("browserWindow-show" + Id);
+ BridgeConnector.Off("browserWindow-show" + Id);
}
}
@@ -326,12 +326,12 @@ public event Action OnHide
{
if (_hide == null)
{
- BridgeConnector.Socket.On("browserWindow-hide" + Id, () =>
+ BridgeConnector.On("browserWindow-hide" + Id, () =>
{
_hide();
});
- BridgeConnector.Socket.Emit("register-browserWindow-hide", Id);
+ BridgeConnector.Emit("register-browserWindow-hide", Id);
}
_hide += value;
}
@@ -340,7 +340,7 @@ public event Action OnHide
_hide -= value;
if (_hide == null)
- BridgeConnector.Socket.Off("browserWindow-hide" + Id);
+ BridgeConnector.Off("browserWindow-hide" + Id);
}
}
@@ -355,12 +355,12 @@ public event Action OnMaximize
{
if (_maximize == null)
{
- BridgeConnector.Socket.On("browserWindow-maximize" + Id, () =>
+ BridgeConnector.On("browserWindow-maximize" + Id, () =>
{
_maximize();
});
- BridgeConnector.Socket.Emit("register-browserWindow-maximize", Id);
+ BridgeConnector.Emit("register-browserWindow-maximize", Id);
}
_maximize += value;
}
@@ -369,7 +369,7 @@ public event Action OnMaximize
_maximize -= value;
if (_maximize == null)
- BridgeConnector.Socket.Off("browserWindow-maximize" + Id);
+ BridgeConnector.Off("browserWindow-maximize" + Id);
}
}
@@ -384,12 +384,12 @@ public event Action OnUnmaximize
{
if (_unmaximize == null)
{
- BridgeConnector.Socket.On("browserWindow-unmaximize" + Id, () =>
+ BridgeConnector.On("browserWindow-unmaximize" + Id, () =>
{
_unmaximize();
});
- BridgeConnector.Socket.Emit("register-browserWindow-unmaximize", Id);
+ BridgeConnector.Emit("register-browserWindow-unmaximize", Id);
}
_unmaximize += value;
}
@@ -398,7 +398,7 @@ public event Action OnUnmaximize
_unmaximize -= value;
if (_unmaximize == null)
- BridgeConnector.Socket.Off("browserWindow-unmaximize" + Id);
+ BridgeConnector.Off("browserWindow-unmaximize" + Id);
}
}
@@ -413,12 +413,12 @@ public event Action OnMinimize
{
if (_minimize == null)
{
- BridgeConnector.Socket.On("browserWindow-minimize" + Id, () =>
+ BridgeConnector.On("browserWindow-minimize" + Id, () =>
{
_minimize();
});
- BridgeConnector.Socket.Emit("register-browserWindow-minimize", Id);
+ BridgeConnector.Emit("register-browserWindow-minimize", Id);
}
_minimize += value;
}
@@ -427,7 +427,7 @@ public event Action OnMinimize
_minimize -= value;
if (_minimize == null)
- BridgeConnector.Socket.Off("browserWindow-minimize" + Id);
+ BridgeConnector.Off("browserWindow-minimize" + Id);
}
}
@@ -442,12 +442,12 @@ public event Action OnRestore
{
if (_restore == null)
{
- BridgeConnector.Socket.On("browserWindow-restore" + Id, () =>
+ BridgeConnector.On("browserWindow-restore" + Id, () =>
{
_restore();
});
- BridgeConnector.Socket.Emit("register-browserWindow-restore", Id);
+ BridgeConnector.Emit("register-browserWindow-restore", Id);
}
_restore += value;
}
@@ -456,7 +456,7 @@ public event Action OnRestore
_restore -= value;
if (_restore == null)
- BridgeConnector.Socket.Off("browserWindow-restore" + Id);
+ BridgeConnector.Off("browserWindow-restore" + Id);
}
}
@@ -471,12 +471,12 @@ public event Action OnResize
{
if (_resize == null)
{
- BridgeConnector.Socket.On("browserWindow-resize" + Id, () =>
+ BridgeConnector.On("browserWindow-resize" + Id, () =>
{
_resize();
});
- BridgeConnector.Socket.Emit("register-browserWindow-resize", Id);
+ BridgeConnector.Emit("register-browserWindow-resize", Id);
}
_resize += value;
}
@@ -485,7 +485,7 @@ public event Action OnResize
_resize -= value;
if (_resize == null)
- BridgeConnector.Socket.Off("browserWindow-resize" + Id);
+ BridgeConnector.Off("browserWindow-resize" + Id);
}
}
@@ -502,12 +502,12 @@ public event Action OnMove
{
if (_move == null)
{
- BridgeConnector.Socket.On("browserWindow-move" + Id, () =>
+ BridgeConnector.On("browserWindow-move" + Id, () =>
{
_move();
});
- BridgeConnector.Socket.Emit("register-browserWindow-move", Id);
+ BridgeConnector.Emit("register-browserWindow-move", Id);
}
_move += value;
}
@@ -516,7 +516,7 @@ public event Action OnMove
_move -= value;
if (_move == null)
- BridgeConnector.Socket.Off("browserWindow-move" + Id);
+ BridgeConnector.Off("browserWindow-move" + Id);
}
}
@@ -531,12 +531,12 @@ public event Action OnMoved
{
if (_moved == null)
{
- BridgeConnector.Socket.On("browserWindow-moved" + Id, () =>
+ BridgeConnector.On("browserWindow-moved" + Id, () =>
{
_moved();
});
- BridgeConnector.Socket.Emit("register-browserWindow-moved", Id);
+ BridgeConnector.Emit("register-browserWindow-moved", Id);
}
_moved += value;
}
@@ -545,7 +545,7 @@ public event Action OnMoved
_moved -= value;
if (_moved == null)
- BridgeConnector.Socket.Off("browserWindow-moved" + Id);
+ BridgeConnector.Off("browserWindow-moved" + Id);
}
}
@@ -560,12 +560,12 @@ public event Action OnEnterFullScreen
{
if (_enterFullScreen == null)
{
- BridgeConnector.Socket.On("browserWindow-enter-full-screen" + Id, () =>
+ BridgeConnector.On("browserWindow-enter-full-screen" + Id, () =>
{
_enterFullScreen();
});
- BridgeConnector.Socket.Emit("register-browserWindow-enter-full-screen", Id);
+ BridgeConnector.Emit("register-browserWindow-enter-full-screen", Id);
}
_enterFullScreen += value;
}
@@ -574,7 +574,7 @@ public event Action OnEnterFullScreen
_enterFullScreen -= value;
if (_enterFullScreen == null)
- BridgeConnector.Socket.Off("browserWindow-enter-full-screen" + Id);
+ BridgeConnector.Off("browserWindow-enter-full-screen" + Id);
}
}
@@ -589,12 +589,12 @@ public event Action OnLeaveFullScreen
{
if (_leaveFullScreen == null)
{
- BridgeConnector.Socket.On("browserWindow-leave-full-screen" + Id, () =>
+ BridgeConnector.On("browserWindow-leave-full-screen" + Id, () =>
{
_leaveFullScreen();
});
- BridgeConnector.Socket.Emit("register-browserWindow-leave-full-screen", Id);
+ BridgeConnector.Emit("register-browserWindow-leave-full-screen", Id);
}
_leaveFullScreen += value;
}
@@ -603,7 +603,7 @@ public event Action OnLeaveFullScreen
_leaveFullScreen -= value;
if (_leaveFullScreen == null)
- BridgeConnector.Socket.Off("browserWindow-leave-full-screen" + Id);
+ BridgeConnector.Off("browserWindow-leave-full-screen" + Id);
}
}
@@ -618,12 +618,12 @@ public event Action OnEnterHtmlFullScreen
{
if (_enterHtmlFullScreen == null)
{
- BridgeConnector.Socket.On("browserWindow-enter-html-full-screen" + Id, () =>
+ BridgeConnector.On("browserWindow-enter-html-full-screen" + Id, () =>
{
_enterHtmlFullScreen();
});
- BridgeConnector.Socket.Emit("register-browserWindow-enter-html-full-screen", Id);
+ BridgeConnector.Emit("register-browserWindow-enter-html-full-screen", Id);
}
_enterHtmlFullScreen += value;
}
@@ -632,7 +632,7 @@ public event Action OnEnterHtmlFullScreen
_enterHtmlFullScreen -= value;
if (_enterHtmlFullScreen == null)
- BridgeConnector.Socket.Off("browserWindow-enter-html-full-screen" + Id);
+ BridgeConnector.Off("browserWindow-enter-html-full-screen" + Id);
}
}
@@ -647,12 +647,12 @@ public event Action OnLeaveHtmlFullScreen
{
if (_leaveHtmlFullScreen == null)
{
- BridgeConnector.Socket.On("browserWindow-leave-html-full-screen" + Id, () =>
+ BridgeConnector.On("browserWindow-leave-html-full-screen" + Id, () =>
{
_leaveHtmlFullScreen();
});
- BridgeConnector.Socket.Emit("register-browserWindow-leave-html-full-screen", Id);
+ BridgeConnector.Emit("register-browserWindow-leave-html-full-screen", Id);
}
_leaveHtmlFullScreen += value;
}
@@ -661,7 +661,7 @@ public event Action OnLeaveHtmlFullScreen
_leaveHtmlFullScreen -= value;
if (_leaveHtmlFullScreen == null)
- BridgeConnector.Socket.Off("browserWindow-leave-html-full-screen" + Id);
+ BridgeConnector.Off("browserWindow-leave-html-full-screen" + Id);
}
}
@@ -682,12 +682,12 @@ public event Action OnAppCommand
{
if (_appCommand == null)
{
- BridgeConnector.Socket.On("browserWindow-app-command" + Id, (command) =>
+ BridgeConnector.On("browserWindow-app-command" + Id, (command) =>
{
- _appCommand(command.ToString());
+ _appCommand(command);
});
- BridgeConnector.Socket.Emit("register-browserWindow-app-command", Id);
+ BridgeConnector.Emit("register-browserWindow-app-command", Id);
}
_appCommand += value;
}
@@ -696,7 +696,7 @@ public event Action OnAppCommand
_appCommand -= value;
if (_appCommand == null)
- BridgeConnector.Socket.Off("browserWindow-app-command" + Id);
+ BridgeConnector.Off("browserWindow-app-command" + Id);
}
}
@@ -711,12 +711,12 @@ public event Action OnScrollTouchBegin
{
if (_scrollTouchBegin == null)
{
- BridgeConnector.Socket.On("browserWindow-scroll-touch-begin" + Id, () =>
+ BridgeConnector.On("browserWindow-scroll-touch-begin" + Id, () =>
{
_scrollTouchBegin();
});
- BridgeConnector.Socket.Emit("register-browserWindow-scroll-touch-begin", Id);
+ BridgeConnector.Emit("register-browserWindow-scroll-touch-begin", Id);
}
_scrollTouchBegin += value;
}
@@ -725,7 +725,7 @@ public event Action OnScrollTouchBegin
_scrollTouchBegin -= value;
if (_scrollTouchBegin == null)
- BridgeConnector.Socket.Off("browserWindow-scroll-touch-begin" + Id);
+ BridgeConnector.Off("browserWindow-scroll-touch-begin" + Id);
}
}
@@ -740,12 +740,12 @@ public event Action OnScrollTouchEnd
{
if (_scrollTouchEnd == null)
{
- BridgeConnector.Socket.On("browserWindow-scroll-touch-end" + Id, () =>
+ BridgeConnector.On("browserWindow-scroll-touch-end" + Id, () =>
{
_scrollTouchEnd();
});
- BridgeConnector.Socket.Emit("register-browserWindow-scroll-touch-end", Id);
+ BridgeConnector.Emit("register-browserWindow-scroll-touch-end", Id);
}
_scrollTouchEnd += value;
}
@@ -754,7 +754,7 @@ public event Action OnScrollTouchEnd
_scrollTouchEnd -= value;
if (_scrollTouchEnd == null)
- BridgeConnector.Socket.Off("browserWindow-scroll-touch-end" + Id);
+ BridgeConnector.Off("browserWindow-scroll-touch-end" + Id);
}
}
@@ -769,12 +769,12 @@ public event Action OnScrollTouchEdge
{
if (_scrollTouchEdge == null)
{
- BridgeConnector.Socket.On("browserWindow-scroll-touch-edge" + Id, () =>
+ BridgeConnector.On("browserWindow-scroll-touch-edge" + Id, () =>
{
_scrollTouchEdge();
});
- BridgeConnector.Socket.Emit("register-browserWindow-scroll-touch-edge", Id);
+ BridgeConnector.Emit("register-browserWindow-scroll-touch-edge", Id);
}
_scrollTouchEdge += value;
}
@@ -783,7 +783,7 @@ public event Action OnScrollTouchEdge
_scrollTouchEdge -= value;
if (_scrollTouchEdge == null)
- BridgeConnector.Socket.Off("browserWindow-scroll-touch-edge" + Id);
+ BridgeConnector.Off("browserWindow-scroll-touch-edge" + Id);
}
}
@@ -798,12 +798,12 @@ public event Action OnSwipe
{
if (_swipe == null)
{
- BridgeConnector.Socket.On("browserWindow-swipe" + Id, (direction) =>
+ BridgeConnector.On("browserWindow-swipe" + Id, (direction) =>
{
- _swipe(direction.ToString());
+ _swipe(direction);
});
- BridgeConnector.Socket.Emit("register-browserWindow-swipe", Id);
+ BridgeConnector.Emit("register-browserWindow-swipe", Id);
}
_swipe += value;
}
@@ -812,7 +812,7 @@ public event Action OnSwipe
_swipe -= value;
if (_swipe == null)
- BridgeConnector.Socket.Off("browserWindow-swipe" + Id);
+ BridgeConnector.Off("browserWindow-swipe" + Id);
}
}
@@ -827,12 +827,12 @@ public event Action OnSheetBegin
{
if (_sheetBegin == null)
{
- BridgeConnector.Socket.On("browserWindow-sheet-begin" + Id, () =>
+ BridgeConnector.On("browserWindow-sheet-begin" + Id, () =>
{
_sheetBegin();
});
- BridgeConnector.Socket.Emit("register-browserWindow-sheet-begin", Id);
+ BridgeConnector.Emit("register-browserWindow-sheet-begin", Id);
}
_sheetBegin += value;
}
@@ -841,7 +841,7 @@ public event Action OnSheetBegin
_sheetBegin -= value;
if (_sheetBegin == null)
- BridgeConnector.Socket.Off("browserWindow-sheet-begin" + Id);
+ BridgeConnector.Off("browserWindow-sheet-begin" + Id);
}
}
@@ -856,12 +856,12 @@ public event Action OnSheetEnd
{
if (_sheetEnd == null)
{
- BridgeConnector.Socket.On("browserWindow-sheet-end" + Id, () =>
+ BridgeConnector.On("browserWindow-sheet-end" + Id, () =>
{
_sheetEnd();
});
- BridgeConnector.Socket.Emit("register-browserWindow-sheet-end", Id);
+ BridgeConnector.Emit("register-browserWindow-sheet-end", Id);
}
_sheetEnd += value;
}
@@ -870,7 +870,7 @@ public event Action OnSheetEnd
_sheetEnd -= value;
if (_sheetEnd == null)
- BridgeConnector.Socket.Off("browserWindow-sheet-end" + Id);
+ BridgeConnector.Off("browserWindow-sheet-end" + Id);
}
}
@@ -885,12 +885,12 @@ public event Action OnNewWindowForTab
{
if (_newWindowForTab == null)
{
- BridgeConnector.Socket.On("browserWindow-new-window-for-tab" + Id, () =>
+ BridgeConnector.On("browserWindow-new-window-for-tab" + Id, () =>
{
_newWindowForTab();
});
- BridgeConnector.Socket.Emit("register-browserWindow-new-window-for-tab", Id);
+ BridgeConnector.Emit("register-browserWindow-new-window-for-tab", Id);
}
_newWindowForTab += value;
}
@@ -899,7 +899,7 @@ public event Action OnNewWindowForTab
_newWindowForTab -= value;
if (_newWindowForTab == null)
- BridgeConnector.Socket.Off("browserWindow-new-window-for-tab" + Id);
+ BridgeConnector.Off("browserWindow-new-window-for-tab" + Id);
}
}
@@ -917,7 +917,7 @@ internal BrowserWindow(int id) {
///
public void Destroy()
{
- BridgeConnector.Socket.Emit("browserWindowDestroy", Id);
+ BridgeConnector.Emit("browserWindowDestroy", Id);
}
///
@@ -926,7 +926,7 @@ public void Destroy()
///
public void Close()
{
- BridgeConnector.Socket.Emit("browserWindowClose", Id);
+ BridgeConnector.Emit("browserWindowClose", Id);
}
///
@@ -934,7 +934,7 @@ public void Close()
///
public void Focus()
{
- BridgeConnector.Socket.Emit("browserWindowFocus", Id);
+ BridgeConnector.Emit("browserWindowFocus", Id);
}
///
@@ -942,53 +942,27 @@ public void Focus()
///
public void Blur()
{
- BridgeConnector.Socket.Emit("browserWindowBlur", Id);
+ BridgeConnector.Emit("browserWindowBlur", Id);
}
///
/// Whether the window is focused.
///
///
- public Task IsFocusedAsync()
- {
- var taskCompletionSource = new TaskCompletionSource();
-
- BridgeConnector.Socket.On("browserWindow-isFocused-completed", (isFocused) => {
- BridgeConnector.Socket.Off("browserWindow-isFocused-completed");
-
- taskCompletionSource.SetResult((bool)isFocused);
- });
-
- BridgeConnector.Socket.Emit("browserWindowIsFocused", Id);
-
- return taskCompletionSource.Task;
- }
+ public Task IsFocusedAsync() => BridgeConnector.OnResult("browserWindowIsFocused", "browserWindow-isFocused-completed" + Id, Id);
///
/// Whether the window is destroyed.
///
///
- public Task IsDestroyedAsync()
- {
- var taskCompletionSource = new TaskCompletionSource();
-
- BridgeConnector.Socket.On("browserWindow-isDestroyed-completed", (isDestroyed) => {
- BridgeConnector.Socket.Off("browserWindow-isDestroyed-completed");
-
- taskCompletionSource.SetResult((bool)isDestroyed);
- });
-
- BridgeConnector.Socket.Emit("browserWindowIsDestroyed", Id);
-
- return taskCompletionSource.Task;
- }
+ public Task IsDestroyedAsync() => BridgeConnector.OnResult("browserWindowIsDestroyed", "browserWindow-isDestroyed-completed" + Id, Id);
///
/// Shows and gives focus to the window.
///
public void Show()
{
- BridgeConnector.Socket.Emit("browserWindowShow", Id);
+ BridgeConnector.Emit("browserWindowShow", Id);
}
///
@@ -996,7 +970,7 @@ public void Show()
///
public void ShowInactive()
{
- BridgeConnector.Socket.Emit("browserWindowShowInactive", Id);
+ BridgeConnector.Emit("browserWindowShowInactive", Id);
}
///
@@ -1004,7 +978,7 @@ public void ShowInactive()
///
public void Hide()
{
- BridgeConnector.Socket.Emit("browserWindowHide", Id);
+ BridgeConnector.Emit("browserWindowHide", Id);
}
///
@@ -1013,17 +987,7 @@ public void Hide()
///
public Task IsVisibleAsync()
{
- var taskCompletionSource = new TaskCompletionSource();
-
- BridgeConnector.Socket.On("browserWindow-isVisible-completed", (isVisible) => {
- BridgeConnector.Socket.Off("browserWindow-isVisible-completed");
-
- taskCompletionSource.SetResult((bool)isVisible);
- });
-
- BridgeConnector.Socket.Emit("browserWindowIsVisible", Id);
-
- return taskCompletionSource.Task;
+ return BridgeConnector.OnResult("browserWindowIsVisible", "browserWindow-isVisible-completed" + Id, Id);
}
///
@@ -1032,17 +996,7 @@ public Task IsVisibleAsync()
///
public Task IsModalAsync()
{
- var taskCompletionSource = new TaskCompletionSource();
-
- BridgeConnector.Socket.On("browserWindow-isModal-completed", (isModal) => {
- BridgeConnector.Socket.Off("browserWindow-isModal-completed");
-
- taskCompletionSource.SetResult((bool)isModal);
- });
-
- BridgeConnector.Socket.Emit("browserWindowIsModal", Id);
-
- return taskCompletionSource.Task;
+ return BridgeConnector.OnResult("browserWindowIsModal", "browserWindow-isModal-completed" + Id, Id);
}
///
@@ -1050,7 +1004,7 @@ public Task IsModalAsync()
///
public void Maximize()
{
- BridgeConnector.Socket.Emit("browserWindowMaximize", Id);
+ BridgeConnector.Emit("browserWindowMaximize", Id);
}
///
@@ -1058,7 +1012,7 @@ public void Maximize()
///
public void Unmaximize()
{
- BridgeConnector.Socket.Emit("browserWindowUnmaximize", Id);
+ BridgeConnector.Emit("browserWindowUnmaximize", Id);
}
///
@@ -1067,17 +1021,7 @@ public void Unmaximize()
///
public Task IsMaximizedAsync()
{
- var taskCompletionSource = new TaskCompletionSource();
-
- BridgeConnector.Socket.On("browserWindow-isMaximized-completed", (isMaximized) => {
- BridgeConnector.Socket.Off("browserWindow-isMaximized-completed");
-
- taskCompletionSource.SetResult((bool)isMaximized);
- });
-
- BridgeConnector.Socket.Emit("browserWindowIsMaximized", Id);
-
- return taskCompletionSource.Task;
+ return BridgeConnector.OnResult("browserWindowIsMaximized", "browserWindow-isMaximized-completed" + Id, Id);
}
///
@@ -1085,7 +1029,7 @@ public Task IsMaximizedAsync()
///
public void Minimize()
{
- BridgeConnector.Socket.Emit("browserWindowMinimize", Id);
+ BridgeConnector.Emit("browserWindowMinimize", Id);
}
///
@@ -1093,7 +1037,7 @@ public void Minimize()
///
public void Restore()
{
- BridgeConnector.Socket.Emit("browserWindowRestore", Id);
+ BridgeConnector.Emit("browserWindowRestore", Id);
}
///
@@ -1102,17 +1046,7 @@ public void Restore()
///
public Task IsMinimizedAsync()
{
- var taskCompletionSource = new TaskCompletionSource();
-
- BridgeConnector.Socket.On("browserWindow-isMinimized-completed", (isMinimized) => {
- BridgeConnector.Socket.Off("browserWindow-isMinimized-completed");
-
- taskCompletionSource.SetResult((bool)isMinimized);
- });
-
- BridgeConnector.Socket.Emit("browserWindowIsMinimized", Id);
-
- return taskCompletionSource.Task;
+ return BridgeConnector.OnResult("browserWindowIsMinimized", "browserWindow-isMinimized-completed" + Id, Id);
}
///
@@ -1120,7 +1054,7 @@ public Task IsMinimizedAsync()
///
public void SetFullScreen(bool flag)
{
- BridgeConnector.Socket.Emit("browserWindowSetFullScreen", Id, flag);
+ BridgeConnector.Emit("browserWindowSetFullScreen", Id, flag);
}
///
@@ -1129,17 +1063,7 @@ public void SetFullScreen(bool flag)
///
public Task IsFullScreenAsync()
{
- var taskCompletionSource = new TaskCompletionSource();
-
- BridgeConnector.Socket.On("browserWindow-isFullScreen-completed", (isFullScreen) => {
- BridgeConnector.Socket.Off("browserWindow-isFullScreen-completed");
-
- taskCompletionSource.SetResult((bool)isFullScreen);
- });
-
- BridgeConnector.Socket.Emit("browserWindowIsFullScreen", Id);
-
- return taskCompletionSource.Task;
+ return BridgeConnector.OnResult("browserWindowIsFullScreen", "browserWindow-isFullScreen-completed" + Id, Id);
}
///
@@ -1158,7 +1082,7 @@ public Task IsFullScreenAsync()
/// The extra size not to be included while maintaining the aspect ratio.
public void SetAspectRatio(int aspectRatio, Size extraSize)
{
- BridgeConnector.Socket.Emit("browserWindowSetAspectRatio", Id, aspectRatio, JObject.FromObject(extraSize, _jsonSerializer));
+ BridgeConnector.Emit("browserWindowSetAspectRatio", Id, aspectRatio, extraSize);
}
///
@@ -1169,7 +1093,7 @@ public void SetAspectRatio(int aspectRatio, Size extraSize)
/// file to open.
public void PreviewFile(string path)
{
- BridgeConnector.Socket.Emit("browserWindowPreviewFile", Id, path);
+ BridgeConnector.Emit("browserWindowPreviewFile", Id, path);
}
///
@@ -1182,7 +1106,7 @@ public void PreviewFile(string path)
/// purely visual and does not affect the content type of the file. Defaults to path.
public void PreviewFile(string path, string displayname)
{
- BridgeConnector.Socket.Emit("browserWindowPreviewFile", Id, path, displayname);
+ BridgeConnector.Emit("browserWindowPreviewFile", Id, path, displayname);
}
///
@@ -1190,7 +1114,7 @@ public void PreviewFile(string path, string displayname)
///
public void CloseFilePreview()
{
- BridgeConnector.Socket.Emit("browserWindowCloseFilePreview", Id);
+ BridgeConnector.Emit("browserWindowCloseFilePreview", Id);
}
///
@@ -1199,7 +1123,7 @@ public void CloseFilePreview()
///
public void SetBounds(Rectangle bounds)
{
- BridgeConnector.Socket.Emit("browserWindowSetBounds", Id, JObject.FromObject(bounds, _jsonSerializer));
+ BridgeConnector.Emit("browserWindowSetBounds", Id, bounds);
}
///
@@ -1209,7 +1133,7 @@ public void SetBounds(Rectangle bounds)
///
public void SetBounds(Rectangle bounds, bool animate)
{
- BridgeConnector.Socket.Emit("browserWindowSetBounds", Id, JObject.FromObject(bounds, _jsonSerializer), animate);
+ BridgeConnector.Emit("browserWindowSetBounds", Id, bounds, animate);
}
///
@@ -1218,17 +1142,7 @@ public void SetBounds(Rectangle bounds, bool animate)
///
public Task GetBoundsAsync()
{
- var taskCompletionSource = new TaskCompletionSource();
-
- BridgeConnector.Socket.On("browserWindow-getBounds-completed", (getBounds) => {
- BridgeConnector.Socket.Off("browserWindow-getBounds-completed");
-
- taskCompletionSource.SetResult(((JObject)getBounds).ToObject());
- });
-
- BridgeConnector.Socket.Emit("browserWindowGetBounds", Id);
-
- return taskCompletionSource.Task;
+ return BridgeConnector.OnResult("browserWindowGetBounds", "browserWindow-getBounds-completed" + Id, Id);
}
///
@@ -1237,7 +1151,7 @@ public Task GetBoundsAsync()
///
public void SetContentBounds(Rectangle bounds)
{
- BridgeConnector.Socket.Emit("browserWindowSetContentBounds", Id, JObject.FromObject(bounds, _jsonSerializer));
+ BridgeConnector.Emit("browserWindowSetContentBounds", Id, bounds);
}
///
@@ -1247,7 +1161,7 @@ public void SetContentBounds(Rectangle bounds)
///
public void SetContentBounds(Rectangle bounds, bool animate)
{
- BridgeConnector.Socket.Emit("browserWindowSetContentBounds", Id, JObject.FromObject(bounds, _jsonSerializer), animate);
+ BridgeConnector.Emit("browserWindowSetContentBounds", Id, bounds, animate);
}
///
@@ -1256,17 +1170,7 @@ public void SetContentBounds(Rectangle bounds, bool animate)
///
public Task GetContentBoundsAsync()
{
- var taskCompletionSource = new TaskCompletionSource();
-
- BridgeConnector.Socket.On("browserWindow-getContentBounds-completed", (getContentBounds) => {
- BridgeConnector.Socket.Off("browserWindow-getContentBounds-completed");
-
- taskCompletionSource.SetResult(((JObject)getContentBounds).ToObject());
- });
-
- BridgeConnector.Socket.Emit("browserWindowGetContentBounds", Id);
-
- return taskCompletionSource.Task;
+ return BridgeConnector.OnResult("browserWindowGetContentBounds", "browserWindow-getContentBounds-completed" + Id, Id);
}
///
@@ -1276,7 +1180,7 @@ public Task GetContentBoundsAsync()
///
public void SetSize(int width, int height)
{
- BridgeConnector.Socket.Emit("browserWindowSetSize", Id, width, height);
+ BridgeConnector.Emit("browserWindowSetSize", Id, width, height);
}
///
@@ -1287,7 +1191,7 @@ public void SetSize(int width, int height)
///
public void SetSize(int width, int height, bool animate)
{
- BridgeConnector.Socket.Emit("browserWindowSetSize", Id, width, height, animate);
+ BridgeConnector.Emit("browserWindowSetSize", Id, width, height, animate);
}
///
@@ -1296,17 +1200,7 @@ public void SetSize(int width, int height, bool animate)
///
public Task GetSizeAsync()
{
- var taskCompletionSource = new TaskCompletionSource();
-
- BridgeConnector.Socket.On("browserWindow-getSize-completed", (size) => {
- BridgeConnector.Socket.Off("browserWindow-getSize-completed");
-
- taskCompletionSource.SetResult(((JArray)size).ToObject());
- });
-
- BridgeConnector.Socket.Emit("browserWindowGetSize", Id);
-
- return taskCompletionSource.Task;
+ return BridgeConnector.OnResult("browserWindowGetSize", "browserWindow-getSize-completed" + Id, Id);
}
///
@@ -1316,7 +1210,7 @@ public Task GetSizeAsync()
///
public void SetContentSize(int width, int height)
{
- BridgeConnector.Socket.Emit("browserWindowSetContentSize", Id, width, height);
+ BridgeConnector.Emit("browserWindowSetContentSize", Id, width, height);
}
///
@@ -1327,7 +1221,7 @@ public void SetContentSize(int width, int height)
///
public void SetContentSize(int width, int height, bool animate)
{
- BridgeConnector.Socket.Emit("browserWindowSetContentSize", Id, width, height, animate);
+ BridgeConnector.Emit("browserWindowSetContentSize", Id, width, height, animate);
}
///
@@ -1336,17 +1230,7 @@ public void SetContentSize(int width, int height, bool animate)
///
public Task GetContentSizeAsync()
{
- var taskCompletionSource = new TaskCompletionSource();
-
- BridgeConnector.Socket.On("browserWindow-getContentSize-completed", (size) => {
- BridgeConnector.Socket.Off("browserWindow-getContentSize-completed");
-
- taskCompletionSource.SetResult(((JArray)size).ToObject());
- });
-
- BridgeConnector.Socket.Emit("browserWindowGetContentSize", Id);
-
- return taskCompletionSource.Task;
+ return BridgeConnector.OnResult("browserWindowGetContentSize", "browserWindow-getContentSize-completed" + Id, Id);
}
///
@@ -1356,7 +1240,7 @@ public Task GetContentSizeAsync()
///
public void SetMinimumSize(int width, int height)
{
- BridgeConnector.Socket.Emit("browserWindowSetMinimumSize", Id, width, height);
+ BridgeConnector.Emit("browserWindowSetMinimumSize", Id, width, height);
}
///
@@ -1365,17 +1249,7 @@ public void SetMinimumSize(int width, int height)
///
public Task GetMinimumSizeAsync()
{
- var taskCompletionSource = new TaskCompletionSource();
-
- BridgeConnector.Socket.On("browserWindow-getMinimumSize-completed", (size) => {
- BridgeConnector.Socket.Off("browserWindow-getMinimumSize-completed");
-
- taskCompletionSource.SetResult(((JArray)size).ToObject());
- });
-
- BridgeConnector.Socket.Emit("browserWindowGetMinimumSize", Id);
-
- return taskCompletionSource.Task;
+ return BridgeConnector.OnResult("browserWindowGetMinimumSize", "browserWindow-getMinimumSize-completed" + Id, Id);
}
///
@@ -1385,7 +1259,7 @@ public Task GetMinimumSizeAsync()
///
public void SetMaximumSize(int width, int height)
{
- BridgeConnector.Socket.Emit("browserWindowSetMaximumSize", Id, width, height);
+ BridgeConnector.Emit("browserWindowSetMaximumSize", Id, width, height);
}
///
@@ -1394,17 +1268,7 @@ public void SetMaximumSize(int width, int height)
///
public Task GetMaximumSizeAsync()
{
- var taskCompletionSource = new TaskCompletionSource();
-
- BridgeConnector.Socket.On("browserWindow-getMaximumSize-completed", (size) => {
- BridgeConnector.Socket.Off("browserWindow-getMaximumSize-completed");
-
- taskCompletionSource.SetResult(((JArray)size).ToObject());
- });
-
- BridgeConnector.Socket.Emit("browserWindowGetMaximumSize", Id);
-
- return taskCompletionSource.Task;
+ return BridgeConnector.OnResult("browserWindowGetMaximumSize", "browserWindow-getMaximumSize-completed" + Id, Id);
}
///
@@ -1413,7 +1277,7 @@ public Task GetMaximumSizeAsync()
///
public void SetResizable(bool resizable)
{
- BridgeConnector.Socket.Emit("browserWindowSetResizable", Id, resizable);
+ BridgeConnector.Emit("browserWindowSetResizable", Id, resizable);
}
///
@@ -1422,17 +1286,7 @@ public void SetResizable(bool resizable)
///
public Task IsResizableAsync()
{
- var taskCompletionSource = new TaskCompletionSource();
-
- BridgeConnector.Socket.On("browserWindow-isResizable-completed", (resizable) => {
- BridgeConnector.Socket.Off("browserWindow-isResizable-completed");
-
- taskCompletionSource.SetResult((bool)resizable);
- });
-
- BridgeConnector.Socket.Emit("browserWindowIsResizable", Id);
-
- return taskCompletionSource.Task;
+ return BridgeConnector.OnResult("browserWindowIsResizable", "browserWindow-isResizable-completed" + Id, Id);
}
///
@@ -1441,7 +1295,7 @@ public Task IsResizableAsync()
///
public void SetMovable(bool movable)
{
- BridgeConnector.Socket.Emit("browserWindowSetMovable", Id, movable);
+ BridgeConnector.Emit("browserWindowSetMovable", Id, movable);
}
///
@@ -1452,17 +1306,7 @@ public void SetMovable(bool movable)
/// On Linux always returns true.
public Task IsMovableAsync()
{
- var taskCompletionSource = new TaskCompletionSource();
-
- BridgeConnector.Socket.On("browserWindow-isMovable-completed", (movable) => {
- BridgeConnector.Socket.Off("browserWindow-isMovable-completed");
-
- taskCompletionSource.SetResult((bool)movable);
- });
-
- BridgeConnector.Socket.Emit("browserWindowIsMovable", Id);
-
- return taskCompletionSource.Task;
+ return BridgeConnector.OnResult("browserWindowIsMovable", "browserWindow-isMovable-completed" + Id, Id);
}
///
@@ -1471,7 +1315,7 @@ public Task IsMovableAsync()
///
public void SetMinimizable(bool minimizable)
{
- BridgeConnector.Socket.Emit("browserWindowSetMinimizable", Id, minimizable);
+ BridgeConnector.Emit("browserWindowSetMinimizable", Id, minimizable);
}
///
@@ -1482,17 +1326,7 @@ public void SetMinimizable(bool minimizable)
/// On Linux always returns true.
public Task IsMinimizableAsync()
{
- var taskCompletionSource = new TaskCompletionSource();
-
- BridgeConnector.Socket.On("browserWindow-isMinimizable-completed", (minimizable) => {
- BridgeConnector.Socket.Off("browserWindow-isMinimizable-completed");
-
- taskCompletionSource.SetResult((bool)minimizable);
- });
-
- BridgeConnector.Socket.Emit("browserWindowIsMinimizable", Id);
-
- return taskCompletionSource.Task;
+ return BridgeConnector.OnResult("browserWindowIsMinimizable", "browserWindow-isMinimizable-completed" + Id, Id);
}
///
@@ -1501,7 +1335,7 @@ public Task IsMinimizableAsync()
///
public void SetMaximizable(bool maximizable)
{
- BridgeConnector.Socket.Emit("browserWindowSetMaximizable", Id, maximizable);
+ BridgeConnector.Emit("browserWindowSetMaximizable", Id, maximizable);
}
///
@@ -1512,17 +1346,7 @@ public void SetMaximizable(bool maximizable)
/// On Linux always returns true.
public Task IsMaximizableAsync()
{
- var taskCompletionSource = new TaskCompletionSource();
-
- BridgeConnector.Socket.On("browserWindow-isMaximizable-completed", (maximizable) => {
- BridgeConnector.Socket.Off("browserWindow-isMaximizable-completed");
-
- taskCompletionSource.SetResult((bool)maximizable);
- });
-
- BridgeConnector.Socket.Emit("browserWindowIsMaximizable", Id);
-
- return taskCompletionSource.Task;
+ return BridgeConnector.OnResult("browserWindowIsMaximizable", "browserWindow-isMaximizable-completed" + Id, Id);
}
///
@@ -1531,7 +1355,7 @@ public Task IsMaximizableAsync()
///
public void SetFullScreenable(bool fullscreenable)
{
- BridgeConnector.Socket.Emit("browserWindowSetFullScreenable", Id, fullscreenable);
+ BridgeConnector.Emit("browserWindowSetFullScreenable", Id, fullscreenable);
}
///
@@ -1540,17 +1364,7 @@ public void SetFullScreenable(bool fullscreenable)
///
public Task IsFullScreenableAsync()
{
- var taskCompletionSource = new TaskCompletionSource();
-
- BridgeConnector.Socket.On("browserWindow-isFullScreenable-completed", (fullscreenable) => {
- BridgeConnector.Socket.Off("browserWindow-isFullScreenable-completed");
-
- taskCompletionSource.SetResult((bool)fullscreenable);
- });
-
- BridgeConnector.Socket.Emit("browserWindowIsFullScreenable", Id);
-
- return taskCompletionSource.Task;
+ return BridgeConnector.OnResult("browserWindowIsFullScreenable", "browserWindow-isFullScreenable-completed" + Id, Id);
}
///
@@ -1559,7 +1373,7 @@ public Task IsFullScreenableAsync()
///
public void SetClosable(bool closable)
{
- BridgeConnector.Socket.Emit("browserWindowSetClosable", Id, closable);
+ BridgeConnector.Emit("browserWindowSetClosable", Id, closable);
}
///
@@ -1570,17 +1384,7 @@ public void SetClosable(bool closable)
/// On Linux always returns true.
public Task IsClosableAsync()
{
- var taskCompletionSource = new TaskCompletionSource();
-
- BridgeConnector.Socket.On("browserWindow-isClosable-completed", (closable) => {
- BridgeConnector.Socket.Off("browserWindow-isClosable-completed");
-
- taskCompletionSource.SetResult((bool)closable);
- });
-
- BridgeConnector.Socket.Emit("browserWindowIsClosable", Id);
-
- return taskCompletionSource.Task;
+ return BridgeConnector.OnResult("browserWindowIsClosable", "browserWindow-isClosable-completed" + Id, Id);
}
///
@@ -1591,7 +1395,7 @@ public Task IsClosableAsync()
///
public void SetAlwaysOnTop(bool flag)
{
- BridgeConnector.Socket.Emit("browserWindowSetAlwaysOnTop", Id, flag);
+ BridgeConnector.Emit("browserWindowSetAlwaysOnTop", Id, flag);
}
///
@@ -1605,7 +1409,7 @@ public void SetAlwaysOnTop(bool flag)
/// See the macOS docs
public void SetAlwaysOnTop(bool flag, OnTopLevel level)
{
- BridgeConnector.Socket.Emit("browserWindowSetAlwaysOnTop", Id, flag, level.GetDescription());
+ BridgeConnector.Emit("browserWindowSetAlwaysOnTop", Id, flag, level.GetDescription());
}
///
@@ -1621,7 +1425,7 @@ public void SetAlwaysOnTop(bool flag, OnTopLevel level)
/// The default is 0. Note that Apple discourages setting levels higher than 1 above screen-saver.
public void SetAlwaysOnTop(bool flag, OnTopLevel level, int relativeLevel)
{
- BridgeConnector.Socket.Emit("browserWindowSetAlwaysOnTop", Id, flag, level.GetDescription(), relativeLevel);
+ BridgeConnector.Emit("browserWindowSetAlwaysOnTop", Id, flag, level.GetDescription(), relativeLevel);
}
///
@@ -1630,17 +1434,7 @@ public void SetAlwaysOnTop(bool flag, OnTopLevel level, int relativeLevel)
///
public Task IsAlwaysOnTopAsync()
{
- var taskCompletionSource = new TaskCompletionSource();
-
- BridgeConnector.Socket.On("browserWindow-isAlwaysOnTop-completed", (isAlwaysOnTop) => {
- BridgeConnector.Socket.Off("browserWindow-isAlwaysOnTop-completed");
-
- taskCompletionSource.SetResult((bool)isAlwaysOnTop);
- });
-
- BridgeConnector.Socket.Emit("browserWindowIsAlwaysOnTop", Id);
-
- return taskCompletionSource.Task;
+ return BridgeConnector.OnResult("browserWindowIsAlwaysOnTop", "browserWindow-isAlwaysOnTop-completed" + Id, Id);
}
///
@@ -1648,7 +1442,7 @@ public Task