From b03bc7c9ebcbd9148c7ace6057c34aff1b7a6bdf Mon Sep 17 00:00:00 2001 From: theolivenbaum Date: Mon, 12 Jul 2021 21:33:35 +0200 Subject: [PATCH] Clean-up --- ElectronNET.API/App.cs | 2 +- ElectronNET.API/AutoUpdater.cs | 10 +-- ElectronNET.API/BridgeConnector.cs | 67 +++---------------- ElectronNET.API/BrowserWindow.cs | 42 ++++++------ ElectronNET.API/CommandLine.cs | 2 +- ElectronNET.API/Dock.cs | 2 +- .../Entities/CookieChangedCause.cs | 11 +-- .../Entities/CookieRemovedResponse.cs | 10 +++ ElectronNET.API/NativeTheme.cs | 6 +- ElectronNET.API/Notification.cs | 2 +- ElectronNET.API/Session.cs | 2 +- ElectronNET.API/Shell.cs | 8 +-- ElectronNET.API/Tray.cs | 2 +- ElectronNET.API/WebContents.cs | 8 +-- 14 files changed, 64 insertions(+), 110 deletions(-) create mode 100644 ElectronNET.API/Entities/CookieRemovedResponse.cs diff --git a/ElectronNET.API/App.cs b/ElectronNET.API/App.cs index eabbbfc..a8e137a 100644 --- a/ElectronNET.API/App.cs +++ b/ElectronNET.API/App.cs @@ -340,7 +340,7 @@ namespace ElectronNET.API { BridgeConnector.On("app-accessibility-support-changed" + GetHashCode(), (state) => { - _accessibilitySupportChanged((bool)state); + _accessibilitySupportChanged(state); }); BridgeConnector.Emit("register-app-accessibility-support-changed-event", GetHashCode()); diff --git a/ElectronNET.API/AutoUpdater.cs b/ElectronNET.API/AutoUpdater.cs index ae1c337..e16ad49 100644 --- a/ElectronNET.API/AutoUpdater.cs +++ b/ElectronNET.API/AutoUpdater.cs @@ -23,7 +23,7 @@ namespace ElectronNET.API BridgeConnector.On("autoUpdater-autoDownload-get-reply", (result) => { BridgeConnector.Off("autoUpdater-autoDownload-get-reply"); - taskCompletionSource.SetResult((bool)result); + taskCompletionSource.SetResult(result); }); BridgeConnector.Emit("autoUpdater-autoDownload-get"); @@ -43,7 +43,7 @@ namespace ElectronNET.API BridgeConnector.On("autoUpdater-autoInstallOnAppQuit-get-reply", (result) => { BridgeConnector.Off("autoUpdater-autoInstallOnAppQuit-get-reply"); - taskCompletionSource.SetResult((bool)result); + taskCompletionSource.SetResult(result); }); BridgeConnector.Emit("autoUpdater-autoInstallOnAppQuit-get"); @@ -64,7 +64,7 @@ namespace ElectronNET.API BridgeConnector.On("autoUpdater-allowPrerelease-get-reply", (result) => { BridgeConnector.Off("autoUpdater-allowPrerelease-get-reply"); - taskCompletionSource.SetResult((bool)result); + taskCompletionSource.SetResult(result); }); BridgeConnector.Emit("autoUpdater-allowPrerelease-get"); @@ -83,7 +83,7 @@ namespace ElectronNET.API BridgeConnector.On("autoUpdater-fullChangelog-get-reply", (result) => { BridgeConnector.Off("autoUpdater-fullChangelog-get-reply"); - taskCompletionSource.SetResult((bool)result); + taskCompletionSource.SetResult(result); }); BridgeConnector.Emit("autoUpdater-fullChangelog-get"); @@ -98,7 +98,7 @@ namespace ElectronNET.API BridgeConnector.On("autoUpdater-allowDowngrade-get-reply", (result) => { BridgeConnector.Off("autoUpdater-allowDowngrade-get-reply"); - taskCompletionSource.SetResult((bool)result); + taskCompletionSource.SetResult(result); }); BridgeConnector.Emit("autoUpdater-allowDowngrade-get"); diff --git a/ElectronNET.API/BridgeConnector.cs b/ElectronNET.API/BridgeConnector.cs index fa910fe..bb5c444 100644 --- a/ElectronNET.API/BridgeConnector.cs +++ b/ElectronNET.API/BridgeConnector.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using SocketIOClient; using SocketIOClient.Newtonsoft.Json; @@ -10,21 +11,22 @@ namespace ElectronNET.API private static object _syncRoot = new object(); - public static void Emit(string eventString, params object[] args) => Socket.EmitAsync(eventString, args); + public static void Emit(string eventString, params object[] args) + { + //We don't care about waiting for the event to be emitted, so this doesn't need to be async + + Task.Run(() => Socket.EmitAsync(eventString, args)); + } + 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 On(string eventString, Action fn) => Socket.On(eventString, (o) => fn(o.GetValue(0))); public static void Once(string eventString, Action fn) => Socket.On(eventString, (o) => { Socket.Off(eventString); fn(o.GetValue(0)); }); - private static SocketIO Socket { get @@ -67,55 +69,4 @@ namespace ElectronNET.API } } } - - public interface IListener : System.IComparable - { - int GetId(); - void Call(params object[] args); - } - - public class ListenerImpl : IListener - { - private static int id_counter = 0; - private int Id; - private readonly Action fn1; - private readonly Action fn; - - public ListenerImpl(Action fn) - { - - this.fn = fn; - this.Id = id_counter++; - } - - public ListenerImpl(Action fn) - { - - this.fn1 = fn; - this.Id = id_counter++; - } - - public void Call(params object[] args) - { - if (fn != null) - { - var arg = args.Length > 0 ? args[0] : null; - fn(arg); - } - else - { - fn1(); - } - } - - public int CompareTo(IListener other) - { - return this.GetId().CompareTo(other.GetId()); - } - - public int GetId() - { - return Id; - } - } } diff --git a/ElectronNET.API/BrowserWindow.cs b/ElectronNET.API/BrowserWindow.cs index b08081c..4ebd586 100644 --- a/ElectronNET.API/BrowserWindow.cs +++ b/ElectronNET.API/BrowserWindow.cs @@ -956,7 +956,7 @@ namespace ElectronNET.API BridgeConnector.On("browserWindow-isFocused-completed", (isFocused) => { BridgeConnector.Off("browserWindow-isFocused-completed"); - taskCompletionSource.SetResult((bool)isFocused); + taskCompletionSource.SetResult(isFocused); }); BridgeConnector.Emit("browserWindowIsFocused", Id); @@ -975,7 +975,7 @@ namespace ElectronNET.API BridgeConnector.On("browserWindow-isDestroyed-completed", (isDestroyed) => { BridgeConnector.Off("browserWindow-isDestroyed-completed"); - taskCompletionSource.SetResult((bool)isDestroyed); + taskCompletionSource.SetResult(isDestroyed); }); BridgeConnector.Emit("browserWindowIsDestroyed", Id); @@ -1018,7 +1018,7 @@ namespace ElectronNET.API BridgeConnector.On("browserWindow-isVisible-completed", (isVisible) => { BridgeConnector.Off("browserWindow-isVisible-completed"); - taskCompletionSource.SetResult((bool)isVisible); + taskCompletionSource.SetResult(isVisible); }); BridgeConnector.Emit("browserWindowIsVisible", Id); @@ -1037,7 +1037,7 @@ namespace ElectronNET.API BridgeConnector.On("browserWindow-isModal-completed", (isModal) => { BridgeConnector.Off("browserWindow-isModal-completed"); - taskCompletionSource.SetResult((bool)isModal); + taskCompletionSource.SetResult(isModal); }); BridgeConnector.Emit("browserWindowIsModal", Id); @@ -1072,7 +1072,7 @@ namespace ElectronNET.API BridgeConnector.On("browserWindow-isMaximized-completed", (isMaximized) => { BridgeConnector.Off("browserWindow-isMaximized-completed"); - taskCompletionSource.SetResult((bool)isMaximized); + taskCompletionSource.SetResult(isMaximized); }); BridgeConnector.Emit("browserWindowIsMaximized", Id); @@ -1107,7 +1107,7 @@ namespace ElectronNET.API BridgeConnector.On("browserWindow-isMinimized-completed", (isMinimized) => { BridgeConnector.Off("browserWindow-isMinimized-completed"); - taskCompletionSource.SetResult((bool)isMinimized); + taskCompletionSource.SetResult(isMinimized); }); BridgeConnector.Emit("browserWindowIsMinimized", Id); @@ -1134,7 +1134,7 @@ namespace ElectronNET.API BridgeConnector.On("browserWindow-isFullScreen-completed", (isFullScreen) => { BridgeConnector.Off("browserWindow-isFullScreen-completed"); - taskCompletionSource.SetResult((bool)isFullScreen); + taskCompletionSource.SetResult(isFullScreen); }); BridgeConnector.Emit("browserWindowIsFullScreen", Id); @@ -1427,7 +1427,7 @@ namespace ElectronNET.API BridgeConnector.On("browserWindow-isResizable-completed", (resizable) => { BridgeConnector.Off("browserWindow-isResizable-completed"); - taskCompletionSource.SetResult((bool)resizable); + taskCompletionSource.SetResult(resizable); }); BridgeConnector.Emit("browserWindowIsResizable", Id); @@ -1457,7 +1457,7 @@ namespace ElectronNET.API BridgeConnector.On("browserWindow-isMovable-completed", (movable) => { BridgeConnector.Off("browserWindow-isMovable-completed"); - taskCompletionSource.SetResult((bool)movable); + taskCompletionSource.SetResult(movable); }); BridgeConnector.Emit("browserWindowIsMovable", Id); @@ -1487,7 +1487,7 @@ namespace ElectronNET.API BridgeConnector.On("browserWindow-isMinimizable-completed", (minimizable) => { BridgeConnector.Off("browserWindow-isMinimizable-completed"); - taskCompletionSource.SetResult((bool)minimizable); + taskCompletionSource.SetResult(minimizable); }); BridgeConnector.Emit("browserWindowIsMinimizable", Id); @@ -1517,7 +1517,7 @@ namespace ElectronNET.API BridgeConnector.On("browserWindow-isMaximizable-completed", (maximizable) => { BridgeConnector.Off("browserWindow-isMaximizable-completed"); - taskCompletionSource.SetResult((bool)maximizable); + taskCompletionSource.SetResult(maximizable); }); BridgeConnector.Emit("browserWindowIsMaximizable", Id); @@ -1545,7 +1545,7 @@ namespace ElectronNET.API BridgeConnector.On("browserWindow-isFullScreenable-completed", (fullscreenable) => { BridgeConnector.Off("browserWindow-isFullScreenable-completed"); - taskCompletionSource.SetResult((bool)fullscreenable); + taskCompletionSource.SetResult(fullscreenable); }); BridgeConnector.Emit("browserWindowIsFullScreenable", Id); @@ -1575,7 +1575,7 @@ namespace ElectronNET.API BridgeConnector.On("browserWindow-isClosable-completed", (closable) => { BridgeConnector.Off("browserWindow-isClosable-completed"); - taskCompletionSource.SetResult((bool)closable); + taskCompletionSource.SetResult(closable); }); BridgeConnector.Emit("browserWindowIsClosable", Id); @@ -1635,7 +1635,7 @@ namespace ElectronNET.API BridgeConnector.On("browserWindow-isAlwaysOnTop-completed", (isAlwaysOnTop) => { BridgeConnector.Off("browserWindow-isAlwaysOnTop-completed"); - taskCompletionSource.SetResult((bool)isAlwaysOnTop); + taskCompletionSource.SetResult(isAlwaysOnTop); }); BridgeConnector.Emit("browserWindowIsAlwaysOnTop", Id); @@ -1801,7 +1801,7 @@ namespace ElectronNET.API BridgeConnector.On("browserWindow-isKiosk-completed", (isKiosk) => { BridgeConnector.Off("browserWindow-isKiosk-completed"); - taskCompletionSource.SetResult((bool)isKiosk); + taskCompletionSource.SetResult(isKiosk); }); BridgeConnector.Emit("browserWindowIsKiosk", Id); @@ -1878,7 +1878,7 @@ namespace ElectronNET.API BridgeConnector.On("browserWindow-isDocumentEdited-completed", (edited) => { BridgeConnector.Off("browserWindow-isDocumentEdited-completed"); - taskCompletionSource.SetResult((bool)edited); + taskCompletionSource.SetResult(edited); }); BridgeConnector.Emit("browserWindowIsDocumentEdited", Id); @@ -2021,7 +2021,7 @@ namespace ElectronNET.API BridgeConnector.On("browserWindow-hasShadow-completed", (hasShadow) => { BridgeConnector.Off("browserWindow-hasShadow-completed"); - taskCompletionSource.SetResult((bool)hasShadow); + taskCompletionSource.SetResult(hasShadow); }); BridgeConnector.Emit("browserWindowHasShadow", Id); @@ -2057,7 +2057,7 @@ namespace ElectronNET.API BridgeConnector.On("browserWindowSetThumbarButtons-completed", (success) => { BridgeConnector.Off("browserWindowSetThumbarButtons-completed"); - taskCompletionSource.SetResult((bool)success); + taskCompletionSource.SetResult(success); }); thumbarButtons.AddThumbarButtonsId(); @@ -2137,7 +2137,7 @@ namespace ElectronNET.API BridgeConnector.On("browserWindow-isMenuBarAutoHide-completed", (isMenuBarAutoHide) => { BridgeConnector.Off("browserWindow-isMenuBarAutoHide-completed"); - taskCompletionSource.SetResult((bool)isMenuBarAutoHide); + taskCompletionSource.SetResult(isMenuBarAutoHide); }); BridgeConnector.Emit("browserWindowIsMenuBarAutoHide", Id); @@ -2166,7 +2166,7 @@ namespace ElectronNET.API BridgeConnector.On("browserWindow-isMenuBarVisible-completed", (isMenuBarVisible) => { BridgeConnector.Off("browserWindow-isMenuBarVisible-completed"); - taskCompletionSource.SetResult((bool)isMenuBarVisible); + taskCompletionSource.SetResult(isMenuBarVisible); }); BridgeConnector.Emit("browserWindowIsMenuBarVisible", Id); @@ -2198,7 +2198,7 @@ namespace ElectronNET.API BridgeConnector.On("browserWindow-isVisibleOnAllWorkspaces-completed", (isVisibleOnAllWorkspaces) => { BridgeConnector.Off("browserWindow-isVisibleOnAllWorkspaces-completed"); - taskCompletionSource.SetResult((bool)isVisibleOnAllWorkspaces); + taskCompletionSource.SetResult(isVisibleOnAllWorkspaces); }); BridgeConnector.Emit("browserWindowIsVisibleOnAllWorkspaces", Id); diff --git a/ElectronNET.API/CommandLine.cs b/ElectronNET.API/CommandLine.cs index 6b09058..09c5e1e 100644 --- a/ElectronNET.API/CommandLine.cs +++ b/ElectronNET.API/CommandLine.cs @@ -76,7 +76,7 @@ namespace ElectronNET.API BridgeConnector.On("appCommandLineHasSwitchCompleted", (result) => { BridgeConnector.Off("appCommandLineHasSwitchCompleted"); - taskCompletionSource.SetResult((bool)result); + taskCompletionSource.SetResult(result); }); BridgeConnector.Emit("appCommandLineHasSwitch", switchName); diff --git a/ElectronNET.API/Dock.cs b/ElectronNET.API/Dock.cs index 3602527..e947fdf 100644 --- a/ElectronNET.API/Dock.cs +++ b/ElectronNET.API/Dock.cs @@ -154,7 +154,7 @@ namespace ElectronNET.API BridgeConnector.On("dock-isVisible-completed", (isVisible) => { BridgeConnector.Off("dock-isVisible-completed"); - taskCompletionSource.SetResult((bool) isVisible); + taskCompletionSource.SetResult(isVisible); }); BridgeConnector.Emit("dock-isVisible"); diff --git a/ElectronNET.API/Entities/CookieChangedCause.cs b/ElectronNET.API/Entities/CookieChangedCause.cs index ee467a3..f48c8f9 100644 --- a/ElectronNET.API/Entities/CookieChangedCause.cs +++ b/ElectronNET.API/Entities/CookieChangedCause.cs @@ -1,15 +1,8 @@ using Newtonsoft.Json; using Newtonsoft.Json.Converters; -namespace ElectronNET.API.Entities { - - public class CookieRemovedResponse - { - public Cookie cookie {get;set;} - - public CookieChangedCause cause { get; set; } - public bool removed { get; set; } - } +namespace ElectronNET.API.Entities +{ /// /// The cause of the change diff --git a/ElectronNET.API/Entities/CookieRemovedResponse.cs b/ElectronNET.API/Entities/CookieRemovedResponse.cs new file mode 100644 index 0000000..88dece6 --- /dev/null +++ b/ElectronNET.API/Entities/CookieRemovedResponse.cs @@ -0,0 +1,10 @@ +namespace ElectronNET.API.Entities +{ + public class CookieRemovedResponse + { + public Cookie cookie {get;set;} + + public CookieChangedCause cause { get; set; } + public bool removed { get; set; } + } +} \ No newline at end of file diff --git a/ElectronNET.API/NativeTheme.cs b/ElectronNET.API/NativeTheme.cs index 9305e8f..a87b030 100644 --- a/ElectronNET.API/NativeTheme.cs +++ b/ElectronNET.API/NativeTheme.cs @@ -131,7 +131,7 @@ namespace ElectronNET.API BridgeConnector.On("nativeTheme-shouldUseDarkColors-completed", (shouldUseDarkColors) => { BridgeConnector.Off("nativeTheme-shouldUseDarkColors-completed"); - taskCompletionSource.SetResult((bool)shouldUseDarkColors); + taskCompletionSource.SetResult(shouldUseDarkColors); }); BridgeConnector.Emit("nativeTheme-shouldUseDarkColors"); @@ -150,7 +150,7 @@ namespace ElectronNET.API BridgeConnector.On("nativeTheme-shouldUseHighContrastColors-completed", (shouldUseHighContrastColors) => { BridgeConnector.Off("nativeTheme-shouldUseHighContrastColors-completed"); - taskCompletionSource.SetResult((bool)shouldUseHighContrastColors); + taskCompletionSource.SetResult(shouldUseHighContrastColors); }); BridgeConnector.Emit("nativeTheme-shouldUseHighContrastColors"); @@ -169,7 +169,7 @@ namespace ElectronNET.API BridgeConnector.On("nativeTheme-shouldUseInvertedColorScheme-completed", (shouldUseInvertedColorScheme) => { BridgeConnector.Off("nativeTheme-shouldUseInvertedColorScheme-completed"); - taskCompletionSource.SetResult((bool)shouldUseInvertedColorScheme); + taskCompletionSource.SetResult(shouldUseInvertedColorScheme); }); BridgeConnector.Emit("nativeTheme-shouldUseInvertedColorScheme"); diff --git a/ElectronNET.API/Notification.cs b/ElectronNET.API/Notification.cs index fcde73b..fab7d7c 100644 --- a/ElectronNET.API/Notification.cs +++ b/ElectronNET.API/Notification.cs @@ -127,7 +127,7 @@ namespace ElectronNET.API BridgeConnector.On("notificationIsSupportedComplete", (isSupported) => { BridgeConnector.Off("notificationIsSupportedComplete"); - taskCompletionSource.SetResult((bool)isSupported); + taskCompletionSource.SetResult(isSupported); }); BridgeConnector.Emit("notificationIsSupported"); diff --git a/ElectronNET.API/Session.cs b/ElectronNET.API/Session.cs index 097874a..3b006c1 100644 --- a/ElectronNET.API/Session.cs +++ b/ElectronNET.API/Session.cs @@ -233,7 +233,7 @@ namespace ElectronNET.API BridgeConnector.On("webContents-session-getCacheSize-completed" + guid, (size) => { BridgeConnector.Off("webContents-session-getCacheSize-completed" + guid); - taskCompletionSource.SetResult((int)size); + taskCompletionSource.SetResult(size); }); BridgeConnector.Emit("webContents-session-getCacheSize", Id, guid); diff --git a/ElectronNET.API/Shell.cs b/ElectronNET.API/Shell.cs index 308e7f9..d126f39 100644 --- a/ElectronNET.API/Shell.cs +++ b/ElectronNET.API/Shell.cs @@ -67,7 +67,7 @@ namespace ElectronNET.API { BridgeConnector.Off("shell-openPathCompleted"); - taskCompletionSource.SetResult((string) errorMessage); + taskCompletionSource.SetResult(errorMessage); }); BridgeConnector.Emit("shell-openPath", path); @@ -101,7 +101,7 @@ namespace ElectronNET.API { BridgeConnector.Off("shell-openExternalCompleted"); - taskCompletionSource.SetResult((string) error); + taskCompletionSource.SetResult(error); }); if (options == null) @@ -129,7 +129,7 @@ namespace ElectronNET.API { BridgeConnector.Off("shell-trashItem-completed"); - taskCompletionSource.SetResult((bool) success); + taskCompletionSource.SetResult(success); }); BridgeConnector.Emit("shell-trashItem", fullPath); @@ -160,7 +160,7 @@ namespace ElectronNET.API { BridgeConnector.Off("shell-writeShortcutLinkCompleted"); - taskCompletionSource.SetResult((bool) success); + taskCompletionSource.SetResult(success); }); BridgeConnector.Emit("shell-writeShortcutLink", shortcutPath, operation.GetDescription(), JObject.FromObject(options, _jsonSerializer)); diff --git a/ElectronNET.API/Tray.cs b/ElectronNET.API/Tray.cs index ff484f7..933f64a 100644 --- a/ElectronNET.API/Tray.cs +++ b/ElectronNET.API/Tray.cs @@ -329,7 +329,7 @@ namespace ElectronNET.API { BridgeConnector.Off("tray-isDestroyedCompleted"); - taskCompletionSource.SetResult((bool)isDestroyed); + taskCompletionSource.SetResult(isDestroyed); }); BridgeConnector.Emit("tray-isDestroyed"); diff --git a/ElectronNET.API/WebContents.cs b/ElectronNET.API/WebContents.cs index 36b7f80..10ed187 100644 --- a/ElectronNET.API/WebContents.cs +++ b/ElectronNET.API/WebContents.cs @@ -36,7 +36,7 @@ namespace ElectronNET.API { BridgeConnector.On("webContents-crashed" + Id, (killed) => { - _crashed((bool)killed); + _crashed(killed); }); BridgeConnector.Emit("register-webContents-crashed", Id); @@ -139,7 +139,7 @@ namespace ElectronNET.API BridgeConnector.On("webContents-print-completed", (success) => { BridgeConnector.Off("webContents-print-completed"); - taskCompletionSource.SetResult((bool)success); + taskCompletionSource.SetResult(success); }); if(options == null) @@ -170,7 +170,7 @@ namespace ElectronNET.API BridgeConnector.On("webContents-printToPDF-completed", (success) => { BridgeConnector.Off("webContents-printToPDF-completed"); - taskCompletionSource.SetResult((bool)success); + taskCompletionSource.SetResult(success); }); if(options == null) @@ -198,7 +198,7 @@ namespace ElectronNET.API BridgeConnector.On(eventString, (url) => { BridgeConnector.Off(eventString); - taskCompletionSource.SetResult((string)url); + taskCompletionSource.SetResult(url); }); BridgeConnector.Emit("webContents-getUrl", Id);