From b339485fdceb7d6f8f3c1e1f9ef973cb503c75a6 Mon Sep 17 00:00:00 2001 From: Gregor Biswanger Date: Fri, 24 Mar 2023 02:17:09 +0100 Subject: [PATCH] Change signature of PrintToPDFOptions --- ElectronNET.API/BrowserWindow.cs | 4459 ++++++++--------- ElectronNET.API/Entities/Margins.cs | 33 + ElectronNET.API/Entities/PrintToPDFOptions.cs | 82 +- ElectronNET.API/WebContents.cs | 575 ++- ElectronNET.Host/api/webContents.js | 2 +- ElectronNET.Host/api/webContents.js.map | 2 +- ElectronNET.Host/api/webContents.ts | 2 +- 7 files changed, 2607 insertions(+), 2548 deletions(-) create mode 100644 ElectronNET.API/Entities/Margins.cs diff --git a/ElectronNET.API/BrowserWindow.cs b/ElectronNET.API/BrowserWindow.cs index d28663e..cb295d2 100644 --- a/ElectronNET.API/BrowserWindow.cs +++ b/ElectronNET.API/BrowserWindow.cs @@ -9,2249 +9,2248 @@ using System.Linq; using System.Runtime.InteropServices; using System.Threading.Tasks; -namespace ElectronNET.API +namespace ElectronNET.API; + +/// +/// Create and control browser windows. +/// +public class BrowserWindow { /// - /// Create and control browser windows. + /// Gets the identifier. /// - public class BrowserWindow + /// + /// The identifier. + /// + public int Id { get; private set; } + + /// + /// Emitted when the web page has been rendered (while not being shown) and + /// window can be displayed without a visual flash. + /// + public event Action OnReadyToShow { - /// - /// Gets the identifier. - /// - /// - /// The identifier. - /// - public int Id { get; private set; } - - /// - /// Emitted when the web page has been rendered (while not being shown) and - /// window can be displayed without a visual flash. - /// - public event Action OnReadyToShow + add { - add + if (_readyToShow == null) { - if (_readyToShow == null) + BridgeConnector.Socket.On("browserWindow-ready-to-show" + Id, () => { - BridgeConnector.Socket.On("browserWindow-ready-to-show" + Id, () => - { - _readyToShow(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-ready-to-show", Id); - } - _readyToShow += value; - } - remove - { - _readyToShow -= value; - - if (_readyToShow == null) - BridgeConnector.Socket.Off("browserWindow-ready-to-show" + Id); - } - } - - private event Action _readyToShow; - - /// - /// Emitted when the document changed its title. - /// - public event Action OnPageTitleUpdated - { - add - { - if (_pageTitleUpdated == null) - { - BridgeConnector.Socket.On("browserWindow-page-title-updated" + Id, (title) => - { - _pageTitleUpdated(title.ToString()); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-page-title-updated", Id); - } - _pageTitleUpdated += value; - } - remove - { - _pageTitleUpdated -= value; - - if (_pageTitleUpdated == null) - BridgeConnector.Socket.Off("browserWindow-page-title-updated" + Id); - } - } - - private event Action _pageTitleUpdated; - - /// - /// Emitted when the window is going to be closed. - /// - public event Action OnClose - { - add - { - if (_close == null) - { - BridgeConnector.Socket.On("browserWindow-close" + Id, () => - { - _close(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-close", Id); - } - _close += value; - } - remove - { - _close -= value; - - if (_close == null) - BridgeConnector.Socket.Off("browserWindow-close" + Id); - } - } - - private event Action _close; - - /// - /// Emitted when the window is closed. - /// After you have received this event you should remove the - /// reference to the window and avoid using it any more. - /// - public event Action OnClosed - { - add - { - if (_closed == null) - { - BridgeConnector.Socket.On("browserWindow-closed" + Id, () => - { - _closed(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-closed", Id); - } - _closed += value; - } - remove - { - _closed -= value; - - if (_closed == null) - BridgeConnector.Socket.Off("browserWindow-closed" + Id); - } - } - - private event Action _closed; - - /// - /// Emitted when window session is going to end due to force shutdown or machine restart or session log off. - /// - public event Action OnSessionEnd - { - add - { - if (_sessionEnd == null) - { - BridgeConnector.Socket.On("browserWindow-session-end" + Id, () => - { - _sessionEnd(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-session-end", Id); - } - _sessionEnd += value; - } - remove - { - _sessionEnd -= value; - - if (_sessionEnd == null) - BridgeConnector.Socket.Off("browserWindow-session-end" + Id); - } - } - - private event Action _sessionEnd; - - /// - /// Emitted when the web page becomes unresponsive. - /// - public event Action OnUnresponsive - { - add - { - if (_unresponsive == null) - { - BridgeConnector.Socket.On("browserWindow-unresponsive" + Id, () => - { - _unresponsive(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-unresponsive", Id); - } - _unresponsive += value; - } - remove - { - _unresponsive -= value; - - if (_unresponsive == null) - BridgeConnector.Socket.Off("browserWindow-unresponsive" + Id); - } - } - - private event Action _unresponsive; - - /// - /// Emitted when the unresponsive web page becomes responsive again. - /// - public event Action OnResponsive - { - add - { - if (_responsive == null) - { - BridgeConnector.Socket.On("browserWindow-responsive" + Id, () => - { - _responsive(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-responsive", Id); - } - _responsive += value; - } - remove - { - _responsive -= value; - - if (_responsive == null) - BridgeConnector.Socket.Off("browserWindow-responsive" + Id); - } - } - - private event Action _responsive; - - /// - /// Emitted when the window loses focus. - /// - public event Action OnBlur - { - add - { - if (_blur == null) - { - BridgeConnector.Socket.On("browserWindow-blur" + Id, () => - { - _blur(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-blur", Id); - } - _blur += value; - } - remove - { - _blur -= value; - - if (_blur == null) - BridgeConnector.Socket.Off("browserWindow-blur" + Id); - } - } - - private event Action _blur; - - /// - /// Emitted when the window gains focus. - /// - public event Action OnFocus - { - add - { - if (_focus == null) - { - BridgeConnector.Socket.On("browserWindow-focus" + Id, () => - { - _focus(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-focus", Id); - } - _focus += value; - } - remove - { - _focus -= value; - - if (_focus == null) - BridgeConnector.Socket.Off("browserWindow-focus" + Id); - } - } - - private event Action _focus; - - /// - /// Emitted when the window is shown. - /// - public event Action OnShow - { - add - { - if (_show == null) - { - BridgeConnector.Socket.On("browserWindow-show" + Id, () => - { - _show(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-show", Id); - } - _show += value; - } - remove - { - _show -= value; - - if (_show == null) - BridgeConnector.Socket.Off("browserWindow-show" + Id); - } - } - - private event Action _show; - - /// - /// Emitted when the window is hidden. - /// - public event Action OnHide - { - add - { - if (_hide == null) - { - BridgeConnector.Socket.On("browserWindow-hide" + Id, () => - { - _hide(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-hide", Id); - } - _hide += value; - } - remove - { - _hide -= value; - - if (_hide == null) - BridgeConnector.Socket.Off("browserWindow-hide" + Id); - } - } - - private event Action _hide; - - /// - /// Emitted when window is maximized. - /// - public event Action OnMaximize - { - add - { - if (_maximize == null) - { - BridgeConnector.Socket.On("browserWindow-maximize" + Id, () => - { - _maximize(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-maximize", Id); - } - _maximize += value; - } - remove - { - _maximize -= value; - - if (_maximize == null) - BridgeConnector.Socket.Off("browserWindow-maximize" + Id); - } - } - - private event Action _maximize; - - /// - /// Emitted when the window exits from a maximized state. - /// - public event Action OnUnmaximize - { - add - { - if (_unmaximize == null) - { - BridgeConnector.Socket.On("browserWindow-unmaximize" + Id, () => - { - _unmaximize(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-unmaximize", Id); - } - _unmaximize += value; - } - remove - { - _unmaximize -= value; - - if (_unmaximize == null) - BridgeConnector.Socket.Off("browserWindow-unmaximize" + Id); - } - } - - private event Action _unmaximize; - - /// - /// Emitted when the window is minimized. - /// - public event Action OnMinimize - { - add - { - if (_minimize == null) - { - BridgeConnector.Socket.On("browserWindow-minimize" + Id, () => - { - _minimize(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-minimize", Id); - } - _minimize += value; - } - remove - { - _minimize -= value; - - if (_minimize == null) - BridgeConnector.Socket.Off("browserWindow-minimize" + Id); - } - } - - private event Action _minimize; - - /// - /// Emitted when the window is restored from a minimized state. - /// - public event Action OnRestore - { - add - { - if (_restore == null) - { - BridgeConnector.Socket.On("browserWindow-restore" + Id, () => - { - _restore(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-restore", Id); - } - _restore += value; - } - remove - { - _restore -= value; - - if (_restore == null) - BridgeConnector.Socket.Off("browserWindow-restore" + Id); - } - } - - private event Action _restore; - - /// - /// Emitted when the window is being resized. - /// - public event Action OnResize - { - add - { - if (_resize == null) - { - BridgeConnector.Socket.On("browserWindow-resize" + Id, () => - { - _resize(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-resize", Id); - } - _resize += value; - } - remove - { - _resize -= value; - - if (_resize == null) - BridgeConnector.Socket.Off("browserWindow-resize" + Id); - } - } - - private event Action _resize; - - /// - /// Emitted when the window is being moved to a new position. - /// - /// Note: On macOS this event is just an alias of moved. - /// - public event Action OnMove - { - add - { - if (_move == null) - { - BridgeConnector.Socket.On("browserWindow-move" + Id, () => - { - _move(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-move", Id); - } - _move += value; - } - remove - { - _move -= value; - - if (_move == null) - BridgeConnector.Socket.Off("browserWindow-move" + Id); - } - } - - private event Action _move; - - /// - /// macOS: Emitted once when the window is moved to a new position. - /// - public event Action OnMoved - { - add - { - if (_moved == null) - { - BridgeConnector.Socket.On("browserWindow-moved" + Id, () => - { - _moved(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-moved", Id); - } - _moved += value; - } - remove - { - _moved -= value; - - if (_moved == null) - BridgeConnector.Socket.Off("browserWindow-moved" + Id); - } - } - - private event Action _moved; - - /// - /// Emitted when the window enters a full-screen state. - /// - public event Action OnEnterFullScreen - { - add - { - if (_enterFullScreen == null) - { - BridgeConnector.Socket.On("browserWindow-enter-full-screen" + Id, () => - { - _enterFullScreen(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-enter-full-screen", Id); - } - _enterFullScreen += value; - } - remove - { - _enterFullScreen -= value; - - if (_enterFullScreen == null) - BridgeConnector.Socket.Off("browserWindow-enter-full-screen" + Id); - } - } - - private event Action _enterFullScreen; - - /// - /// Emitted when the window leaves a full-screen state. - /// - public event Action OnLeaveFullScreen - { - add - { - if (_leaveFullScreen == null) - { - BridgeConnector.Socket.On("browserWindow-leave-full-screen" + Id, () => - { - _leaveFullScreen(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-leave-full-screen", Id); - } - _leaveFullScreen += value; - } - remove - { - _leaveFullScreen -= value; - - if (_leaveFullScreen == null) - BridgeConnector.Socket.Off("browserWindow-leave-full-screen" + Id); - } - } - - private event Action _leaveFullScreen; - - /// - /// Emitted when the window enters a full-screen state triggered by HTML API. - /// - public event Action OnEnterHtmlFullScreen - { - add - { - if (_enterHtmlFullScreen == null) - { - BridgeConnector.Socket.On("browserWindow-enter-html-full-screen" + Id, () => - { - _enterHtmlFullScreen(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-enter-html-full-screen", Id); - } - _enterHtmlFullScreen += value; - } - remove - { - _enterHtmlFullScreen -= value; - - if (_enterHtmlFullScreen == null) - BridgeConnector.Socket.Off("browserWindow-enter-html-full-screen" + Id); - } - } - - private event Action _enterHtmlFullScreen; - - /// - /// Emitted when the window leaves a full-screen state triggered by HTML API. - /// - public event Action OnLeaveHtmlFullScreen - { - add - { - if (_leaveHtmlFullScreen == null) - { - BridgeConnector.Socket.On("browserWindow-leave-html-full-screen" + Id, () => - { - _leaveHtmlFullScreen(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-leave-html-full-screen", Id); - } - _leaveHtmlFullScreen += value; - } - remove - { - _leaveHtmlFullScreen -= value; - - if (_leaveHtmlFullScreen == null) - BridgeConnector.Socket.Off("browserWindow-leave-html-full-screen" + Id); - } - } - - private event Action _leaveHtmlFullScreen; - - /// - /// Emitted when an App Command is invoked. These are typically related to - /// keyboard media keys or browser commands, as well as the “Back” button - /// built into some mice on Windows. - /// - /// Commands are lowercased, underscores are replaced with hyphens, - /// and the APPCOMMAND_ prefix is stripped off.e.g.APPCOMMAND_BROWSER_BACKWARD - /// is emitted as browser-backward. - /// - public event Action OnAppCommand - { - add - { - if (_appCommand == null) - { - BridgeConnector.Socket.On("browserWindow-app-command" + Id, (command) => - { - _appCommand(command.ToString()); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-app-command", Id); - } - _appCommand += value; - } - remove - { - _appCommand -= value; - - if (_appCommand == null) - BridgeConnector.Socket.Off("browserWindow-app-command" + Id); - } - } - - private event Action _appCommand; - - /// - /// Emitted on 3-finger swipe. Possible directions are up, right, down, left. - /// - public event Action OnSwipe - { - add - { - if (_swipe == null) - { - BridgeConnector.Socket.On("browserWindow-swipe" + Id, (direction) => - { - _swipe(direction.ToString()); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-swipe", Id); - } - _swipe += value; - } - remove - { - _swipe -= value; - - if (_swipe == null) - BridgeConnector.Socket.Off("browserWindow-swipe" + Id); - } - } - - private event Action _swipe; - - /// - /// Emitted when the window opens a sheet. - /// - public event Action OnSheetBegin - { - add - { - if (_sheetBegin == null) - { - BridgeConnector.Socket.On("browserWindow-sheet-begin" + Id, () => - { - _sheetBegin(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-sheet-begin", Id); - } - _sheetBegin += value; - } - remove - { - _sheetBegin -= value; - - if (_sheetBegin == null) - BridgeConnector.Socket.Off("browserWindow-sheet-begin" + Id); - } - } - - private event Action _sheetBegin; - - /// - /// Emitted when the window has closed a sheet. - /// - public event Action OnSheetEnd - { - add - { - if (_sheetEnd == null) - { - BridgeConnector.Socket.On("browserWindow-sheet-end" + Id, () => - { - _sheetEnd(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-sheet-end", Id); - } - _sheetEnd += value; - } - remove - { - _sheetEnd -= value; - - if (_sheetEnd == null) - BridgeConnector.Socket.Off("browserWindow-sheet-end" + Id); - } - } - - private event Action _sheetEnd; - - /// - /// Emitted when the native new tab button is clicked. - /// - public event Action OnNewWindowForTab - { - add - { - if (_newWindowForTab == null) - { - BridgeConnector.Socket.On("browserWindow-new-window-for-tab" + Id, () => - { - _newWindowForTab(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-new-window-for-tab", Id); - } - _newWindowForTab += value; - } - remove - { - _newWindowForTab -= value; - - if (_newWindowForTab == null) - BridgeConnector.Socket.Off("browserWindow-new-window-for-tab" + Id); - } - } - - private event Action _newWindowForTab; - - internal BrowserWindow(int id) { - Id = id; - WebContents = new WebContents(id); - } - - /// - /// Force closing the window, the unload and beforeunload event won’t be - /// emitted for the web page, and close event will also not be emitted - /// for this window, but it guarantees the closed event will be emitted. - /// - public void Destroy() - { - BridgeConnector.Socket.Emit("browserWindowDestroy", Id); - } - - /// - /// Try to close the window. This has the same effect as a user manually - /// clicking the close button of the window. The web page may cancel the close though. - /// - public void Close() - { - BridgeConnector.Socket.Emit("browserWindowClose", Id); - } - - /// - /// Focuses on the window. - /// - public void Focus() - { - BridgeConnector.Socket.Emit("browserWindowFocus", Id); - } - - /// - /// Removes focus from the window. - /// - public void Blur() - { - BridgeConnector.Socket.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; - } - - /// - /// 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; - } - - /// - /// Shows and gives focus to the window. - /// - public void Show() - { - BridgeConnector.Socket.Emit("browserWindowShow", Id); - } - - /// - /// Shows the window but doesn’t focus on it. - /// - public void ShowInactive() - { - BridgeConnector.Socket.Emit("browserWindowShowInactive", Id); - } - - /// - /// Hides the window. - /// - public void Hide() - { - BridgeConnector.Socket.Emit("browserWindowHide", Id); - } - - /// - /// Whether the window is visible to the user. - /// - /// - 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; - } - - /// - /// Whether current window is a modal window. - /// - /// - 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; - } - - /// - /// Maximizes the window. This will also show (but not focus) the window if it isn’t being displayed already. - /// - public void Maximize() - { - BridgeConnector.Socket.Emit("browserWindowMaximize", Id); - } - - /// - /// Unmaximizes the window. - /// - public void Unmaximize() - { - BridgeConnector.Socket.Emit("browserWindowUnmaximize", Id); - } - - /// - /// Whether the window is maximized. - /// - /// - 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; - } - - /// - /// Minimizes the window. On some platforms the minimized window will be shown in the Dock. - /// - public void Minimize() - { - BridgeConnector.Socket.Emit("browserWindowMinimize", Id); - } - - /// - /// Restores the window from minimized state to its previous state. - /// - public void Restore() - { - BridgeConnector.Socket.Emit("browserWindowRestore", Id); - } - - /// - /// Whether the window is minimized. - /// - /// - 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; - } - - /// - /// Sets whether the window should be in fullscreen mode. - /// - public void SetFullScreen(bool flag) - { - BridgeConnector.Socket.Emit("browserWindowSetFullScreen", Id, flag); - } - - /// - /// Whether the window is in fullscreen mode. - /// - /// - 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; - } - - /// - /// This will make a window maintain an aspect ratio. The extra size allows a developer to have space, - /// specified in pixels, not included within the aspect ratio calculations. This API already takes into - /// account the difference between a window’s size and its content size. - /// - /// Consider a normal window with an HD video player and associated controls.Perhaps there are 15 pixels - /// of controls on the left edge, 25 pixels of controls on the right edge and 50 pixels of controls below - /// the player. In order to maintain a 16:9 aspect ratio (standard aspect ratio for HD @1920x1080) within - /// the player itself we would call this function with arguments of 16/9 and[40, 50]. The second argument - /// doesn’t care where the extra width and height are within the content view–only that they exist. Just - /// sum any extra width and height areas you have within the overall content view. - /// - /// The aspect ratio to maintain for some portion of the content view. - /// 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)); - } - - /// - /// Uses Quick Look to preview a file at a given path. - /// - /// The absolute path to the file to preview with QuickLook. This is important as - /// Quick Look uses the file name and file extension on the path to determine the content type of the - /// file to open. - public void PreviewFile(string path) - { - BridgeConnector.Socket.Emit("browserWindowPreviewFile", Id, path); - } - - /// - /// Uses Quick Look to preview a file at a given path. - /// - /// The absolute path to the file to preview with QuickLook. This is important as - /// Quick Look uses the file name and file extension on the path to determine the content type of the - /// file to open. - /// The name of the file to display on the Quick Look modal view. This is - /// 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); - } - - /// - /// Closes the currently open Quick Look panel. - /// - public void CloseFilePreview() - { - BridgeConnector.Socket.Emit("browserWindowCloseFilePreview", Id); - } - - /// - /// Resizes and moves the window to the supplied bounds - /// - /// - public void SetBounds(Rectangle bounds) - { - BridgeConnector.Socket.Emit("browserWindowSetBounds", Id, JObject.FromObject(bounds, _jsonSerializer)); - } - - /// - /// Resizes and moves the window to the supplied bounds - /// - /// - /// - public void SetBounds(Rectangle bounds, bool animate) - { - BridgeConnector.Socket.Emit("browserWindowSetBounds", Id, JObject.FromObject(bounds, _jsonSerializer), animate); - } - - /// - /// Gets the bounds asynchronous. - /// - /// - 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; - } - - /// - /// Resizes and moves the window’s client area (e.g. the web page) to the supplied bounds. - /// - /// - public void SetContentBounds(Rectangle bounds) - { - BridgeConnector.Socket.Emit("browserWindowSetContentBounds", Id, JObject.FromObject(bounds, _jsonSerializer)); - } - - /// - /// Resizes and moves the window’s client area (e.g. the web page) to the supplied bounds. - /// - /// - /// - public void SetContentBounds(Rectangle bounds, bool animate) - { - BridgeConnector.Socket.Emit("browserWindowSetContentBounds", Id, JObject.FromObject(bounds, _jsonSerializer), animate); - } - - /// - /// Gets the content bounds asynchronous. - /// - /// - 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; - } - - /// - /// Resizes the window to width and height. - /// - /// - /// - public void SetSize(int width, int height) - { - BridgeConnector.Socket.Emit("browserWindowSetSize", Id, width, height); - } - - /// - /// Resizes the window to width and height. - /// - /// - /// - /// - public void SetSize(int width, int height, bool animate) - { - BridgeConnector.Socket.Emit("browserWindowSetSize", Id, width, height, animate); - } - - /// - /// Contains the window’s width and height. - /// - /// - 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; - } - - /// - /// Resizes the window’s client area (e.g. the web page) to width and height. - /// - /// - /// - public void SetContentSize(int width, int height) - { - BridgeConnector.Socket.Emit("browserWindowSetContentSize", Id, width, height); - } - - /// - /// Resizes the window’s client area (e.g. the web page) to width and height. - /// - /// - /// - /// - public void SetContentSize(int width, int height, bool animate) - { - BridgeConnector.Socket.Emit("browserWindowSetContentSize", Id, width, height, animate); - } - - /// - /// Contains the window’s client area’s width and height. - /// - /// - 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; - } - - /// - /// Sets the minimum size of window to width and height. - /// - /// - /// - public void SetMinimumSize(int width, int height) - { - BridgeConnector.Socket.Emit("browserWindowSetMinimumSize", Id, width, height); - } - - /// - /// Contains the window’s minimum width and 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; - } - - /// - /// Sets the maximum size of window to width and height. - /// - /// - /// - public void SetMaximumSize(int width, int height) - { - BridgeConnector.Socket.Emit("browserWindowSetMaximumSize", Id, width, height); - } - - /// - /// Contains the window’s maximum width and 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; - } - - /// - /// Sets whether the window can be manually resized by user. - /// - /// - public void SetResizable(bool resizable) - { - BridgeConnector.Socket.Emit("browserWindowSetResizable", Id, resizable); - } - - /// - /// Whether the window can be manually resized by user. - /// - /// - 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; - } - - /// - /// Sets whether the window can be moved by user. On Linux does nothing. - /// - /// - public void SetMovable(bool movable) - { - BridgeConnector.Socket.Emit("browserWindowSetMovable", Id, movable); - } - - /// - /// Whether the window can be moved by user. - /// - /// On Linux always returns true. - /// - /// 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; - } - - /// - /// Sets whether the window can be manually minimized by user. On Linux does nothing. - /// - /// - public void SetMinimizable(bool minimizable) - { - BridgeConnector.Socket.Emit("browserWindowSetMinimizable", Id, minimizable); - } - - /// - /// Whether the window can be manually minimized by user. - /// - /// On Linux always returns true. - /// - /// 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; - } - - /// - /// Sets whether the window can be manually maximized by user. On Linux does nothing. - /// - /// - public void SetMaximizable(bool maximizable) - { - BridgeConnector.Socket.Emit("browserWindowSetMaximizable", Id, maximizable); - } - - /// - /// Whether the window can be manually maximized by user. - /// - /// On Linux always returns true. - /// - /// 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; - } - - /// - /// Sets whether the maximize/zoom window button toggles fullscreen mode or maximizes the window. - /// - /// - public void SetFullScreenable(bool fullscreenable) - { - BridgeConnector.Socket.Emit("browserWindowSetFullScreenable", Id, fullscreenable); - } - - /// - /// Whether the maximize/zoom window button toggles fullscreen mode or maximizes the window. - /// - /// - 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; - } - - /// - /// Sets whether the window can be manually closed by user. On Linux does nothing. - /// - /// - public void SetClosable(bool closable) - { - BridgeConnector.Socket.Emit("browserWindowSetClosable", Id, closable); - } - - /// - /// Whether the window can be manually closed by user. - /// - /// On Linux always returns true. - /// - /// 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; - } - - /// - /// Sets whether the window should show always on top of other windows. - /// After setting this, the window is still a normal window, not a toolbox - /// window which can not be focused on. - /// - /// - public void SetAlwaysOnTop(bool flag) - { - BridgeConnector.Socket.Emit("browserWindowSetAlwaysOnTop", Id, flag); - } - - /// - /// Sets whether the window should show always on top of other windows. - /// After setting this, the window is still a normal window, not a toolbox - /// window which can not be focused on. - /// - /// - /// Values include normal, floating, torn-off-menu, modal-panel, main-menu, - /// status, pop-up-menu and screen-saver. The default is floating. - /// See the macOS docs - public void SetAlwaysOnTop(bool flag, OnTopLevel level) - { - BridgeConnector.Socket.Emit("browserWindowSetAlwaysOnTop", Id, flag, level.GetDescription()); - } - - /// - /// Sets whether the window should show always on top of other windows. - /// After setting this, the window is still a normal window, not a toolbox - /// window which can not be focused on. - /// - /// - /// Values include normal, floating, torn-off-menu, modal-panel, main-menu, - /// status, pop-up-menu and screen-saver. The default is floating. - /// See the macOS docs - /// The number of layers higher to set this window relative to the given 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); - } - - /// - /// Whether the window is always on top of other windows. - /// - /// - 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; - } - - /// - /// Moves window to the center of the screen. - /// - public void Center() - { - BridgeConnector.Socket.Emit("browserWindowCenter", Id); - } - - /// - /// Moves window to x and y. - /// - /// - /// - public void SetPosition(int x, int y) - { - // Workaround Windows 10 / Electron Bug - // https://github.com/electron/electron/issues/4045 - if (isWindows10()) - { - x = x - 7; - } - - BridgeConnector.Socket.Emit("browserWindowSetPosition", Id, x, y); - } - - /// - /// Moves window to x and y. - /// - /// - /// - /// - public void SetPosition(int x, int y, bool animate) - { - // Workaround Windows 10 / Electron Bug - // https://github.com/electron/electron/issues/4045 - if (isWindows10()) - { - x = x - 7; - } - - BridgeConnector.Socket.Emit("browserWindowSetPosition", Id, x, y, animate); - } - - private bool isWindows10() - { - return RuntimeInformation.OSDescription.Contains("Windows 10"); - } - - /// - /// Contains the window’s current position. - /// - /// - public Task GetPositionAsync() - { - var taskCompletionSource = new TaskCompletionSource(); - - BridgeConnector.Socket.On("browserWindow-getPosition-completed", (position) => { - BridgeConnector.Socket.Off("browserWindow-getPosition-completed"); - - taskCompletionSource.SetResult(((JArray)position).ToObject()); - }); - - BridgeConnector.Socket.Emit("browserWindowGetPosition", Id); - - return taskCompletionSource.Task; - } - - /// - /// Changes the title of native window to title. - /// - /// - public void SetTitle(string title) - { - BridgeConnector.Socket.Emit("browserWindowSetTitle", Id, title); - } - - /// - /// The title of the native window. - /// - /// Note: The title of web page can be different from the title of the native window. - /// - /// - public Task GetTitleAsync() - { - var taskCompletionSource = new TaskCompletionSource(); - - BridgeConnector.Socket.On("browserWindow-getTitle-completed", (title) => { - BridgeConnector.Socket.Off("browserWindow-getTitle-completed"); - - taskCompletionSource.SetResult(title.ToString()); - }); - - BridgeConnector.Socket.Emit("browserWindowGetTitle", Id); - - return taskCompletionSource.Task; - } - - /// - /// Changes the attachment point for sheets on macOS. - /// By default, sheets are attached just below the window frame, - /// but you may want to display them beneath a HTML-rendered toolbar. - /// - /// - public void SetSheetOffset(float offsetY) - { - BridgeConnector.Socket.Emit("browserWindowSetSheetOffset", Id, offsetY); - } - - /// - /// Changes the attachment point for sheets on macOS. - /// By default, sheets are attached just below the window frame, - /// but you may want to display them beneath a HTML-rendered toolbar. - /// - /// - /// - public void SetSheetOffset(float offsetY, float offsetX) - { - BridgeConnector.Socket.Emit("browserWindowSetSheetOffset", Id, offsetY, offsetX); - } - - /// - /// Starts or stops flashing the window to attract user’s attention. - /// - /// - public void FlashFrame(bool flag) - { - BridgeConnector.Socket.Emit("browserWindowFlashFrame", Id, flag); - } - - /// - /// Makes the window not show in the taskbar. - /// - /// - public void SetSkipTaskbar(bool skip) - { - BridgeConnector.Socket.Emit("browserWindowSetSkipTaskbar", Id, skip); - } - - /// - /// Enters or leaves the kiosk mode. - /// - /// - public void SetKiosk(bool flag) - { - BridgeConnector.Socket.Emit("browserWindowSetKiosk", Id, flag); - } - - /// - /// Whether the window is in kiosk mode. - /// - /// - public Task IsKioskAsync() - { - var taskCompletionSource = new TaskCompletionSource(); - - BridgeConnector.Socket.On("browserWindow-isKiosk-completed", (isKiosk) => { - BridgeConnector.Socket.Off("browserWindow-isKiosk-completed"); - - taskCompletionSource.SetResult((bool)isKiosk); - }); - - BridgeConnector.Socket.Emit("browserWindowIsKiosk", Id); - - return taskCompletionSource.Task; - } - - /// - /// Returns the native type of the handle is HWND on Windows, NSView* on macOS, and Window (unsigned long) on Linux. - /// - /// string of the native handle obtained, HWND on Windows, NSView* on macOS, and Window (unsigned long) on Linux. - public Task GetNativeWindowHandle() - { - var taskCompletionSource = new TaskCompletionSource(); - - BridgeConnector.Socket.On("browserWindow-getNativeWindowHandle-completed", (nativeWindowHandle) => - { - BridgeConnector.Socket.Off("browserWindow-getNativeWindowHandle-completed"); - taskCompletionSource.SetResult(nativeWindowHandle.ToString()); - }); - - BridgeConnector.Socket.Emit("browserWindowGetNativeWindowHandle", Id); - - return taskCompletionSource.Task; - } - - /// - /// Sets the pathname of the file the window represents, - /// and the icon of the file will show in window’s title bar. - /// - /// - public void SetRepresentedFilename(string filename) - { - BridgeConnector.Socket.Emit("browserWindowSetRepresentedFilename", Id, filename); - } - - /// - /// The pathname of the file the window represents. - /// - /// - public Task GetRepresentedFilenameAsync() - { - var taskCompletionSource = new TaskCompletionSource(); - - BridgeConnector.Socket.On("browserWindow-getRepresentedFilename-completed", (pathname) => { - BridgeConnector.Socket.Off("browserWindow-getRepresentedFilename-completed"); - - taskCompletionSource.SetResult(pathname.ToString()); - }); - - BridgeConnector.Socket.Emit("browserWindowGetRepresentedFilename", Id); - - return taskCompletionSource.Task; - } - - /// - /// Specifies whether the window’s document has been edited, - /// and the icon in title bar will become gray when set to true. - /// - /// - public void SetDocumentEdited(bool edited) - { - BridgeConnector.Socket.Emit("browserWindowSetDocumentEdited", Id, edited); - } - - /// - /// Whether the window’s document has been edited. - /// - /// - public Task IsDocumentEditedAsync() - { - var taskCompletionSource = new TaskCompletionSource(); - - BridgeConnector.Socket.On("browserWindow-isDocumentEdited-completed", (edited) => { - BridgeConnector.Socket.Off("browserWindow-isDocumentEdited-completed"); - - taskCompletionSource.SetResult((bool)edited); - }); - - BridgeConnector.Socket.Emit("browserWindowIsDocumentEdited", Id); - - return taskCompletionSource.Task; - } - - /// - /// Focuses the on web view. - /// - public void FocusOnWebView() - { - BridgeConnector.Socket.Emit("browserWindowFocusOnWebView", Id); - } - - /// - /// Blurs the web view. - /// - public void BlurWebView() - { - BridgeConnector.Socket.Emit("browserWindowBlurWebView", Id); - } - - /// - /// The url can be a remote address (e.g. http://) or - /// a path to a local HTML file using the file:// protocol. - /// - /// - public void LoadURL(string url) - { - BridgeConnector.Socket.Emit("browserWindowLoadURL", Id, url); - } - - /// - /// The url can be a remote address (e.g. http://) or - /// a path to a local HTML file using the file:// protocol. - /// - /// - /// - public void LoadURL(string url, LoadURLOptions options) - { - BridgeConnector.Socket.Emit("browserWindowLoadURL", Id, url, JObject.FromObject(options, _jsonSerializer)); - } - - /// - /// Same as webContents.reload. - /// - public void Reload() - { - BridgeConnector.Socket.Emit("browserWindowReload", Id); - } - - /// - /// Gets the menu items. - /// - /// - /// The menu items. - /// - public IReadOnlyCollection MenuItems { get { return _items.AsReadOnly(); } } - private List _items = new List(); - - /// - /// Sets the menu as the window’s menu bar, - /// setting it to null will remove the menu bar. - /// - /// - public void SetMenu(MenuItem[] menuItems) - { - menuItems.AddMenuItemsId(); - BridgeConnector.Socket.Emit("browserWindowSetMenu", Id, JArray.FromObject(menuItems, _jsonSerializer)); - _items.AddRange(menuItems); - - BridgeConnector.Socket.Off("windowMenuItemClicked"); - BridgeConnector.Socket.On("windowMenuItemClicked", (id) => { - MenuItem menuItem = _items.GetMenuItem(id.ToString()); - menuItem?.Click(); - }); - } - - /// - /// Remove the window's menu bar. - /// - public void RemoveMenu() - { - BridgeConnector.Socket.Emit("browserWindowRemoveMenu", Id); - } - - /// - /// Sets progress value in progress bar. Valid range is [0, 1.0]. Remove progress - /// bar when progress smaler as 0; Change to indeterminate mode when progress bigger as 1. On Linux - /// platform, only supports Unity desktop environment, you need to specify the - /// .desktop file name to desktopName field in package.json.By default, it will - /// assume app.getName().desktop.On Windows, a mode can be passed.Accepted values - /// are none, normal, indeterminate, error, and paused. If you call setProgressBar - /// without a mode set (but with a value within the valid range), normal will be - /// assumed. - /// - /// - public void SetProgressBar(double progress) - { - BridgeConnector.Socket.Emit("browserWindowSetProgressBar", Id, progress); - } - - /// - /// Sets progress value in progress bar. Valid range is [0, 1.0]. Remove progress - /// bar when progress smaler as 0; Change to indeterminate mode when progress bigger as 1. On Linux - /// platform, only supports Unity desktop environment, you need to specify the - /// .desktop file name to desktopName field in package.json.By default, it will - /// assume app.getName().desktop.On Windows, a mode can be passed.Accepted values - /// are none, normal, indeterminate, error, and paused. If you call setProgressBar - /// without a mode set (but with a value within the valid range), normal will be - /// assumed. - /// - /// - /// - public void SetProgressBar(double progress, ProgressBarOptions progressBarOptions) - { - BridgeConnector.Socket.Emit("browserWindowSetProgressBar", Id, progress, JObject.FromObject(progressBarOptions, _jsonSerializer)); - } - - /// - /// Sets whether the window should have a shadow. On Windows and Linux does nothing. - /// - /// - public void SetHasShadow(bool hasShadow) - { - BridgeConnector.Socket.Emit("browserWindowSetHasShadow", Id, hasShadow); - } - - /// - /// Whether the window has a shadow. - /// - /// On Windows and Linux always returns true. - /// - /// - public Task HasShadowAsync() - { - var taskCompletionSource = new TaskCompletionSource(); - - BridgeConnector.Socket.On("browserWindow-hasShadow-completed", (hasShadow) => { - BridgeConnector.Socket.Off("browserWindow-hasShadow-completed"); - - taskCompletionSource.SetResult((bool)hasShadow); - }); - - BridgeConnector.Socket.Emit("browserWindowHasShadow", Id); - - return taskCompletionSource.Task; - } - - /// - /// Gets the thumbar buttons. - /// - /// - /// The thumbar buttons. - /// - public IReadOnlyCollection ThumbarButtons { get { return _thumbarButtons.AsReadOnly(); } } - private List _thumbarButtons = new List(); - - /// - /// Add a thumbnail toolbar with a specified set of buttons to the thumbnail - /// image of a window in a taskbar button layout. Returns a Boolean object - /// indicates whether the thumbnail has been added successfully. - /// - /// The number of buttons in thumbnail toolbar should be no greater than 7 due - /// to the limited room.Once you setup the thumbnail toolbar, the toolbar cannot - /// be removed due to the platform’s limitation.But you can call the API with an - /// empty array to clean the buttons. - /// - /// - /// Whether the buttons were added successfully. - public Task SetThumbarButtonsAsync(ThumbarButton[] thumbarButtons) - { - var taskCompletionSource = new TaskCompletionSource(); - - BridgeConnector.Socket.On("browserWindowSetThumbarButtons-completed", (success) => { - BridgeConnector.Socket.Off("browserWindowSetThumbarButtons-completed"); - - taskCompletionSource.SetResult((bool)success); - }); - - thumbarButtons.AddThumbarButtonsId(); - BridgeConnector.Socket.Emit("browserWindowSetThumbarButtons", Id, JArray.FromObject(thumbarButtons, _jsonSerializer)); - _thumbarButtons.Clear(); - _thumbarButtons.AddRange(thumbarButtons); - - BridgeConnector.Socket.Off("thumbarButtonClicked"); - BridgeConnector.Socket.On("thumbarButtonClicked", (id) => { - ThumbarButton thumbarButton = _thumbarButtons.GetThumbarButton(id.ToString()); - thumbarButton?.Click(); - }); - - return taskCompletionSource.Task; - } - - /// - /// Sets the region of the window to show as the thumbnail image displayed when hovering over - /// the window in the taskbar. You can reset the thumbnail to be the entire window by specifying - /// an empty region: {x: 0, y: 0, width: 0, height: 0}. - /// - /// - public void SetThumbnailClip(Rectangle rectangle) - { - BridgeConnector.Socket.Emit("browserWindowSetThumbnailClip", Id, rectangle); - } - - /// - /// Sets the toolTip that is displayed when hovering over the window thumbnail in the taskbar. - /// - /// - public void SetThumbnailToolTip(string tooltip) - { - BridgeConnector.Socket.Emit("browserWindowSetThumbnailToolTip", Id, tooltip); - } - - /// - /// Sets the properties for the window’s taskbar button. - /// - /// Note: relaunchCommand and relaunchDisplayName must always be set together. - /// If one of those properties is not set, then neither will be used. - /// - /// - public void SetAppDetails(AppDetailsOptions options) - { - BridgeConnector.Socket.Emit("browserWindowSetAppDetails", Id, JObject.FromObject(options, _jsonSerializer)); - } - - /// - /// Same as webContents.showDefinitionForSelection(). - /// - public void ShowDefinitionForSelection() - { - BridgeConnector.Socket.Emit("browserWindowShowDefinitionForSelection", Id); - } - - /// - /// Sets whether the window menu bar should hide itself automatically. - /// Once set the menu bar will only show when users press the single Alt key. - /// - /// If the menu bar is already visible, calling setAutoHideMenuBar(true) won’t hide it immediately. - /// - /// - public void SetAutoHideMenuBar(bool hide) - { - BridgeConnector.Socket.Emit("browserWindowSetAutoHideMenuBar", Id, hide); - } - - /// - /// Whether menu bar automatically hides itself. - /// - /// - public Task IsMenuBarAutoHideAsync() - { - var taskCompletionSource = new TaskCompletionSource(); - - BridgeConnector.Socket.On("browserWindow-isMenuBarAutoHide-completed", (isMenuBarAutoHide) => { - BridgeConnector.Socket.Off("browserWindow-isMenuBarAutoHide-completed"); - - taskCompletionSource.SetResult((bool)isMenuBarAutoHide); - }); - - BridgeConnector.Socket.Emit("browserWindowIsMenuBarAutoHide", Id); - - return taskCompletionSource.Task; - } - - /// - /// Sets whether the menu bar should be visible. If the menu bar is auto-hide, - /// users can still bring up the menu bar by pressing the single Alt key. - /// - /// - public void SetMenuBarVisibility(bool visible) - { - BridgeConnector.Socket.Emit("browserWindowSetMenuBarVisibility", Id, visible); - } - - /// - /// Whether the menu bar is visible. - /// - /// - public Task IsMenuBarVisibleAsync() - { - var taskCompletionSource = new TaskCompletionSource(); - - BridgeConnector.Socket.On("browserWindow-isMenuBarVisible-completed", (isMenuBarVisible) => { - BridgeConnector.Socket.Off("browserWindow-isMenuBarVisible-completed"); - - taskCompletionSource.SetResult((bool)isMenuBarVisible); - }); - - BridgeConnector.Socket.Emit("browserWindowIsMenuBarVisible", Id); - - return taskCompletionSource.Task; - } - - /// - /// Sets whether the window should be visible on all workspaces. - /// - /// Note: This API does nothing on Windows. - /// - /// - public void SetVisibleOnAllWorkspaces(bool visible) - { - BridgeConnector.Socket.Emit("browserWindowSetVisibleOnAllWorkspaces", Id, visible); - } - - /// - /// Whether the window is visible on all workspaces. - /// - /// Note: This API always returns false on Windows. - /// - /// - public Task IsVisibleOnAllWorkspacesAsync() - { - var taskCompletionSource = new TaskCompletionSource(); - - BridgeConnector.Socket.On("browserWindow-isVisibleOnAllWorkspaces-completed", (isVisibleOnAllWorkspaces) => { - BridgeConnector.Socket.Off("browserWindow-isVisibleOnAllWorkspaces-completed"); - - taskCompletionSource.SetResult((bool)isVisibleOnAllWorkspaces); - }); - - BridgeConnector.Socket.Emit("browserWindowIsVisibleOnAllWorkspaces", Id); - - return taskCompletionSource.Task; - } - - /// - /// Makes the window ignore all mouse events. - /// - /// All mouse events happened in this window will be passed to the window - /// below this window, but if this window has focus, it will still receive keyboard events. - /// - /// - public void SetIgnoreMouseEvents(bool ignore) - { - BridgeConnector.Socket.Emit("browserWindowSetIgnoreMouseEvents", Id, ignore); - } - - /// - /// Prevents the window contents from being captured by other apps. - /// - /// On macOS it sets the NSWindow’s sharingType to NSWindowSharingNone. - /// On Windows it calls SetWindowDisplayAffinity with WDA_MONITOR. - /// - /// - public void SetContentProtection(bool enable) - { - BridgeConnector.Socket.Emit("browserWindowSetContentProtection", Id, enable); - } - - /// - /// Changes whether the window can be focused. - /// - /// - public void SetFocusable(bool focusable) - { - BridgeConnector.Socket.Emit("browserWindowSetFocusable", Id, focusable); - } - - /// - /// Sets parent as current window’s parent window, - /// passing null will turn current window into a top-level window. - /// - /// - public void SetParentWindow(BrowserWindow parent) - { - BridgeConnector.Socket.Emit("browserWindowSetParentWindow", Id, JObject.FromObject(parent, _jsonSerializer)); - } - - /// - /// The parent window. - /// - /// - public Task GetParentWindowAsync() - { - var taskCompletionSource = new TaskCompletionSource(); - - BridgeConnector.Socket.On("browserWindow-getParentWindow-completed", (id) => { - BridgeConnector.Socket.Off("browserWindow-getParentWindow-completed"); - var browserWindowId = int.Parse(id.ToString()); - var browserWindow = Electron.WindowManager.BrowserWindows.ToList().Single(x => x.Id == browserWindowId); - - taskCompletionSource.SetResult(browserWindow); - }); - - BridgeConnector.Socket.Emit("browserWindowGetParentWindow", Id); - - return taskCompletionSource.Task; - } - - /// - /// All child windows. - /// - /// - public Task> GetChildWindowsAsync() - { - var taskCompletionSource = new TaskCompletionSource>(); - - BridgeConnector.Socket.On("browserWindow-getChildWindows-completed", (ids) => { - BridgeConnector.Socket.Off("browserWindow-getChildWindows-completed"); - var browserWindowIds = ((JArray)ids).ToObject(); - var browserWindows = new List(); - - browserWindowIds.ToList().ForEach(id => - { - var browserWindow = Electron.WindowManager.BrowserWindows.ToList().Single(x => x.Id == id); - browserWindows.Add(browserWindow); + _readyToShow(); }); + BridgeConnector.Socket.Emit("register-browserWindow-ready-to-show", Id); + } + _readyToShow += value; + } + remove + { + _readyToShow -= value; - taskCompletionSource.SetResult(browserWindows); + if (_readyToShow == null) + BridgeConnector.Socket.Off("browserWindow-ready-to-show" + Id); + } + } + + private event Action _readyToShow; + + /// + /// Emitted when the document changed its title. + /// + public event Action OnPageTitleUpdated + { + add + { + if (_pageTitleUpdated == null) + { + BridgeConnector.Socket.On("browserWindow-page-title-updated" + Id, (title) => + { + _pageTitleUpdated(title.ToString()); + }); + + BridgeConnector.Socket.Emit("register-browserWindow-page-title-updated", Id); + } + _pageTitleUpdated += value; + } + remove + { + _pageTitleUpdated -= value; + + if (_pageTitleUpdated == null) + BridgeConnector.Socket.Off("browserWindow-page-title-updated" + Id); + } + } + + private event Action _pageTitleUpdated; + + /// + /// Emitted when the window is going to be closed. + /// + public event Action OnClose + { + add + { + if (_close == null) + { + BridgeConnector.Socket.On("browserWindow-close" + Id, () => + { + _close(); + }); + + BridgeConnector.Socket.Emit("register-browserWindow-close", Id); + } + _close += value; + } + remove + { + _close -= value; + + if (_close == null) + BridgeConnector.Socket.Off("browserWindow-close" + Id); + } + } + + private event Action _close; + + /// + /// Emitted when the window is closed. + /// After you have received this event you should remove the + /// reference to the window and avoid using it any more. + /// + public event Action OnClosed + { + add + { + if (_closed == null) + { + BridgeConnector.Socket.On("browserWindow-closed" + Id, () => + { + _closed(); + }); + + BridgeConnector.Socket.Emit("register-browserWindow-closed", Id); + } + _closed += value; + } + remove + { + _closed -= value; + + if (_closed == null) + BridgeConnector.Socket.Off("browserWindow-closed" + Id); + } + } + + private event Action _closed; + + /// + /// Emitted when window session is going to end due to force shutdown or machine restart or session log off. + /// + public event Action OnSessionEnd + { + add + { + if (_sessionEnd == null) + { + BridgeConnector.Socket.On("browserWindow-session-end" + Id, () => + { + _sessionEnd(); + }); + + BridgeConnector.Socket.Emit("register-browserWindow-session-end", Id); + } + _sessionEnd += value; + } + remove + { + _sessionEnd -= value; + + if (_sessionEnd == null) + BridgeConnector.Socket.Off("browserWindow-session-end" + Id); + } + } + + private event Action _sessionEnd; + + /// + /// Emitted when the web page becomes unresponsive. + /// + public event Action OnUnresponsive + { + add + { + if (_unresponsive == null) + { + BridgeConnector.Socket.On("browserWindow-unresponsive" + Id, () => + { + _unresponsive(); + }); + + BridgeConnector.Socket.Emit("register-browserWindow-unresponsive", Id); + } + _unresponsive += value; + } + remove + { + _unresponsive -= value; + + if (_unresponsive == null) + BridgeConnector.Socket.Off("browserWindow-unresponsive" + Id); + } + } + + private event Action _unresponsive; + + /// + /// Emitted when the unresponsive web page becomes responsive again. + /// + public event Action OnResponsive + { + add + { + if (_responsive == null) + { + BridgeConnector.Socket.On("browserWindow-responsive" + Id, () => + { + _responsive(); + }); + + BridgeConnector.Socket.Emit("register-browserWindow-responsive", Id); + } + _responsive += value; + } + remove + { + _responsive -= value; + + if (_responsive == null) + BridgeConnector.Socket.Off("browserWindow-responsive" + Id); + } + } + + private event Action _responsive; + + /// + /// Emitted when the window loses focus. + /// + public event Action OnBlur + { + add + { + if (_blur == null) + { + BridgeConnector.Socket.On("browserWindow-blur" + Id, () => + { + _blur(); + }); + + BridgeConnector.Socket.Emit("register-browserWindow-blur", Id); + } + _blur += value; + } + remove + { + _blur -= value; + + if (_blur == null) + BridgeConnector.Socket.Off("browserWindow-blur" + Id); + } + } + + private event Action _blur; + + /// + /// Emitted when the window gains focus. + /// + public event Action OnFocus + { + add + { + if (_focus == null) + { + BridgeConnector.Socket.On("browserWindow-focus" + Id, () => + { + _focus(); + }); + + BridgeConnector.Socket.Emit("register-browserWindow-focus", Id); + } + _focus += value; + } + remove + { + _focus -= value; + + if (_focus == null) + BridgeConnector.Socket.Off("browserWindow-focus" + Id); + } + } + + private event Action _focus; + + /// + /// Emitted when the window is shown. + /// + public event Action OnShow + { + add + { + if (_show == null) + { + BridgeConnector.Socket.On("browserWindow-show" + Id, () => + { + _show(); + }); + + BridgeConnector.Socket.Emit("register-browserWindow-show", Id); + } + _show += value; + } + remove + { + _show -= value; + + if (_show == null) + BridgeConnector.Socket.Off("browserWindow-show" + Id); + } + } + + private event Action _show; + + /// + /// Emitted when the window is hidden. + /// + public event Action OnHide + { + add + { + if (_hide == null) + { + BridgeConnector.Socket.On("browserWindow-hide" + Id, () => + { + _hide(); + }); + + BridgeConnector.Socket.Emit("register-browserWindow-hide", Id); + } + _hide += value; + } + remove + { + _hide -= value; + + if (_hide == null) + BridgeConnector.Socket.Off("browserWindow-hide" + Id); + } + } + + private event Action _hide; + + /// + /// Emitted when window is maximized. + /// + public event Action OnMaximize + { + add + { + if (_maximize == null) + { + BridgeConnector.Socket.On("browserWindow-maximize" + Id, () => + { + _maximize(); + }); + + BridgeConnector.Socket.Emit("register-browserWindow-maximize", Id); + } + _maximize += value; + } + remove + { + _maximize -= value; + + if (_maximize == null) + BridgeConnector.Socket.Off("browserWindow-maximize" + Id); + } + } + + private event Action _maximize; + + /// + /// Emitted when the window exits from a maximized state. + /// + public event Action OnUnmaximize + { + add + { + if (_unmaximize == null) + { + BridgeConnector.Socket.On("browserWindow-unmaximize" + Id, () => + { + _unmaximize(); + }); + + BridgeConnector.Socket.Emit("register-browserWindow-unmaximize", Id); + } + _unmaximize += value; + } + remove + { + _unmaximize -= value; + + if (_unmaximize == null) + BridgeConnector.Socket.Off("browserWindow-unmaximize" + Id); + } + } + + private event Action _unmaximize; + + /// + /// Emitted when the window is minimized. + /// + public event Action OnMinimize + { + add + { + if (_minimize == null) + { + BridgeConnector.Socket.On("browserWindow-minimize" + Id, () => + { + _minimize(); + }); + + BridgeConnector.Socket.Emit("register-browserWindow-minimize", Id); + } + _minimize += value; + } + remove + { + _minimize -= value; + + if (_minimize == null) + BridgeConnector.Socket.Off("browserWindow-minimize" + Id); + } + } + + private event Action _minimize; + + /// + /// Emitted when the window is restored from a minimized state. + /// + public event Action OnRestore + { + add + { + if (_restore == null) + { + BridgeConnector.Socket.On("browserWindow-restore" + Id, () => + { + _restore(); + }); + + BridgeConnector.Socket.Emit("register-browserWindow-restore", Id); + } + _restore += value; + } + remove + { + _restore -= value; + + if (_restore == null) + BridgeConnector.Socket.Off("browserWindow-restore" + Id); + } + } + + private event Action _restore; + + /// + /// Emitted when the window is being resized. + /// + public event Action OnResize + { + add + { + if (_resize == null) + { + BridgeConnector.Socket.On("browserWindow-resize" + Id, () => + { + _resize(); + }); + + BridgeConnector.Socket.Emit("register-browserWindow-resize", Id); + } + _resize += value; + } + remove + { + _resize -= value; + + if (_resize == null) + BridgeConnector.Socket.Off("browserWindow-resize" + Id); + } + } + + private event Action _resize; + + /// + /// Emitted when the window is being moved to a new position. + /// + /// Note: On macOS this event is just an alias of moved. + /// + public event Action OnMove + { + add + { + if (_move == null) + { + BridgeConnector.Socket.On("browserWindow-move" + Id, () => + { + _move(); + }); + + BridgeConnector.Socket.Emit("register-browserWindow-move", Id); + } + _move += value; + } + remove + { + _move -= value; + + if (_move == null) + BridgeConnector.Socket.Off("browserWindow-move" + Id); + } + } + + private event Action _move; + + /// + /// macOS: Emitted once when the window is moved to a new position. + /// + public event Action OnMoved + { + add + { + if (_moved == null) + { + BridgeConnector.Socket.On("browserWindow-moved" + Id, () => + { + _moved(); + }); + + BridgeConnector.Socket.Emit("register-browserWindow-moved", Id); + } + _moved += value; + } + remove + { + _moved -= value; + + if (_moved == null) + BridgeConnector.Socket.Off("browserWindow-moved" + Id); + } + } + + private event Action _moved; + + /// + /// Emitted when the window enters a full-screen state. + /// + public event Action OnEnterFullScreen + { + add + { + if (_enterFullScreen == null) + { + BridgeConnector.Socket.On("browserWindow-enter-full-screen" + Id, () => + { + _enterFullScreen(); + }); + + BridgeConnector.Socket.Emit("register-browserWindow-enter-full-screen", Id); + } + _enterFullScreen += value; + } + remove + { + _enterFullScreen -= value; + + if (_enterFullScreen == null) + BridgeConnector.Socket.Off("browserWindow-enter-full-screen" + Id); + } + } + + private event Action _enterFullScreen; + + /// + /// Emitted when the window leaves a full-screen state. + /// + public event Action OnLeaveFullScreen + { + add + { + if (_leaveFullScreen == null) + { + BridgeConnector.Socket.On("browserWindow-leave-full-screen" + Id, () => + { + _leaveFullScreen(); + }); + + BridgeConnector.Socket.Emit("register-browserWindow-leave-full-screen", Id); + } + _leaveFullScreen += value; + } + remove + { + _leaveFullScreen -= value; + + if (_leaveFullScreen == null) + BridgeConnector.Socket.Off("browserWindow-leave-full-screen" + Id); + } + } + + private event Action _leaveFullScreen; + + /// + /// Emitted when the window enters a full-screen state triggered by HTML API. + /// + public event Action OnEnterHtmlFullScreen + { + add + { + if (_enterHtmlFullScreen == null) + { + BridgeConnector.Socket.On("browserWindow-enter-html-full-screen" + Id, () => + { + _enterHtmlFullScreen(); + }); + + BridgeConnector.Socket.Emit("register-browserWindow-enter-html-full-screen", Id); + } + _enterHtmlFullScreen += value; + } + remove + { + _enterHtmlFullScreen -= value; + + if (_enterHtmlFullScreen == null) + BridgeConnector.Socket.Off("browserWindow-enter-html-full-screen" + Id); + } + } + + private event Action _enterHtmlFullScreen; + + /// + /// Emitted when the window leaves a full-screen state triggered by HTML API. + /// + public event Action OnLeaveHtmlFullScreen + { + add + { + if (_leaveHtmlFullScreen == null) + { + BridgeConnector.Socket.On("browserWindow-leave-html-full-screen" + Id, () => + { + _leaveHtmlFullScreen(); + }); + + BridgeConnector.Socket.Emit("register-browserWindow-leave-html-full-screen", Id); + } + _leaveHtmlFullScreen += value; + } + remove + { + _leaveHtmlFullScreen -= value; + + if (_leaveHtmlFullScreen == null) + BridgeConnector.Socket.Off("browserWindow-leave-html-full-screen" + Id); + } + } + + private event Action _leaveHtmlFullScreen; + + /// + /// Emitted when an App Command is invoked. These are typically related to + /// keyboard media keys or browser commands, as well as the “Back” button + /// built into some mice on Windows. + /// + /// Commands are lowercased, underscores are replaced with hyphens, + /// and the APPCOMMAND_ prefix is stripped off.e.g.APPCOMMAND_BROWSER_BACKWARD + /// is emitted as browser-backward. + /// + public event Action OnAppCommand + { + add + { + if (_appCommand == null) + { + BridgeConnector.Socket.On("browserWindow-app-command" + Id, (command) => + { + _appCommand(command.ToString()); + }); + + BridgeConnector.Socket.Emit("register-browserWindow-app-command", Id); + } + _appCommand += value; + } + remove + { + _appCommand -= value; + + if (_appCommand == null) + BridgeConnector.Socket.Off("browserWindow-app-command" + Id); + } + } + + private event Action _appCommand; + + /// + /// Emitted on 3-finger swipe. Possible directions are up, right, down, left. + /// + public event Action OnSwipe + { + add + { + if (_swipe == null) + { + BridgeConnector.Socket.On("browserWindow-swipe" + Id, (direction) => + { + _swipe(direction.ToString()); + }); + + BridgeConnector.Socket.Emit("register-browserWindow-swipe", Id); + } + _swipe += value; + } + remove + { + _swipe -= value; + + if (_swipe == null) + BridgeConnector.Socket.Off("browserWindow-swipe" + Id); + } + } + + private event Action _swipe; + + /// + /// Emitted when the window opens a sheet. + /// + public event Action OnSheetBegin + { + add + { + if (_sheetBegin == null) + { + BridgeConnector.Socket.On("browserWindow-sheet-begin" + Id, () => + { + _sheetBegin(); + }); + + BridgeConnector.Socket.Emit("register-browserWindow-sheet-begin", Id); + } + _sheetBegin += value; + } + remove + { + _sheetBegin -= value; + + if (_sheetBegin == null) + BridgeConnector.Socket.Off("browserWindow-sheet-begin" + Id); + } + } + + private event Action _sheetBegin; + + /// + /// Emitted when the window has closed a sheet. + /// + public event Action OnSheetEnd + { + add + { + if (_sheetEnd == null) + { + BridgeConnector.Socket.On("browserWindow-sheet-end" + Id, () => + { + _sheetEnd(); + }); + + BridgeConnector.Socket.Emit("register-browserWindow-sheet-end", Id); + } + _sheetEnd += value; + } + remove + { + _sheetEnd -= value; + + if (_sheetEnd == null) + BridgeConnector.Socket.Off("browserWindow-sheet-end" + Id); + } + } + + private event Action _sheetEnd; + + /// + /// Emitted when the native new tab button is clicked. + /// + public event Action OnNewWindowForTab + { + add + { + if (_newWindowForTab == null) + { + BridgeConnector.Socket.On("browserWindow-new-window-for-tab" + Id, () => + { + _newWindowForTab(); + }); + + BridgeConnector.Socket.Emit("register-browserWindow-new-window-for-tab", Id); + } + _newWindowForTab += value; + } + remove + { + _newWindowForTab -= value; + + if (_newWindowForTab == null) + BridgeConnector.Socket.Off("browserWindow-new-window-for-tab" + Id); + } + } + + private event Action _newWindowForTab; + + internal BrowserWindow(int id) { + Id = id; + WebContents = new WebContents(id); + } + + /// + /// Force closing the window, the unload and beforeunload event won’t be + /// emitted for the web page, and close event will also not be emitted + /// for this window, but it guarantees the closed event will be emitted. + /// + public void Destroy() + { + BridgeConnector.Socket.Emit("browserWindowDestroy", Id); + } + + /// + /// Try to close the window. This has the same effect as a user manually + /// clicking the close button of the window. The web page may cancel the close though. + /// + public void Close() + { + BridgeConnector.Socket.Emit("browserWindowClose", Id); + } + + /// + /// Focuses on the window. + /// + public void Focus() + { + BridgeConnector.Socket.Emit("browserWindowFocus", Id); + } + + /// + /// Removes focus from the window. + /// + public void Blur() + { + BridgeConnector.Socket.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; + } + + /// + /// 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; + } + + /// + /// Shows and gives focus to the window. + /// + public void Show() + { + BridgeConnector.Socket.Emit("browserWindowShow", Id); + } + + /// + /// Shows the window but doesn’t focus on it. + /// + public void ShowInactive() + { + BridgeConnector.Socket.Emit("browserWindowShowInactive", Id); + } + + /// + /// Hides the window. + /// + public void Hide() + { + BridgeConnector.Socket.Emit("browserWindowHide", Id); + } + + /// + /// Whether the window is visible to the user. + /// + /// + 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; + } + + /// + /// Whether current window is a modal window. + /// + /// + 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; + } + + /// + /// Maximizes the window. This will also show (but not focus) the window if it isn’t being displayed already. + /// + public void Maximize() + { + BridgeConnector.Socket.Emit("browserWindowMaximize", Id); + } + + /// + /// Unmaximizes the window. + /// + public void Unmaximize() + { + BridgeConnector.Socket.Emit("browserWindowUnmaximize", Id); + } + + /// + /// Whether the window is maximized. + /// + /// + 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; + } + + /// + /// Minimizes the window. On some platforms the minimized window will be shown in the Dock. + /// + public void Minimize() + { + BridgeConnector.Socket.Emit("browserWindowMinimize", Id); + } + + /// + /// Restores the window from minimized state to its previous state. + /// + public void Restore() + { + BridgeConnector.Socket.Emit("browserWindowRestore", Id); + } + + /// + /// Whether the window is minimized. + /// + /// + 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; + } + + /// + /// Sets whether the window should be in fullscreen mode. + /// + public void SetFullScreen(bool flag) + { + BridgeConnector.Socket.Emit("browserWindowSetFullScreen", Id, flag); + } + + /// + /// Whether the window is in fullscreen mode. + /// + /// + 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; + } + + /// + /// This will make a window maintain an aspect ratio. The extra size allows a developer to have space, + /// specified in pixels, not included within the aspect ratio calculations. This API already takes into + /// account the difference between a window’s size and its content size. + /// + /// Consider a normal window with an HD video player and associated controls.Perhaps there are 15 pixels + /// of controls on the left edge, 25 pixels of controls on the right edge and 50 pixels of controls below + /// the player. In order to maintain a 16:9 aspect ratio (standard aspect ratio for HD @1920x1080) within + /// the player itself we would call this function with arguments of 16/9 and[40, 50]. The second argument + /// doesn’t care where the extra width and height are within the content view–only that they exist. Just + /// sum any extra width and height areas you have within the overall content view. + /// + /// The aspect ratio to maintain for some portion of the content view. + /// 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)); + } + + /// + /// Uses Quick Look to preview a file at a given path. + /// + /// The absolute path to the file to preview with QuickLook. This is important as + /// Quick Look uses the file name and file extension on the path to determine the content type of the + /// file to open. + public void PreviewFile(string path) + { + BridgeConnector.Socket.Emit("browserWindowPreviewFile", Id, path); + } + + /// + /// Uses Quick Look to preview a file at a given path. + /// + /// The absolute path to the file to preview with QuickLook. This is important as + /// Quick Look uses the file name and file extension on the path to determine the content type of the + /// file to open. + /// The name of the file to display on the Quick Look modal view. This is + /// 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); + } + + /// + /// Closes the currently open Quick Look panel. + /// + public void CloseFilePreview() + { + BridgeConnector.Socket.Emit("browserWindowCloseFilePreview", Id); + } + + /// + /// Resizes and moves the window to the supplied bounds + /// + /// + public void SetBounds(Rectangle bounds) + { + BridgeConnector.Socket.Emit("browserWindowSetBounds", Id, JObject.FromObject(bounds, _jsonSerializer)); + } + + /// + /// Resizes and moves the window to the supplied bounds + /// + /// + /// + public void SetBounds(Rectangle bounds, bool animate) + { + BridgeConnector.Socket.Emit("browserWindowSetBounds", Id, JObject.FromObject(bounds, _jsonSerializer), animate); + } + + /// + /// Gets the bounds asynchronous. + /// + /// + 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; + } + + /// + /// Resizes and moves the window’s client area (e.g. the web page) to the supplied bounds. + /// + /// + public void SetContentBounds(Rectangle bounds) + { + BridgeConnector.Socket.Emit("browserWindowSetContentBounds", Id, JObject.FromObject(bounds, _jsonSerializer)); + } + + /// + /// Resizes and moves the window’s client area (e.g. the web page) to the supplied bounds. + /// + /// + /// + public void SetContentBounds(Rectangle bounds, bool animate) + { + BridgeConnector.Socket.Emit("browserWindowSetContentBounds", Id, JObject.FromObject(bounds, _jsonSerializer), animate); + } + + /// + /// Gets the content bounds asynchronous. + /// + /// + 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; + } + + /// + /// Resizes the window to width and height. + /// + /// + /// + public void SetSize(int width, int height) + { + BridgeConnector.Socket.Emit("browserWindowSetSize", Id, width, height); + } + + /// + /// Resizes the window to width and height. + /// + /// + /// + /// + public void SetSize(int width, int height, bool animate) + { + BridgeConnector.Socket.Emit("browserWindowSetSize", Id, width, height, animate); + } + + /// + /// Contains the window’s width and height. + /// + /// + 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; + } + + /// + /// Resizes the window’s client area (e.g. the web page) to width and height. + /// + /// + /// + public void SetContentSize(int width, int height) + { + BridgeConnector.Socket.Emit("browserWindowSetContentSize", Id, width, height); + } + + /// + /// Resizes the window’s client area (e.g. the web page) to width and height. + /// + /// + /// + /// + public void SetContentSize(int width, int height, bool animate) + { + BridgeConnector.Socket.Emit("browserWindowSetContentSize", Id, width, height, animate); + } + + /// + /// Contains the window’s client area’s width and height. + /// + /// + 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; + } + + /// + /// Sets the minimum size of window to width and height. + /// + /// + /// + public void SetMinimumSize(int width, int height) + { + BridgeConnector.Socket.Emit("browserWindowSetMinimumSize", Id, width, height); + } + + /// + /// Contains the window’s minimum width and 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; + } + + /// + /// Sets the maximum size of window to width and height. + /// + /// + /// + public void SetMaximumSize(int width, int height) + { + BridgeConnector.Socket.Emit("browserWindowSetMaximumSize", Id, width, height); + } + + /// + /// Contains the window’s maximum width and 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; + } + + /// + /// Sets whether the window can be manually resized by user. + /// + /// + public void SetResizable(bool resizable) + { + BridgeConnector.Socket.Emit("browserWindowSetResizable", Id, resizable); + } + + /// + /// Whether the window can be manually resized by user. + /// + /// + 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; + } + + /// + /// Sets whether the window can be moved by user. On Linux does nothing. + /// + /// + public void SetMovable(bool movable) + { + BridgeConnector.Socket.Emit("browserWindowSetMovable", Id, movable); + } + + /// + /// Whether the window can be moved by user. + /// + /// On Linux always returns true. + /// + /// 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; + } + + /// + /// Sets whether the window can be manually minimized by user. On Linux does nothing. + /// + /// + public void SetMinimizable(bool minimizable) + { + BridgeConnector.Socket.Emit("browserWindowSetMinimizable", Id, minimizable); + } + + /// + /// Whether the window can be manually minimized by user. + /// + /// On Linux always returns true. + /// + /// 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; + } + + /// + /// Sets whether the window can be manually maximized by user. On Linux does nothing. + /// + /// + public void SetMaximizable(bool maximizable) + { + BridgeConnector.Socket.Emit("browserWindowSetMaximizable", Id, maximizable); + } + + /// + /// Whether the window can be manually maximized by user. + /// + /// On Linux always returns true. + /// + /// 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; + } + + /// + /// Sets whether the maximize/zoom window button toggles fullscreen mode or maximizes the window. + /// + /// + public void SetFullScreenable(bool fullscreenable) + { + BridgeConnector.Socket.Emit("browserWindowSetFullScreenable", Id, fullscreenable); + } + + /// + /// Whether the maximize/zoom window button toggles fullscreen mode or maximizes the window. + /// + /// + 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; + } + + /// + /// Sets whether the window can be manually closed by user. On Linux does nothing. + /// + /// + public void SetClosable(bool closable) + { + BridgeConnector.Socket.Emit("browserWindowSetClosable", Id, closable); + } + + /// + /// Whether the window can be manually closed by user. + /// + /// On Linux always returns true. + /// + /// 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; + } + + /// + /// Sets whether the window should show always on top of other windows. + /// After setting this, the window is still a normal window, not a toolbox + /// window which can not be focused on. + /// + /// + public void SetAlwaysOnTop(bool flag) + { + BridgeConnector.Socket.Emit("browserWindowSetAlwaysOnTop", Id, flag); + } + + /// + /// Sets whether the window should show always on top of other windows. + /// After setting this, the window is still a normal window, not a toolbox + /// window which can not be focused on. + /// + /// + /// Values include normal, floating, torn-off-menu, modal-panel, main-menu, + /// status, pop-up-menu and screen-saver. The default is floating. + /// See the macOS docs + public void SetAlwaysOnTop(bool flag, OnTopLevel level) + { + BridgeConnector.Socket.Emit("browserWindowSetAlwaysOnTop", Id, flag, level.GetDescription()); + } + + /// + /// Sets whether the window should show always on top of other windows. + /// After setting this, the window is still a normal window, not a toolbox + /// window which can not be focused on. + /// + /// + /// Values include normal, floating, torn-off-menu, modal-panel, main-menu, + /// status, pop-up-menu and screen-saver. The default is floating. + /// See the macOS docs + /// The number of layers higher to set this window relative to the given 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); + } + + /// + /// Whether the window is always on top of other windows. + /// + /// + 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; + } + + /// + /// Moves window to the center of the screen. + /// + public void Center() + { + BridgeConnector.Socket.Emit("browserWindowCenter", Id); + } + + /// + /// Moves window to x and y. + /// + /// + /// + public void SetPosition(int x, int y) + { + // Workaround Windows 10 / Electron Bug + // https://github.com/electron/electron/issues/4045 + if (isWindows10()) + { + x = x - 7; + } + + BridgeConnector.Socket.Emit("browserWindowSetPosition", Id, x, y); + } + + /// + /// Moves window to x and y. + /// + /// + /// + /// + public void SetPosition(int x, int y, bool animate) + { + // Workaround Windows 10 / Electron Bug + // https://github.com/electron/electron/issues/4045 + if (isWindows10()) + { + x = x - 7; + } + + BridgeConnector.Socket.Emit("browserWindowSetPosition", Id, x, y, animate); + } + + private bool isWindows10() + { + return RuntimeInformation.OSDescription.Contains("Windows 10"); + } + + /// + /// Contains the window’s current position. + /// + /// + public Task GetPositionAsync() + { + var taskCompletionSource = new TaskCompletionSource(); + + BridgeConnector.Socket.On("browserWindow-getPosition-completed", (position) => { + BridgeConnector.Socket.Off("browserWindow-getPosition-completed"); + + taskCompletionSource.SetResult(((JArray)position).ToObject()); + }); + + BridgeConnector.Socket.Emit("browserWindowGetPosition", Id); + + return taskCompletionSource.Task; + } + + /// + /// Changes the title of native window to title. + /// + /// + public void SetTitle(string title) + { + BridgeConnector.Socket.Emit("browserWindowSetTitle", Id, title); + } + + /// + /// The title of the native window. + /// + /// Note: The title of web page can be different from the title of the native window. + /// + /// + public Task GetTitleAsync() + { + var taskCompletionSource = new TaskCompletionSource(); + + BridgeConnector.Socket.On("browserWindow-getTitle-completed", (title) => { + BridgeConnector.Socket.Off("browserWindow-getTitle-completed"); + + taskCompletionSource.SetResult(title.ToString()); + }); + + BridgeConnector.Socket.Emit("browserWindowGetTitle", Id); + + return taskCompletionSource.Task; + } + + /// + /// Changes the attachment point for sheets on macOS. + /// By default, sheets are attached just below the window frame, + /// but you may want to display them beneath a HTML-rendered toolbar. + /// + /// + public void SetSheetOffset(float offsetY) + { + BridgeConnector.Socket.Emit("browserWindowSetSheetOffset", Id, offsetY); + } + + /// + /// Changes the attachment point for sheets on macOS. + /// By default, sheets are attached just below the window frame, + /// but you may want to display them beneath a HTML-rendered toolbar. + /// + /// + /// + public void SetSheetOffset(float offsetY, float offsetX) + { + BridgeConnector.Socket.Emit("browserWindowSetSheetOffset", Id, offsetY, offsetX); + } + + /// + /// Starts or stops flashing the window to attract user’s attention. + /// + /// + public void FlashFrame(bool flag) + { + BridgeConnector.Socket.Emit("browserWindowFlashFrame", Id, flag); + } + + /// + /// Makes the window not show in the taskbar. + /// + /// + public void SetSkipTaskbar(bool skip) + { + BridgeConnector.Socket.Emit("browserWindowSetSkipTaskbar", Id, skip); + } + + /// + /// Enters or leaves the kiosk mode. + /// + /// + public void SetKiosk(bool flag) + { + BridgeConnector.Socket.Emit("browserWindowSetKiosk", Id, flag); + } + + /// + /// Whether the window is in kiosk mode. + /// + /// + public Task IsKioskAsync() + { + var taskCompletionSource = new TaskCompletionSource(); + + BridgeConnector.Socket.On("browserWindow-isKiosk-completed", (isKiosk) => { + BridgeConnector.Socket.Off("browserWindow-isKiosk-completed"); + + taskCompletionSource.SetResult((bool)isKiosk); + }); + + BridgeConnector.Socket.Emit("browserWindowIsKiosk", Id); + + return taskCompletionSource.Task; + } + + /// + /// Returns the native type of the handle is HWND on Windows, NSView* on macOS, and Window (unsigned long) on Linux. + /// + /// string of the native handle obtained, HWND on Windows, NSView* on macOS, and Window (unsigned long) on Linux. + public Task GetNativeWindowHandle() + { + var taskCompletionSource = new TaskCompletionSource(); + + BridgeConnector.Socket.On("browserWindow-getNativeWindowHandle-completed", (nativeWindowHandle) => + { + BridgeConnector.Socket.Off("browserWindow-getNativeWindowHandle-completed"); + taskCompletionSource.SetResult(nativeWindowHandle.ToString()); + }); + + BridgeConnector.Socket.Emit("browserWindowGetNativeWindowHandle", Id); + + return taskCompletionSource.Task; + } + + /// + /// Sets the pathname of the file the window represents, + /// and the icon of the file will show in window’s title bar. + /// + /// + public void SetRepresentedFilename(string filename) + { + BridgeConnector.Socket.Emit("browserWindowSetRepresentedFilename", Id, filename); + } + + /// + /// The pathname of the file the window represents. + /// + /// + public Task GetRepresentedFilenameAsync() + { + var taskCompletionSource = new TaskCompletionSource(); + + BridgeConnector.Socket.On("browserWindow-getRepresentedFilename-completed", (pathname) => { + BridgeConnector.Socket.Off("browserWindow-getRepresentedFilename-completed"); + + taskCompletionSource.SetResult(pathname.ToString()); + }); + + BridgeConnector.Socket.Emit("browserWindowGetRepresentedFilename", Id); + + return taskCompletionSource.Task; + } + + /// + /// Specifies whether the window’s document has been edited, + /// and the icon in title bar will become gray when set to true. + /// + /// + public void SetDocumentEdited(bool edited) + { + BridgeConnector.Socket.Emit("browserWindowSetDocumentEdited", Id, edited); + } + + /// + /// Whether the window’s document has been edited. + /// + /// + public Task IsDocumentEditedAsync() + { + var taskCompletionSource = new TaskCompletionSource(); + + BridgeConnector.Socket.On("browserWindow-isDocumentEdited-completed", (edited) => { + BridgeConnector.Socket.Off("browserWindow-isDocumentEdited-completed"); + + taskCompletionSource.SetResult((bool)edited); + }); + + BridgeConnector.Socket.Emit("browserWindowIsDocumentEdited", Id); + + return taskCompletionSource.Task; + } + + /// + /// Focuses the on web view. + /// + public void FocusOnWebView() + { + BridgeConnector.Socket.Emit("browserWindowFocusOnWebView", Id); + } + + /// + /// Blurs the web view. + /// + public void BlurWebView() + { + BridgeConnector.Socket.Emit("browserWindowBlurWebView", Id); + } + + /// + /// The url can be a remote address (e.g. http://) or + /// a path to a local HTML file using the file:// protocol. + /// + /// + public void LoadURL(string url) + { + BridgeConnector.Socket.Emit("browserWindowLoadURL", Id, url); + } + + /// + /// The url can be a remote address (e.g. http://) or + /// a path to a local HTML file using the file:// protocol. + /// + /// + /// + public void LoadURL(string url, LoadURLOptions options) + { + BridgeConnector.Socket.Emit("browserWindowLoadURL", Id, url, JObject.FromObject(options, _jsonSerializer)); + } + + /// + /// Same as webContents.reload. + /// + public void Reload() + { + BridgeConnector.Socket.Emit("browserWindowReload", Id); + } + + /// + /// Gets the menu items. + /// + /// + /// The menu items. + /// + public IReadOnlyCollection MenuItems { get { return _items.AsReadOnly(); } } + private List _items = new List(); + + /// + /// Sets the menu as the window’s menu bar, + /// setting it to null will remove the menu bar. + /// + /// + public void SetMenu(MenuItem[] menuItems) + { + menuItems.AddMenuItemsId(); + BridgeConnector.Socket.Emit("browserWindowSetMenu", Id, JArray.FromObject(menuItems, _jsonSerializer)); + _items.AddRange(menuItems); + + BridgeConnector.Socket.Off("windowMenuItemClicked"); + BridgeConnector.Socket.On("windowMenuItemClicked", (id) => { + MenuItem menuItem = _items.GetMenuItem(id.ToString()); + menuItem?.Click(); + }); + } + + /// + /// Remove the window's menu bar. + /// + public void RemoveMenu() + { + BridgeConnector.Socket.Emit("browserWindowRemoveMenu", Id); + } + + /// + /// Sets progress value in progress bar. Valid range is [0, 1.0]. Remove progress + /// bar when progress smaler as 0; Change to indeterminate mode when progress bigger as 1. On Linux + /// platform, only supports Unity desktop environment, you need to specify the + /// .desktop file name to desktopName field in package.json.By default, it will + /// assume app.getName().desktop.On Windows, a mode can be passed.Accepted values + /// are none, normal, indeterminate, error, and paused. If you call setProgressBar + /// without a mode set (but with a value within the valid range), normal will be + /// assumed. + /// + /// + public void SetProgressBar(double progress) + { + BridgeConnector.Socket.Emit("browserWindowSetProgressBar", Id, progress); + } + + /// + /// Sets progress value in progress bar. Valid range is [0, 1.0]. Remove progress + /// bar when progress smaler as 0; Change to indeterminate mode when progress bigger as 1. On Linux + /// platform, only supports Unity desktop environment, you need to specify the + /// .desktop file name to desktopName field in package.json.By default, it will + /// assume app.getName().desktop.On Windows, a mode can be passed.Accepted values + /// are none, normal, indeterminate, error, and paused. If you call setProgressBar + /// without a mode set (but with a value within the valid range), normal will be + /// assumed. + /// + /// + /// + public void SetProgressBar(double progress, ProgressBarOptions progressBarOptions) + { + BridgeConnector.Socket.Emit("browserWindowSetProgressBar", Id, progress, JObject.FromObject(progressBarOptions, _jsonSerializer)); + } + + /// + /// Sets whether the window should have a shadow. On Windows and Linux does nothing. + /// + /// + public void SetHasShadow(bool hasShadow) + { + BridgeConnector.Socket.Emit("browserWindowSetHasShadow", Id, hasShadow); + } + + /// + /// Whether the window has a shadow. + /// + /// On Windows and Linux always returns true. + /// + /// + public Task HasShadowAsync() + { + var taskCompletionSource = new TaskCompletionSource(); + + BridgeConnector.Socket.On("browserWindow-hasShadow-completed", (hasShadow) => { + BridgeConnector.Socket.Off("browserWindow-hasShadow-completed"); + + taskCompletionSource.SetResult((bool)hasShadow); + }); + + BridgeConnector.Socket.Emit("browserWindowHasShadow", Id); + + return taskCompletionSource.Task; + } + + /// + /// Gets the thumbar buttons. + /// + /// + /// The thumbar buttons. + /// + public IReadOnlyCollection ThumbarButtons { get { return _thumbarButtons.AsReadOnly(); } } + private List _thumbarButtons = new List(); + + /// + /// Add a thumbnail toolbar with a specified set of buttons to the thumbnail + /// image of a window in a taskbar button layout. Returns a Boolean object + /// indicates whether the thumbnail has been added successfully. + /// + /// The number of buttons in thumbnail toolbar should be no greater than 7 due + /// to the limited room.Once you setup the thumbnail toolbar, the toolbar cannot + /// be removed due to the platform’s limitation.But you can call the API with an + /// empty array to clean the buttons. + /// + /// + /// Whether the buttons were added successfully. + public Task SetThumbarButtonsAsync(ThumbarButton[] thumbarButtons) + { + var taskCompletionSource = new TaskCompletionSource(); + + BridgeConnector.Socket.On("browserWindowSetThumbarButtons-completed", (success) => { + BridgeConnector.Socket.Off("browserWindowSetThumbarButtons-completed"); + + taskCompletionSource.SetResult((bool)success); + }); + + thumbarButtons.AddThumbarButtonsId(); + BridgeConnector.Socket.Emit("browserWindowSetThumbarButtons", Id, JArray.FromObject(thumbarButtons, _jsonSerializer)); + _thumbarButtons.Clear(); + _thumbarButtons.AddRange(thumbarButtons); + + BridgeConnector.Socket.Off("thumbarButtonClicked"); + BridgeConnector.Socket.On("thumbarButtonClicked", (id) => { + ThumbarButton thumbarButton = _thumbarButtons.GetThumbarButton(id.ToString()); + thumbarButton?.Click(); + }); + + return taskCompletionSource.Task; + } + + /// + /// Sets the region of the window to show as the thumbnail image displayed when hovering over + /// the window in the taskbar. You can reset the thumbnail to be the entire window by specifying + /// an empty region: {x: 0, y: 0, width: 0, height: 0}. + /// + /// + public void SetThumbnailClip(Rectangle rectangle) + { + BridgeConnector.Socket.Emit("browserWindowSetThumbnailClip", Id, rectangle); + } + + /// + /// Sets the toolTip that is displayed when hovering over the window thumbnail in the taskbar. + /// + /// + public void SetThumbnailToolTip(string tooltip) + { + BridgeConnector.Socket.Emit("browserWindowSetThumbnailToolTip", Id, tooltip); + } + + /// + /// Sets the properties for the window’s taskbar button. + /// + /// Note: relaunchCommand and relaunchDisplayName must always be set together. + /// If one of those properties is not set, then neither will be used. + /// + /// + public void SetAppDetails(AppDetailsOptions options) + { + BridgeConnector.Socket.Emit("browserWindowSetAppDetails", Id, JObject.FromObject(options, _jsonSerializer)); + } + + /// + /// Same as webContents.showDefinitionForSelection(). + /// + public void ShowDefinitionForSelection() + { + BridgeConnector.Socket.Emit("browserWindowShowDefinitionForSelection", Id); + } + + /// + /// Sets whether the window menu bar should hide itself automatically. + /// Once set the menu bar will only show when users press the single Alt key. + /// + /// If the menu bar is already visible, calling setAutoHideMenuBar(true) won’t hide it immediately. + /// + /// + public void SetAutoHideMenuBar(bool hide) + { + BridgeConnector.Socket.Emit("browserWindowSetAutoHideMenuBar", Id, hide); + } + + /// + /// Whether menu bar automatically hides itself. + /// + /// + public Task IsMenuBarAutoHideAsync() + { + var taskCompletionSource = new TaskCompletionSource(); + + BridgeConnector.Socket.On("browserWindow-isMenuBarAutoHide-completed", (isMenuBarAutoHide) => { + BridgeConnector.Socket.Off("browserWindow-isMenuBarAutoHide-completed"); + + taskCompletionSource.SetResult((bool)isMenuBarAutoHide); + }); + + BridgeConnector.Socket.Emit("browserWindowIsMenuBarAutoHide", Id); + + return taskCompletionSource.Task; + } + + /// + /// Sets whether the menu bar should be visible. If the menu bar is auto-hide, + /// users can still bring up the menu bar by pressing the single Alt key. + /// + /// + public void SetMenuBarVisibility(bool visible) + { + BridgeConnector.Socket.Emit("browserWindowSetMenuBarVisibility", Id, visible); + } + + /// + /// Whether the menu bar is visible. + /// + /// + public Task IsMenuBarVisibleAsync() + { + var taskCompletionSource = new TaskCompletionSource(); + + BridgeConnector.Socket.On("browserWindow-isMenuBarVisible-completed", (isMenuBarVisible) => { + BridgeConnector.Socket.Off("browserWindow-isMenuBarVisible-completed"); + + taskCompletionSource.SetResult((bool)isMenuBarVisible); + }); + + BridgeConnector.Socket.Emit("browserWindowIsMenuBarVisible", Id); + + return taskCompletionSource.Task; + } + + /// + /// Sets whether the window should be visible on all workspaces. + /// + /// Note: This API does nothing on Windows. + /// + /// + public void SetVisibleOnAllWorkspaces(bool visible) + { + BridgeConnector.Socket.Emit("browserWindowSetVisibleOnAllWorkspaces", Id, visible); + } + + /// + /// Whether the window is visible on all workspaces. + /// + /// Note: This API always returns false on Windows. + /// + /// + public Task IsVisibleOnAllWorkspacesAsync() + { + var taskCompletionSource = new TaskCompletionSource(); + + BridgeConnector.Socket.On("browserWindow-isVisibleOnAllWorkspaces-completed", (isVisibleOnAllWorkspaces) => { + BridgeConnector.Socket.Off("browserWindow-isVisibleOnAllWorkspaces-completed"); + + taskCompletionSource.SetResult((bool)isVisibleOnAllWorkspaces); + }); + + BridgeConnector.Socket.Emit("browserWindowIsVisibleOnAllWorkspaces", Id); + + return taskCompletionSource.Task; + } + + /// + /// Makes the window ignore all mouse events. + /// + /// All mouse events happened in this window will be passed to the window + /// below this window, but if this window has focus, it will still receive keyboard events. + /// + /// + public void SetIgnoreMouseEvents(bool ignore) + { + BridgeConnector.Socket.Emit("browserWindowSetIgnoreMouseEvents", Id, ignore); + } + + /// + /// Prevents the window contents from being captured by other apps. + /// + /// On macOS it sets the NSWindow’s sharingType to NSWindowSharingNone. + /// On Windows it calls SetWindowDisplayAffinity with WDA_MONITOR. + /// + /// + public void SetContentProtection(bool enable) + { + BridgeConnector.Socket.Emit("browserWindowSetContentProtection", Id, enable); + } + + /// + /// Changes whether the window can be focused. + /// + /// + public void SetFocusable(bool focusable) + { + BridgeConnector.Socket.Emit("browserWindowSetFocusable", Id, focusable); + } + + /// + /// Sets parent as current window’s parent window, + /// passing null will turn current window into a top-level window. + /// + /// + public void SetParentWindow(BrowserWindow parent) + { + BridgeConnector.Socket.Emit("browserWindowSetParentWindow", Id, JObject.FromObject(parent, _jsonSerializer)); + } + + /// + /// The parent window. + /// + /// + public Task GetParentWindowAsync() + { + var taskCompletionSource = new TaskCompletionSource(); + + BridgeConnector.Socket.On("browserWindow-getParentWindow-completed", (id) => { + BridgeConnector.Socket.Off("browserWindow-getParentWindow-completed"); + var browserWindowId = int.Parse(id.ToString()); + var browserWindow = Electron.WindowManager.BrowserWindows.ToList().Single(x => x.Id == browserWindowId); + + taskCompletionSource.SetResult(browserWindow); + }); + + BridgeConnector.Socket.Emit("browserWindowGetParentWindow", Id); + + return taskCompletionSource.Task; + } + + /// + /// All child windows. + /// + /// + public Task> GetChildWindowsAsync() + { + var taskCompletionSource = new TaskCompletionSource>(); + + BridgeConnector.Socket.On("browserWindow-getChildWindows-completed", (ids) => { + BridgeConnector.Socket.Off("browserWindow-getChildWindows-completed"); + var browserWindowIds = ((JArray)ids).ToObject(); + var browserWindows = new List(); + + browserWindowIds.ToList().ForEach(id => + { + var browserWindow = Electron.WindowManager.BrowserWindows.ToList().Single(x => x.Id == id); + browserWindows.Add(browserWindow); }); - BridgeConnector.Socket.Emit("browserWindowGetChildWindows", Id); - return taskCompletionSource.Task; - } + taskCompletionSource.SetResult(browserWindows); + }); - /// - /// Controls whether to hide cursor when typing. - /// - /// - public void SetAutoHideCursor(bool autoHide) - { - BridgeConnector.Socket.Emit("browserWindowSetAutoHideCursor", Id, autoHide); - } + BridgeConnector.Socket.Emit("browserWindowGetChildWindows", Id); - /// - /// Adds a vibrancy effect to the browser window. - /// Passing null or an empty string will remove the vibrancy effect on the window. - /// - /// Can be appearance-based, light, dark, titlebar, selection, - /// menu, popover, sidebar, medium-light or ultra-dark. - /// See the macOS documentation for more details. - public void SetVibrancy(Vibrancy type) - { - BridgeConnector.Socket.Emit("browserWindowSetVibrancy", Id, type.GetDescription()); - } - - /// - /// Render and control web pages. - /// - public WebContents WebContents { get; internal set; } - - /// - /// A BrowserView can be used to embed additional web content into a BrowserWindow. - /// It is like a child window, except that it is positioned relative to its owning window. - /// It is meant to be an alternative to the webview tag. - /// - /// - public void SetBrowserView(BrowserView browserView) - { - BridgeConnector.Socket.Emit("browserWindow-setBrowserView", Id, browserView.Id); - } - - private JsonSerializer _jsonSerializer = new JsonSerializer() - { - ContractResolver = new CamelCasePropertyNamesContractResolver(), - NullValueHandling = NullValueHandling.Ignore - }; + return taskCompletionSource.Task; } -} + + /// + /// Controls whether to hide cursor when typing. + /// + /// + public void SetAutoHideCursor(bool autoHide) + { + BridgeConnector.Socket.Emit("browserWindowSetAutoHideCursor", Id, autoHide); + } + + /// + /// Adds a vibrancy effect to the browser window. + /// Passing null or an empty string will remove the vibrancy effect on the window. + /// + /// Can be appearance-based, light, dark, titlebar, selection, + /// menu, popover, sidebar, medium-light or ultra-dark. + /// See the macOS documentation for more details. + public void SetVibrancy(Vibrancy type) + { + BridgeConnector.Socket.Emit("browserWindowSetVibrancy", Id, type.GetDescription()); + } + + /// + /// Render and control web pages. + /// + public WebContents WebContents { get; internal set; } + + /// + /// A BrowserView can be used to embed additional web content into a BrowserWindow. + /// It is like a child window, except that it is positioned relative to its owning window. + /// It is meant to be an alternative to the webview tag. + /// + /// + public void SetBrowserView(BrowserView browserView) + { + BridgeConnector.Socket.Emit("browserWindow-setBrowserView", Id, browserView.Id); + } + + private readonly JsonSerializer _jsonSerializer = new() + { + ContractResolver = new CamelCasePropertyNamesContractResolver(), + NullValueHandling = NullValueHandling.Ignore + }; +} \ No newline at end of file diff --git a/ElectronNET.API/Entities/Margins.cs b/ElectronNET.API/Entities/Margins.cs new file mode 100644 index 0000000..b99bb68 --- /dev/null +++ b/ElectronNET.API/Entities/Margins.cs @@ -0,0 +1,33 @@ +namespace ElectronNET.API.Entities; + +/// +/// +/// +public class Margins +{ + /// + /// Can be `default`, `none`, `printableArea`, or `custom`. If `custom` is chosen, + /// you will also need to specify `top`, `bottom`, `left`, and `right`. + /// + public string MarginType { get; set; } + + /// + /// The top margin of the printed web page, in pixels. + /// + public int Top { get; set; } + + /// + /// The bottom margin of the printed web page, in pixels. + /// + public int Bottom { get; set; } + + /// + /// The left margin of the printed web page, in pixels. + /// + public int Left { get; set; } + + /// + /// The right margin of the printed web page, in pixels. + /// + public int Right { get; set; } +} \ No newline at end of file diff --git a/ElectronNET.API/Entities/PrintToPDFOptions.cs b/ElectronNET.API/Entities/PrintToPDFOptions.cs index 3604d38..8ec814c 100644 --- a/ElectronNET.API/Entities/PrintToPDFOptions.cs +++ b/ElectronNET.API/Entities/PrintToPDFOptions.cs @@ -1,35 +1,63 @@ -namespace ElectronNET.API.Entities +namespace ElectronNET.API.Entities; + +/// +/// +/// +public class PrintToPDFOptions { /// - /// + /// Paper orientation. `true` for landscape, `false` for portrait. Defaults to false. /// - public class PrintToPDFOptions - { - /// - /// Specifies the type of margins to use. Uses 0 for default margin, 1 for no - /// margin, and 2 for minimum margin. - /// - public int MarginsType { get; set; } + public bool Landscape { get; set; } = false; - /// - /// Specify page size of the generated PDF. Can be A3, A4, A5, Legal, Letter, - /// Tabloid or an Object containing height and width in microns. - /// - public string PageSize { get; set; } + /// + /// Whether to display header and footer. Defaults to false. + /// + public bool DisplayHeaderFooter { get; set; } = false; - /// - /// Whether to print CSS backgrounds. - /// - public bool PrintBackground { get; set; } + /// + /// Whether to print background graphics. Defaults to false. + /// + public bool PrintBackground { get; set; } = false; - /// - /// Whether to print selection only. - /// - public bool PrintSelectionOnly { get; set; } + /// + /// Scale of the webpage rendering. Defaults to 1. + /// + public double Scale { get; set; } = 1; - /// - /// true for landscape, false for portrait. - /// - public bool Landscape { get; set; } - } + /// + /// Specify page size of the generated PDF. Can be `A0`, `A1`, `A2`, `A3`, `A4`, + /// `A5`, `A6`, `Legal`, `Letter`, `Tabloid`, `Ledger`, or an Object containing + /// `height` and `width` in inches. Defaults to `Letter`. + /// + public string PageSize { get; set; } = "Letter"; + + /// + /// Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, + /// which means print all pages. + /// + public string PageRanges { get; set; } = ""; + + /// + /// HTML template for the print header. Should be valid HTML markup with following + /// classes used to inject printing values into them: `date` (formatted print date), + /// `title` (document title), `url` (document location), `pageNumber` (current page + /// number) and `totalPages` (total pages in the document). For example, `` + /// would generate span containing the title. + /// + public string HeaderTemplate { get; set; } + + /// + /// HTML template for the print footer. Should use the same format as the + /// `headerTemplate`. + /// + public string FooterTemplate { get; set; } + + /// + /// Whether or not to prefer page size as defined by css. Defaults to false, in + /// which case the content will be scaled to fit the paper size. + /// + public bool PreferCSSPageSize { get; set; } = false; + + public Margins Margins { get; set; } } \ No newline at end of file diff --git a/ElectronNET.API/WebContents.cs b/ElectronNET.API/WebContents.cs index c6795f4..cf3c0eb 100644 --- a/ElectronNET.API/WebContents.cs +++ b/ElectronNET.API/WebContents.cs @@ -5,306 +5,305 @@ using Newtonsoft.Json.Serialization; using System; using System.Threading.Tasks; -namespace ElectronNET.API +namespace ElectronNET.API; + +/// +/// Render and control web pages. +/// +public class WebContents { /// - /// Render and control web pages. + /// Gets the identifier. /// - public class WebContents + /// + /// The identifier. + /// + public int Id { get; private set; } + + /// + /// Manage browser sessions, cookies, cache, proxy settings, etc. + /// + public Session Session { get; internal set; } + + /// + /// Emitted when the renderer process crashes or is killed. + /// + public event Action OnCrashed { - /// - /// Gets the identifier. - /// - /// - /// The identifier. - /// - public int Id { get; private set; } - - /// - /// Manage browser sessions, cookies, cache, proxy settings, etc. - /// - public Session Session { get; internal set; } - - /// - /// Emitted when the renderer process crashes or is killed. - /// - public event Action OnCrashed + add { - add + if (_crashed == null) { - if (_crashed == null) + BridgeConnector.Socket.On("webContents-crashed" + Id, (killed) => { - BridgeConnector.Socket.On("webContents-crashed" + Id, (killed) => - { - _crashed((bool)killed); - }); + _crashed((bool)killed); + }); - BridgeConnector.Socket.Emit("register-webContents-crashed", Id); - } - _crashed += value; - } - remove - { - _crashed -= value; - - if (_crashed == null) - BridgeConnector.Socket.Off("webContents-crashed" + Id); + BridgeConnector.Socket.Emit("register-webContents-crashed", Id); } + _crashed += value; } - - private event Action _crashed; - - /// - /// Emitted when the navigation is done, i.e. the spinner of the tab has - /// stopped spinning, and the onload event was dispatched. - /// - public event Action OnDidFinishLoad + remove { - add - { - if (_didFinishLoad == null) - { - BridgeConnector.Socket.On("webContents-didFinishLoad" + Id, () => - { - _didFinishLoad(); - }); + _crashed -= value; - BridgeConnector.Socket.Emit("register-webContents-didFinishLoad", Id); - } - _didFinishLoad += value; - } - remove - { - _didFinishLoad -= value; - - if (_didFinishLoad == null) - BridgeConnector.Socket.Off("webContents-didFinishLoad" + Id); - } + if (_crashed == null) + BridgeConnector.Socket.Off("webContents-crashed" + Id); } - - private event Action _didFinishLoad; - - /// - /// Emitted when an input event is sent to the WebContents. - /// - public event Action InputEvent - { - add - { - if (_inputEvent == null) - { - BridgeConnector.Socket.On("webContents-input-event" + Id, (eventArgs) => - { - var inputEvent = ((JObject)eventArgs).ToObject(); - _inputEvent(inputEvent); - }); - - BridgeConnector.Socket.Emit("register-webContents-input-event", Id); - } - _inputEvent += value; - } - remove - { - _inputEvent -= value; - - if (_inputEvent == null) - BridgeConnector.Socket.Off("webContents-input-event" + Id); - } - } - - private event Action _inputEvent; - - internal WebContents(int id) - { - Id = id; - Session = new Session(id); - } - - /// - /// Opens the devtools. - /// - public void OpenDevTools() - { - BridgeConnector.Socket.Emit("webContentsOpenDevTools", Id); - } - - /// - /// Opens the devtools. - /// - /// - public void OpenDevTools(OpenDevToolsOptions openDevToolsOptions) - { - BridgeConnector.Socket.Emit("webContentsOpenDevTools", Id, JObject.FromObject(openDevToolsOptions, _jsonSerializer)); - } - - /// - /// Get system printers. - /// - /// printers - public Task GetPrintersAsync() - { - var taskCompletionSource = new TaskCompletionSource(); - - BridgeConnector.Socket.On("webContents-getPrinters-completed", (printers) => - { - BridgeConnector.Socket.Off("webContents-getPrinters-completed"); - - taskCompletionSource.SetResult(((Newtonsoft.Json.Linq.JArray)printers).ToObject()); - }); - - BridgeConnector.Socket.Emit("webContents-getPrinters", Id); - - return taskCompletionSource.Task; - } - - /// - /// Prints window's web page. - /// - /// - /// success - public Task PrintAsync(PrintOptions options = null) - { - var taskCompletionSource = new TaskCompletionSource(); - - BridgeConnector.Socket.On("webContents-print-completed", (success) => - { - BridgeConnector.Socket.Off("webContents-print-completed"); - taskCompletionSource.SetResult((bool)success); - }); - - if(options == null) - { - BridgeConnector.Socket.Emit("webContents-print", Id, ""); - } - else - { - BridgeConnector.Socket.Emit("webContents-print", Id, JObject.FromObject(options, _jsonSerializer)); - } - - return taskCompletionSource.Task; - } - - /// - /// Prints window's web page as PDF with Chromium's preview printing custom - /// settings.The landscape will be ignored if @page CSS at-rule is used in the web page. - /// By default, an empty options will be regarded as: Use page-break-before: always; - /// CSS style to force to print to a new page. - /// - /// - /// - /// success - public Task PrintToPDFAsync(string path, PrintToPDFOptions options = null) - { - var taskCompletionSource = new TaskCompletionSource(); - - BridgeConnector.Socket.On("webContents-printToPDF-completed", (success) => - { - BridgeConnector.Socket.Off("webContents-printToPDF-completed"); - taskCompletionSource.SetResult((bool)success); - }); - - if(options == null) - { - BridgeConnector.Socket.Emit("webContents-printToPDF", Id, "", path); - } - else - { - BridgeConnector.Socket.Emit("webContents-printToPDF", Id, JObject.FromObject(options, _jsonSerializer), path); - } - - return taskCompletionSource.Task; - } - - /// - /// Is used to get the Url of the loaded page. - /// It's usefull if a web-server redirects you and you need to know where it redirects. For instance, It's useful in case of Implicit Authorization. - /// - /// URL of the loaded page - public Task GetUrl() - { - var taskCompletionSource = new TaskCompletionSource(); - - var eventString = "webContents-getUrl" + Id; - BridgeConnector.Socket.On(eventString, (url) => - { - BridgeConnector.Socket.Off(eventString); - taskCompletionSource.SetResult((string)url); - }); - - BridgeConnector.Socket.Emit("webContents-getUrl", Id); - - return taskCompletionSource.Task; - } - - /// - /// The async method will resolve when the page has finished loading, - /// and rejects if the page fails to load. - /// - /// A noop rejection handler is already attached, which avoids unhandled rejection - /// errors. - /// - /// Loads the `url` in the window. The `url` must contain the protocol prefix, e.g. - /// the `http://` or `file://`. If the load should bypass http cache then use the - /// `pragma` header to achieve it. - /// - /// - public Task LoadURLAsync(string url) - { - return LoadURLAsync(url, new LoadURLOptions()); - } - - /// - /// The async method will resolve when the page has finished loading, - /// and rejects if the page fails to load. - /// - /// A noop rejection handler is already attached, which avoids unhandled rejection - /// errors. - /// - /// Loads the `url` in the window. The `url` must contain the protocol prefix, e.g. - /// the `http://` or `file://`. If the load should bypass http cache then use the - /// `pragma` header to achieve it. - /// - /// - /// - public Task LoadURLAsync(string url, LoadURLOptions options) - { - var taskCompletionSource = new TaskCompletionSource(); - - BridgeConnector.Socket.On("webContents-loadURL-complete" + Id, () => - { - BridgeConnector.Socket.Off("webContents-loadURL-complete" + Id); - BridgeConnector.Socket.Off("webContents-loadURL-error" + Id); - taskCompletionSource.SetResult(null); - }); - - BridgeConnector.Socket.On("webContents-loadURL-error" + Id, (error) => - { - BridgeConnector.Socket.Off("webContents-loadURL-error" + Id); - taskCompletionSource.SetException(new InvalidOperationException(error.ToString())); - }); - - BridgeConnector.Socket.Emit("webContents-loadURL", Id, url, JObject.FromObject(options, _jsonSerializer)); - - return taskCompletionSource.Task; - } - - /// - /// Inserts CSS into the web page. - /// See: https://www.electronjs.org/docs/api/web-contents#contentsinsertcsscss-options - /// Works for both BrowserWindows and BrowserViews. - /// - /// Whether the webContents belong to a BrowserWindow or not (the other option is a BrowserView) - /// Absolute path to the CSS file location - public void InsertCSS(bool isBrowserWindow, string path) - { - BridgeConnector.Socket.Emit("webContents-insertCSS", Id, isBrowserWindow, path); - } - - private JsonSerializer _jsonSerializer = new JsonSerializer() - { - ContractResolver = new CamelCasePropertyNamesContractResolver(), - NullValueHandling = NullValueHandling.Ignore, - DefaultValueHandling = DefaultValueHandling.Ignore - }; } + + private event Action _crashed; + + /// + /// Emitted when the navigation is done, i.e. the spinner of the tab has + /// stopped spinning, and the onload event was dispatched. + /// + public event Action OnDidFinishLoad + { + add + { + if (_didFinishLoad == null) + { + BridgeConnector.Socket.On("webContents-didFinishLoad" + Id, () => + { + _didFinishLoad(); + }); + + BridgeConnector.Socket.Emit("register-webContents-didFinishLoad", Id); + } + _didFinishLoad += value; + } + remove + { + _didFinishLoad -= value; + + if (_didFinishLoad == null) + BridgeConnector.Socket.Off("webContents-didFinishLoad" + Id); + } + } + + private event Action _didFinishLoad; + + /// + /// Emitted when an input event is sent to the WebContents. + /// + public event Action InputEvent + { + add + { + if (_inputEvent == null) + { + BridgeConnector.Socket.On("webContents-input-event" + Id, (eventArgs) => + { + var inputEvent = ((JObject)eventArgs).ToObject(); + _inputEvent(inputEvent); + }); + + BridgeConnector.Socket.Emit("register-webContents-input-event", Id); + } + _inputEvent += value; + } + remove + { + _inputEvent -= value; + + if (_inputEvent == null) + BridgeConnector.Socket.Off("webContents-input-event" + Id); + } + } + + private event Action _inputEvent; + + internal WebContents(int id) + { + Id = id; + Session = new Session(id); + } + + /// + /// Opens the devtools. + /// + public void OpenDevTools() + { + BridgeConnector.Socket.Emit("webContentsOpenDevTools", Id); + } + + /// + /// Opens the devtools. + /// + /// + public void OpenDevTools(OpenDevToolsOptions openDevToolsOptions) + { + BridgeConnector.Socket.Emit("webContentsOpenDevTools", Id, JObject.FromObject(openDevToolsOptions, _jsonSerializer)); + } + + /// + /// Get system printers. + /// + /// printers + public Task GetPrintersAsync() + { + var taskCompletionSource = new TaskCompletionSource(); + + BridgeConnector.Socket.On("webContents-getPrinters-completed", (printers) => + { + BridgeConnector.Socket.Off("webContents-getPrinters-completed"); + + taskCompletionSource.SetResult(((Newtonsoft.Json.Linq.JArray)printers).ToObject()); + }); + + BridgeConnector.Socket.Emit("webContents-getPrinters", Id); + + return taskCompletionSource.Task; + } + + /// + /// Prints window's web page. + /// + /// + /// success + public Task PrintAsync(PrintOptions options = null) + { + var taskCompletionSource = new TaskCompletionSource(); + + BridgeConnector.Socket.On("webContents-print-completed", (success) => + { + BridgeConnector.Socket.Off("webContents-print-completed"); + taskCompletionSource.SetResult((bool)success); + }); + + if(options == null) + { + BridgeConnector.Socket.Emit("webContents-print", Id, ""); + } + else + { + BridgeConnector.Socket.Emit("webContents-print", Id, JObject.FromObject(options, _jsonSerializer)); + } + + return taskCompletionSource.Task; + } + + /// + /// Prints window's web page as PDF with Chromium's preview printing custom + /// settings.The landscape will be ignored if @page CSS at-rule is used in the web page. + /// By default, an empty options will be regarded as: Use page-break-before: always; + /// CSS style to force to print to a new page. + /// + /// + /// + /// success + public Task PrintToPDFAsync(string path, PrintToPDFOptions options = null) + { + var taskCompletionSource = new TaskCompletionSource(); + + BridgeConnector.Socket.On("webContents-printToPDF-completed", (success) => + { + BridgeConnector.Socket.Off("webContents-printToPDF-completed"); + taskCompletionSource.SetResult((bool)success); + }); + + if(options == null) + { + BridgeConnector.Socket.Emit("webContents-printToPDF", Id, "", path); + } + else + { + BridgeConnector.Socket.Emit("webContents-printToPDF", Id, JObject.FromObject(options, _jsonSerializer), path); + } + + return taskCompletionSource.Task; + } + + /// + /// Is used to get the Url of the loaded page. + /// It's usefull if a web-server redirects you and you need to know where it redirects. For instance, It's useful in case of Implicit Authorization. + /// + /// URL of the loaded page + public Task GetUrl() + { + var taskCompletionSource = new TaskCompletionSource(); + + var eventString = "webContents-getUrl" + Id; + BridgeConnector.Socket.On(eventString, (url) => + { + BridgeConnector.Socket.Off(eventString); + taskCompletionSource.SetResult((string)url); + }); + + BridgeConnector.Socket.Emit("webContents-getUrl", Id); + + return taskCompletionSource.Task; + } + + /// + /// The async method will resolve when the page has finished loading, + /// and rejects if the page fails to load. + /// + /// A noop rejection handler is already attached, which avoids unhandled rejection + /// errors. + /// + /// Loads the `url` in the window. The `url` must contain the protocol prefix, e.g. + /// the `http://` or `file://`. If the load should bypass http cache then use the + /// `pragma` header to achieve it. + /// + /// + public Task LoadURLAsync(string url) + { + return LoadURLAsync(url, new LoadURLOptions()); + } + + /// + /// The async method will resolve when the page has finished loading, + /// and rejects if the page fails to load. + /// + /// A noop rejection handler is already attached, which avoids unhandled rejection + /// errors. + /// + /// Loads the `url` in the window. The `url` must contain the protocol prefix, e.g. + /// the `http://` or `file://`. If the load should bypass http cache then use the + /// `pragma` header to achieve it. + /// + /// + /// + public Task LoadURLAsync(string url, LoadURLOptions options) + { + var taskCompletionSource = new TaskCompletionSource(); + + BridgeConnector.Socket.On("webContents-loadURL-complete" + Id, () => + { + BridgeConnector.Socket.Off("webContents-loadURL-complete" + Id); + BridgeConnector.Socket.Off("webContents-loadURL-error" + Id); + taskCompletionSource.SetResult(null); + }); + + BridgeConnector.Socket.On("webContents-loadURL-error" + Id, (error) => + { + BridgeConnector.Socket.Off("webContents-loadURL-error" + Id); + taskCompletionSource.SetException(new InvalidOperationException(error.ToString())); + }); + + BridgeConnector.Socket.Emit("webContents-loadURL", Id, url, JObject.FromObject(options, _jsonSerializer)); + + return taskCompletionSource.Task; + } + + /// + /// Inserts CSS into the web page. + /// See: https://www.electronjs.org/docs/api/web-contents#contentsinsertcsscss-options + /// Works for both BrowserWindows and BrowserViews. + /// + /// Whether the webContents belong to a BrowserWindow or not (the other option is a BrowserView) + /// Absolute path to the CSS file location + public void InsertCSS(bool isBrowserWindow, string path) + { + BridgeConnector.Socket.Emit("webContents-insertCSS", Id, isBrowserWindow, path); + } + + private readonly JsonSerializer _jsonSerializer = new() + { + ContractResolver = new CamelCasePropertyNamesContractResolver(), + NullValueHandling = NullValueHandling.Ignore, + DefaultValueHandling = DefaultValueHandling.Ignore + }; } \ No newline at end of file diff --git a/ElectronNET.Host/api/webContents.js b/ElectronNET.Host/api/webContents.js index 9656c08..8df9711 100644 --- a/ElectronNET.Host/api/webContents.js +++ b/ElectronNET.Host/api/webContents.js @@ -37,7 +37,7 @@ module.exports = (socket) => { } }); socket.on('webContents-getPrinters', async (id) => { - const printers = await getWindowById(id).webContents.getPrinters(); + const printers = await getWindowById(id).webContents.getPrintersAsync(); electronSocket.emit('webContents-getPrinters-completed', printers); }); socket.on('webContents-print', async (id, options = {}) => { diff --git a/ElectronNET.Host/api/webContents.js.map b/ElectronNET.Host/api/webContents.js.map index 00435e4..e993613 100644 --- a/ElectronNET.Host/api/webContents.js.map +++ b/ElectronNET.Host/api/webContents.js.map @@ -1 +1 @@ -{"version":3,"file":"webContents.js","sourceRoot":"","sources":["webContents.ts"],"names":[],"mappings":";AACA,uCAAsD;AACtD,+CAA0D;AAC1D,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AACzB,IAAI,cAAc,CAAC;AAEnB,iBAAS,CAAC,MAAc,EAAE,EAAE;IAC1B,cAAc,GAAG,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,CAAC,8BAA8B,EAAE,CAAC,EAAE,EAAE,EAAE;QAC/C,MAAM,aAAa,GAAG,aAAa,CAAC,EAAE,CAAC,CAAC;QAExC,aAAa,CAAC,WAAW,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;QACxD,aAAa,CAAC,WAAW,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;YACxD,cAAc,CAAC,IAAI,CAAC,qBAAqB,GAAG,EAAE,EAAE,MAAM,C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,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE;QAC5D,MAAM,aAAa,GAAG,aAAa,CAAC,EAAE,CAAC,CAAC;QACxC,aAAa,CAAC,WAAW,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,mCAAmC,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,eAAe,GAAG,KAAK,EAAE,EAAE;QACzF,MAAM,aAAa,GAAG,aAAa,CAAC,EAAE,CAAC,CAAC;QACxC,MAAM,SAAS,GAAG,MAAM,aAAa,CAAC,WAAW,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,EAAE,EAAE,eAAe,EAAE,eAAe,EAAE,CAAC,CAAC;QAEpH,cAAc,CAAC,IAAI,CAAC,6CAA6C,EAAE,SAAS,CAAC,CAAC;IAChF,CAAC,CAAC,CAAC;IAEH,SAAS,aAAa,CAAC,EAAU;QAC/B,IAAI,EAAE,IAAI,IAAI,EAAE;YACd,OAAO,IAAA,uCAAyB,EAAC,EAAE,GAAG,IAAI,CAAC,CAAC;SAC7C;QAED,OAAO,wBAAa,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAClC,CAAC;AACH,CAAC,CAAC"} \ No newline at end of file diff --git a/ElectronNET.Host/api/webContents.ts b/ElectronNET.Host/api/webContents.ts index f02b1c7..4bf6fdd 100644 --- a/ElectronNET.Host/api/webContents.ts +++ b/ElectronNET.Host/api/webContents.ts @@ -44,7 +44,7 @@ export = (socket: Socket) => { }); socket.on('webContents-getPrinters', async (id) => { - const printers = await getWindowById(id).webContents.getPrinters(); + const printers = await getWindowById(id).webContents.getPrintersAsync(); electronSocket.emit('webContents-getPrinters-completed', printers); });