Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions ElectronNET.API/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,28 @@ public string UserAgentFallback
}
}

string IApp.Name
{
get => this.NameAsync.ConfigureAwait(false).GetAwaiter().GetResult();
set => this.Name = value;
}

/// <summary>
/// Get the app name
/// </summary>
public Task<string> NameAsync => this.GetNameAsync();

string IApp.UserAgentFallback
{
get => this.GetUserAgentFallbackAsync().ConfigureAwait(false).GetAwaiter().GetResult();
set => this.UserAgentFallback = value;
}

/// <summary>
/// Get the app user agent
/// </summary>
public Task<string> UserAgentFallbackAsync => this.GetUserAgentFallbackAsync();

/// <summary>
/// A <see cref="string"/> which is the user agent string Electron will use as a global fallback.
/// <para/>
Expand Down
4 changes: 2 additions & 2 deletions ElectronNET.API/ApplicationSocket.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using ElectronNET.API.Interfaces;
using Quobject.SocketIoClientDotNet.Client;
using SocketIOClient;

namespace ElectronNET.API
{
Expand All @@ -11,6 +11,6 @@ public class ApplicationSocket : IApplicationSocket
/// <summary>
/// Socket used to communicate with main.js
/// </summary>
public Socket Socket { get; internal set; }
public SocketIO Socket { get; internal set; }
}
}
51 changes: 51 additions & 0 deletions ElectronNET.API/AutoUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,57 @@ internal static AutoUpdater Instance
}
}

bool IAutoUpdater.AutoDownload
{
get => this.IsAutoDownloadEnabledAsync().ConfigureAwait(false).GetAwaiter().GetResult();
set => this.AutoDownload = value;
}
bool IAutoUpdater.AutoInstallOnAppQuit
{
get => this.IsAutoInstallOnAppQuitEnabledAsync().ConfigureAwait(false).GetAwaiter().GetResult();
set => this.AutoInstallOnAppQuit = value;
}
bool IAutoUpdater.AllowPrerelease
{
get => this.IsAllowPrereleaseEnabledAsync().ConfigureAwait(false).GetAwaiter().GetResult();
set => this.AllowPrerelease = value;
}
bool IAutoUpdater.FullChangelog
{
get => this.IsFullChangeLogEnabledAsync().ConfigureAwait(false).GetAwaiter().GetResult();
set => this.FullChangelog = value;
}
bool IAutoUpdater.AllowDowngrade
{
get => this.IsAllowDowngradeEnabledAsync().ConfigureAwait(false).GetAwaiter().GetResult();
set => this.AllowDowngrade = value;
}

/// <summary>
/// Gets the update config path
/// </summary>
public string UpdateConfigPath => this.GetUpdateConfigPathAsync().ConfigureAwait(false).GetAwaiter().GetResult();

/// <summary>
/// Gets the current version
/// </summary>
public Task<SemVer> CurrentVersionAsync => this.GetCurrentVersionAsync();

/// <summary>
/// Gets the updater channel
/// </summary>
public string Channel => this.GetChannelAsync().ConfigureAwait(false).GetAwaiter().GetResult();

/// <summary>
/// Gets the updater channel
/// </summary>
public Task<string> ChannelAsync => this.GetChannelAsync();

/// <summary>
/// Get the request headers
/// </summary>
public Task<Dictionary<string, string>> RequestHeadersAsync => this.GetRequestHeadersAsync();

/// <summary>
/// Asks the server whether there is an update.
/// </summary>
Expand Down
20 changes: 13 additions & 7 deletions ElectronNET.API/BridgeConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,7 @@ private static SocketIO Socket
{
if (_socket is null && HybridSupport.IsElectronActive)
{
var socket = new SocketIO($"http://localhost:{BridgeSettings.SocketPort}", new SocketIOOptions()
{
EIO = 3
});
var socket = new SocketIO($"http://localhost:{BridgeSettings.SocketPort}");

socket.JsonSerializer = new CamelCaseNewtonsoftJsonSerializer(socket.Options.EIO);

Expand All @@ -283,7 +280,7 @@ private static SocketIO Socket
Console.WriteLine("BridgeConnector connected!");
};

socket.ConnectAsync().Wait();
socket.ConnectAsync().ConfigureAwait(false).GetAwaiter().GetResult();

_socket = socket;
}
Expand All @@ -299,6 +296,13 @@ private static SocketIO Socket
}
}

internal static SocketIO GetSocket() => Socket;

internal static async Task StartSocket()
{
await Task.Run(GetSocket);
}

private class CamelCaseNewtonsoftJsonSerializer : NewtonsoftJsonSerializer
{
public CamelCaseNewtonsoftJsonSerializer(int eio) : base(eio)
Expand Down Expand Up @@ -371,7 +375,8 @@ public static async Task<T> GetObjectOverSocketAsync<T>(string eventString, stri

try
{
taskCompletionSource.SetResult( ((JObject)value).ToObject<T>() );
var json = value.GetValue().GetRawText();
taskCompletionSource.SetResult(new JObject(json).ToObject<T>());
}
catch (Exception e)
{
Expand Down Expand Up @@ -405,7 +410,8 @@ public static async Task<T> GetArrayOverSocketAsync<T>(string eventString, strin

try
{
taskCompletionSource.SetResult(((JArray)value).ToObject<T>() );
var json = value.GetValue().GetRawText();
taskCompletionSource.SetResult(new JArray(json).ToObject<T>());
}
catch (Exception e)
{
Expand Down
4 changes: 2 additions & 2 deletions ElectronNET.API/Interfaces/IApplicationSocket.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Quobject.SocketIoClientDotNet.Client;
using SocketIOClient;

namespace ElectronNET.API.Interfaces
{
Expand All @@ -10,6 +10,6 @@ public interface IApplicationSocket
/// <summary>
/// Socket used to communicate with main.js
/// </summary>
Socket Socket { get; }
SocketIO Socket { get; }
}
}
7 changes: 2 additions & 5 deletions ElectronNET.API/LifetimeServiceHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
using Quobject.SocketIoClientDotNet.Client;

namespace ElectronNET.API
{
Expand All @@ -15,10 +14,8 @@ public LifetimeServiceHost(IHostApplicationLifetime lifetime)
{
lifetime.ApplicationStarted.Register(async () =>
{
// wait till the socket is open before setting app to ready
while(BridgeConnector.Socket.Io().ReadyState != Manager.ReadyStateEnum.OPEN) {
await Task.Delay(50).ConfigureAwait(false);
}
// wait till the socket is open before setting app to ready
await BridgeConnector.StartSocket();

App.Instance.IsReady = true;
Console.WriteLine("ASP.NET Core host has fully started.");
Expand Down
2 changes: 1 addition & 1 deletion ElectronNET.API/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static IServiceCollection AddElectron(this IServiceCollection services)
.AddSingleton(provider => PowerMonitor.Instance)
.AddSingleton(provider => NativeTheme.Instance)
.AddSingleton(provider => Dock.Instance)
.AddSingleton(provider => new ApplicationSocket { Socket = BridgeConnector.Socket, })
.AddSingleton(provider => new ApplicationSocket { Socket = BridgeConnector.GetSocket(), })
// this set for proper dependency injection
.AddSingleton<IIpcMain>(_ => IpcMain.Instance)
.AddSingleton<IApp>(_ => App.Instance)
Expand Down
12 changes: 6 additions & 6 deletions ElectronNET.Host/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ function startSocketApiBridge(port) {
// instead of 'require('socket.io')(port);' we need to use this workaround
// otherwise the Windows Firewall will be triggered
server = require('http').createServer();
io = require('socket.io')();
io.attach(server);
const { Server } = require('socket.io');
io = new Server(server);

server.listen(port, 'localhost');
server.on('listening', function () {
Expand Down Expand Up @@ -383,11 +383,11 @@ function startAspCoreBackend(electronPort) {
if (detachedProcess) {
console.log('Detached from ASP.NET process');
apiProcess.unref();
}

apiProcess.stderr.on('data', (data) => {
console.log(`stderr: ${data.toString()}`);
});
apiProcess.stderr.on('data', (data) => {
console.log(`stderr: ${data.toString()}`);
});
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion ElectronNET.WebApp/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"Electron.NET App": {
"commandName": "Executable",
"executablePath": "$(SolutionDir)ElectronNET.CLI\\bin\\Debug\\net5.0\\dotnet-electronize.exe",
"executablePath": "$(SolutionDir)ElectronNET.CLI\\bin\\Debug\\net6.0\\dotnet-electronize.exe",
"commandLineArgs": "start",
"workingDirectory": "$(SolutionDir)ElectronNET.WebApp"
}
Expand Down
6 changes: 3 additions & 3 deletions appveyor.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ cd ..

echo "Restore & Build WebApp Demo"
cd ElectronNet.WebApp
dotnet restore ElectronNet.WebApp.NET5.csproj
dotnet build ElectronNet.WebApp.NET5.csproj
dotnet restore ElectronNet.WebApp.csproj
dotnet build ElectronNet.WebApp.csproj

echo "Invoke electronize build in WebApp Demo"

echo "/target win (dev-build)"
electronize build /target win /dotnet-project ElectronNet.WebApp.NET5.csproj /electron-params "--publish never"
electronize build /target win /dotnet-project ElectronNet.WebApp.csproj /electron-params "--publish never"