GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Electron.NET/src/ElectronNET.API/API/WindowManager.cs at develop · ElectronNET/Electron.NET Expand file tree/ Copy pathWindowManager.csMore file actions 226 lines (192 loc) · 7.28 KB / Copy pathWindowManager.csFile metadata and controls226 lines (192 loc) · 7.28 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 using ElectronNET.API.Entities; using ElectronNET.API.Serialization; using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Text.Json; using System.Threading.Tasks; namespace ElectronNET.API { /// <summary> /// /// </summary> public sealed class WindowManager { private static WindowManager _windowManager; private static readonly object SyncRoot = new(); internal WindowManager() { EnsureBrowserWindowClosedSubscription(); } internal static WindowManager Instance { get { if (_windowManager == null) { lock (SyncRoot) { if (_windowManager == null) { _windowManager = new WindowManager(); } } } return _windowManager; } } /// <summary> /// Quit when all windows are closed. (Default is true) /// </summary> /// <value> /// <c>true</c> if [quit window all closed]; otherwise, <c>false</c>. /// </value> public bool IsQuitOnWindowAllClosed { get => _isQuitOnWindowAllClosed; set { BridgeConnector.Socket.Emit("quit-app-window-all-closed", value); _isQuitOnWindowAllClosed = value; } } private bool _isQuitOnWindowAllClosed = true; /// <summary> /// Gets the browser windows. /// </summary> /// <value> /// The browser windows. /// </value> public IReadOnlyCollection<BrowserWindow> BrowserWindows => _browserWindows.AsReadOnly(); private readonly List<BrowserWindow> _browserWindows = new(); /// <summary> /// Gets the browser views. /// </summary> /// <value> /// The browser view. /// </value> public IReadOnlyCollection<BrowserView> BrowserViews => _browserViews.AsReadOnly(); private readonly List<BrowserView> _browserViews = new(); /// <summary> /// Creates the window asynchronous. /// </summary> /// <param name="loadUrl">The load URL.</param> /// <returns></returns> public async Task<BrowserWindow> CreateWindowAsync(string loadUrl = "http://localhost") { return await this.CreateWindowAsync(new BrowserWindowOptions(), loadUrl).ConfigureAwait(false); } /// <summary> /// Creates the window asynchronous. /// </summary> /// <param name="options">The options.</param> /// <param name="loadUrl">The load URL.</param> /// <returns></returns> public async Task<BrowserWindow> CreateWindowAsync(BrowserWindowOptions options, string loadUrl = "http://localhost") { var tcs = new TaskCompletionSource<BrowserWindow>(); BridgeConnector.Socket.Once<int>("BrowserWindowCreated", (id) => { var browserWindow = new BrowserWindow(id); _browserWindows.Add(browserWindow); tcs.SetResult(browserWindow); }); if (loadUrl.Equals("http://localhost", StringComparison.OrdinalIgnoreCase) && ElectronNetRuntime.AspNetWebPort.HasValue) { loadUrl = $"{loadUrl}:{ElectronNetRuntime.AspNetWebPort}"; } // Workaround Windows 10 / Electron Bug // https://github.com/electron/electron/issues/4045 if (IsWindows10()) { options.Width += 14; options.Height += 7; } if (!options.X.HasValue && !options.Y.HasValue) { await BridgeConnector.Socket.Emit("createBrowserWindow", options, loadUrl).ConfigureAwait(false); } else { // Workaround Windows 10 / Electron Bug // https://github.com/electron/electron/issues/4045 if (IsWindows10()) { options.X -= 7; } await BridgeConnector.Socket.Emit("createBrowserWindow", options, loadUrl).ConfigureAwait(false); } return await tcs.Task.ConfigureAwait(false); } private readonly object _browserWindowSubscriptionSync = new(); private bool _browserWindowClosedSubscribed; private void EnsureBrowserWindowClosedSubscription() { if (_browserWindowClosedSubscribed) { return; } lock (_browserWindowSubscriptionSync) { if (_browserWindowClosedSubscribed) { return; } BridgeConnector.Socket.On<int[]>("BrowserWindowClosed", HandleBrowserWindowClosed); BridgeConnector.Socket.On<int>("BrowserWindowRecreated", HandleBrowserWindowRecreated); _browserWindowClosedSubscribed = true; } } private void HandleBrowserWindowRecreated(int id) { if (_browserWindows.All(window => window.Id != id)) { _browserWindows.Add(new BrowserWindow(id)); } } private void HandleBrowserWindowClosed(int[] ids) { if (ids == null || ids.Length == 0) { _browserWindows.Clear(); return; } var existingIds = ids.ToHashSet(); _browserWindows.RemoveAll(window => !existingIds.Contains(window.Id)); } private bool IsWindows10() { return RuntimeInformation.OSDescription.Contains("Windows 10"); } /// <summary> /// 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. /// </summary> /// <returns></returns> public Task<BrowserView> CreateBrowserViewAsync() { return CreateBrowserViewAsync(new BrowserViewConstructorOptions()); } /// <summary> /// 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. /// </summary> /// <param name="options"></param> /// <returns></returns> public async Task<BrowserView> CreateBrowserViewAsync(BrowserViewConstructorOptions options) { var tcs = new TaskCompletionSource<BrowserView>(); BridgeConnector.Socket.Once<int>("BrowserViewCreated", (id) => { BrowserView browserView = new(id); _browserViews.Add(browserView); tcs.SetResult(browserView); }); await BridgeConnector.Socket.Emit("createBrowserView", options).ConfigureAwait(false); return await tcs.Task.ConfigureAwait(false); } } } |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |