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/AutoUpdater.cs at develop · ElectronNET/Electron.NET Expand file tree/ Copy pathAutoUpdater.csMore file actions 378 lines (338 loc) · 12.8 KB / Copy pathAutoUpdater.csFile metadata and controls378 lines (338 loc) · 12.8 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 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 using ElectronNET.API.Entities; using System; using System.Collections.Generic; using System.Threading.Tasks; // ReSharper disable InconsistentNaming namespace ElectronNET.API { /// <summary> /// Enable apps to automatically update themselves. Based on electron-updater. /// </summary> public sealed class AutoUpdater : ApiBase { protected override SocketTaskEventNameTypes SocketTaskEventNameType => SocketTaskEventNameTypes.DashesLowerFirst; protected override SocketTaskMessageNameTypes SocketTaskMessageNameType => SocketTaskMessageNameTypes.DashesLowerFirst; protected override SocketEventNameTypes SocketEventNameType => SocketEventNameTypes.DashedLower; /// <summary> /// Whether to automatically download an update when it is found. (Default is true) /// </summary> public bool AutoDownload { get { return Task.Run(() => this.InvokeAsync<bool>()).Result; } set { BridgeConnector.Socket.Emit("autoUpdater-autoDownload-set", value); } } /// <summary> /// Whether to automatically install a downloaded update on app quit (if `QuitAndInstall` was not called before). /// /// Applicable only on Windows and Linux. /// </summary> public bool AutoInstallOnAppQuit { get { return Task.Run(() => this.InvokeAsync<bool>()).Result; } set { BridgeConnector.Socket.Emit("autoUpdater-autoInstallOnAppQuit-set", value); } } /// <summary> /// *GitHub provider only.* Whether to allow update to pre-release versions. /// Defaults to "true" if application version contains prerelease components (e.g. "0.12.1-alpha.1", here "alpha" is a prerelease component), otherwise "false". /// /// If "true", downgrade will be allowed("allowDowngrade" will be set to "true"). /// </summary> public bool AllowPrerelease { get { return Task.Run(() => this.InvokeAsync<bool>()).Result; } set { BridgeConnector.Socket.Emit("autoUpdater-allowPrerelease-set", value); } } /// <summary> /// *GitHub provider only.* /// Get all release notes (from current version to latest), not just the latest (Default is false). /// </summary> public bool FullChangelog { get { return Task.Run(() => this.InvokeAsync<bool>()).Result; } set { BridgeConnector.Socket.Emit("autoUpdater-fullChangelog-set", value); } } /// <summary> /// Whether to allow version downgrade (when a user from the beta channel wants to go back to the stable channel). /// Taken in account only if channel differs (pre-release version component in terms of semantic versioning). /// Default is false. /// </summary> public bool AllowDowngrade { get { return Task.Run(() => this.InvokeAsync<bool>()).Result; } set { BridgeConnector.Socket.Emit("autoUpdater-allowDowngrade-set", value); } } /// <summary> /// For test only. /// </summary> public string UpdateConfigPath { get { return Task.Run(() => this.InvokeAsync<string>()).Result; } } /// <summary> /// The current application version /// </summary> public Task<SemVer> CurrentVersionAsync { get { return Task.Run(() => this.InvokeAsync<SemVer>()); } } /// <summary> /// Get the update channel. Not applicable for GitHub. /// Doesn’t return channel from the update configuration, only if was previously set. /// </summary> [Obsolete("Use the asynchronous version ChannelAsync instead")] public string Channel { get { return ChannelAsync.Result; } } /// <summary> /// Get the update channel. Not applicable for GitHub. /// Doesn’t return channel from the update configuration, only if was previously set. /// </summary> public Task<string> ChannelAsync { get { return Task.Run(() => this.InvokeAsync<string>()); } } /// <summary> /// Set the update channel. Not applicable for GitHub. /// </summary> public string SetChannel { set { BridgeConnector.Socket.Emit("autoUpdater-channel-set", value); } } /// <summary> /// The request headers. /// </summary> public Task<Dictionary<string, string>> RequestHeadersAsync { get { return Task.Run(() => this.InvokeAsync<Dictionary<string, string>>()); } } /// <summary> /// The request headers. /// </summary> public Dictionary<string, string> RequestHeaders { set { BridgeConnector.Socket.Emit("autoUpdater-requestHeaders-set", value); } } /// <summary> /// Emitted when there is an error while updating. /// </summary> public event Action<string> OnError { add => AddEvent(value, GetHashCode()); remove => RemoveEvent(value, GetHashCode()); } /// <summary> /// Emitted when checking if an update has started. /// </summary> public event Action OnCheckingForUpdate { add => AddEvent(value, GetHashCode()); remove => RemoveEvent(value, GetHashCode()); } /// <summary> /// Emitted when there is an available update. /// The update is downloaded automatically if AutoDownload is true. /// </summary> public event Action<UpdateInfo> OnUpdateAvailable { add => AddEvent(value, GetHashCode()); remove => RemoveEvent(value, GetHashCode()); } /// <summary> /// Emitted when there is no available update. /// </summary> public event Action<UpdateInfo> OnUpdateNotAvailable { add => AddEvent(value, GetHashCode()); remove => RemoveEvent(value, GetHashCode()); } /// <summary> /// Emitted on download progress. /// </summary> public event Action<ProgressInfo> OnDownloadProgress { add => AddEvent(value, GetHashCode()); remove => RemoveEvent(value, GetHashCode()); } /// <summary> /// Emitted on download complete. /// </summary> public event Action<UpdateInfo> OnUpdateDownloaded { add => AddEvent(value, GetHashCode()); remove => RemoveEvent(value, GetHashCode()); } private static AutoUpdater _autoUpdater; private static object _syncRoot = new object(); internal AutoUpdater() { } internal static AutoUpdater Instance { get { if (_autoUpdater == null) { lock (_syncRoot) { if (_autoUpdater == null) { _autoUpdater = new AutoUpdater(); } } } return _autoUpdater; } } /// <summary> /// Asks the server whether there is an update. /// </summary> /// <returns></returns> public Task<UpdateCheckResult> CheckForUpdatesAsync() { var taskCompletionSource = new TaskCompletionSource<UpdateCheckResult>(); string guid = Guid.NewGuid().ToString(); BridgeConnector.Socket.Once<UpdateCheckResult>("autoUpdater-checkForUpdates-completed" + guid, (result) => { try { BridgeConnector.Socket.Off("autoUpdater-checkForUpdatesError" + guid); taskCompletionSource.SetResult(result); } catch (Exception ex) { taskCompletionSource.SetException(ex); } }); BridgeConnector.Socket.Once<string>("autoUpdater-checkForUpdatesError" + guid, (result) => { BridgeConnector.Socket.Off("autoUpdater-checkForUpdates-completed" + guid); string message = "An error occurred in CheckForUpdatesAsync"; if (!string.IsNullOrEmpty(result)) message = result; taskCompletionSource.SetException(new Exception(message)); }); BridgeConnector.Socket.Emit("autoUpdater-checkForUpdates", guid); return taskCompletionSource.Task; } /// <summary> /// Asks the server whether there is an update. /// /// This will immediately download an update, then install when the app quits. /// </summary> /// <returns></returns> public Task<UpdateCheckResult> CheckForUpdatesAndNotifyAsync() { var taskCompletionSource = new TaskCompletionSource<UpdateCheckResult>(); string guid = Guid.NewGuid().ToString(); BridgeConnector.Socket.Once<UpdateCheckResult>("autoUpdater-checkForUpdatesAndNotify-completed" + guid, (result) => { try { BridgeConnector.Socket.Off("autoUpdater-checkForUpdatesAndNotifyError" + guid); taskCompletionSource.SetResult(result); } catch (Exception ex) { taskCompletionSource.SetException(ex); } }); BridgeConnector.Socket.Once<string>("autoUpdater-checkForUpdatesAndNotifyError" + guid, (result) => { BridgeConnector.Socket.Off("autoUpdater-checkForUpdatesAndNotify-completed" + guid); string message = "An error occurred in CheckForUpdatesAndNotifyAsync"; if (!string.IsNullOrEmpty(result)) message = result; taskCompletionSource.SetException(new Exception(message)); }); BridgeConnector.Socket.Emit("autoUpdater-checkForUpdatesAndNotify", guid); return taskCompletionSource.Task; } /// <summary> /// Restarts the app and installs the update after it has been downloaded. /// It should only be called after `update-downloaded` has been emitted. /// /// Note: QuitAndInstall() will close all application windows first and only emit `before-quit` event on `app` after that. /// This is different from the normal quit event sequence. /// </summary> /// <param name="isSilent">*windows-only* Runs the installer in silent mode. Defaults to `false`.</param> /// <param name="isForceRunAfter">Run the app after finish even on silent install. Not applicable for macOS. Ignored if `isSilent` is set to `false`.</param> public void QuitAndInstall(bool isSilent = false, bool isForceRunAfter = false) { BridgeConnector.Socket.Emit("autoUpdater-quitAndInstall", isSilent, isForceRunAfter); } /// <summary> /// Start downloading update manually. You can use this method if "AutoDownload" option is set to "false". /// </summary> /// <returns>Path to downloaded file.</returns> public Task<string> DownloadUpdateAsync() { var tcs = new TaskCompletionSource<string>(); string guid = Guid.NewGuid().ToString(); BridgeConnector.Socket.Once<string>("autoUpdater-downloadUpdate-completed" + guid, tcs.SetResult); BridgeConnector.Socket.Emit("autoUpdater-downloadUpdate", guid); return tcs.Task; } /// <summary> /// Feed URL. /// </summary> /// <returns>Feed URL.</returns> public Task<string> GetFeedURLAsync() { var tcs = new TaskCompletionSource<string>(); string guid = Guid.NewGuid().ToString(); BridgeConnector.Socket.Once<string>("autoUpdater-getFeedURL-completed" + guid, tcs.SetResult); BridgeConnector.Socket.Emit("autoUpdater-getFeedURL", guid); return tcs.Task; } } } |
| You are visitor 01402520 — 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. |