Skip to content
Merged
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
23 changes: 21 additions & 2 deletions src/ElectronNET.API/API/ApiBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@

public abstract class ApiBase
{
protected enum SocketEventNameTypes
{
DashesLowerFirst,
NoDashUpperFirst,
}

internal const int PropertyTimeout = 1000;

private readonly string objectName;
Expand All @@ -31,7 +37,7 @@ protected set
}
}

protected abstract string SocketEventCompleteSuffix { get; }
protected abstract SocketEventNameTypes SocketEventNameType { get; }

protected ApiBase()
{
Expand Down Expand Up @@ -128,7 +134,20 @@ public PropertyGetter(ApiBase apiBase, string callerName, int timeoutMs)
this.tcs = new TaskCompletionSource<T>(TaskCreationOptions.RunContinuationsAsynchronously);
this.tcsTask = this.tcs.Task;

var eventName = apiBase.propertyEventNames.GetOrAdd(callerName, s => $"{apiBase.objectName}-{s.StripAsync().LowerFirst()}{apiBase.SocketEventCompleteSuffix}");
string eventName;

switch (apiBase.SocketEventNameType)
{
case SocketEventNameTypes.DashesLowerFirst:
eventName = apiBase.propertyEventNames.GetOrAdd(callerName, s => $"{apiBase.objectName}-{s.StripAsync().LowerFirst()}-completed");
break;
case SocketEventNameTypes.NoDashUpperFirst:
eventName = apiBase.propertyEventNames.GetOrAdd(callerName, s => $"{apiBase.objectName}{s.StripAsync()}Completed");
break;
default:
throw new ArgumentOutOfRangeException();
}

var messageName = apiBase.propertyMessageNames.GetOrAdd(callerName, s => apiBase.objectName + s.StripAsync());

BridgeConnector.Socket.On<T>(eventName, (result) =>
Expand Down
17 changes: 15 additions & 2 deletions src/ElectronNET.API/API/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace ElectronNET.API
/// </summary>
public sealed class App : ApiBase
{
protected override string SocketEventCompleteSuffix => "Completed";
protected override SocketEventNameTypes SocketEventNameType => SocketEventNameTypes.NoDashUpperFirst;

/// <summary>
/// Emitted when all windows have been closed.
Expand Down Expand Up @@ -1306,7 +1306,20 @@ public Task<string> UserAgentFallbackAsync
{
get
{
return this.GetPropertyAsync<string>();
return Task.Run<string>(() =>
{
var taskCompletionSource = new TaskCompletionSource<string>();

BridgeConnector.Socket.On("appGetUserAgentFallbackCompleted", (result) =>
{
BridgeConnector.Socket.Off("appGetUserAgentFallbackCompleted");
taskCompletionSource.SetResult((string)result);
});

BridgeConnector.Socket.Emit("appGetUserAgentFallback");

return taskCompletionSource.Task;
});
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/ElectronNET.API/API/BrowserView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ public Rectangle Bounds
{
get
{
return Task.Run<Rectangle>(() =>
{
var taskCompletionSource = new TaskCompletionSource<Rectangle>();
var taskCompletionSource = new TaskCompletionSource<Rectangle>();

BridgeConnector.Socket.On("browserView-getBounds-reply", (result) =>
Task.Run(() =>
{
BridgeConnector.Socket.On<Rectangle>("browserView-getBounds-reply", (result) =>
{
BridgeConnector.Socket.Off("browserView-getBounds-reply");
taskCompletionSource.SetResult((Rectangle)result);
taskCompletionSource.SetResult(result);
});

BridgeConnector.Socket.Emit("browserView-getBounds", Id);
});

return taskCompletionSource.Task;
}).Result;
return taskCompletionSource.Task.GetAwaiter().GetResult();
}
set
{
Expand Down
32 changes: 20 additions & 12 deletions src/ElectronNET.API/API/BrowserWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace ElectronNET.API;
/// </summary>
public class BrowserWindow : ApiBase
{
protected override string SocketEventCompleteSuffix => "-completed";
protected override SocketEventNameTypes SocketEventNameType => SocketEventNameTypes.DashesLowerFirst;

/// <summary>
/// Gets the identifier.
Expand Down Expand Up @@ -749,11 +749,10 @@ public void SetPosition(int x, int y)
{
// Workaround Windows 10 / Electron Bug
// https://github.com/electron/electron/issues/4045
if (isWindows10())
{
x = x - 7;
}

////if (isWindows10())
////{
//// x = x - 7;
////}
this.CallMethod2(x, y);
}

Expand All @@ -767,11 +766,10 @@ 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;
}

////if (isWindows10())
////{
//// x = x - 7;
////}
this.CallMethod3(x, y, animate);
}

Expand Down Expand Up @@ -1140,7 +1138,17 @@ public Task<bool> SetThumbarButtonsAsync(ThumbarButton[] thumbarButtons)
/// passing null will turn current window into a top-level window.
/// </summary>
/// <param name="parent"></param>
public void SetParentWindow(BrowserWindow parent) => this.CallMethod1(JObject.FromObject(parent, _jsonSerializer));
public void SetParentWindow(BrowserWindow parent)
{
if (parent == null)
{
BridgeConnector.Socket.Emit("browserWindowSetParentWindow", Id, null);
}
else
{
BridgeConnector.Socket.Emit("browserWindowSetParentWindow", Id, JObject.FromObject(parent, _jsonSerializer));
}
}

/// <summary>
/// The parent window.
Expand Down
14 changes: 8 additions & 6 deletions src/ElectronNET.API/API/Entities/Cookie.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
namespace ElectronNET.API.Entities {
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class Cookie {
public class Cookie
{
/// <summary>
/// The name of the cookie.
/// </summary>
public string Name { get; set;}
public string Name { get; set; }

/// <summary>
/// The value of the cookie.
Expand All @@ -26,7 +28,7 @@ public class Cookie {
/// <summary>
/// (optional) - The path of the cookie.
/// </summary>
public string Path { get; set; }
public string Path { get; set; }

/// <summary>
/// (optional) - Whether the cookie is marked as secure.
Expand All @@ -36,7 +38,7 @@ public class Cookie {
/// <summary>
/// (optional) - Whether the cookie is marked as HTTP only.
/// </summary>
public bool HttpOnly { get; set; }
public bool HttpOnly { get; set; }

/// <summary>
/// (optional) - Whether the cookie is a session cookie or a persistent cookie with an expiration date.
Expand All @@ -48,4 +50,4 @@ public class Cookie {
/// </summary>
public long ExpirationDate { get; set; }
}
}
}
8 changes: 3 additions & 5 deletions src/ElectronNET.API/API/Entities/ProcessMetric.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// Process metrics information.
/// </summary>
public class ProcessMetric
{
Expand All @@ -21,11 +21,9 @@ public class ProcessMetric
public CPUUsage Cpu { get; set; }

/// <summary>
/// Creation time for this process. The time is represented as number of milliseconds since epoch.
/// Since the <see cref="PId"/> can be reused after a process dies, it is useful to use both the <see cref="PId"/>
/// and the <see cref="CreationTime"/> to uniquely identify a process.
/// Creation time for this process in milliseconds since Unix epoch. Can exceed Int32 range and may contain fractional milliseconds.
/// </summary>
public int CreationTime { get; set; }
public double CreationTime { get; set; }

/// <summary>
/// Memory information for the process.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ protected override Task StopCore()
private void Connect()
{
this.socket.Connect();
this.TransitionState(LifetimeState.Started);
if (this.State < LifetimeState.Started)
{
this.TransitionState(LifetimeState.Started);
}
}

private void Socket_BridgeDisconnected(object sender, EventArgs e)
Expand Down
16 changes: 14 additions & 2 deletions src/ElectronNET.API/Runtime/StartupManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,21 @@ private BuildInfo GatherBuildInfo()
{
var buildInfo = new BuildInfo();

var attributes = Assembly.GetEntryAssembly()?.GetCustomAttributes<AssemblyMetadataAttribute>().ToList();
var electronAssembly = Assembly.GetEntryAssembly();

if (attributes?.Count > 0)
if (electronAssembly == null)
{
return buildInfo;
}

if (electronAssembly.GetName().Name == "testhost")
{
electronAssembly = AppDomain.CurrentDomain.GetData("ElectronTestAssembly") as Assembly ?? electronAssembly;
}

var attributes = electronAssembly.GetCustomAttributes<AssemblyMetadataAttribute>().ToList();

if (attributes.Count > 0)
{
buildInfo.ElectronExecutable = attributes.FirstOrDefault(e => e.Key == nameof(buildInfo.ElectronExecutable))?.Value;
buildInfo.ElectronVersion = attributes.FirstOrDefault(e => e.Key == nameof(buildInfo.ElectronVersion))?.Value;
Expand Down
46 changes: 41 additions & 5 deletions src/ElectronNET.Host/api/browserWindows.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/ElectronNET.Host/api/browserWindows.js.map

Large diffs are not rendered by default.

Loading