Skip to content

Commit d2f6308

Browse files
author
Dan Gidman
committed
Merge remote-tracking branch 'upstream/master' into bug/442
2 parents e73655b + f06b958 commit d2f6308

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2720
-998
lines changed

Changelog.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# Not released
22

3-
# 9.31.3
3+
# 11.5.1
44

55
ElectronNET.CLI:
66

7+
* New Feature: Added new build and start commandline options for single exe (thanks [nathanwienand](https://github.com/nathanwienand)) [\#506](https://github.com/ElectronNET/Electron.NET/pull/506)
78
* New Feature: Set a description of the app in `electron.manifest.json` (thanks [BurtsevC](https://github.com/BurtsevC)) [\#433](https://github.com/ElectronNET/Electron.NET/pull/433)
89
* New Feature: Set a target for the start command (thanks [gabecook](https://github.com/gabecook)) [\#463](https://github.com/ElectronNET/Electron.NET/pull/463)
910
* New Feature: `electronize init` support for F# projects (thanks [kojo12228](https://github.com/kojo12228)) [\#457](https://github.com/ElectronNET/Electron.NET/pull/457)
@@ -12,7 +13,12 @@ ElectronNET.CLI:
1213

1314
ElectronNET.API:
1415

15-
* New Feature: Native Electron 9.2.0 support, but not all new features (we search contributors)
16+
* New Feature: Native Electron 11.1.1 support, but not all new features (we search contributors)
17+
* Breaking API Changes (from native Electron 11.0): - Removed: BrowserView.{destroy, fromId, fromWebContents, getAllViews} and id property of BrowserView
18+
* New Feature: Upgrade to .NET 5 (thanks [scottkuhl](https://github.com/scottkuhl)) [\#509](https://github.com/ElectronNET/Electron.NET/pull/509)
19+
* New Feature: Adding a configurable default electron port. (thanks [aarong-av](https://github.com/aarong-av)) [\#505](https://github.com/ElectronNET/Electron.NET/pull/505)
20+
* New Feature: Added support for launching the application with a file on MacOS (thanks [dlitty](https://github.com/dlitty)) [\#478](https://github.com/ElectronNET/Electron.NET/pull/478)
21+
* Improved: Avoid Blocking Calls in App and AutoUpdater (thanks [freosc](https://github.com/freosc)) [\#474](https://github.com/ElectronNET/Electron.NET/pull/474)
1622
* Fixed bug: Set default WebPreferences.DefaultFontSize (thanks [duncanawoods](https://github.com/duncanawoods)) [\#468](https://github.com/ElectronNET/Electron.NET/pull/468)
1723

1824
# Released

ElectronNET.API/App.cs

Lines changed: 109 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,70 @@ internal set
398398
}
399399
private bool _isReady = false;
400400

401+
/// <summary>
402+
/// Emitted when a MacOS user wants to open a file with the application. The open-file event is usually emitted
403+
/// when the application is already open and the OS wants to reuse the application to open the file.
404+
/// open-file is also emitted when a file is dropped onto the dock and the application is not yet running.
405+
/// <para/>
406+
/// On Windows, you have to parse the arguments using App.CommandLine to get the filepath.
407+
/// </summary>
408+
public event Action<string> OpenFile
409+
{
410+
add
411+
{
412+
if (_openFile == null)
413+
{
414+
BridgeConnector.Socket.On("app-open-file" + GetHashCode(), (file) =>
415+
{
416+
_openFile(file.ToString());
417+
});
418+
419+
BridgeConnector.Socket.Emit("register-app-open-file-event", GetHashCode());
420+
}
421+
_openFile += value;
422+
}
423+
remove
424+
{
425+
_openFile -= value;
426+
427+
if (_openFile == null)
428+
BridgeConnector.Socket.Off("app-open-file" + GetHashCode());
429+
}
430+
}
431+
432+
private event Action<string> _openFile;
433+
434+
435+
/// <summary>
436+
/// Emitted when a MacOS user wants to open a URL with the application. Your application's Info.plist file must
437+
/// define the URL scheme within the CFBundleURLTypes key, and set NSPrincipalClass to AtomApplication.
438+
/// </summary>
439+
public event Action<string> OpenUrl
440+
{
441+
add
442+
{
443+
if (_openUrl == null)
444+
{
445+
BridgeConnector.Socket.On("app-open-url" + GetHashCode(), (url) =>
446+
{
447+
_openUrl(url.ToString());
448+
});
449+
450+
BridgeConnector.Socket.Emit("register-app-open-url-event", GetHashCode());
451+
}
452+
_openUrl += value;
453+
}
454+
remove
455+
{
456+
_openUrl -= value;
457+
458+
if (_openUrl == null)
459+
BridgeConnector.Socket.Off("app-open-url" + GetHashCode());
460+
}
461+
}
462+
463+
private event Action<string> _openUrl;
464+
401465
/// <summary>
402466
/// A <see cref="string"/> property that indicates the current application's name, which is the name in the
403467
/// application's package.json file.
@@ -407,6 +471,27 @@ internal set
407471
/// which will be preferred over name by Electron.
408472
/// </summary>
409473
public string Name
474+
{
475+
[Obsolete("Use the asynchronous version NameAsync instead")]
476+
get
477+
{
478+
return NameAsync.Result;
479+
}
480+
set
481+
{
482+
BridgeConnector.Socket.Emit("appSetName", value);
483+
}
484+
}
485+
486+
/// <summary>
487+
/// A <see cref="string"/> property that indicates the current application's name, which is the name in the
488+
/// application's package.json file.
489+
///
490+
/// Usually the name field of package.json is a short lowercase name, according to the npm modules spec. You
491+
/// should usually also specify a productName field, which is your application's full capitalized name, and
492+
/// which will be preferred over name by Electron.
493+
/// </summary>
494+
public Task<string> NameAsync
410495
{
411496
get
412497
{
@@ -423,14 +508,11 @@ public string Name
423508
BridgeConnector.Socket.Emit("appGetName");
424509

425510
return taskCompletionSource.Task;
426-
}).Result;
427-
}
428-
set
429-
{
430-
BridgeConnector.Socket.Emit("appSetName", value);
511+
});
431512
}
432513
}
433514

515+
434516
internal App()
435517
{
436518
CommandLine = new CommandLine();
@@ -1479,6 +1561,27 @@ public void SetAboutPanelOptions(AboutPanelOptions options)
14791561
/// is used.
14801562
/// </summary>
14811563
public string UserAgentFallback
1564+
{
1565+
[Obsolete("Use the asynchronous version UserAgentFallbackAsync instead")]
1566+
get
1567+
{
1568+
return UserAgentFallbackAsync.Result;
1569+
}
1570+
set
1571+
{
1572+
BridgeConnector.Socket.Emit("appSetUserAgentFallback", value);
1573+
}
1574+
}
1575+
1576+
/// <summary>
1577+
/// A <see cref="string"/> which is the user agent string Electron will use as a global fallback.
1578+
/// <para/>
1579+
/// This is the user agent that will be used when no user agent is set at the webContents or
1580+
/// session level. It is useful for ensuring that your entire app has the same user agent. Set to a
1581+
/// custom value as early as possible in your app's initialization to ensure that your overridden value
1582+
/// is used.
1583+
/// </summary>
1584+
public Task<string> UserAgentFallbackAsync
14821585
{
14831586
get
14841587
{
@@ -1495,11 +1598,7 @@ public string UserAgentFallback
14951598
BridgeConnector.Socket.Emit("appGetUserAgentFallback");
14961599

14971600
return taskCompletionSource.Task;
1498-
}).Result;
1499-
}
1500-
set
1501-
{
1502-
BridgeConnector.Socket.Emit("appSetUserAgentFallback", value);
1601+
});
15031602
}
15041603
}
15051604

ElectronNET.API/AutoUpdater.cs

Lines changed: 120 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
using ElectronNET.API.Entities;
2+
using Newtonsoft.Json;
23
using Newtonsoft.Json.Linq;
4+
using Newtonsoft.Json.Serialization;
35
using System;
6+
using System.Collections.Generic;
47
using System.Threading.Tasks;
58

69
namespace ElectronNET.API
@@ -182,11 +185,48 @@ public string UpdateConfigPath
182185
}
183186
}
184187

188+
/// <summary>
189+
/// The current application version
190+
/// </summary>
191+
public Task<SemVer> CurrentVersionAsync
192+
{
193+
get
194+
{
195+
return Task.Run<SemVer>(() =>
196+
{
197+
var taskCompletionSource = new TaskCompletionSource<SemVer>();
198+
199+
BridgeConnector.Socket.On("autoUpdater-currentVersion-get-reply", (result) =>
200+
{
201+
BridgeConnector.Socket.Off("autoUpdater-currentVersion-get-reply");
202+
SemVer version = ((JObject)result).ToObject<SemVer>();
203+
taskCompletionSource.SetResult(version);
204+
});
205+
BridgeConnector.Socket.Emit("autoUpdater-currentVersion-get");
206+
207+
return taskCompletionSource.Task;
208+
});
209+
}
210+
}
211+
185212
/// <summary>
186213
/// Get the update channel. Not applicable for GitHub.
187214
/// Doesn’t return channel from the update configuration, only if was previously set.
188215
/// </summary>
216+
[Obsolete("Use the asynchronous version ChannelAsync instead")]
189217
public string Channel
218+
{
219+
get
220+
{
221+
return ChannelAsync.Result;
222+
}
223+
}
224+
225+
/// <summary>
226+
/// Get the update channel. Not applicable for GitHub.
227+
/// Doesn’t return channel from the update configuration, only if was previously set.
228+
/// </summary>
229+
public Task<string> ChannelAsync
190230
{
191231
get
192232
{
@@ -199,11 +239,45 @@ public string Channel
199239
BridgeConnector.Socket.Off("autoUpdater-channel-get-reply");
200240
taskCompletionSource.SetResult(result.ToString());
201241
});
202-
203242
BridgeConnector.Socket.Emit("autoUpdater-channel-get");
204243

205244
return taskCompletionSource.Task;
206-
}).Result;
245+
});
246+
}
247+
}
248+
249+
250+
251+
/// <summary>
252+
/// The request headers.
253+
/// </summary>
254+
public Task<Dictionary<string, string>> RequestHeadersAsync
255+
{
256+
get
257+
{
258+
return Task.Run(() =>
259+
{
260+
var taskCompletionSource = new TaskCompletionSource<Dictionary<string, string>>();
261+
BridgeConnector.Socket.On("autoUpdater-requestHeaders-get-reply", (headers) =>
262+
{
263+
BridgeConnector.Socket.Off("autoUpdater-requestHeaders-get-reply");
264+
Dictionary<string, string> result = ((JObject)headers).ToObject<Dictionary<string, string>>();
265+
taskCompletionSource.SetResult(result);
266+
});
267+
BridgeConnector.Socket.Emit("autoUpdater-requestHeaders-get");
268+
return taskCompletionSource.Task;
269+
});
270+
}
271+
}
272+
273+
/// <summary>
274+
/// The request headers.
275+
/// </summary>
276+
public Dictionary<string, string> RequestHeaders
277+
{
278+
set
279+
{
280+
BridgeConnector.Socket.Emit("autoUpdater-requestHeaders-set", JObject.FromObject(value, _jsonSerializer));
207281
}
208282
}
209283

@@ -416,9 +490,26 @@ public Task<UpdateCheckResult> CheckForUpdatesAsync()
416490
string guid = Guid.NewGuid().ToString();
417491

418492
BridgeConnector.Socket.On("autoUpdaterCheckForUpdatesComplete" + guid, (updateCheckResult) =>
493+
{
494+
try
495+
{
496+
BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesComplete" + guid);
497+
BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesError" + guid);
498+
taskCompletionSource.SetResult(JObject.Parse(updateCheckResult.ToString()).ToObject<UpdateCheckResult>());
499+
}
500+
catch (Exception ex)
501+
{
502+
taskCompletionSource.SetException(ex);
503+
}
504+
});
505+
BridgeConnector.Socket.On("autoUpdaterCheckForUpdatesError" + guid, (error) =>
419506
{
420507
BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesComplete" + guid);
421-
taskCompletionSource.SetResult(JObject.Parse(updateCheckResult.ToString()).ToObject<UpdateCheckResult>());
508+
BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesError" + guid);
509+
string message = "An error occurred in CheckForUpdatesAsync";
510+
if (error != null && !string.IsNullOrEmpty(error.ToString()))
511+
message = JsonConvert.SerializeObject(error);
512+
taskCompletionSource.SetException(new Exception(message));
422513
});
423514

424515
BridgeConnector.Socket.Emit("autoUpdaterCheckForUpdates", guid);
@@ -438,9 +529,29 @@ public Task<UpdateCheckResult> CheckForUpdatesAndNotifyAsync()
438529
string guid = Guid.NewGuid().ToString();
439530

440531
BridgeConnector.Socket.On("autoUpdaterCheckForUpdatesAndNotifyComplete" + guid, (updateCheckResult) =>
532+
{
533+
try
534+
{
535+
BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesAndNotifyComplete" + guid);
536+
BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesAndNotifyError" + guid);
537+
if (updateCheckResult == null)
538+
taskCompletionSource.SetResult(null);
539+
else
540+
taskCompletionSource.SetResult(JObject.Parse(updateCheckResult.ToString()).ToObject<UpdateCheckResult>());
541+
}
542+
catch (Exception ex)
543+
{
544+
taskCompletionSource.SetException(ex);
545+
}
546+
});
547+
BridgeConnector.Socket.On("autoUpdaterCheckForUpdatesAndNotifyError" + guid, (error) =>
441548
{
442549
BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesAndNotifyComplete" + guid);
443-
taskCompletionSource.SetResult(JObject.Parse(updateCheckResult.ToString()).ToObject<UpdateCheckResult>());
550+
BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesAndNotifyError" + guid);
551+
string message = "An error occurred in autoUpdaterCheckForUpdatesAndNotify";
552+
if (error != null)
553+
message = JsonConvert.SerializeObject(error);
554+
taskCompletionSource.SetException(new Exception(message));
444555
});
445556

446557
BridgeConnector.Socket.Emit("autoUpdaterCheckForUpdatesAndNotify", guid);
@@ -501,5 +612,10 @@ public Task<string> GetFeedURLAsync()
501612

502613
return taskCompletionSource.Task;
503614
}
615+
616+
private readonly JsonSerializer _jsonSerializer = new JsonSerializer()
617+
{
618+
ContractResolver = new CamelCasePropertyNamesContractResolver()
619+
};
504620
}
505621
}

0 commit comments

Comments
 (0)