Skip to content

Commit 9bb2552

Browse files
committed
Merge remote-tracking branch 'softworkz/submit_tests_fixes' into develop
2 parents 5dc3dbe + 9c1b688 commit 9bb2552

Some content is hidden

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

48 files changed

+1661
-59
lines changed

src/ElectronNET.API/API/ApiBase.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99

1010
public abstract class ApiBase
1111
{
12+
protected enum SocketEventNameTypes
13+
{
14+
DashesLowerFirst,
15+
NoDashUpperFirst,
16+
}
17+
1218
internal const int PropertyTimeout = 1000;
1319

1420
private readonly string objectName;
@@ -31,7 +37,7 @@ protected set
3137
}
3238
}
3339

34-
protected abstract string SocketEventCompleteSuffix { get; }
40+
protected abstract SocketEventNameTypes SocketEventNameType { get; }
3541

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

131-
var eventName = apiBase.propertyEventNames.GetOrAdd(callerName, s => $"{apiBase.objectName}-{s.StripAsync().LowerFirst()}{apiBase.SocketEventCompleteSuffix}");
137+
string eventName;
138+
139+
switch (apiBase.SocketEventNameType)
140+
{
141+
case SocketEventNameTypes.DashesLowerFirst:
142+
eventName = apiBase.propertyEventNames.GetOrAdd(callerName, s => $"{apiBase.objectName}-{s.StripAsync().LowerFirst()}-completed");
143+
break;
144+
case SocketEventNameTypes.NoDashUpperFirst:
145+
eventName = apiBase.propertyEventNames.GetOrAdd(callerName, s => $"{apiBase.objectName}{s.StripAsync()}Completed");
146+
break;
147+
default:
148+
throw new ArgumentOutOfRangeException();
149+
}
150+
132151
var messageName = apiBase.propertyMessageNames.GetOrAdd(callerName, s => apiBase.objectName + s.StripAsync());
133152

134153
BridgeConnector.Socket.On<T>(eventName, (result) =>

src/ElectronNET.API/API/App.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace ElectronNET.API
1818
/// </summary>
1919
public sealed class App : ApiBase
2020
{
21-
protected override string SocketEventCompleteSuffix => "Completed";
21+
protected override SocketEventNameTypes SocketEventNameType => SocketEventNameTypes.NoDashUpperFirst;
2222

2323
/// <summary>
2424
/// Emitted when all windows have been closed.
@@ -1298,7 +1298,20 @@ public Task<string> UserAgentFallbackAsync
12981298
{
12991299
get
13001300
{
1301-
return this.GetPropertyAsync<string>();
1301+
return Task.Run<string>(() =>
1302+
{
1303+
var taskCompletionSource = new TaskCompletionSource<string>();
1304+
1305+
BridgeConnector.Socket.On("appGetUserAgentFallbackCompleted", (result) =>
1306+
{
1307+
BridgeConnector.Socket.Off("appGetUserAgentFallbackCompleted");
1308+
taskCompletionSource.SetResult((string)result);
1309+
});
1310+
1311+
BridgeConnector.Socket.Emit("appGetUserAgentFallback");
1312+
1313+
return taskCompletionSource.Task;
1314+
});
13021315
}
13031316
}
13041317

src/ElectronNET.API/API/BrowserView.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,20 @@ public Rectangle Bounds
3535
{
3636
get
3737
{
38-
return Task.Run<Rectangle>(() =>
39-
{
40-
var taskCompletionSource = new TaskCompletionSource<Rectangle>();
38+
var taskCompletionSource = new TaskCompletionSource<Rectangle>();
4139

42-
BridgeConnector.Socket.On("browserView-getBounds-reply", (result) =>
40+
Task.Run(() =>
41+
{
42+
BridgeConnector.Socket.On<Rectangle>("browserView-getBounds-reply", (result) =>
4343
{
4444
BridgeConnector.Socket.Off("browserView-getBounds-reply");
45-
taskCompletionSource.SetResult((Rectangle)result);
45+
taskCompletionSource.SetResult(result);
4646
});
4747

4848
BridgeConnector.Socket.Emit("browserView-getBounds", Id);
49+
});
4950

50-
return taskCompletionSource.Task;
51-
}).Result;
51+
return taskCompletionSource.Task.GetAwaiter().GetResult();
5252
}
5353
set
5454
{
@@ -59,7 +59,7 @@ public Rectangle Bounds
5959
/// <summary>
6060
/// BrowserView
6161
/// </summary>
62-
internal BrowserView(int id)
62+
internal BrowserView(int id)
6363
{
6464
Id = id;
6565

src/ElectronNET.API/API/BrowserWindow.cs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace ElectronNET.API;
2323
/// </summary>
2424
public class BrowserWindow : ApiBase
2525
{
26-
protected override string SocketEventCompleteSuffix => "-completed";
26+
protected override SocketEventNameTypes SocketEventNameType => SocketEventNameTypes.DashesLowerFirst;
2727

2828
/// <summary>
2929
/// Gets the identifier.
@@ -748,10 +748,10 @@ public void SetPosition(int x, int y)
748748
{
749749
// Workaround Windows 10 / Electron Bug
750750
// https://github.com/electron/electron/issues/4045
751-
if (isWindows10())
752-
{
753-
x = x - 7;
754-
}
751+
////if (isWindows10())
752+
////{
753+
//// x = x - 7;
754+
////}
755755
this.CallMethod2(x, y);
756756
}
757757

@@ -765,10 +765,10 @@ public void SetPosition(int x, int y, bool animate)
765765
{
766766
// Workaround Windows 10 / Electron Bug
767767
// https://github.com/electron/electron/issues/4045
768-
if (isWindows10())
769-
{
770-
x = x - 7;
771-
}
768+
////if (isWindows10())
769+
////{
770+
//// x = x - 7;
771+
////}
772772
this.CallMethod3(x, y, animate);
773773
}
774774

@@ -1123,7 +1123,17 @@ public Task<bool> SetThumbarButtonsAsync(ThumbarButton[] thumbarButtons)
11231123
/// passing null will turn current window into a top-level window.
11241124
/// </summary>
11251125
/// <param name="parent"></param>
1126-
public void SetParentWindow(BrowserWindow parent) => this.CallMethod1(JObject.FromObject(parent, _jsonSerializer));
1126+
public void SetParentWindow(BrowserWindow parent)
1127+
{
1128+
if (parent == null)
1129+
{
1130+
BridgeConnector.Socket.Emit("browserWindowSetParentWindow", Id, null);
1131+
}
1132+
else
1133+
{
1134+
BridgeConnector.Socket.Emit("browserWindowSetParentWindow", Id, JObject.FromObject(parent, _jsonSerializer));
1135+
}
1136+
}
11271137

11281138
/// <summary>
11291139
/// The parent window.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace ElectronNET.API.Entities;
2+
3+
public class PageSize
4+
{
5+
private readonly string _value;
6+
7+
public PageSize()
8+
{
9+
}
10+
11+
private PageSize(string value) : this() => _value = value;
12+
13+
public double Height { get; set; }
14+
15+
public double Width { get; set; }
16+
17+
public static implicit operator string(PageSize pageSize) => pageSize?._value;
18+
19+
public static implicit operator PageSize(string value) => new(value);
20+
}

src/ElectronNET.API/API/Entities/PrintToPDFOptions.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
namespace ElectronNET.API.Entities;
1+
using ElectronNET.Converter;
2+
using Newtonsoft.Json;
3+
4+
namespace ElectronNET.API.Entities;
25

36
/// <summary>
47
///
@@ -30,7 +33,8 @@ public class PrintToPDFOptions
3033
/// `A5`, `A6`, `Legal`, `Letter`, `Tabloid`, `Ledger`, or an Object containing
3134
/// `height` and `width` in inches. Defaults to `Letter`.
3235
/// </summary>
33-
public object PageSize { get; set; } = "Letter";
36+
[JsonConverter(typeof(PageSizeConverter))]
37+
public PageSize PageSize { get; set; } = "Letter";
3438

3539
/// <summary>
3640
/// Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string,

src/ElectronNET.API/API/Entities/ProcessMetric.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace ElectronNET.API.Entities
22
{
33
/// <summary>
4-
///
4+
/// Process metrics information.
55
/// </summary>
66
public class ProcessMetric
77
{
@@ -21,11 +21,9 @@ public class ProcessMetric
2121
public CPUUsage Cpu { get; set; }
2222

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

3028
/// <summary>
3129
/// Memory information for the process.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using ElectronNET.API.Entities;
2+
using Newtonsoft.Json;
3+
using System;
4+
5+
namespace ElectronNET.Converter;
6+
7+
public class PageSizeConverter : JsonConverter<PageSize>
8+
{
9+
public override PageSize ReadJson(JsonReader reader, Type objectType, PageSize existingValue, bool hasExistingValue, JsonSerializer serializer)
10+
{
11+
if (reader.TokenType == JsonToken.String)
12+
{
13+
return (string)reader.Value;
14+
}
15+
else if (reader.TokenType == JsonToken.StartObject)
16+
{
17+
return serializer.Deserialize<PageSize>(reader);
18+
}
19+
else
20+
{
21+
throw new JsonSerializationException("Invalid value for PageSize. Expected true, false, or an object.");
22+
}
23+
}
24+
25+
public override void WriteJson(JsonWriter writer, PageSize value, JsonSerializer serializer)
26+
{
27+
if (value is null)
28+
{
29+
writer.WriteUndefined();
30+
}
31+
32+
var str = (string)value;
33+
34+
if (str is not null)
35+
{
36+
writer.WriteValue(str);
37+
}
38+
else
39+
{
40+
serializer.Serialize(writer, value);
41+
}
42+
}
43+
}

src/ElectronNET.API/Runtime/Services/SocketBridge/SocketBridgeService.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ protected override Task StopCore()
4040
private void Connect()
4141
{
4242
this.socket.Connect();
43-
this.TransitionState(LifetimeState.Started);
43+
if (this.State < LifetimeState.Started)
44+
{
45+
this.TransitionState(LifetimeState.Started);
46+
}
4447
}
4548

4649
private void Socket_BridgeDisconnected(object sender, EventArgs e)

src/ElectronNET.API/Runtime/StartupManager.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,21 @@ private BuildInfo GatherBuildInfo()
129129
{
130130
var buildInfo = new BuildInfo();
131131

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

134-
if (attributes?.Count > 0)
134+
if (electronAssembly == null)
135+
{
136+
return buildInfo;
137+
}
138+
139+
if (electronAssembly.GetName().Name == "testhost")
140+
{
141+
electronAssembly = AppDomain.CurrentDomain.GetData("ElectronTestAssembly") as Assembly ?? electronAssembly;
142+
}
143+
144+
var attributes = electronAssembly.GetCustomAttributes<AssemblyMetadataAttribute>().ToList();
145+
146+
if (attributes.Count > 0)
135147
{
136148
buildInfo.ElectronExecutable = attributes.FirstOrDefault(e => e.Key == nameof(buildInfo.ElectronExecutable))?.Value;
137149
buildInfo.ElectronVersion = attributes.FirstOrDefault(e => e.Key == nameof(buildInfo.ElectronVersion))?.Value;

0 commit comments

Comments
 (0)