mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-09-22 23:15:25 +00:00
Merge pull request #917 from Denny09310/feature/system-text-json
refactor: Migrating from Newtonsoft.Json to System.Text.Json
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
using ElectronNET.API.Serialization;
|
||||
using ElectronNET.Common;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using ElectronNET.Common;
|
||||
|
||||
public abstract class ApiBase
|
||||
{
|
||||
@@ -156,8 +158,19 @@
|
||||
|
||||
lock (this)
|
||||
{
|
||||
this.tcs?.SetResult(result);
|
||||
this.tcs = null;
|
||||
try
|
||||
{
|
||||
var value = result;
|
||||
this.tcs?.SetResult(value);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.tcs?.TrySetException(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.tcs = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -170,7 +183,7 @@
|
||||
BridgeConnector.Socket.Emit(messageName);
|
||||
}
|
||||
|
||||
System.Threading.Tasks.Task.Delay(ApiBase.PropertyTimeout).ContinueWith(_ =>
|
||||
System.Threading.Tasks.Task.Delay(PropertyTimeout).ContinueWith(_ =>
|
||||
{
|
||||
if (this.tcs != null)
|
||||
{
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
using ElectronNET.API.Entities;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using ElectronNET.API.Entities;
|
||||
using ElectronNET.API.Extensions;
|
||||
using ElectronNET.API.Serialization;
|
||||
using ElectronNET.Common;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ElectronNET.API.Extensions;
|
||||
using ElectronNET.Common;
|
||||
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
@@ -271,7 +270,7 @@ namespace ElectronNET.API
|
||||
/// <returns><see langword="true"/> when Chrome's accessibility support is enabled, <see langword="false"/> otherwise.</returns>
|
||||
public event Action<bool> AccessibilitySupportChanged
|
||||
{
|
||||
add => ApiEventManager.AddEvent("app-accessibility-support-changed", GetHashCode(), _accessibilitySupportChanged, value, (args) => (bool)args);
|
||||
add => ApiEventManager.AddEvent("app-accessibility-support-changed", GetHashCode(), _accessibilitySupportChanged, value, (args) => args.GetBoolean());
|
||||
remove => ApiEventManager.RemoveEvent("app-accessibility-support-changed", GetHashCode(), _accessibilitySupportChanged, value);
|
||||
}
|
||||
|
||||
@@ -414,10 +413,7 @@ namespace ElectronNET.API
|
||||
private static App _app;
|
||||
private static object _syncRoot = new object();
|
||||
|
||||
private readonly JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver()
|
||||
};
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Try to close all windows. The <see cref="BeforeQuit"/> event will be emitted first. If all windows are successfully
|
||||
@@ -475,7 +471,7 @@ namespace ElectronNET.API
|
||||
/// <param name="relaunchOptions">Options for the relaunch.</param>
|
||||
public void Relaunch(RelaunchOptions relaunchOptions)
|
||||
{
|
||||
this.CallMethod1(JObject.FromObject(relaunchOptions, _jsonSerializer));
|
||||
this.CallMethod1(relaunchOptions);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -495,7 +491,7 @@ namespace ElectronNET.API
|
||||
/// </summary>
|
||||
public void Focus(FocusOptions focusOptions)
|
||||
{
|
||||
this.CallMethod1(JObject.FromObject(focusOptions, _jsonSerializer));
|
||||
this.CallMethod1(focusOptions);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -551,11 +547,11 @@ namespace ElectronNET.API
|
||||
var taskCompletionSource = new TaskCompletionSource<string>();
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.Socket.On("appGetPathCompleted", (path) =>
|
||||
BridgeConnector.Socket.On<string>("appGetPathCompleted", (path) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("appGetPathCompleted");
|
||||
|
||||
taskCompletionSource.SetResult(path.ToString());
|
||||
taskCompletionSource.SetResult(path);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("appGetPath", pathName.GetDescription());
|
||||
@@ -720,10 +716,10 @@ namespace ElectronNET.API
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.Socket.On("appSetAsDefaultProtocolClientCompleted", (success) =>
|
||||
BridgeConnector.Socket.On<bool>("appSetAsDefaultProtocolClientCompleted", (success) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("appSetAsDefaultProtocolClientCompleted");
|
||||
taskCompletionSource.SetResult((bool)success);
|
||||
taskCompletionSource.SetResult(success);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("appSetAsDefaultProtocolClient", protocol, path, args);
|
||||
@@ -774,10 +770,10 @@ namespace ElectronNET.API
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.Socket.On("appRemoveAsDefaultProtocolClientCompleted", (success) =>
|
||||
BridgeConnector.Socket.On<bool>("appRemoveAsDefaultProtocolClientCompleted", (success) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("appRemoveAsDefaultProtocolClientCompleted");
|
||||
taskCompletionSource.SetResult((bool)success);
|
||||
taskCompletionSource.SetResult(success);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("appRemoveAsDefaultProtocolClient", protocol, path, args);
|
||||
@@ -846,10 +842,10 @@ namespace ElectronNET.API
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.Socket.On("appIsDefaultProtocolClientCompleted", (success) =>
|
||||
BridgeConnector.Socket.On<bool>("appIsDefaultProtocolClientCompleted", (success) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("appIsDefaultProtocolClientCompleted");
|
||||
taskCompletionSource.SetResult((bool)success);
|
||||
taskCompletionSource.SetResult(success);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("appIsDefaultProtocolClient", protocol, path, args);
|
||||
@@ -874,13 +870,13 @@ namespace ElectronNET.API
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.Socket.On("appSetUserTasksCompleted", (success) =>
|
||||
BridgeConnector.Socket.On<bool>("appSetUserTasksCompleted", (success) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("appSetUserTasksCompleted");
|
||||
taskCompletionSource.SetResult((bool)success);
|
||||
taskCompletionSource.SetResult(success);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("appSetUserTasks", JArray.FromObject(userTasks, _jsonSerializer));
|
||||
BridgeConnector.Socket.Emit("appSetUserTasks", userTasks);
|
||||
|
||||
return await taskCompletionSource.Task
|
||||
.ConfigureAwait(false);
|
||||
@@ -916,7 +912,7 @@ namespace ElectronNET.API
|
||||
/// <param name="categories">Array of <see cref="JumpListCategory"/> objects.</param>
|
||||
public void SetJumpList(JumpListCategory[] categories)
|
||||
{
|
||||
this.CallMethod1(JArray.FromObject(categories, _jsonSerializer));
|
||||
this.CallMethod1(categories);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -947,19 +943,21 @@ namespace ElectronNET.API
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.Socket.On("appRequestSingleInstanceLockCompleted", (success) =>
|
||||
BridgeConnector.Socket.On<bool>("appRequestSingleInstanceLockCompleted", (success) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("appRequestSingleInstanceLockCompleted");
|
||||
taskCompletionSource.SetResult((bool)success);
|
||||
taskCompletionSource.SetResult(success);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Off("secondInstance");
|
||||
BridgeConnector.Socket.On("secondInstance", (result) =>
|
||||
BridgeConnector.Socket.On<JsonElement>("secondInstance", (result) =>
|
||||
{
|
||||
JArray results = (JArray)result;
|
||||
string[] args = results.First.ToObject<string[]>();
|
||||
string workingDirectory = results.Last.ToObject<string>();
|
||||
|
||||
var arr = result.EnumerateArray();
|
||||
var e = arr.GetEnumerator();
|
||||
e.MoveNext();
|
||||
var args = e.Current.Deserialize<string[]>(JsonSerializerOptions.Default);
|
||||
e.MoveNext();
|
||||
var workingDirectory = e.Current.GetString();
|
||||
newInstanceOpened(args, workingDirectory);
|
||||
});
|
||||
|
||||
@@ -1071,13 +1069,13 @@ namespace ElectronNET.API
|
||||
var taskCompletionSource = new TaskCompletionSource<int>();
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.Socket.On("appImportCertificateCompleted", (result) =>
|
||||
BridgeConnector.Socket.On<int>("appImportCertificateCompleted", (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("appImportCertificateCompleted");
|
||||
taskCompletionSource.SetResult((int)result);
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("appImportCertificate", JObject.FromObject(options, _jsonSerializer));
|
||||
BridgeConnector.Socket.Emit("appImportCertificate", options);
|
||||
|
||||
return await taskCompletionSource.Task
|
||||
.ConfigureAwait(false);
|
||||
@@ -1127,10 +1125,10 @@ namespace ElectronNET.API
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.Socket.On("appSetBadgeCountCompleted", (success) =>
|
||||
BridgeConnector.Socket.On<bool>("appSetBadgeCountCompleted", (success) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("appSetBadgeCountCompleted");
|
||||
taskCompletionSource.SetResult((bool)success);
|
||||
taskCompletionSource.SetResult(success);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("appSetBadgeCount", count);
|
||||
@@ -1187,12 +1185,9 @@ namespace ElectronNET.API
|
||||
var taskCompletionSource = new TaskCompletionSource<LoginItemSettings>();
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.Socket.On("appGetLoginItemSettingsCompleted", (loginItemSettings) =>
|
||||
BridgeConnector.Socket.On<LoginItemSettings>("appGetLoginItemSettingsCompleted", (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("appGetLoginItemSettingsCompleted");
|
||||
|
||||
var result = ((JObject)loginItemSettings).ToObject<LoginItemSettings>();
|
||||
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
|
||||
@@ -1202,7 +1197,7 @@ namespace ElectronNET.API
|
||||
}
|
||||
else
|
||||
{
|
||||
BridgeConnector.Socket.Emit("appGetLoginItemSettings", JObject.FromObject(options, _jsonSerializer));
|
||||
BridgeConnector.Socket.Emit("appGetLoginItemSettings", options);
|
||||
}
|
||||
|
||||
return await taskCompletionSource.Task
|
||||
@@ -1218,7 +1213,7 @@ namespace ElectronNET.API
|
||||
/// <param name="loginSettings"></param>
|
||||
public void SetLoginItemSettings(LoginSettings loginSettings)
|
||||
{
|
||||
this.CallMethod1(JObject.FromObject(loginSettings, _jsonSerializer));
|
||||
this.CallMethod1(loginSettings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1270,7 +1265,7 @@ namespace ElectronNET.API
|
||||
/// <param name="options">About panel options.</param>
|
||||
public void SetAboutPanelOptions(AboutPanelOptions options)
|
||||
{
|
||||
this.CallMethod1(JObject.FromObject(options, _jsonSerializer));
|
||||
this.CallMethod1(options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1306,14 +1301,14 @@ namespace ElectronNET.API
|
||||
{
|
||||
get
|
||||
{
|
||||
return Task.Run<string>(() =>
|
||||
return Task.Run(() =>
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<string>();
|
||||
|
||||
BridgeConnector.Socket.On("appGetUserAgentFallbackCompleted", (result) =>
|
||||
BridgeConnector.Socket.On<string>("appGetUserAgentFallbackCompleted", (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("appGetUserAgentFallbackCompleted");
|
||||
taskCompletionSource.SetResult((string)result);
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("appGetUserAgentFallback");
|
||||
@@ -1364,4 +1359,4 @@ namespace ElectronNET.API
|
||||
public async Task Once(string eventName, Action<object> action)
|
||||
=> await Events.Instance.Once(ModuleName, eventName, action).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
using ElectronNET.API.Entities;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using ElectronNET.API.Entities;
|
||||
using ElectronNET.API.Serialization;
|
||||
using ElectronNET.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using ElectronNET.Common;
|
||||
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
@@ -23,14 +22,14 @@ namespace ElectronNET.API
|
||||
{
|
||||
get
|
||||
{
|
||||
return Task.Run<bool>(() =>
|
||||
return Task.Run(() =>
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("autoUpdater-autoDownload-get-reply", (result) =>
|
||||
BridgeConnector.Socket.On<bool>("autoUpdater-autoDownload-get-reply", (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("autoUpdater-autoDownload-get-reply");
|
||||
taskCompletionSource.SetResult((bool)result);
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("autoUpdater-autoDownload-get");
|
||||
@@ -53,14 +52,14 @@ namespace ElectronNET.API
|
||||
{
|
||||
get
|
||||
{
|
||||
return Task.Run<bool>(() =>
|
||||
return Task.Run(() =>
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("autoUpdater-autoInstallOnAppQuit-get-reply", (result) =>
|
||||
BridgeConnector.Socket.On<bool>("autoUpdater-autoInstallOnAppQuit-get-reply", (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("autoUpdater-autoInstallOnAppQuit-get-reply");
|
||||
taskCompletionSource.SetResult((bool)result);
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("autoUpdater-autoInstallOnAppQuit-get");
|
||||
@@ -84,14 +83,14 @@ namespace ElectronNET.API
|
||||
{
|
||||
get
|
||||
{
|
||||
return Task.Run<bool>(() =>
|
||||
return Task.Run(() =>
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("autoUpdater-allowPrerelease-get-reply", (result) =>
|
||||
BridgeConnector.Socket.On<bool>("autoUpdater-allowPrerelease-get-reply", (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("autoUpdater-allowPrerelease-get-reply");
|
||||
taskCompletionSource.SetResult((bool)result);
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("autoUpdater-allowPrerelease-get");
|
||||
@@ -113,14 +112,14 @@ namespace ElectronNET.API
|
||||
{
|
||||
get
|
||||
{
|
||||
return Task.Run<bool>(() =>
|
||||
return Task.Run(() =>
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("autoUpdater-fullChangelog-get-reply", (result) =>
|
||||
BridgeConnector.Socket.On<bool>("autoUpdater-fullChangelog-get-reply", (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("autoUpdater-fullChangelog-get-reply");
|
||||
taskCompletionSource.SetResult((bool)result);
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("autoUpdater-fullChangelog-get");
|
||||
@@ -143,14 +142,14 @@ namespace ElectronNET.API
|
||||
{
|
||||
get
|
||||
{
|
||||
return Task.Run<bool>(() =>
|
||||
return Task.Run(() =>
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("autoUpdater-allowDowngrade-get-reply", (result) =>
|
||||
BridgeConnector.Socket.On<bool>("autoUpdater-allowDowngrade-get-reply", (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("autoUpdater-allowDowngrade-get-reply");
|
||||
taskCompletionSource.SetResult((bool)result);
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("autoUpdater-allowDowngrade-get");
|
||||
@@ -171,14 +170,14 @@ namespace ElectronNET.API
|
||||
{
|
||||
get
|
||||
{
|
||||
return Task.Run<string>(() =>
|
||||
return Task.Run(() =>
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<string>();
|
||||
|
||||
BridgeConnector.Socket.On("autoUpdater-updateConfigPath-get-reply", (result) =>
|
||||
BridgeConnector.Socket.On<string>("autoUpdater-updateConfigPath-get-reply", (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("autoUpdater-updateConfigPath-get-reply");
|
||||
taskCompletionSource.SetResult(result.ToString());
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("autoUpdater-updateConfigPath-get");
|
||||
@@ -195,15 +194,14 @@ namespace ElectronNET.API
|
||||
{
|
||||
get
|
||||
{
|
||||
return Task.Run<SemVer>(() =>
|
||||
return Task.Run(() =>
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<SemVer>();
|
||||
|
||||
BridgeConnector.Socket.On("autoUpdater-currentVersion-get-reply", (result) =>
|
||||
BridgeConnector.Socket.On<SemVer>("autoUpdater-currentVersion-get-reply", (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("autoUpdater-currentVersion-get-reply");
|
||||
SemVer version = ((JObject)result).ToObject<SemVer>();
|
||||
taskCompletionSource.SetResult(version);
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
BridgeConnector.Socket.Emit("autoUpdater-currentVersion-get");
|
||||
|
||||
@@ -233,14 +231,14 @@ namespace ElectronNET.API
|
||||
{
|
||||
get
|
||||
{
|
||||
return Task.Run<string>(() =>
|
||||
return Task.Run(() =>
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<string>();
|
||||
|
||||
BridgeConnector.Socket.On("autoUpdater-channel-get-reply", (result) =>
|
||||
BridgeConnector.Socket.On<string>("autoUpdater-channel-get-reply", (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("autoUpdater-channel-get-reply");
|
||||
taskCompletionSource.SetResult(result.ToString());
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
BridgeConnector.Socket.Emit("autoUpdater-channel-get");
|
||||
|
||||
@@ -260,10 +258,9 @@ namespace ElectronNET.API
|
||||
return Task.Run(() =>
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<Dictionary<string, string>>();
|
||||
BridgeConnector.Socket.On("autoUpdater-requestHeaders-get-reply", (headers) =>
|
||||
BridgeConnector.Socket.On<Dictionary<string, string>>("autoUpdater-requestHeaders-get-reply", (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("autoUpdater-requestHeaders-get-reply");
|
||||
Dictionary<string, string> result = ((JObject)headers).ToObject<Dictionary<string, string>>();
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
BridgeConnector.Socket.Emit("autoUpdater-requestHeaders-get");
|
||||
@@ -279,7 +276,7 @@ namespace ElectronNET.API
|
||||
{
|
||||
set
|
||||
{
|
||||
BridgeConnector.Socket.Emit("autoUpdater-requestHeaders-set", JObject.FromObject(value, _jsonSerializer));
|
||||
BridgeConnector.Socket.Emit("autoUpdater-requestHeaders-set", value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -311,7 +308,7 @@ namespace ElectronNET.API
|
||||
/// </summary>
|
||||
public event Action<UpdateInfo> OnUpdateAvailable
|
||||
{
|
||||
add => ApiEventManager.AddEvent("autoUpdater-update-available", GetHashCode(), _updateAvailable, value, (args) => JObject.Parse(args.ToString()).ToObject<UpdateInfo>());
|
||||
add => ApiEventManager.AddEvent("autoUpdater-update-available", GetHashCode(), _updateAvailable, value, (args) => args.Deserialize(ElectronJsonContext.Default.UpdateInfo));
|
||||
remove => ApiEventManager.RemoveEvent("autoUpdater-update-available", GetHashCode(), _updateAvailable, value);
|
||||
}
|
||||
|
||||
@@ -322,7 +319,7 @@ namespace ElectronNET.API
|
||||
/// </summary>
|
||||
public event Action<UpdateInfo> OnUpdateNotAvailable
|
||||
{
|
||||
add => ApiEventManager.AddEvent("autoUpdater-update-not-available", GetHashCode(), _updateNotAvailable, value, (args) => JObject.Parse(args.ToString()).ToObject<UpdateInfo>());
|
||||
add => ApiEventManager.AddEvent("autoUpdater-update-not-available", GetHashCode(), _updateNotAvailable, value, (args) => args.Deserialize(ElectronJsonContext.Default.UpdateInfo));
|
||||
remove => ApiEventManager.RemoveEvent("autoUpdater-update-not-available", GetHashCode(), _updateNotAvailable, value);
|
||||
}
|
||||
|
||||
@@ -333,7 +330,7 @@ namespace ElectronNET.API
|
||||
/// </summary>
|
||||
public event Action<ProgressInfo> OnDownloadProgress
|
||||
{
|
||||
add => ApiEventManager.AddEvent("autoUpdater-download-progress", GetHashCode(), _downloadProgress, value, (args) => JObject.Parse(args.ToString()).ToObject<ProgressInfo>());
|
||||
add => ApiEventManager.AddEvent("autoUpdater-download-progress", GetHashCode(), _downloadProgress, value, (args) => args.Deserialize(ElectronJsonContext.Default.ProgressInfo));
|
||||
remove => ApiEventManager.RemoveEvent("autoUpdater-download-progress", GetHashCode(), _downloadProgress, value);
|
||||
}
|
||||
|
||||
@@ -344,7 +341,7 @@ namespace ElectronNET.API
|
||||
/// </summary>
|
||||
public event Action<UpdateInfo> OnUpdateDownloaded
|
||||
{
|
||||
add => ApiEventManager.AddEvent("autoUpdater-update-downloaded", GetHashCode(), _updateDownloaded, value, (args) => JObject.Parse(args.ToString()).ToObject<UpdateInfo>());
|
||||
add => ApiEventManager.AddEvent("autoUpdater-update-downloaded", GetHashCode(), _updateDownloaded, value, (args) => args.Deserialize(ElectronJsonContext.Default.UpdateInfo));
|
||||
remove => ApiEventManager.RemoveEvent("autoUpdater-update-downloaded", GetHashCode(), _updateDownloaded, value);
|
||||
}
|
||||
|
||||
@@ -385,26 +382,25 @@ namespace ElectronNET.API
|
||||
var taskCompletionSource = new TaskCompletionSource<UpdateCheckResult>();
|
||||
string guid = Guid.NewGuid().ToString();
|
||||
|
||||
BridgeConnector.Socket.On("autoUpdaterCheckForUpdatesComplete" + guid, (updateCheckResult) =>
|
||||
BridgeConnector.Socket.On<UpdateCheckResult>("autoUpdaterCheckForUpdatesComplete" + guid, (result) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesComplete" + guid);
|
||||
BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesError" + guid);
|
||||
taskCompletionSource.SetResult(JObject.Parse(updateCheckResult.ToString()).ToObject<UpdateCheckResult>());
|
||||
taskCompletionSource.SetResult(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
taskCompletionSource.SetException(ex);
|
||||
}
|
||||
});
|
||||
BridgeConnector.Socket.On("autoUpdaterCheckForUpdatesError" + guid, (error) =>
|
||||
BridgeConnector.Socket.On<string>("autoUpdaterCheckForUpdatesError" + guid, (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesComplete" + guid);
|
||||
BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesError" + guid);
|
||||
string message = "An error occurred in CheckForUpdatesAsync";
|
||||
if (error != null && !string.IsNullOrEmpty(error.ToString()))
|
||||
message = JsonConvert.SerializeObject(error);
|
||||
if (!string.IsNullOrEmpty(result)) message = result;
|
||||
taskCompletionSource.SetException(new Exception(message));
|
||||
});
|
||||
|
||||
@@ -424,29 +420,25 @@ namespace ElectronNET.API
|
||||
var taskCompletionSource = new TaskCompletionSource<UpdateCheckResult>();
|
||||
string guid = Guid.NewGuid().ToString();
|
||||
|
||||
BridgeConnector.Socket.On("autoUpdaterCheckForUpdatesAndNotifyComplete" + guid, (updateCheckResult) =>
|
||||
BridgeConnector.Socket.On<UpdateCheckResult>("autoUpdaterCheckForUpdatesAndNotifyComplete" + guid, (result) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesAndNotifyComplete" + guid);
|
||||
BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesAndNotifyError" + guid);
|
||||
if (updateCheckResult == null)
|
||||
taskCompletionSource.SetResult(null);
|
||||
else
|
||||
taskCompletionSource.SetResult(JObject.Parse(updateCheckResult.ToString()).ToObject<UpdateCheckResult>());
|
||||
taskCompletionSource.SetResult(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
taskCompletionSource.SetException(ex);
|
||||
}
|
||||
});
|
||||
BridgeConnector.Socket.On("autoUpdaterCheckForUpdatesAndNotifyError" + guid, (error) =>
|
||||
BridgeConnector.Socket.On<string>("autoUpdaterCheckForUpdatesAndNotifyError" + guid, (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesAndNotifyComplete" + guid);
|
||||
BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesAndNotifyError" + guid);
|
||||
string message = "An error occurred in autoUpdaterCheckForUpdatesAndNotify";
|
||||
if (error != null)
|
||||
message = JsonConvert.SerializeObject(error);
|
||||
if (!string.IsNullOrEmpty(result)) message = result;
|
||||
taskCompletionSource.SetException(new Exception(message));
|
||||
});
|
||||
|
||||
@@ -478,10 +470,10 @@ namespace ElectronNET.API
|
||||
var taskCompletionSource = new TaskCompletionSource<string>();
|
||||
string guid = Guid.NewGuid().ToString();
|
||||
|
||||
BridgeConnector.Socket.On("autoUpdaterDownloadUpdateComplete" + guid, (downloadedPath) =>
|
||||
BridgeConnector.Socket.On<string>("autoUpdaterDownloadUpdateComplete" + guid, (downloadedPath) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("autoUpdaterDownloadUpdateComplete" + guid);
|
||||
taskCompletionSource.SetResult(downloadedPath.ToString());
|
||||
taskCompletionSource.SetResult(downloadedPath);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("autoUpdaterDownloadUpdate", guid);
|
||||
@@ -498,10 +490,10 @@ namespace ElectronNET.API
|
||||
var taskCompletionSource = new TaskCompletionSource<string>();
|
||||
string guid = Guid.NewGuid().ToString();
|
||||
|
||||
BridgeConnector.Socket.On("autoUpdaterGetFeedURLComplete" + guid, (downloadedPath) =>
|
||||
BridgeConnector.Socket.On<string>("autoUpdaterGetFeedURLComplete" + guid, (downloadedPath) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("autoUpdaterGetFeedURLComplete" + guid);
|
||||
taskCompletionSource.SetResult(downloadedPath.ToString());
|
||||
taskCompletionSource.SetResult(downloadedPath);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("autoUpdaterGetFeedURL", guid);
|
||||
@@ -509,9 +501,8 @@ namespace ElectronNET.API
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
private readonly JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver()
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
using ElectronNET.API.Entities;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using ElectronNET.API.Entities;
|
||||
using ElectronNET.API.Serialization;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
/// <summary>
|
||||
/// A BrowserView can be used to embed additional web content into a BrowserWindow.
|
||||
/// It is like a child window, except that it is positioned relative to its owning window.
|
||||
/// A BrowserView can be used to embed additional web content into a BrowserWindow.
|
||||
/// It is like a child window, except that it is positioned relative to its owning window.
|
||||
/// It is meant to be an alternative to the webview tag.
|
||||
/// </summary>
|
||||
public class BrowserView
|
||||
@@ -16,9 +15,6 @@ namespace ElectronNET.API
|
||||
/// <summary>
|
||||
/// Gets the identifier.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The identifier.
|
||||
/// </value>
|
||||
public int Id { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -28,7 +24,6 @@ namespace ElectronNET.API
|
||||
|
||||
/// <summary>
|
||||
/// Resizes and moves the view to the supplied bounds relative to the window.
|
||||
///
|
||||
/// (experimental)
|
||||
/// </summary>
|
||||
public Rectangle Bounds
|
||||
@@ -52,7 +47,7 @@ namespace ElectronNET.API
|
||||
}
|
||||
set
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserView-setBounds", Id, JObject.FromObject(value, _jsonSerializer));
|
||||
BridgeConnector.Socket.Emit("browserView-setBounds", Id, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,12 +69,11 @@ namespace ElectronNET.API
|
||||
/// <param name="options"></param>
|
||||
public void SetAutoResize(AutoResizeOptions options)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserView-setAutoResize", Id, JObject.FromObject(options, _jsonSerializer));
|
||||
BridgeConnector.Socket.Emit("browserView-setAutoResize", Id, options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Color in #aarrggbb or #argb form. The alpha channel is optional.
|
||||
///
|
||||
/// (experimental)
|
||||
/// </summary>
|
||||
/// <param name="color">Color in #aarrggbb or #argb form. The alpha channel is optional.</param>
|
||||
@@ -87,11 +81,6 @@ namespace ElectronNET.API
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserView-setBackgroundColor", Id, color);
|
||||
}
|
||||
|
||||
private JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,23 +1,17 @@
|
||||
using ElectronNET.API.Entities;
|
||||
using ElectronNET.API.Entities;
|
||||
using ElectronNET.API.Extensions;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
using ElectronNET.Common;
|
||||
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace ElectronNET.API;
|
||||
|
||||
using System.Collections.Concurrent;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ElectronNET.Common;
|
||||
using System.Text.Json;
|
||||
|
||||
/// <summary>
|
||||
/// Create and control browser windows.
|
||||
@@ -469,7 +463,7 @@ public class BrowserWindow : ApiBase
|
||||
/// <param name="aspectRatio">The aspect ratio to maintain for some portion of the content view.</param>
|
||||
/// <param name="extraSize">The extra size not to be included while maintaining the aspect ratio.</param>
|
||||
public void SetAspectRatio(double aspectRatio, Size extraSize) =>
|
||||
this.CallMethod2(aspectRatio, JObject.FromObject(extraSize, _jsonSerializer));
|
||||
this.CallMethod2(aspectRatio, extraSize);
|
||||
|
||||
/// <summary>
|
||||
/// This will make a window maintain an aspect ratio. The extra size allows a developer to have space,
|
||||
@@ -486,7 +480,7 @@ public class BrowserWindow : ApiBase
|
||||
/// <param name="aspectRatio">The aspect ratio to maintain for some portion of the content view.</param>
|
||||
/// <param name="extraSize">The extra size not to be included while maintaining the aspect ratio.</param>
|
||||
public void SetAspectRatio(int aspectRatio, Size extraSize) =>
|
||||
this.CallMethod2(aspectRatio, JObject.FromObject(extraSize, _jsonSerializer));
|
||||
this.CallMethod2(aspectRatio, extraSize);
|
||||
|
||||
/// <summary>
|
||||
/// Uses Quick Look to preview a file at a given path.
|
||||
@@ -515,14 +509,14 @@ public class BrowserWindow : ApiBase
|
||||
/// Resizes and moves the window to the supplied bounds
|
||||
/// </summary>
|
||||
/// <param name="bounds"></param>
|
||||
public void SetBounds(Rectangle bounds) => this.CallMethod1(JObject.FromObject(bounds, _jsonSerializer));
|
||||
public void SetBounds(Rectangle bounds) => this.CallMethod1(bounds);
|
||||
|
||||
/// <summary>
|
||||
/// Resizes and moves the window to the supplied bounds
|
||||
/// </summary>
|
||||
/// <param name="bounds"></param>
|
||||
/// <param name="animate"></param>
|
||||
public void SetBounds(Rectangle bounds, bool animate) => this.CallMethod2(JObject.FromObject(bounds, _jsonSerializer), animate);
|
||||
public void SetBounds(Rectangle bounds, bool animate) => this.CallMethod2(bounds, animate);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the bounds asynchronous.
|
||||
@@ -534,14 +528,14 @@ public class BrowserWindow : ApiBase
|
||||
/// Resizes and moves the window’s client area (e.g. the web page) to the supplied bounds.
|
||||
/// </summary>
|
||||
/// <param name="bounds"></param>
|
||||
public void SetContentBounds(Rectangle bounds) => this.CallMethod1(JObject.FromObject(bounds, _jsonSerializer));
|
||||
public void SetContentBounds(Rectangle bounds) => this.CallMethod1(bounds);
|
||||
|
||||
/// <summary>
|
||||
/// Resizes and moves the window’s client area (e.g. the web page) to the supplied bounds.
|
||||
/// </summary>
|
||||
/// <param name="bounds"></param>
|
||||
/// <param name="animate"></param>
|
||||
public void SetContentBounds(Rectangle bounds, bool animate) => this.CallMethod2(JObject.FromObject(bounds, _jsonSerializer), animate);
|
||||
public void SetContentBounds(Rectangle bounds, bool animate) => this.CallMethod2(bounds, animate);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the content bounds asynchronous.
|
||||
@@ -749,10 +743,10 @@ public class BrowserWindow : ApiBase
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
|
||||
@@ -766,10 +760,11 @@ public class BrowserWindow : ApiBase
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
|
||||
@@ -894,7 +889,7 @@ public class BrowserWindow : ApiBase
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="options"></param>
|
||||
public void LoadURL(string url, LoadURLOptions options) => this.CallMethod2(url, JObject.FromObject(options, _jsonSerializer));
|
||||
public void LoadURL(string url, LoadURLOptions options) => this.CallMethod2(url, options);
|
||||
|
||||
/// <summary>
|
||||
/// Same as webContents.reload.
|
||||
@@ -925,13 +920,13 @@ public class BrowserWindow : ApiBase
|
||||
public void SetMenu(MenuItem[] menuItems)
|
||||
{
|
||||
menuItems.AddMenuItemsId();
|
||||
this.CallMethod1(JArray.FromObject(menuItems, _jsonSerializer));
|
||||
this.CallMethod1(menuItems);
|
||||
_items.AddRange(menuItems);
|
||||
|
||||
BridgeConnector.Socket.Off("windowMenuItemClicked");
|
||||
BridgeConnector.Socket.On("windowMenuItemClicked", (id) =>
|
||||
BridgeConnector.Socket.On<string>("windowMenuItemClicked", (id) =>
|
||||
{
|
||||
MenuItem menuItem = _items.GetMenuItem(id.ToString());
|
||||
MenuItem menuItem = _items.GetMenuItem(id);
|
||||
menuItem?.Click();
|
||||
});
|
||||
}
|
||||
@@ -967,7 +962,7 @@ public class BrowserWindow : ApiBase
|
||||
/// <param name="progress"></param>
|
||||
/// <param name="progressBarOptions"></param>
|
||||
public void SetProgressBar(double progress, ProgressBarOptions progressBarOptions) =>
|
||||
this.CallMethod2(progress, JObject.FromObject(progressBarOptions, _jsonSerializer));
|
||||
this.CallMethod2(progress, progressBarOptions);
|
||||
|
||||
/// <summary>
|
||||
/// Sets whether the window should have a shadow. On Windows and Linux does nothing.
|
||||
@@ -1015,22 +1010,22 @@ public class BrowserWindow : ApiBase
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("browserWindowSetThumbarButtons-completed", (success) =>
|
||||
BridgeConnector.Socket.On<bool>("browserWindowSetThumbarButtons-completed", (success) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("browserWindowSetThumbarButtons-completed");
|
||||
|
||||
taskCompletionSource.SetResult((bool)success);
|
||||
taskCompletionSource.SetResult(success);
|
||||
});
|
||||
|
||||
thumbarButtons.AddThumbarButtonsId();
|
||||
BridgeConnector.Socket.Emit("browserWindowSetThumbarButtons", Id, JArray.FromObject(thumbarButtons, _jsonSerializer));
|
||||
BridgeConnector.Socket.Emit("browserWindowSetThumbarButtons", Id, thumbarButtons);
|
||||
_thumbarButtons.Clear();
|
||||
_thumbarButtons.AddRange(thumbarButtons);
|
||||
|
||||
BridgeConnector.Socket.Off("thumbarButtonClicked");
|
||||
BridgeConnector.Socket.On("thumbarButtonClicked", (id) =>
|
||||
BridgeConnector.Socket.On<string>("thumbarButtonClicked", (id) =>
|
||||
{
|
||||
ThumbarButton thumbarButton = _thumbarButtons.GetThumbarButton(id.ToString());
|
||||
ThumbarButton thumbarButton = _thumbarButtons.GetThumbarButton(id);
|
||||
thumbarButton?.Click();
|
||||
});
|
||||
|
||||
@@ -1058,7 +1053,7 @@ public class BrowserWindow : ApiBase
|
||||
/// If one of those properties is not set, then neither will be used.
|
||||
/// </summary>
|
||||
/// <param name="options"></param>
|
||||
public void SetAppDetails(AppDetailsOptions options) => this.CallMethod1(JObject.FromObject(options, _jsonSerializer));
|
||||
public void SetAppDetails(AppDetailsOptions options) => this.CallMethod1(options);
|
||||
|
||||
/// <summary>
|
||||
/// Same as webContents.showDefinitionForSelection().
|
||||
@@ -1146,7 +1141,7 @@ public class BrowserWindow : ApiBase
|
||||
}
|
||||
else
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindowSetParentWindow", Id, JObject.FromObject(parent, _jsonSerializer));
|
||||
BridgeConnector.Socket.Emit("browserWindowSetParentWindow", Id, parent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1210,10 +1205,4 @@ public class BrowserWindow : ApiBase
|
||||
// This message name does not match the default ApiBase naming convention.
|
||||
BridgeConnector.Socket.Emit("browserWindow-setBrowserView", Id, browserView.Id);
|
||||
}
|
||||
|
||||
private readonly JsonSerializer _jsonSerializer = new()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore
|
||||
};
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
using ElectronNET.API.Entities;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using ElectronNET.API.Entities;
|
||||
using ElectronNET.API.Serialization;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronNET.API
|
||||
@@ -46,11 +45,11 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<string>();
|
||||
|
||||
BridgeConnector.Socket.On("clipboard-readText-Completed", (text) =>
|
||||
BridgeConnector.Socket.On<string>("clipboard-readText-Completed", (text) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("clipboard-readText-Completed");
|
||||
|
||||
taskCompletionSource.SetResult(text.ToString());
|
||||
taskCompletionSource.SetResult(text);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("clipboard-readText", type);
|
||||
@@ -77,11 +76,11 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<string>();
|
||||
|
||||
BridgeConnector.Socket.On("clipboard-readHTML-Completed", (text) =>
|
||||
BridgeConnector.Socket.On<string>("clipboard-readHTML-Completed", (text) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("clipboard-readHTML-Completed");
|
||||
|
||||
taskCompletionSource.SetResult(text.ToString());
|
||||
taskCompletionSource.SetResult(text);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("clipboard-readHTML", type);
|
||||
@@ -108,11 +107,11 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<string>();
|
||||
|
||||
BridgeConnector.Socket.On("clipboard-readRTF-Completed", (text) =>
|
||||
BridgeConnector.Socket.On<string>("clipboard-readRTF-Completed", (text) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("clipboard-readRTF-Completed");
|
||||
|
||||
taskCompletionSource.SetResult(text.ToString());
|
||||
taskCompletionSource.SetResult(text);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("clipboard-readRTF", type);
|
||||
@@ -140,11 +139,10 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<ReadBookmark>();
|
||||
|
||||
BridgeConnector.Socket.On("clipboard-readBookmark-Completed", (bookmark) =>
|
||||
BridgeConnector.Socket.On<ReadBookmark>("clipboard-readBookmark-Completed", (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("clipboard-readBookmark-Completed");
|
||||
|
||||
taskCompletionSource.SetResult(((JObject)bookmark).ToObject<ReadBookmark>());
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("clipboard-readBookmark");
|
||||
@@ -177,11 +175,10 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<string>();
|
||||
|
||||
BridgeConnector.Socket.On("clipboard-readFindText-Completed", (text) =>
|
||||
BridgeConnector.Socket.On<string>("clipboard-readFindText-Completed", (text) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("clipboard-readFindText-Completed");
|
||||
|
||||
taskCompletionSource.SetResult(text.ToString());
|
||||
taskCompletionSource.SetResult(text);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("clipboard-readFindText");
|
||||
@@ -217,11 +214,10 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<string[]>();
|
||||
|
||||
BridgeConnector.Socket.On("clipboard-availableFormats-Completed", (formats) =>
|
||||
BridgeConnector.Socket.On<string[]>("clipboard-availableFormats-Completed", (formats) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("clipboard-availableFormats-Completed");
|
||||
|
||||
taskCompletionSource.SetResult(((JArray)formats).ToObject<string[]>());
|
||||
taskCompletionSource.SetResult(formats);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("clipboard-availableFormats", type);
|
||||
@@ -236,7 +232,7 @@ namespace ElectronNET.API
|
||||
/// <param name="type"></param>
|
||||
public void Write(Data data, string type = "")
|
||||
{
|
||||
BridgeConnector.Socket.Emit("clipboard-write", JObject.FromObject(data, _jsonSerializer), type);
|
||||
BridgeConnector.Socket.Emit("clipboard-write", data, type);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -248,13 +244,10 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<NativeImage>();
|
||||
|
||||
BridgeConnector.Socket.On("clipboard-readImage-Completed", (image) =>
|
||||
BridgeConnector.Socket.On<NativeImage>("clipboard-readImage-Completed", (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("clipboard-readImage-Completed");
|
||||
|
||||
var nativeImage = ((JObject)image).ToObject<NativeImage>();
|
||||
|
||||
taskCompletionSource.SetResult(nativeImage);
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("clipboard-readImage", type);
|
||||
@@ -269,14 +262,7 @@ namespace ElectronNET.API
|
||||
/// <param name="type"></param>
|
||||
public void WriteImage(NativeImage image, string type = "")
|
||||
{
|
||||
BridgeConnector.Socket.Emit("clipboard-writeImage", JsonConvert.SerializeObject(image), type);
|
||||
BridgeConnector.Socket.Emit("clipboard-writeImage", JsonSerializer.Serialize(image, ElectronJson.Options), type);
|
||||
}
|
||||
|
||||
private JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Threading;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronNET.API
|
||||
@@ -75,10 +76,10 @@ namespace ElectronNET.API
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.Socket.On("appCommandLineHasSwitchCompleted", (result) =>
|
||||
BridgeConnector.Socket.On<bool>("appCommandLineHasSwitchCompleted", (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("appCommandLineHasSwitchCompleted");
|
||||
taskCompletionSource.SetResult((bool)result);
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("appCommandLineHasSwitch", switchName);
|
||||
@@ -103,10 +104,10 @@ namespace ElectronNET.API
|
||||
var taskCompletionSource = new TaskCompletionSource<string>();
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.Socket.On("appCommandLineGetSwitchValueCompleted", (result) =>
|
||||
BridgeConnector.Socket.On<string>("appCommandLineGetSwitchValueCompleted", (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("appCommandLineGetSwitchValueCompleted");
|
||||
taskCompletionSource.SetResult((string)result);
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("appCommandLineGetSwitchValue", switchName);
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using ElectronNET.API.Entities;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using ElectronNET.API.Serialization;
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
@@ -34,11 +32,15 @@ namespace ElectronNET.API
|
||||
{
|
||||
if (_changed == null)
|
||||
{
|
||||
BridgeConnector.Socket.On("webContents-session-cookies-changed" + Id, (args) =>
|
||||
BridgeConnector.Socket.On<JsonElement>("webContents-session-cookies-changed" + Id, (args) =>
|
||||
{
|
||||
Cookie cookie = ((JArray)args)[0].ToObject<Cookie>();
|
||||
CookieChangedCause cause = ((JArray)args)[1].ToObject<CookieChangedCause>();
|
||||
bool removed = ((JArray)args)[2].ToObject<bool>();
|
||||
var e = args.EnumerateArray().GetEnumerator();
|
||||
e.MoveNext();
|
||||
var cookie = e.Current.Deserialize<Cookie>(ElectronJson.Options);
|
||||
e.MoveNext();
|
||||
var cause = e.Current.Deserialize<CookieChangedCause>(ElectronJson.Options);
|
||||
e.MoveNext();
|
||||
var removed = e.Current.GetBoolean();
|
||||
_changed(cookie, cause, removed);
|
||||
});
|
||||
|
||||
@@ -58,11 +60,6 @@ namespace ElectronNET.API
|
||||
|
||||
private event Action<Cookie, CookieChangedCause, bool> _changed;
|
||||
|
||||
private JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
using ElectronNET.API.Entities;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using ElectronNET.API.Entities;
|
||||
using ElectronNET.API.Serialization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronNET.API
|
||||
@@ -52,18 +50,16 @@ namespace ElectronNET.API
|
||||
var taskCompletionSource = new TaskCompletionSource<string[]>();
|
||||
var guid = Guid.NewGuid().ToString();
|
||||
|
||||
BridgeConnector.Socket.On("showOpenDialogComplete" + guid, (filePaths) =>
|
||||
BridgeConnector.Socket.On<string[]>("showOpenDialogComplete" + guid, (filePaths) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("showOpenDialogComplete" + guid);
|
||||
|
||||
var result = ((JArray)filePaths).ToObject<string[]>();
|
||||
taskCompletionSource.SetResult(result);
|
||||
taskCompletionSource.SetResult(filePaths);
|
||||
});
|
||||
|
||||
|
||||
BridgeConnector.Socket.Emit("showOpenDialog",
|
||||
JObject.FromObject(browserWindow, _jsonSerializer),
|
||||
JObject.FromObject(options, _jsonSerializer), guid);
|
||||
browserWindow,
|
||||
options, guid);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
@@ -79,16 +75,15 @@ namespace ElectronNET.API
|
||||
var taskCompletionSource = new TaskCompletionSource<string>();
|
||||
var guid = Guid.NewGuid().ToString();
|
||||
|
||||
BridgeConnector.Socket.On("showSaveDialogComplete" + guid, (filename) =>
|
||||
BridgeConnector.Socket.On<string>("showSaveDialogComplete" + guid, (filename) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("showSaveDialogComplete" + guid);
|
||||
|
||||
taskCompletionSource.SetResult(filename.ToString());
|
||||
taskCompletionSource.SetResult(filename);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("showSaveDialog",
|
||||
JObject.FromObject(browserWindow, _jsonSerializer),
|
||||
JObject.FromObject(options, _jsonSerializer),
|
||||
browserWindow,
|
||||
options,
|
||||
guid);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
@@ -148,28 +143,34 @@ namespace ElectronNET.API
|
||||
var taskCompletionSource = new TaskCompletionSource<MessageBoxResult>();
|
||||
var guid = Guid.NewGuid().ToString();
|
||||
|
||||
BridgeConnector.Socket.On("showMessageBoxComplete" + guid, (args) =>
|
||||
BridgeConnector.Socket.On<JsonElement>("showMessageBoxComplete" + guid, (args) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("showMessageBoxComplete" + guid);
|
||||
|
||||
var result = ((JArray)args);
|
||||
// args is [response:int, checkboxChecked:boolean]
|
||||
var arr = args.EnumerateArray();
|
||||
var e = arr.GetEnumerator();
|
||||
e.MoveNext();
|
||||
var response = e.Current.GetInt32();
|
||||
e.MoveNext();
|
||||
var checkbox = e.Current.GetBoolean();
|
||||
|
||||
taskCompletionSource.SetResult(new MessageBoxResult
|
||||
{
|
||||
Response = (int)result.First,
|
||||
CheckboxChecked = (bool)result.Last
|
||||
Response = response,
|
||||
CheckboxChecked = checkbox
|
||||
});
|
||||
});
|
||||
|
||||
if (browserWindow == null)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("showMessageBox", JObject.FromObject(messageBoxOptions, _jsonSerializer), guid);
|
||||
BridgeConnector.Socket.Emit("showMessageBox", messageBoxOptions, guid);
|
||||
}
|
||||
else
|
||||
{
|
||||
BridgeConnector.Socket.Emit("showMessageBox",
|
||||
JObject.FromObject(browserWindow, _jsonSerializer),
|
||||
JObject.FromObject(messageBoxOptions, _jsonSerializer),
|
||||
browserWindow,
|
||||
messageBoxOptions,
|
||||
guid);
|
||||
}
|
||||
|
||||
@@ -223,18 +224,13 @@ namespace ElectronNET.API
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("showCertificateTrustDialog",
|
||||
JObject.FromObject(browserWindow, _jsonSerializer),
|
||||
JObject.FromObject(options, _jsonSerializer),
|
||||
browserWindow,
|
||||
options,
|
||||
guid);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
private JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ElectronNET.API.Entities;
|
||||
using ElectronNET.API.Extensions;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using ElectronNET.API.Serialization;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
@@ -57,10 +56,10 @@ namespace ElectronNET.API
|
||||
var taskCompletionSource = new TaskCompletionSource<int>();
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.Socket.On("dock-bounce-completed", (id) =>
|
||||
BridgeConnector.Socket.On<int>("dock-bounce-completed", (id) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("dock-bounce-completed");
|
||||
taskCompletionSource.SetResult((int)id);
|
||||
taskCompletionSource.SetResult(id);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("dock-bounce", type.GetDescription());
|
||||
@@ -109,10 +108,10 @@ namespace ElectronNET.API
|
||||
var taskCompletionSource = new TaskCompletionSource<string>();
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.Socket.On("dock-getBadge-completed", (text) =>
|
||||
BridgeConnector.Socket.On<string>("dock-getBadge-completed", (text) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("dock-getBadge-completed");
|
||||
taskCompletionSource.SetResult((string)text);
|
||||
taskCompletionSource.SetResult(text);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("dock-getBadge");
|
||||
@@ -151,10 +150,10 @@ namespace ElectronNET.API
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.Socket.On("dock-isVisible-completed", (isVisible) =>
|
||||
BridgeConnector.Socket.On<bool>("dock-isVisible-completed", (isVisible) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("dock-isVisible-completed");
|
||||
taskCompletionSource.SetResult((bool)isVisible);
|
||||
taskCompletionSource.SetResult(isVisible);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("dock-isVisible");
|
||||
@@ -186,13 +185,13 @@ namespace ElectronNET.API
|
||||
public void SetMenu(MenuItem[] menuItems)
|
||||
{
|
||||
menuItems.AddMenuItemsId();
|
||||
BridgeConnector.Socket.Emit("dock-setMenu", JArray.FromObject(menuItems, _jsonSerializer));
|
||||
BridgeConnector.Socket.Emit("dock-setMenu", new[] { menuItems });
|
||||
_items.AddRange(menuItems);
|
||||
|
||||
BridgeConnector.Socket.Off("dockMenuItemClicked");
|
||||
BridgeConnector.Socket.On("dockMenuItemClicked", (id) =>
|
||||
BridgeConnector.Socket.On<string>("dockMenuItemClicked", (id) =>
|
||||
{
|
||||
MenuItem menuItem = _items.GetMenuItem(id.ToString());
|
||||
MenuItem menuItem = _items.GetMenuItem(id);
|
||||
menuItem?.Click();
|
||||
});
|
||||
}
|
||||
@@ -208,10 +207,10 @@ namespace ElectronNET.API
|
||||
var taskCompletionSource = new TaskCompletionSource<Menu>();
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.Socket.On("dock-getMenu-completed", (menu) =>
|
||||
BridgeConnector.Socket.On<Menu>("dock-getMenu-completed", (menu) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("dock-getMenu-completed");
|
||||
taskCompletionSource.SetResult(((JObject)menu).ToObject<Menu>());
|
||||
taskCompletionSource.SetResult(menu);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("dock-getMenu");
|
||||
@@ -230,10 +229,6 @@ namespace ElectronNET.API
|
||||
BridgeConnector.Socket.Emit("dock-setIcon", image);
|
||||
}
|
||||
|
||||
private JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace ElectronNET.API.Entities
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using ElectronNET.Converter;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using ElectronNET.Converter;
|
||||
|
||||
using System.ComponentModel;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
@@ -213,7 +213,6 @@ namespace ElectronNET.API.Entities
|
||||
/// The style of window title bar. Default is default. Possible values are:
|
||||
/// 'default' | 'hidden' | 'hiddenInset' | 'customButtonsOnHover'
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public TitleBarStyle TitleBarStyle { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -256,7 +255,6 @@ namespace ElectronNET.API.Entities
|
||||
/// appearance-based, light, dark, titlebar, selection, menu, popover, sidebar,
|
||||
/// medium-light or ultra-dark.
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public Vibrancy Vibrancy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -294,3 +292,7 @@ namespace ElectronNET.API.Entities
|
||||
public string ProxyCredentials { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
/// <summary>
|
||||
/// Percentage of CPU used since the last call to getCPUUsage. First call returns 0.
|
||||
/// </summary>
|
||||
public int PercentCPUUsage { get; set; }
|
||||
public double PercentCPUUsage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The number of average idle cpu wakeups per second since the last call to
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace ElectronNET.API.Entities
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// Provide metadata about the current loaded Chrome extension
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// The cause of the change
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public enum CookieChangedCause
|
||||
{
|
||||
/// <summary>
|
||||
///The cookie was changed directly by a consumer's action.
|
||||
/// </summary>
|
||||
[JsonProperty("explicit")]
|
||||
[JsonPropertyName("explicit")]
|
||||
@explicit,
|
||||
|
||||
/// <summary>
|
||||
@@ -33,7 +32,7 @@ namespace ElectronNET.API.Entities
|
||||
/// <summary>
|
||||
/// The cookie was overwritten with an already-expired expiration date.
|
||||
/// </summary>
|
||||
[JsonProperty("expired_overwrite")]
|
||||
[JsonPropertyName("expired_overwrite")]
|
||||
expiredOverwrite
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace ElectronNET.API.Entities
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
/// <summary>
|
||||
/// Unique identifier associated with the display.
|
||||
/// </summary>
|
||||
public string Id { get; set; }
|
||||
public long Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// true for an internal display and false for an external display.
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronNET.API.Entities
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// Docs: https://electronjs.org/docs/api/structures/extension
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
@@ -10,43 +11,43 @@ namespace ElectronNET.API.Entities
|
||||
/// <summary>
|
||||
/// Canvas.
|
||||
/// </summary>
|
||||
[JsonProperty("2d_canvas")]
|
||||
[JsonPropertyName("2d_canvas")]
|
||||
public string Canvas { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Flash.
|
||||
/// </summary>
|
||||
[JsonProperty("flash_3d")]
|
||||
[JsonPropertyName("flash_3d")]
|
||||
public string Flash3D { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Flash Stage3D.
|
||||
/// </summary>
|
||||
[JsonProperty("flash_stage3d")]
|
||||
[JsonPropertyName("flash_stage3d")]
|
||||
public string FlashStage3D { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Flash Stage3D Baseline profile.
|
||||
/// </summary>
|
||||
[JsonProperty("flash_stage3d_baseline")]
|
||||
[JsonPropertyName("flash_stage3d_baseline")]
|
||||
public string FlashStage3dBaseline { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Compositing.
|
||||
/// </summary>
|
||||
[JsonProperty("gpu_compositing")]
|
||||
[JsonPropertyName("gpu_compositing")]
|
||||
public string GpuCompositing { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Multiple Raster Threads.
|
||||
/// </summary>
|
||||
[JsonProperty("multiple_raster_threads")]
|
||||
[JsonPropertyName("multiple_raster_threads")]
|
||||
public string MultipleRasterThreads { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Native GpuMemoryBuffers.
|
||||
/// </summary>
|
||||
[JsonProperty("native_gpu_memory_buffers")]
|
||||
[JsonPropertyName("native_gpu_memory_buffers")]
|
||||
public string NativeGpuMemoryBuffers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -57,19 +58,19 @@ namespace ElectronNET.API.Entities
|
||||
/// <summary>
|
||||
/// Video Decode.
|
||||
/// </summary>
|
||||
[JsonProperty("video_decode")]
|
||||
[JsonPropertyName("video_decode")]
|
||||
public string VideoDecode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Video Encode.
|
||||
/// </summary>
|
||||
[JsonProperty("video_encode")]
|
||||
[JsonPropertyName("video_encode")]
|
||||
public string VideoEncode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// VPx Video Decode.
|
||||
/// </summary>
|
||||
[JsonProperty("vpx_decode")]
|
||||
[JsonPropertyName("vpx_decode")]
|
||||
public string VpxDecode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
using Newtonsoft.Json.Converters;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
using ElectronNET.Converter;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
@@ -76,7 +75,8 @@ namespace ElectronNET.API.Entities
|
||||
/// `touchScrollStarted`, `pointerDown`, `pointerUp`, `pointerMove`,
|
||||
/// `pointerRawUpdate`, `pointerCancel` or `pointerCausedUaAction`.
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public InputEventType Type { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
@@ -21,7 +21,7 @@ namespace ElectronNET.API.Entities
|
||||
/// <summary>
|
||||
/// One of the following: "tasks" | "frequent" | "recent" | "custom"
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public JumpListCategoryType Type { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
@@ -52,7 +52,8 @@ namespace ElectronNET.API.Entities
|
||||
/// <summary>
|
||||
/// One of the following: "task" | "separator" | "file"
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public JumpListItemType Type { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
@@ -21,13 +19,11 @@ namespace ElectronNET.API.Entities
|
||||
/// Define the action of the menu item, when specified the click property will be
|
||||
/// ignored.
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public MenuRole Role { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Can be normal, separator, submenu, checkbox or radio.
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public MenuType Type { get; set; }
|
||||
|
||||
|
||||
@@ -101,3 +97,5 @@ namespace ElectronNET.API.Entities
|
||||
public string Position { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
@@ -13,7 +13,6 @@ namespace ElectronNET.API.Entities
|
||||
/// displays the same icon as "info", unless you set an icon using the "icon"
|
||||
/// option. On macOS, both "warning" and "error" display the same warning icon.
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public MessageBoxType Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -99,3 +98,5 @@ namespace ElectronNET.API.Entities
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.RegularExpressions;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
|
||||
@@ -1,25 +1,30 @@
|
||||
using System;
|
||||
using ElectronNET.API.Serialization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
internal class NativeImageJsonConverter : JsonConverter
|
||||
internal class NativeImageJsonConverter : JsonConverter<NativeImage>
|
||||
{
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
public override void Write(Utf8JsonWriter writer, NativeImage value, JsonSerializerOptions options)
|
||||
{
|
||||
if (value is NativeImage nativeImage)
|
||||
if (value is null)
|
||||
{
|
||||
var scaledImages = nativeImage.GetAllScaledImages();
|
||||
serializer.Serialize(writer, scaledImages);
|
||||
writer.WriteNullValue();
|
||||
return;
|
||||
}
|
||||
|
||||
var scaledImages = value.GetAllScaledImages();
|
||||
JsonSerializer.Serialize(writer, scaledImages, ElectronJson.Options);
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
public override NativeImage Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
var dict = serializer.Deserialize<Dictionary<float, string>>(reader);
|
||||
var dict = JsonSerializer.Deserialize<Dictionary<float, string>>(ref reader, ElectronJson.Options);
|
||||
var newDictionary = new Dictionary<float, Image>();
|
||||
foreach (var item in dict)
|
||||
{
|
||||
@@ -29,7 +34,6 @@ namespace ElectronNET.API.Entities
|
||||
|
||||
return new NativeImage(newDictionary);
|
||||
}
|
||||
|
||||
public override bool CanConvert(Type objectType) => objectType == typeof(NativeImage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
@@ -86,7 +86,7 @@ namespace ElectronNET.API.Entities
|
||||
/// <value>
|
||||
/// The show identifier.
|
||||
/// </value>
|
||||
[JsonProperty]
|
||||
[JsonInclude]
|
||||
internal string ShowID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -101,7 +101,7 @@ namespace ElectronNET.API.Entities
|
||||
/// <value>
|
||||
/// The click identifier.
|
||||
/// </value>
|
||||
[JsonProperty]
|
||||
[JsonInclude]
|
||||
internal string ClickID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -118,7 +118,7 @@ namespace ElectronNET.API.Entities
|
||||
/// <value>
|
||||
/// The close identifier.
|
||||
/// </value>
|
||||
[JsonProperty]
|
||||
[JsonInclude]
|
||||
internal string CloseID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -135,7 +135,7 @@ namespace ElectronNET.API.Entities
|
||||
/// <value>
|
||||
/// The reply identifier.
|
||||
/// </value>
|
||||
[JsonProperty]
|
||||
[JsonInclude]
|
||||
internal string ReplyID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -150,7 +150,7 @@ namespace ElectronNET.API.Entities
|
||||
/// <value>
|
||||
/// The action identifier.
|
||||
/// </value>
|
||||
[JsonProperty]
|
||||
[JsonInclude]
|
||||
internal string ActionID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
@@ -13,7 +13,7 @@ namespace ElectronNET.API.Entities
|
||||
/// detach.Defaults to last used dock state.In undocked mode it's possible to dock
|
||||
/// back.In detach mode it's not.
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public DevToolsMode Mode { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
@@ -33,7 +33,6 @@ namespace ElectronNET.API.Entities
|
||||
/// Contains which features the dialog should use. The following values are supported:
|
||||
/// 'openFile' | 'openDirectory' | 'multiSelections' | 'showHiddenFiles' | 'createDirectory' | 'promptToCreate' | 'noResolveAliases' | 'treatPackageAsDirectory'
|
||||
/// </summary>
|
||||
[JsonProperty("properties", ItemConverterType = typeof(StringEnumConverter))]
|
||||
public OpenDialogProperty[] Properties { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -58,4 +57,5 @@ namespace ElectronNET.API.Entities
|
||||
/// </example>
|
||||
public FileFilter[] Filters { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using ElectronNET.Converter;
|
||||
using Newtonsoft.Json;
|
||||
using ElectronNET.Converter;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace ElectronNET.API.Entities;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
@@ -11,7 +11,7 @@ namespace ElectronNET.API.Entities
|
||||
/// <summary>
|
||||
/// Mode for the progress bar. Can be 'none' | 'normal' | 'indeterminate' | 'error' | 'paused'.
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public ProgressBarMode Mode { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace ElectronNET.API.Entities
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
@@ -28,7 +28,6 @@ namespace ElectronNET.API.Entities
|
||||
/// Scheme of the authentication. Can be basic, digest, ntlm, negotiate.
|
||||
/// Must be provided if removing by origin.
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public Scheme Scheme { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -51,3 +50,5 @@ namespace ElectronNET.API.Entities
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using System;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
@@ -36,7 +35,6 @@ namespace ElectronNET.API.Entities
|
||||
/// hidden - The button is not shown to the user.
|
||||
/// noninteractive - The button is enabled but not interactive; no pressed button state is drawn.This value is intended for instances where the button is used in a notification.
|
||||
/// </summary>
|
||||
[JsonProperty("flags", ItemConverterType = typeof(StringEnumConverter))]
|
||||
public ThumbarButtonFlag[] Flags { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -58,4 +56,5 @@ namespace ElectronNET.API.Entities
|
||||
Icon = icon;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
@@ -10,7 +11,7 @@ namespace ElectronNET.API.Entities
|
||||
/// <summary>
|
||||
/// The default style
|
||||
/// </summary>
|
||||
[JsonProperty("default")]
|
||||
[JsonPropertyName("default")]
|
||||
defaultStyle,
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronNET.API
|
||||
@@ -52,11 +53,11 @@ namespace ElectronNET.API
|
||||
_shortcuts.Add(accelerator, function);
|
||||
|
||||
BridgeConnector.Socket.Off("globalShortcut-pressed");
|
||||
BridgeConnector.Socket.On("globalShortcut-pressed", (shortcut) =>
|
||||
BridgeConnector.Socket.On<string>("globalShortcut-pressed", (shortcut) =>
|
||||
{
|
||||
if (_shortcuts.ContainsKey(shortcut.ToString()))
|
||||
if (_shortcuts.TryGetValue(shortcut, out var action))
|
||||
{
|
||||
_shortcuts[shortcut.ToString()]();
|
||||
action();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -74,11 +75,11 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("globalShortcut-isRegisteredCompleted", (isRegistered) =>
|
||||
BridgeConnector.Socket.On<bool>("globalShortcut-isRegisteredCompleted", (isRegistered) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("globalShortcut-isRegisteredCompleted");
|
||||
|
||||
taskCompletionSource.SetResult((bool)isRegistered);
|
||||
taskCompletionSource.SetResult(isRegistered);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("globalShortcut-isRegistered", accelerator);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using ElectronNET.API.Serialization;
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronNET.API
|
||||
@@ -49,10 +48,10 @@ namespace ElectronNET.API
|
||||
/// <param name="arguments">Optional parameters.</param>
|
||||
public void Call(string socketEventName, params dynamic[] arguments)
|
||||
{
|
||||
BridgeConnector.Socket.On(socketEventName + "Error" + oneCallguid, (result) =>
|
||||
BridgeConnector.Socket.On<string>(socketEventName + "Error" + oneCallguid, (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off(socketEventName + "Error" + oneCallguid);
|
||||
Electron.Dialog.ShowErrorBox("Host Hook Exception", result.ToString());
|
||||
Electron.Dialog.ShowErrorBox("Host Hook Exception", result);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit(socketEventName, arguments, oneCallguid);
|
||||
@@ -70,14 +69,14 @@ namespace ElectronNET.API
|
||||
var taskCompletionSource = new TaskCompletionSource<T>();
|
||||
string guid = Guid.NewGuid().ToString();
|
||||
|
||||
BridgeConnector.Socket.On(socketEventName + "Error" + guid, (result) =>
|
||||
BridgeConnector.Socket.On<string>(socketEventName + "Error" + guid, (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off(socketEventName + "Error" + guid);
|
||||
Electron.Dialog.ShowErrorBox("Host Hook Exception", result.ToString());
|
||||
Electron.Dialog.ShowErrorBox("Host Hook Exception", result);
|
||||
taskCompletionSource.SetException(new Exception($"Host Hook Exception {result}"));
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.On(socketEventName + "Complete" + guid, (result) =>
|
||||
BridgeConnector.Socket.On<JsonElement>(socketEventName + "Complete" + guid, (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off(socketEventName + "Error" + guid);
|
||||
BridgeConnector.Socket.Off(socketEventName + "Complete" + guid);
|
||||
@@ -85,31 +84,11 @@ namespace ElectronNET.API
|
||||
|
||||
try
|
||||
{
|
||||
if (result.GetType().IsValueType || result is string)
|
||||
{
|
||||
data = (T)result;
|
||||
}
|
||||
else
|
||||
{
|
||||
var token = JToken.Parse(result.ToString());
|
||||
if (token is JArray)
|
||||
{
|
||||
data = token.ToObject<T>();
|
||||
}
|
||||
else if (token is JObject)
|
||||
{
|
||||
data = token.ToObject<T>();
|
||||
}
|
||||
else
|
||||
{
|
||||
data = (T)result;
|
||||
}
|
||||
}
|
||||
data = result.Deserialize<T>(ElectronJson.Options);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
taskCompletionSource.SetException(exception);
|
||||
//throw new InvalidCastException("Return value does not match with the generic type.", exception);
|
||||
}
|
||||
|
||||
taskCompletionSource.SetResult(data);
|
||||
@@ -120,11 +99,6 @@ namespace ElectronNET.API
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
private JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using ElectronNET.API.Serialization;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronNET.API
|
||||
@@ -50,7 +48,7 @@ namespace ElectronNET.API
|
||||
{
|
||||
await BridgeConnector.Socket.Emit("registerIpcMainChannel", channel).ConfigureAwait(false);
|
||||
BridgeConnector.Socket.Off(channel);
|
||||
BridgeConnector.Socket.On(channel, (args) =>
|
||||
BridgeConnector.Socket.On<System.Text.Json.JsonElement>(channel, (args) =>
|
||||
{
|
||||
List<object> objectArray = FormatArguments(args);
|
||||
|
||||
@@ -65,19 +63,10 @@ namespace ElectronNET.API
|
||||
});
|
||||
}
|
||||
|
||||
private List<object> FormatArguments(object args)
|
||||
private static List<object> FormatArguments(System.Text.Json.JsonElement args)
|
||||
{
|
||||
List<object> objectArray = ((JArray)args).ToObject<object[]>().ToList();
|
||||
|
||||
for (int index = 0; index < objectArray.Count; index++)
|
||||
{
|
||||
var item = objectArray[index];
|
||||
if (item == null)
|
||||
{
|
||||
objectArray.Remove(item);
|
||||
}
|
||||
}
|
||||
|
||||
var objectArray = args.Deserialize<object[]>(ElectronJson.Options).ToList();
|
||||
objectArray.RemoveAll(item => item is null);
|
||||
return objectArray;
|
||||
}
|
||||
|
||||
@@ -93,7 +82,7 @@ namespace ElectronNET.API
|
||||
public void OnSync(string channel, Func<object, object> listener)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("registerSyncIpcMainChannel", channel);
|
||||
BridgeConnector.Socket.On(channel, (args) =>
|
||||
BridgeConnector.Socket.On<System.Text.Json.JsonElement>(channel, (args) =>
|
||||
{
|
||||
List<object> objectArray = FormatArguments(args);
|
||||
object parameter;
|
||||
@@ -120,7 +109,7 @@ namespace ElectronNET.API
|
||||
public void Once(string channel, Action<object> listener)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("registerOnceIpcMainChannel", channel);
|
||||
BridgeConnector.Socket.Once<object>(channel, (args) =>
|
||||
BridgeConnector.Socket.Once<System.Text.Json.JsonElement>(channel, (args) =>
|
||||
{
|
||||
List<object> objectArray = FormatArguments(args);
|
||||
|
||||
@@ -155,34 +144,7 @@ namespace ElectronNET.API
|
||||
/// <param name="data">Arguments data.</param>
|
||||
public void Send(BrowserWindow browserWindow, string channel, params object[] data)
|
||||
{
|
||||
List<JObject> jobjects = new List<JObject>();
|
||||
List<JArray> jarrays = new List<JArray>();
|
||||
List<object> objects = new List<object>();
|
||||
|
||||
foreach (var parameterObject in data)
|
||||
{
|
||||
if (parameterObject.GetType().IsArray || parameterObject.GetType().IsGenericType && parameterObject is IEnumerable)
|
||||
{
|
||||
jarrays.Add(JArray.FromObject(parameterObject, _jsonSerializer));
|
||||
}
|
||||
else if (parameterObject.GetType().IsClass && !parameterObject.GetType().IsPrimitive && !(parameterObject is string))
|
||||
{
|
||||
jobjects.Add(JObject.FromObject(parameterObject, _jsonSerializer));
|
||||
}
|
||||
else if (parameterObject.GetType().IsPrimitive || (parameterObject is string))
|
||||
{
|
||||
objects.Add(parameterObject);
|
||||
}
|
||||
}
|
||||
|
||||
if (jobjects.Count > 0 || jarrays.Count > 0)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("sendToIpcRenderer", JObject.FromObject(browserWindow, _jsonSerializer), channel, jarrays.ToArray(), jobjects.ToArray(), objects.ToArray());
|
||||
}
|
||||
else
|
||||
{
|
||||
BridgeConnector.Socket.Emit("sendToIpcRenderer", JObject.FromObject(browserWindow, _jsonSerializer), channel, data);
|
||||
}
|
||||
BridgeConnector.Socket.Emit("sendToIpcRenderer", browserWindow, channel, data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -196,41 +158,9 @@ namespace ElectronNET.API
|
||||
/// <param name="data">Arguments data.</param>
|
||||
public void Send(BrowserView browserView, string channel, params object[] data)
|
||||
{
|
||||
List<JObject> jobjects = new List<JObject>();
|
||||
List<JArray> jarrays = new List<JArray>();
|
||||
List<object> objects = new List<object>();
|
||||
|
||||
foreach (var parameterObject in data)
|
||||
{
|
||||
if (parameterObject.GetType().IsArray || parameterObject.GetType().IsGenericType && parameterObject is IEnumerable)
|
||||
{
|
||||
jarrays.Add(JArray.FromObject(parameterObject, _jsonSerializer));
|
||||
}
|
||||
else if (parameterObject.GetType().IsClass && !parameterObject.GetType().IsPrimitive && !(parameterObject is string))
|
||||
{
|
||||
jobjects.Add(JObject.FromObject(parameterObject, _jsonSerializer));
|
||||
}
|
||||
else if (parameterObject.GetType().IsPrimitive || (parameterObject is string))
|
||||
{
|
||||
objects.Add(parameterObject);
|
||||
}
|
||||
}
|
||||
|
||||
if (jobjects.Count > 0 || jarrays.Count > 0)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("sendToIpcRendererBrowserView", browserView.Id, channel, jarrays.ToArray(), jobjects.ToArray(), objects.ToArray());
|
||||
}
|
||||
else
|
||||
{
|
||||
BridgeConnector.Socket.Emit("sendToIpcRendererBrowserView", browserView.Id, channel, data);
|
||||
}
|
||||
BridgeConnector.Socket.Emit("sendToIpcRendererBrowserView", browserView.Id, channel, data);
|
||||
}
|
||||
|
||||
private JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
using ElectronNET.API.Entities;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using System.Collections.Generic;
|
||||
using ElectronNET.API.Entities;
|
||||
using ElectronNET.API.Extensions;
|
||||
using System.Linq;
|
||||
using ElectronNET.API.Serialization;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
@@ -67,13 +66,13 @@ namespace ElectronNET.API
|
||||
menuItems.AddMenuItemsId();
|
||||
menuItems.AddSubmenuTypes();
|
||||
|
||||
BridgeConnector.Socket.Emit("menu-setApplicationMenu", JArray.FromObject(menuItems, _jsonSerializer));
|
||||
BridgeConnector.Socket.Emit("menu-setApplicationMenu", new[] { menuItems });
|
||||
_menuItems.AddRange(menuItems);
|
||||
|
||||
BridgeConnector.Socket.Off("menuItemClicked");
|
||||
BridgeConnector.Socket.On("menuItemClicked", (id) =>
|
||||
BridgeConnector.Socket.On<string>("menuItemClicked", (id) =>
|
||||
{
|
||||
MenuItem menuItem = _menuItems.GetMenuItem(id.ToString());
|
||||
MenuItem menuItem = _menuItems.GetMenuItem(id);
|
||||
menuItem.Click?.Invoke();
|
||||
});
|
||||
}
|
||||
@@ -98,7 +97,7 @@ namespace ElectronNET.API
|
||||
menuItems.AddMenuItemsId();
|
||||
menuItems.AddSubmenuTypes();
|
||||
|
||||
BridgeConnector.Socket.Emit("menu-setContextMenu", browserWindow.Id, JArray.FromObject(menuItems, _jsonSerializer));
|
||||
BridgeConnector.Socket.Emit("menu-setContextMenu", browserWindow.Id, menuItems);
|
||||
|
||||
if (!_contextMenuItems.ContainsKey(browserWindow.Id))
|
||||
{
|
||||
@@ -108,10 +107,14 @@ namespace ElectronNET.API
|
||||
}
|
||||
|
||||
BridgeConnector.Socket.Off("contextMenuItemClicked");
|
||||
BridgeConnector.Socket.On("contextMenuItemClicked", (results) =>
|
||||
BridgeConnector.Socket.On<JsonElement>("contextMenuItemClicked", (results) =>
|
||||
{
|
||||
var id = ((JArray)results).First.ToString();
|
||||
var browserWindowId = (int)((JArray)results).Last;
|
||||
var arr = results.EnumerateArray();
|
||||
var e = arr.GetEnumerator();
|
||||
e.MoveNext();
|
||||
var id = e.Current.GetString();
|
||||
e.MoveNext();
|
||||
var browserWindowId = e.Current.GetInt32();
|
||||
|
||||
MenuItem menuItem = _contextMenuItems[browserWindowId].GetMenuItem(id);
|
||||
menuItem.Click?.Invoke();
|
||||
@@ -127,10 +130,6 @@ namespace ElectronNET.API
|
||||
BridgeConnector.Socket.Emit("menu-contextMenuPopup", browserWindow.Id);
|
||||
}
|
||||
|
||||
private JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using ElectronNET.API.Entities;
|
||||
using ElectronNET.API.Entities;
|
||||
using ElectronNET.API.Extensions;
|
||||
using ElectronNET.Common;
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
@@ -108,13 +109,10 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<ThemeSourceMode>();
|
||||
|
||||
BridgeConnector.Socket.On("nativeTheme-themeSource-getCompleted", (themeSource) =>
|
||||
BridgeConnector.Socket.On<ThemeSourceMode>("nativeTheme-themeSource-getCompleted", (themeSource) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("nativeTheme-themeSource-getCompleted");
|
||||
|
||||
var themeSourceValue = (ThemeSourceMode)Enum.Parse(typeof(ThemeSourceMode), (string)themeSource, true);
|
||||
|
||||
taskCompletionSource.SetResult(themeSourceValue);
|
||||
taskCompletionSource.SetResult(themeSource);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("nativeTheme-themeSource-get");
|
||||
@@ -131,11 +129,10 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("nativeTheme-shouldUseDarkColors-completed", (shouldUseDarkColors) =>
|
||||
BridgeConnector.Socket.On<bool>("nativeTheme-shouldUseDarkColors-completed", (shouldUseDarkColors) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("nativeTheme-shouldUseDarkColors-completed");
|
||||
|
||||
taskCompletionSource.SetResult((bool)shouldUseDarkColors);
|
||||
taskCompletionSource.SetResult(shouldUseDarkColors);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("nativeTheme-shouldUseDarkColors");
|
||||
@@ -151,11 +148,10 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("nativeTheme-shouldUseHighContrastColors-completed", (shouldUseHighContrastColors) =>
|
||||
BridgeConnector.Socket.On<bool>("nativeTheme-shouldUseHighContrastColors-completed", (shouldUseHighContrastColors) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("nativeTheme-shouldUseHighContrastColors-completed");
|
||||
|
||||
taskCompletionSource.SetResult((bool)shouldUseHighContrastColors);
|
||||
taskCompletionSource.SetResult(shouldUseHighContrastColors);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("nativeTheme-shouldUseHighContrastColors");
|
||||
@@ -171,11 +167,10 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("nativeTheme-shouldUseInvertedColorScheme-completed", (shouldUseInvertedColorScheme) =>
|
||||
BridgeConnector.Socket.On<bool>("nativeTheme-shouldUseInvertedColorScheme-completed", (shouldUseInvertedColorScheme) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("nativeTheme-shouldUseInvertedColorScheme-completed");
|
||||
|
||||
taskCompletionSource.SetResult((bool)shouldUseInvertedColorScheme);
|
||||
taskCompletionSource.SetResult(shouldUseInvertedColorScheme);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("nativeTheme-shouldUseInvertedColorScheme");
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
using ElectronNET.API.Entities;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using ElectronNET.API.Entities;
|
||||
using ElectronNET.API.Serialization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronNET.API
|
||||
@@ -50,7 +49,7 @@ namespace ElectronNET.API
|
||||
{
|
||||
GenerateIDsForDefinedActions(notificationOptions);
|
||||
|
||||
BridgeConnector.Socket.Emit("createNotification", JObject.FromObject(notificationOptions, _jsonSerializer));
|
||||
BridgeConnector.Socket.Emit("createNotification", notificationOptions);
|
||||
}
|
||||
|
||||
private static void GenerateIDsForDefinedActions(NotificationOptions notificationOptions)
|
||||
@@ -63,7 +62,7 @@ namespace ElectronNET.API
|
||||
isActionDefined = true;
|
||||
|
||||
BridgeConnector.Socket.Off("NotificationEventShow");
|
||||
BridgeConnector.Socket.On("NotificationEventShow", (id) => { _notificationOptions.Single(x => x.ShowID == id.ToString()).OnShow(); });
|
||||
BridgeConnector.Socket.On<string>("NotificationEventShow", (id) => { _notificationOptions.Single(x => x.ShowID == id).OnShow(); });
|
||||
}
|
||||
|
||||
if (notificationOptions.OnClick != null)
|
||||
@@ -72,7 +71,7 @@ namespace ElectronNET.API
|
||||
isActionDefined = true;
|
||||
|
||||
BridgeConnector.Socket.Off("NotificationEventClick");
|
||||
BridgeConnector.Socket.On("NotificationEventClick", (id) => { _notificationOptions.Single(x => x.ClickID == id.ToString()).OnClick(); });
|
||||
BridgeConnector.Socket.On<string>("NotificationEventClick", (id) => { _notificationOptions.Single(x => x.ClickID == id).OnClick(); });
|
||||
}
|
||||
|
||||
if (notificationOptions.OnClose != null)
|
||||
@@ -81,7 +80,7 @@ namespace ElectronNET.API
|
||||
isActionDefined = true;
|
||||
|
||||
BridgeConnector.Socket.Off("NotificationEventClose");
|
||||
BridgeConnector.Socket.On("NotificationEventClose", (id) => { _notificationOptions.Single(x => x.CloseID == id.ToString()).OnClose(); });
|
||||
BridgeConnector.Socket.On<string>("NotificationEventClose", (id) => { _notificationOptions.Single(x => x.CloseID == id).OnClose(); });
|
||||
}
|
||||
|
||||
if (notificationOptions.OnReply != null)
|
||||
@@ -90,10 +89,9 @@ namespace ElectronNET.API
|
||||
isActionDefined = true;
|
||||
|
||||
BridgeConnector.Socket.Off("NotificationEventReply");
|
||||
BridgeConnector.Socket.On("NotificationEventReply", (args) =>
|
||||
BridgeConnector.Socket.On<string[]>("NotificationEventReply", (args) =>
|
||||
{
|
||||
var arguments = ((JArray)args).ToObject<string[]>();
|
||||
_notificationOptions.Single(x => x.ReplyID == arguments[0].ToString()).OnReply(arguments[1].ToString());
|
||||
_notificationOptions.Single(x => x.ReplyID == args[0]).OnReply(args[1]);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -103,10 +101,9 @@ namespace ElectronNET.API
|
||||
isActionDefined = true;
|
||||
|
||||
BridgeConnector.Socket.Off("NotificationEventAction");
|
||||
BridgeConnector.Socket.On("NotificationEventAction", (args) =>
|
||||
BridgeConnector.Socket.On<string[]>("NotificationEventAction", (args) =>
|
||||
{
|
||||
var arguments = ((JArray)args).ToObject<string[]>();
|
||||
_notificationOptions.Single(x => x.ReplyID == arguments[0].ToString()).OnAction(arguments[1].ToString());
|
||||
_notificationOptions.Single(x => x.ActionID == args[0]).OnAction(args[1]);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -124,10 +121,10 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("notificationIsSupportedComplete", (isSupported) =>
|
||||
BridgeConnector.Socket.On<bool>("notificationIsSupportedComplete", (isSupported) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("notificationIsSupportedComplete");
|
||||
taskCompletionSource.SetResult((bool)isSupported);
|
||||
taskCompletionSource.SetResult(isSupported);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("notificationIsSupported");
|
||||
@@ -135,11 +132,6 @@ namespace ElectronNET.API
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
private JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using ElectronNET.Common;
|
||||
using ElectronNET.Common;
|
||||
using System;
|
||||
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using ElectronNET.API.Entities;
|
||||
using ElectronNET.API.Serialization;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
@@ -49,10 +48,10 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<string>();
|
||||
|
||||
BridgeConnector.Socket.On("process-execPath-Completed", (result) =>
|
||||
BridgeConnector.Socket.On<string>("process-execPath-Completed", (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("process-execPath-Completed");
|
||||
taskCompletionSource.SetResult(result.ToString());
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("process-execPath");
|
||||
@@ -73,10 +72,10 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<string[]>();
|
||||
|
||||
BridgeConnector.Socket.On("process-argv-Completed", (result) =>
|
||||
BridgeConnector.Socket.On<string[]>("process-argv-Completed", (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("process-argv-Completed");
|
||||
taskCompletionSource.SetResult(((JArray)result).ToObject<string[]>());
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("process-argv");
|
||||
@@ -94,10 +93,10 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<string>();
|
||||
|
||||
BridgeConnector.Socket.On("process-type-Completed", (result) =>
|
||||
BridgeConnector.Socket.On<string>("process-type-Completed", (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("process-type-Completed");
|
||||
taskCompletionSource.SetResult(result.ToString());
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("process-type");
|
||||
@@ -116,10 +115,10 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<ProcessVersions>();
|
||||
|
||||
BridgeConnector.Socket.On("process-versions-Completed", (result) =>
|
||||
BridgeConnector.Socket.On<ProcessVersions>("process-versions-Completed", (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("process-versions-Completed");
|
||||
taskCompletionSource.SetResult(((JObject)result).ToObject<ProcessVersions>());
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("process-versions");
|
||||
@@ -138,10 +137,10 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("process-defaultApp-Completed", (result) =>
|
||||
BridgeConnector.Socket.On<bool>("process-defaultApp-Completed", (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("process-defaultApp-Completed");
|
||||
taskCompletionSource.SetResult(bool.Parse(result.ToString()));
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("process-defaultApp");
|
||||
@@ -159,10 +158,10 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("process-isMainFrame-Completed", (result) =>
|
||||
BridgeConnector.Socket.On<bool>("process-isMainFrame-Completed", (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("process-isMainFrame-Completed");
|
||||
taskCompletionSource.SetResult(bool.Parse(result.ToString()));
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("process-isMainFrame");
|
||||
@@ -179,10 +178,10 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<string>();
|
||||
|
||||
BridgeConnector.Socket.On("process-resourcesPath-Completed", (result) =>
|
||||
BridgeConnector.Socket.On<string>("process-resourcesPath-Completed", (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("process-resourcesPath-Completed");
|
||||
taskCompletionSource.SetResult(result.ToString());
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("process-resourcesPath");
|
||||
@@ -200,10 +199,10 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<double>();
|
||||
|
||||
BridgeConnector.Socket.On("process-uptime-Completed", (result) =>
|
||||
BridgeConnector.Socket.On<double>("process-uptime-Completed", (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("process-uptime-Completed");
|
||||
taskCompletionSource.SetResult(double.Parse(result.ToString()));
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("process-uptime");
|
||||
@@ -220,10 +219,10 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<int>();
|
||||
|
||||
BridgeConnector.Socket.On("process-pid-Completed", (result) =>
|
||||
BridgeConnector.Socket.On<int>("process-pid-Completed", (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("process-pid-Completed");
|
||||
taskCompletionSource.SetResult(int.Parse(result.ToString()));
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("process-pid");
|
||||
@@ -241,10 +240,10 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<string>();
|
||||
|
||||
BridgeConnector.Socket.On("process-arch-Completed", (result) =>
|
||||
BridgeConnector.Socket.On<string>("process-arch-Completed", (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("process-arch-Completed");
|
||||
taskCompletionSource.SetResult(result.ToString());
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("process-arch");
|
||||
@@ -261,10 +260,10 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<string>();
|
||||
|
||||
BridgeConnector.Socket.On("process-platform-Completed", (result) =>
|
||||
BridgeConnector.Socket.On<string>("process-platform-Completed", (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("process-platform-Completed");
|
||||
taskCompletionSource.SetResult(result.ToString());
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("process-platform");
|
||||
@@ -272,4 +271,4 @@ namespace ElectronNET.API
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
using ElectronNET.API.Entities;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using ElectronNET.API.Entities;
|
||||
using ElectronNET.API.Serialization;
|
||||
using ElectronNET.Common;
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
@@ -18,7 +17,7 @@ namespace ElectronNET.API
|
||||
/// </summary>
|
||||
public event Action<Display> OnDisplayAdded
|
||||
{
|
||||
add => ApiEventManager.AddEvent("screen-display-added", GetHashCode(), _onDisplayAdded, value, (args) => ((JObject)args).ToObject<Display>());
|
||||
add => ApiEventManager.AddEvent("screen-display-added", GetHashCode(), _onDisplayAdded, value, (args) => args.Deserialize(ElectronJsonContext.Default.Display));
|
||||
remove => ApiEventManager.RemoveEvent("screen-display-added", GetHashCode(), _onDisplayAdded, value);
|
||||
}
|
||||
|
||||
@@ -29,7 +28,7 @@ namespace ElectronNET.API
|
||||
/// </summary>
|
||||
public event Action<Display> OnDisplayRemoved
|
||||
{
|
||||
add => ApiEventManager.AddEvent("screen-display-removed", GetHashCode(), _onDisplayRemoved, value, (args) => ((JObject)args).ToObject<Display>());
|
||||
add => ApiEventManager.AddEvent("screen-display-removed", GetHashCode(), _onDisplayRemoved, value, (args) => args.Deserialize(ElectronJsonContext.Default.Display));
|
||||
remove => ApiEventManager.RemoveEvent("screen-display-removed", GetHashCode(), _onDisplayRemoved, value);
|
||||
}
|
||||
|
||||
@@ -82,11 +81,10 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<Point>();
|
||||
|
||||
BridgeConnector.Socket.On("screen-getCursorScreenPointCompleted", (point) =>
|
||||
BridgeConnector.Socket.On<Point>("screen-getCursorScreenPointCompleted", (point) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("screen-getCursorScreenPointCompleted");
|
||||
|
||||
taskCompletionSource.SetResult(((JObject)point).ToObject<Point>());
|
||||
taskCompletionSource.SetResult(point);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("screen-getCursorScreenPoint");
|
||||
@@ -102,11 +100,10 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<int>();
|
||||
|
||||
BridgeConnector.Socket.On("screen-getMenuBarHeightCompleted", (height) =>
|
||||
BridgeConnector.Socket.On<int>("screen-getMenuBarHeightCompleted", (height) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("screen-getMenuBarHeightCompleted");
|
||||
|
||||
taskCompletionSource.SetResult(int.Parse(height.ToString()));
|
||||
taskCompletionSource.SetResult(height);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("screen-getMenuBarHeight");
|
||||
@@ -122,11 +119,10 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<Display>();
|
||||
|
||||
BridgeConnector.Socket.On("screen-getPrimaryDisplayCompleted", (display) =>
|
||||
BridgeConnector.Socket.On<Display>("screen-getPrimaryDisplayCompleted", (display) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("screen-getPrimaryDisplayCompleted");
|
||||
|
||||
taskCompletionSource.SetResult(((JObject)display).ToObject<Display>());
|
||||
taskCompletionSource.SetResult(display);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("screen-getPrimaryDisplay");
|
||||
@@ -142,11 +138,10 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<Display[]>();
|
||||
|
||||
BridgeConnector.Socket.On("screen-getAllDisplaysCompleted", (displays) =>
|
||||
BridgeConnector.Socket.On<Display[]>("screen-getAllDisplaysCompleted", (displays) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("screen-getAllDisplaysCompleted");
|
||||
|
||||
taskCompletionSource.SetResult(((JArray)displays).ToObject<Display[]>());
|
||||
taskCompletionSource.SetResult(displays);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("screen-getAllDisplays");
|
||||
@@ -162,14 +157,13 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<Display>();
|
||||
|
||||
BridgeConnector.Socket.On("screen-getDisplayNearestPointCompleted", (display) =>
|
||||
BridgeConnector.Socket.On<Display>("screen-getDisplayNearestPointCompleted", (display) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("screen-getDisplayNearestPointCompleted");
|
||||
|
||||
taskCompletionSource.SetResult(((JObject)display).ToObject<Display>());
|
||||
taskCompletionSource.SetResult(display);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("screen-getDisplayNearestPoint", JObject.FromObject(point, _jsonSerializer));
|
||||
BridgeConnector.Socket.Emit("screen-getDisplayNearestPoint", point);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
@@ -183,23 +177,17 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<Display>();
|
||||
|
||||
BridgeConnector.Socket.On("screen-getDisplayMatching", (display) =>
|
||||
BridgeConnector.Socket.On<Display>("screen-getDisplayMatching", (display) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("screen-getDisplayMatching");
|
||||
|
||||
taskCompletionSource.SetResult(((JObject)display).ToObject<Display>());
|
||||
taskCompletionSource.SetResult(display);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("screen-getDisplayMatching", JObject.FromObject(rectangle, _jsonSerializer));
|
||||
BridgeConnector.Socket.Emit("screen-getDisplayMatching", rectangle);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
private JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
using ElectronNET.API.Entities;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using ElectronNET.API.Entities;
|
||||
using ElectronNET.API.Serialization;
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronNET.API
|
||||
@@ -59,7 +58,7 @@ namespace ElectronNET.API
|
||||
taskCompletionSource.SetResult(null);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("webContents-session-clearAuthCache", Id, JObject.FromObject(options, _jsonSerializer), guid);
|
||||
BridgeConnector.Socket.Emit("webContents-session-clearAuthCache", Id, options, guid);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
@@ -159,7 +158,7 @@ namespace ElectronNET.API
|
||||
taskCompletionSource.SetResult(null);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("webContents-session-clearStorageData-options", Id, JObject.FromObject(options, _jsonSerializer), guid);
|
||||
BridgeConnector.Socket.Emit("webContents-session-clearStorageData-options", Id, options, guid);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
@@ -174,7 +173,7 @@ namespace ElectronNET.API
|
||||
/// <param name="options"></param>
|
||||
public void CreateInterruptedDownload(CreateInterruptedDownloadOptions options)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("webContents-session-createInterruptedDownload", Id, JObject.FromObject(options, _jsonSerializer));
|
||||
BridgeConnector.Socket.Emit("webContents-session-createInterruptedDownload", Id, options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -192,7 +191,7 @@ namespace ElectronNET.API
|
||||
/// <param name="options"></param>
|
||||
public void EnableNetworkEmulation(EnableNetworkEmulationOptions options)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("webContents-session-enableNetworkEmulation", Id, JObject.FromObject(options, _jsonSerializer));
|
||||
BridgeConnector.Socket.Emit("webContents-session-enableNetworkEmulation", Id, options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -213,10 +212,8 @@ namespace ElectronNET.API
|
||||
var taskCompletionSource = new TaskCompletionSource<int[]>();
|
||||
string guid = Guid.NewGuid().ToString();
|
||||
|
||||
BridgeConnector.Socket.On("webContents-session-getBlobData-completed" + guid, (buffer) =>
|
||||
BridgeConnector.Socket.On<int[]>("webContents-session-getBlobData-completed" + guid, (result) =>
|
||||
{
|
||||
var result = ((JArray)buffer).ToObject<int[]>();
|
||||
|
||||
BridgeConnector.Socket.Off("webContents-session-getBlobData-completed" + guid);
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
@@ -235,10 +232,10 @@ namespace ElectronNET.API
|
||||
var taskCompletionSource = new TaskCompletionSource<int>();
|
||||
string guid = Guid.NewGuid().ToString();
|
||||
|
||||
BridgeConnector.Socket.On("webContents-session-getCacheSize-completed" + guid, (size) =>
|
||||
BridgeConnector.Socket.On<int>("webContents-session-getCacheSize-completed" + guid, (size) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("webContents-session-getCacheSize-completed" + guid);
|
||||
taskCompletionSource.SetResult((int)size);
|
||||
taskCompletionSource.SetResult(size);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("webContents-session-getCacheSize", Id, guid);
|
||||
@@ -255,9 +252,8 @@ namespace ElectronNET.API
|
||||
var taskCompletionSource = new TaskCompletionSource<string[]>();
|
||||
string guid = Guid.NewGuid().ToString();
|
||||
|
||||
BridgeConnector.Socket.On("webContents-session-getPreloads-completed" + guid, (preloads) =>
|
||||
BridgeConnector.Socket.On<string[]>("webContents-session-getPreloads-completed" + guid, (result) =>
|
||||
{
|
||||
var result = ((JArray)preloads).ToObject<string[]>();
|
||||
BridgeConnector.Socket.Off("webContents-session-getPreloads-completed" + guid);
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
@@ -276,10 +272,10 @@ namespace ElectronNET.API
|
||||
var taskCompletionSource = new TaskCompletionSource<string>();
|
||||
string guid = Guid.NewGuid().ToString();
|
||||
|
||||
BridgeConnector.Socket.On("webContents-session-getUserAgent-completed" + guid, (userAgent) =>
|
||||
BridgeConnector.Socket.On<string>("webContents-session-getUserAgent-completed" + guid, (userAgent) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("webContents-session-getUserAgent-completed" + guid);
|
||||
taskCompletionSource.SetResult(userAgent.ToString());
|
||||
taskCompletionSource.SetResult(userAgent);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("webContents-session-getUserAgent", Id, guid);
|
||||
@@ -298,10 +294,10 @@ namespace ElectronNET.API
|
||||
var taskCompletionSource = new TaskCompletionSource<string>();
|
||||
string guid = Guid.NewGuid().ToString();
|
||||
|
||||
BridgeConnector.Socket.On("webContents-session-resolveProxy-completed" + guid, (proxy) =>
|
||||
BridgeConnector.Socket.On<string>("webContents-session-resolveProxy-completed" + guid, (proxy) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("webContents-session-resolveProxy-completed" + guid);
|
||||
taskCompletionSource.SetResult(proxy.ToString());
|
||||
taskCompletionSource.SetResult(proxy);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("webContents-session-resolveProxy", Id, url, guid);
|
||||
@@ -346,7 +342,7 @@ namespace ElectronNET.API
|
||||
taskCompletionSource.SetResult(null);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("webContents-session-setProxy", Id, JObject.FromObject(config, _jsonSerializer), guid);
|
||||
BridgeConnector.Socket.Emit("webContents-session-setProxy", Id, config, guid);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
@@ -387,12 +383,10 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<ChromeExtensionInfo[]>();
|
||||
|
||||
BridgeConnector.Socket.On("webContents-session-getAllExtensions-completed", (extensionslist) =>
|
||||
BridgeConnector.Socket.On<ChromeExtensionInfo[]>("webContents-session-getAllExtensions-completed", (extensionslist) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("webContents-session-getAllExtensions-completed");
|
||||
var chromeExtensionInfos = ((JArray)extensionslist).ToObject<ChromeExtensionInfo[]>();
|
||||
|
||||
taskCompletionSource.SetResult(chromeExtensionInfos);
|
||||
taskCompletionSource.SetResult(extensionslist);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("webContents-session-getAllExtensions", Id);
|
||||
@@ -441,11 +435,10 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<Extension>();
|
||||
|
||||
BridgeConnector.Socket.On("webContents-session-loadExtension-completed", (extension) =>
|
||||
BridgeConnector.Socket.On<Extension>("webContents-session-loadExtension-completed", (extension) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("webContents-session-loadExtension-completed");
|
||||
|
||||
taskCompletionSource.SetResult(((JObject)extension).ToObject<Extension>());
|
||||
taskCompletionSource.SetResult(extension);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("webContents-session-loadExtension", Id, path, allowFileAccess);
|
||||
@@ -453,11 +446,6 @@ namespace ElectronNET.API
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
private JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
using ElectronNET.API.Entities;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
using ElectronNET.API.Entities;
|
||||
using ElectronNET.API.Extensions;
|
||||
using ElectronNET.API.Serialization;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
@@ -62,11 +61,10 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<string>();
|
||||
|
||||
BridgeConnector.Socket.On("shell-openPathCompleted", (errorMessage) =>
|
||||
BridgeConnector.Socket.On<string>("shell-openPathCompleted", (errorMessage) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("shell-openPathCompleted");
|
||||
|
||||
taskCompletionSource.SetResult((string)errorMessage);
|
||||
taskCompletionSource.SetResult(errorMessage);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("shell-openPath", path);
|
||||
@@ -96,11 +94,10 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<string>();
|
||||
|
||||
BridgeConnector.Socket.On("shell-openExternalCompleted", (error) =>
|
||||
BridgeConnector.Socket.On<string>("shell-openExternalCompleted", (error) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("shell-openExternalCompleted");
|
||||
|
||||
taskCompletionSource.SetResult((string)error);
|
||||
taskCompletionSource.SetResult(error);
|
||||
});
|
||||
|
||||
if (options == null)
|
||||
@@ -109,7 +106,7 @@ namespace ElectronNET.API
|
||||
}
|
||||
else
|
||||
{
|
||||
BridgeConnector.Socket.Emit("shell-openExternal", url, JObject.FromObject(options, _jsonSerializer));
|
||||
BridgeConnector.Socket.Emit("shell-openExternal", url, options);
|
||||
}
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
@@ -124,11 +121,10 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("shell-trashItem-completed", (success) =>
|
||||
BridgeConnector.Socket.On<bool>("shell-trashItem-completed", (success) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("shell-trashItem-completed");
|
||||
|
||||
taskCompletionSource.SetResult((bool)success);
|
||||
taskCompletionSource.SetResult(success);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("shell-trashItem", fullPath);
|
||||
@@ -155,14 +151,13 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("shell-writeShortcutLinkCompleted", (success) =>
|
||||
BridgeConnector.Socket.On<bool>("shell-writeShortcutLinkCompleted", (success) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("shell-writeShortcutLinkCompleted");
|
||||
|
||||
taskCompletionSource.SetResult((bool)success);
|
||||
taskCompletionSource.SetResult(success);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("shell-writeShortcutLink", shortcutPath, operation.GetDescription(), JObject.FromObject(options, _jsonSerializer));
|
||||
BridgeConnector.Socket.Emit("shell-writeShortcutLink", shortcutPath, operation.GetDescription(), options);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
@@ -177,14 +172,10 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<ShortcutDetails>();
|
||||
|
||||
BridgeConnector.Socket.On("shell-readShortcutLinkCompleted", (shortcutDetails) =>
|
||||
BridgeConnector.Socket.On<ShortcutDetails>("shell-readShortcutLinkCompleted", (shortcutDetails) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("shell-readShortcutLinkCompleted");
|
||||
|
||||
var shortcutObject = shortcutDetails as JObject;
|
||||
var details = shortcutObject?.ToObject<ShortcutDetails>();
|
||||
|
||||
taskCompletionSource.SetResult(details);
|
||||
taskCompletionSource.SetResult(shortcutDetails);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("shell-readShortcutLink", shortcutPath);
|
||||
@@ -192,11 +183,6 @@ namespace ElectronNET.API
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
private readonly JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
using ElectronNET.API.Entities;
|
||||
using ElectronNET.API.Entities;
|
||||
using ElectronNET.API.Extensions;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using ElectronNET.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using ElectronNET.Common;
|
||||
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
@@ -140,7 +137,7 @@ namespace ElectronNET.API
|
||||
public async Task Show(string image, MenuItem[] menuItems)
|
||||
{
|
||||
menuItems.AddMenuItemsId();
|
||||
await BridgeConnector.Socket.Emit("create-tray", image, JArray.FromObject(menuItems, this._jsonSerializer)).ConfigureAwait(false);
|
||||
await BridgeConnector.Socket.Emit("create-tray", image, menuItems).ConfigureAwait(false);
|
||||
_items.Clear();
|
||||
_items.AddRange(menuItems);
|
||||
|
||||
@@ -212,7 +209,7 @@ namespace ElectronNET.API
|
||||
/// <param name="options"></param>
|
||||
public async Task DisplayBalloon(DisplayBalloonOptions options)
|
||||
{
|
||||
await BridgeConnector.Socket.Emit("tray-displayBalloon", JObject.FromObject(options, this._jsonSerializer)).ConfigureAwait(false);
|
||||
await BridgeConnector.Socket.Emit("tray-displayBalloon", options).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -235,11 +232,7 @@ namespace ElectronNET.API
|
||||
return await taskCompletionSource.Task.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private readonly JsonSerializer _jsonSerializer = new()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore
|
||||
};
|
||||
|
||||
|
||||
private const string ModuleName = "tray";
|
||||
|
||||
@@ -275,4 +268,4 @@ namespace ElectronNET.API
|
||||
public async Task Once<T>(string eventName, Action<T> action)
|
||||
=> await Events.Instance.Once(ModuleName, eventName, action).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
using ElectronNET.API.Entities;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using ElectronNET.API.Entities;
|
||||
using ElectronNET.API.Serialization;
|
||||
using ElectronNET.Common;
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
@@ -33,7 +32,7 @@ public class WebContents
|
||||
/// </summary>
|
||||
public event Action<bool> OnCrashed
|
||||
{
|
||||
add => ApiEventManager.AddEvent("webContents-crashed", Id, _crashed, value, (args) => (bool)args);
|
||||
add => ApiEventManager.AddEvent("webContents-crashed", Id, _crashed, value, (args) => args.GetBoolean());
|
||||
remove => ApiEventManager.RemoveEvent("webContents-crashed", Id, _crashed, value);
|
||||
}
|
||||
|
||||
@@ -102,7 +101,7 @@ public class WebContents
|
||||
/// </summary>
|
||||
public event Action<OnDidFailLoadInfo> OnDidFailLoad
|
||||
{
|
||||
add => ApiEventManager.AddEvent("webContents-didFailLoad", Id, _didFailLoad, value, (args) => ((JObject)args).ToObject<OnDidFailLoadInfo>());
|
||||
add => ApiEventManager.AddEvent("webContents-didFailLoad", Id, _didFailLoad, value, (args) => args.Deserialize<OnDidFailLoadInfo>(ElectronJson.Options));
|
||||
remove => ApiEventManager.RemoveEvent("webContents-didFailLoad", Id, _didFailLoad, value);
|
||||
}
|
||||
|
||||
@@ -113,7 +112,7 @@ public class WebContents
|
||||
/// </summary>
|
||||
public event Action<InputEvent> InputEvent
|
||||
{
|
||||
add => ApiEventManager.AddEvent("webContents-input-event", Id, _inputEvent, value, (args) => ((JObject)args).ToObject<InputEvent>());
|
||||
add => ApiEventManager.AddEvent("webContents-input-event", Id, _inputEvent, value, (args) => args.Deserialize<InputEvent>(ElectronJson.Options));
|
||||
remove => ApiEventManager.RemoveEvent("webContents-input-event", Id, _inputEvent, value);
|
||||
}
|
||||
|
||||
@@ -150,7 +149,7 @@ public class WebContents
|
||||
/// <param name="openDevToolsOptions"></param>
|
||||
public void OpenDevTools(OpenDevToolsOptions openDevToolsOptions)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("webContentsOpenDevTools", Id, JObject.FromObject(openDevToolsOptions, _jsonSerializer));
|
||||
BridgeConnector.Socket.Emit("webContentsOpenDevTools", Id, openDevToolsOptions);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -161,11 +160,10 @@ public class WebContents
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<PrinterInfo[]>();
|
||||
|
||||
BridgeConnector.Socket.On("webContents-getPrinters-completed", (printers) =>
|
||||
BridgeConnector.Socket.On<PrinterInfo[]>("webContents-getPrinters-completed", (printers) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("webContents-getPrinters-completed");
|
||||
|
||||
taskCompletionSource.SetResult(((Newtonsoft.Json.Linq.JArray)printers).ToObject<PrinterInfo[]>());
|
||||
taskCompletionSource.SetResult(printers);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("webContents-getPrinters", Id);
|
||||
@@ -182,10 +180,10 @@ public class WebContents
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("webContents-print-completed", (success) =>
|
||||
BridgeConnector.Socket.On<bool>("webContents-print-completed", (success) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("webContents-print-completed");
|
||||
taskCompletionSource.SetResult((bool)success);
|
||||
taskCompletionSource.SetResult(success);
|
||||
});
|
||||
|
||||
if (options == null)
|
||||
@@ -194,7 +192,7 @@ public class WebContents
|
||||
}
|
||||
else
|
||||
{
|
||||
BridgeConnector.Socket.Emit("webContents-print", Id, JObject.FromObject(options, _jsonSerializer));
|
||||
BridgeConnector.Socket.Emit("webContents-print", Id, options);
|
||||
}
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
@@ -213,10 +211,10 @@ public class WebContents
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("webContents-printToPDF-completed", (success) =>
|
||||
BridgeConnector.Socket.On<bool>("webContents-printToPDF-completed", (success) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("webContents-printToPDF-completed");
|
||||
taskCompletionSource.SetResult((bool)success);
|
||||
taskCompletionSource.SetResult(success);
|
||||
});
|
||||
|
||||
if (options == null)
|
||||
@@ -225,7 +223,7 @@ public class WebContents
|
||||
}
|
||||
else
|
||||
{
|
||||
BridgeConnector.Socket.Emit("webContents-printToPDF", Id, JObject.FromObject(options, _jsonSerializer), path);
|
||||
BridgeConnector.Socket.Emit("webContents-printToPDF", Id, options, path);
|
||||
}
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
@@ -247,11 +245,11 @@ public class WebContents
|
||||
/// Code execution will be suspended until web page stop loading.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public Task<object> ExecuteJavaScriptAsync(string code, bool userGesture = false)
|
||||
public Task<T> ExecuteJavaScriptAsync<T>(string code, bool userGesture = false)
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<object>();
|
||||
var taskCompletionSource = new TaskCompletionSource<T>();
|
||||
|
||||
BridgeConnector.Socket.On("webContents-executeJavaScript-completed", (result) =>
|
||||
BridgeConnector.Socket.On<T>("webContents-executeJavaScript-completed", (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("webContents-executeJavaScript-completed");
|
||||
taskCompletionSource.SetResult(result);
|
||||
@@ -272,10 +270,10 @@ public class WebContents
|
||||
var taskCompletionSource = new TaskCompletionSource<string>();
|
||||
|
||||
var eventString = "webContents-getUrl" + Id;
|
||||
BridgeConnector.Socket.On(eventString, (url) =>
|
||||
BridgeConnector.Socket.On<string>(eventString, (url) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off(eventString);
|
||||
taskCompletionSource.SetResult((string)url);
|
||||
taskCompletionSource.SetResult(url);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("webContents-getUrl", Id);
|
||||
@@ -324,13 +322,13 @@ public class WebContents
|
||||
taskCompletionSource.SetResult(null);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.On("webContents-loadURL-error" + Id, (error) =>
|
||||
BridgeConnector.Socket.On<string>("webContents-loadURL-error" + Id, (error) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("webContents-loadURL-error" + Id);
|
||||
taskCompletionSource.SetException(new InvalidOperationException(error.ToString()));
|
||||
taskCompletionSource.SetException(new InvalidOperationException(error));
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("webContents-loadURL", Id, url, JObject.FromObject(options, _jsonSerializer));
|
||||
BridgeConnector.Socket.Emit("webContents-loadURL", Id, url, options);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
@@ -347,10 +345,5 @@ public class WebContents
|
||||
BridgeConnector.Socket.Emit("webContents-insertCSS", Id, isBrowserWindow, path);
|
||||
}
|
||||
|
||||
private readonly JsonSerializer _jsonSerializer = new()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using ElectronNET.API.Serialization;
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
@@ -33,18 +34,17 @@ namespace ElectronNET.API.Entities
|
||||
{
|
||||
if (_onBeforeRequest == null)
|
||||
{
|
||||
BridgeConnector.Socket.On($"webContents-session-webRequest-onBeforeRequest{Id}",
|
||||
BridgeConnector.Socket.On<System.Text.Json.JsonElement>($"webContents-session-webRequest-onBeforeRequest{Id}",
|
||||
(args) =>
|
||||
{
|
||||
////var details = ((JObject)args[0]).ToObject<OnBeforeRequestDetails>();
|
||||
////var callback = args.Length > 1 ? (Action<object>)((response) => { BridgeConnector.Socket.Emit($"webContents-session-webRequest-onBeforeRequest-response{Id}", response); }) : null;
|
||||
var details = ((JObject)args).ToObject<OnBeforeRequestDetails>();
|
||||
//// var details0 = args[0].Deserialize<OnBeforeRequestDetails>(ElectronNET.ElectronJson.Options);
|
||||
var details = args.Deserialize<OnBeforeRequestDetails>(ElectronJson.Options);
|
||||
var callback = (Action<object>)((response) => { BridgeConnector.Socket.Emit($"webContents-session-webRequest-onBeforeRequest-response{Id}", response); });
|
||||
|
||||
_onBeforeRequest?.Invoke(details, callback);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("register-webContents-session-webRequest-onBeforeRequest", Id, JObject.FromObject(filter));
|
||||
BridgeConnector.Socket.Emit("register-webContents-session-webRequest-onBeforeRequest", Id, filter);
|
||||
}
|
||||
|
||||
_onBeforeRequest += listener;
|
||||
@@ -59,4 +59,4 @@ namespace ElectronNET.API.Entities
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
using ElectronNET.API.Entities;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using ElectronNET.API.Entities;
|
||||
using ElectronNET.API.Serialization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Sockets;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronNET.API
|
||||
@@ -100,34 +98,29 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<BrowserWindow>();
|
||||
|
||||
BridgeConnector.Socket.On("BrowserWindowCreated", (id) =>
|
||||
BridgeConnector.Socket.On<int>("BrowserWindowCreated", (id) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("BrowserWindowCreated");
|
||||
|
||||
var browserWindowId = int.Parse(id.ToString()!);
|
||||
|
||||
var browserWindow = new BrowserWindow(browserWindowId);
|
||||
var browserWindow = new BrowserWindow(id);
|
||||
_browserWindows.Add(browserWindow);
|
||||
|
||||
taskCompletionSource.SetResult(browserWindow);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.On<object>("BrowserWindowClosed", (ids) =>
|
||||
BridgeConnector.Socket.On<int[]>("BrowserWindowClosed", (ids) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("BrowserWindowClosed");
|
||||
|
||||
var browserWindowIds = ((JArray)ids).ToObject<int[]>();
|
||||
|
||||
for (int index = 0; index < _browserWindows.Count; index++)
|
||||
{
|
||||
if (!browserWindowIds.Contains(_browserWindows[index].Id))
|
||||
if (!ids.Contains(_browserWindows[index].Id))
|
||||
{
|
||||
_browserWindows.RemoveAt(index);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (loadUrl.ToUpper() == "HTTP://LOCALHOST" && ElectronNetRuntime.AspNetWebPort.HasValue)
|
||||
if (loadUrl.Equals("http://localhost", StringComparison.OrdinalIgnoreCase) && ElectronNetRuntime.AspNetWebPort.HasValue)
|
||||
{
|
||||
loadUrl = $"{loadUrl}:{ElectronNetRuntime.AspNetWebPort}";
|
||||
}
|
||||
@@ -145,7 +138,7 @@ namespace ElectronNET.API
|
||||
options.X = 0;
|
||||
options.Y = 0;
|
||||
|
||||
await BridgeConnector.Socket.Emit("createBrowserWindow", JObject.FromObject(options, this._jsonSerializer), loadUrl).ConfigureAwait(false);
|
||||
await BridgeConnector.Socket.Emit("createBrowserWindow", options, loadUrl).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -156,7 +149,7 @@ namespace ElectronNET.API
|
||||
options.X -= 7;
|
||||
}
|
||||
|
||||
await BridgeConnector.Socket.Emit("createBrowserWindow", JObject.FromObject(options, this._jsonSerializer), loadUrl).ConfigureAwait(false);
|
||||
await BridgeConnector.Socket.Emit("createBrowserWindow", options, loadUrl).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
return await taskCompletionSource.Task.ConfigureAwait(false);
|
||||
@@ -189,32 +182,20 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<BrowserView>();
|
||||
|
||||
BridgeConnector.Socket.On("BrowserViewCreated", (id) =>
|
||||
BridgeConnector.Socket.On<int>("BrowserViewCreated", (id) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("BrowserViewCreated");
|
||||
|
||||
string browserViewId = id.ToString();
|
||||
BrowserView browserView = new BrowserView(int.Parse(browserViewId));
|
||||
BrowserView browserView = new(id);
|
||||
|
||||
_browserViews.Add(browserView);
|
||||
|
||||
taskCompletionSource.SetResult(browserView);
|
||||
});
|
||||
|
||||
var ownjsonSerializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore
|
||||
};
|
||||
await BridgeConnector.Socket.Emit("createBrowserView", JObject.FromObject(options, ownjsonSerializer)).ConfigureAwait(false);
|
||||
await BridgeConnector.Socket.Emit("createBrowserView", options).ConfigureAwait(false);
|
||||
|
||||
return await taskCompletionSource.Task.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private readonly JsonSerializer _jsonSerializer = new()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,12 @@
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace ElectronNET.API;
|
||||
|
||||
using ElectronNET.API.Serialization;
|
||||
using SocketIO.Serializer.SystemTextJson;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using SocketIO.Serializer.NewtonsoftJson;
|
||||
using SocketIO = SocketIOClient.SocketIO;
|
||||
|
||||
internal class SocketIoFacade
|
||||
@@ -17,14 +18,9 @@ internal class SocketIoFacade
|
||||
public SocketIoFacade(string uri)
|
||||
{
|
||||
_socket = new SocketIO(uri);
|
||||
var jsonSerializer = new NewtonsoftJsonSerializer(new JsonSerializerSettings
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore
|
||||
});
|
||||
|
||||
_socket.Serializer = jsonSerializer;
|
||||
_socket.Serializer = new SystemTextJsonSerializer(ElectronJson.Options);
|
||||
// Use default System.Text.Json serializer from SocketIOClient.
|
||||
// Outgoing args are normalized to camelCase via SerializeArg in Emit.
|
||||
}
|
||||
|
||||
public event EventHandler BridgeDisconnected;
|
||||
@@ -70,14 +66,14 @@ internal class SocketIoFacade
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Remove this method when SocketIoClient supports object deserialization
|
||||
// Keep object overload for compatibility; value will be a JsonElement boxed as object.
|
||||
public void On(string eventName, Action<object> action)
|
||||
{
|
||||
lock (_lockObj)
|
||||
{
|
||||
_socket.On(eventName, response =>
|
||||
{
|
||||
var value = response.GetValue<object>();
|
||||
var value = (object)response.GetValue<JsonElement>();
|
||||
////Console.WriteLine($"Called Event {eventName} - data {value}");
|
||||
Task.Run(() => action(value));
|
||||
});
|
||||
@@ -125,4 +121,4 @@ internal class SocketIoFacade
|
||||
{
|
||||
_socket.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using ElectronNET.API;
|
||||
using ElectronNET.API.Entities;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using ElectronNET.API.Serialization;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace ElectronNET.Common;
|
||||
|
||||
@@ -24,11 +26,11 @@ internal static class ApiEventManager
|
||||
if (callback == null) BridgeConnector.Socket.Off(eventName + id);
|
||||
}
|
||||
|
||||
internal static void AddEvent<T>(string eventName, object id, Action<T> callback, Action<T> value, Func<object, T> converter, string suffix = "")
|
||||
internal static void AddEvent<T>(string eventName, object id, Action<T> callback, Action<T> value, Func<JsonElement, T> converter, string suffix = "")
|
||||
{
|
||||
if (callback == null)
|
||||
{
|
||||
BridgeConnector.Socket.On(eventName + id, (args) =>
|
||||
BridgeConnector.Socket.On<JsonElement>(eventName + id, (args) =>
|
||||
{
|
||||
var converted = converter.Invoke(args);
|
||||
callback(converted);
|
||||
@@ -60,11 +62,11 @@ internal static class ApiEventManager
|
||||
{
|
||||
if (callback == null)
|
||||
{
|
||||
BridgeConnector.Socket.On<dynamic>(eventName + id, (result) =>
|
||||
BridgeConnector.Socket.On<JsonElement>(eventName + id, (result) =>
|
||||
{
|
||||
var args = ((JArray)result).ToObject<object[]>();
|
||||
var trayClickEventArgs = ((JObject)args[0]).ToObject<TrayClickEventArgs>();
|
||||
var bounds = ((JObject)args[1]).ToObject<Rectangle>();
|
||||
var array = result.EnumerateArray().ToArray();
|
||||
var trayClickEventArgs = array[0].Deserialize(ElectronJsonContext.Default.TrayClickEventArgs);
|
||||
var bounds = array[1].Deserialize(ElectronJsonContext.Default.Rectangle);
|
||||
callback(trayClickEventArgs, bounds);
|
||||
});
|
||||
BridgeConnector.Socket.Emit($"register-{eventName}", id);
|
||||
@@ -82,10 +84,11 @@ internal static class ApiEventManager
|
||||
{
|
||||
if (callback == null)
|
||||
{
|
||||
BridgeConnector.Socket.On(eventName + id, (args) =>
|
||||
BridgeConnector.Socket.On<JsonElement>(eventName + id, (args) =>
|
||||
{
|
||||
var display = ((JArray)args).First.ToObject<Display>();
|
||||
var metrics = ((JArray)args).Last.ToObject<string[]>();
|
||||
var arr = args.EnumerateArray().ToArray();
|
||||
var display = arr[0].Deserialize(ElectronJsonContext.Default.Display);
|
||||
var metrics = arr[1].Deserialize<string[]>(ElectronJson.Options);
|
||||
callback(display, metrics);
|
||||
});
|
||||
BridgeConnector.Socket.Emit($"register-{eventName}", id);
|
||||
@@ -98,4 +101,5 @@ internal static class ApiEventManager
|
||||
callback -= value;
|
||||
if (callback == null) BridgeConnector.Socket.Off(eventName + id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
namespace ElectronNET.Common
|
||||
{
|
||||
using System;
|
||||
using ElectronNET.Runtime.Data;
|
||||
using ElectronNET.Runtime.Services;
|
||||
using System;
|
||||
|
||||
internal static class Extensions
|
||||
{
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
/// and .net versions and on every platform where .net runs. This is just the innermost core, that's why
|
||||
/// there are many dead ends, but it has all the crucial parts.
|
||||
/// </remarks>
|
||||
/// <seealso cref="System.IDisposable" />
|
||||
/// <seealso cref="IDisposable" />
|
||||
[SuppressMessage("ReSharper", "SuspiciousLockOverSynchronizationPrimitive")]
|
||||
public class ProcessRunner : IDisposable
|
||||
{
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
private ProcessWindowStyle windowStyle;
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor. At least the <see cref='System.Diagnostics.ProcessStartInfo.FileName'/>
|
||||
/// Default constructor. At least the <see cref='ProcessStartInfo.FileName'/>
|
||||
/// property must be set before starting the process.
|
||||
/// </summary>
|
||||
public RunnerParams()
|
||||
|
||||
@@ -1,54 +1,45 @@
|
||||
namespace ElectronNET.Converter;
|
||||
|
||||
using ElectronNET.API.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ElectronNET.API.Entities;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class ModifierTypeListConverter : JsonConverter<List<ModifierType>>
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="reader"></param>
|
||||
/// <param name="objectType"></param>
|
||||
/// <param name="existingValue"></param>
|
||||
/// <param name="hasExistingValue"></param>
|
||||
/// <param name="serializer"></param>
|
||||
/// <returns></returns>
|
||||
public override List<ModifierType> ReadJson(JsonReader reader, Type objectType, List<ModifierType> existingValue, bool hasExistingValue, JsonSerializer serializer)
|
||||
public override List<ModifierType> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
var token = JToken.Load(reader);
|
||||
|
||||
if (token.Type == JTokenType.Null)
|
||||
if (reader.TokenType == JsonTokenType.Null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
return token.ToObject<List<string>>().Select(m => (ModifierType)Enum.Parse(typeof(ModifierType), m)).ToList();
|
||||
var list = new List<ModifierType>();
|
||||
if (reader.TokenType != JsonTokenType.StartArray)
|
||||
{
|
||||
throw new JsonException("Expected array for ModifierType list");
|
||||
}
|
||||
while (reader.Read())
|
||||
{
|
||||
if (reader.TokenType == JsonTokenType.EndArray) break;
|
||||
if (reader.TokenType != JsonTokenType.String) throw new JsonException("Expected string enum value");
|
||||
var s = reader.GetString();
|
||||
list.Add((ModifierType)Enum.Parse(typeof(ModifierType), s, ignoreCase: true));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="writer"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="serializer"></param>
|
||||
public override void WriteJson(JsonWriter writer, List<ModifierType> value, JsonSerializer serializer)
|
||||
public override void Write(Utf8JsonWriter writer, List<ModifierType> value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStartArray();
|
||||
|
||||
foreach (var modifier in value)
|
||||
{
|
||||
writer.WriteValue(modifier.ToString());
|
||||
writer.WriteStringValue(modifier.ToString());
|
||||
}
|
||||
|
||||
writer.WriteEndArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,43 +1,46 @@
|
||||
using ElectronNET.API.Entities;
|
||||
using Newtonsoft.Json;
|
||||
using ElectronNET.API.Entities;
|
||||
using ElectronNET.API.Serialization;
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace ElectronNET.Converter;
|
||||
|
||||
public class PageSizeConverter : JsonConverter<PageSize>
|
||||
{
|
||||
public override PageSize ReadJson(JsonReader reader, Type objectType, PageSize existingValue, bool hasExistingValue, JsonSerializer serializer)
|
||||
public override PageSize Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (reader.TokenType == JsonToken.String)
|
||||
if (reader.TokenType == JsonTokenType.String)
|
||||
{
|
||||
return (string)reader.Value;
|
||||
return reader.GetString();
|
||||
}
|
||||
else if (reader.TokenType == JsonToken.StartObject)
|
||||
else if (reader.TokenType == JsonTokenType.StartObject)
|
||||
{
|
||||
return serializer.Deserialize<PageSize>(reader);
|
||||
return JsonSerializer.Deserialize<PageSize>(ref reader, ElectronJson.Options);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new JsonSerializationException("Invalid value for PageSize. Expected true, false, or an object.");
|
||||
throw new JsonException("Invalid value for PageSize. Expected string or an object.");
|
||||
}
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, PageSize value, JsonSerializer serializer)
|
||||
public override void Write(Utf8JsonWriter writer, PageSize value, JsonSerializerOptions options)
|
||||
{
|
||||
if (value is null)
|
||||
{
|
||||
writer.WriteUndefined();
|
||||
return;
|
||||
}
|
||||
|
||||
var str = (string)value;
|
||||
|
||||
if (str is not null)
|
||||
{
|
||||
writer.WriteValue(str);
|
||||
writer.WriteStringValue(str);
|
||||
}
|
||||
else
|
||||
{
|
||||
serializer.Serialize(writer, value);
|
||||
JsonSerializer.Serialize(writer, value, ElectronJson.Options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,43 +1,46 @@
|
||||
using ElectronNET.API.Entities;
|
||||
using Newtonsoft.Json;
|
||||
using ElectronNET.API.Entities;
|
||||
using ElectronNET.API.Serialization;
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace ElectronNET.Converter;
|
||||
|
||||
public class TitleBarOverlayConverter : JsonConverter<TitleBarOverlay>
|
||||
{
|
||||
public override TitleBarOverlay ReadJson(JsonReader reader, Type objectType, TitleBarOverlay existingValue, bool hasExistingValue, JsonSerializer serializer)
|
||||
public override TitleBarOverlay Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (reader.TokenType == JsonToken.Boolean)
|
||||
if (reader.TokenType == JsonTokenType.True || reader.TokenType == JsonTokenType.False)
|
||||
{
|
||||
return (bool)reader.Value;
|
||||
return (bool)reader.GetBoolean();
|
||||
}
|
||||
else if (reader.TokenType == JsonToken.StartObject)
|
||||
else if (reader.TokenType == JsonTokenType.StartObject)
|
||||
{
|
||||
return serializer.Deserialize<TitleBarOverlay>(reader);
|
||||
using var doc = JsonDocument.ParseValue(ref reader);
|
||||
return doc.RootElement.Deserialize<TitleBarOverlay>(ElectronJson.Options);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new JsonSerializationException("Invalid value for TitleBarOverlay. Expected true, false, or an object.");
|
||||
throw new JsonException("Invalid value for TitleBarOverlay. Expected boolean or an object.");
|
||||
}
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, TitleBarOverlay value, JsonSerializer serializer)
|
||||
public override void Write(Utf8JsonWriter writer, TitleBarOverlay value, JsonSerializerOptions options)
|
||||
{
|
||||
if (value is null)
|
||||
{
|
||||
writer.WriteUndefined();
|
||||
return;
|
||||
}
|
||||
|
||||
var @bool = (bool?)value;
|
||||
if (@bool.HasValue)
|
||||
{
|
||||
writer.WriteValue(@bool.Value);
|
||||
writer.WriteBooleanValue(@bool.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
serializer.Serialize(writer, value);
|
||||
JsonSerializer.Serialize(writer, value, ElectronJson.Options);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,8 +27,6 @@
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="SocketIO.Serializer.NewtonsoftJson" Version="3.1.2" />
|
||||
<PackageReference Include="SocketIOClient" Version="3.1.2" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.16" />
|
||||
<PackageReference Include="System.Text.Json" Version="8.0.5" />
|
||||
@@ -38,4 +36,4 @@
|
||||
<InternalsVisibleTo Include="ElectronNET.AspNet" />
|
||||
<InternalsVisibleTo Include="ElectronNET.Core.AspNet" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
namespace ElectronNET
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Immutable;
|
||||
using System.Threading.Tasks;
|
||||
using ElectronNET.API;
|
||||
using ElectronNET.Runtime;
|
||||
using ElectronNET.Runtime.Controllers;
|
||||
using ElectronNET.Runtime.Data;
|
||||
using System;
|
||||
using System.Collections.Immutable;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public static class ElectronNetRuntime
|
||||
{
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
namespace ElectronNET.Runtime.Controllers
|
||||
{
|
||||
using System.Threading.Tasks;
|
||||
using ElectronNET.API;
|
||||
using ElectronNET.Runtime.Services;
|
||||
using ElectronNET.Runtime.Services.ElectronProcess;
|
||||
using ElectronNET.Runtime.Services.SocketBridge;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
internal abstract class RuntimeControllerBase : LifetimeServiceBase, IElectronNetRuntimeController
|
||||
{
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
namespace ElectronNET.Runtime.Controllers
|
||||
{
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using ElectronNET.API;
|
||||
using ElectronNET.Common;
|
||||
using ElectronNET.Runtime.Data;
|
||||
using ElectronNET.Runtime.Helpers;
|
||||
using ElectronNET.Runtime.Services.ElectronProcess;
|
||||
using ElectronNET.Runtime.Services.SocketBridge;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
internal class RuntimeControllerDotNetFirst : RuntimeControllerBase
|
||||
{
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
namespace ElectronNET.Runtime.Controllers
|
||||
{
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using ElectronNET.API;
|
||||
using ElectronNET.Runtime.Data;
|
||||
using ElectronNET.Runtime.Services.ElectronProcess;
|
||||
using ElectronNET.Runtime.Services.SocketBridge;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
internal class RuntimeControllerElectronFirst : RuntimeControllerBase
|
||||
{
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
namespace ElectronNET.Runtime
|
||||
{
|
||||
using ElectronNET.Runtime.Data;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using ElectronNET.Runtime.Data;
|
||||
|
||||
public interface IElectronNetRuntimeController
|
||||
{
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
namespace ElectronNET.Runtime.Services.ElectronProcess
|
||||
{
|
||||
using ElectronNET.Common;
|
||||
using ElectronNET.Runtime.Data;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using ElectronNET.Common;
|
||||
using ElectronNET.Runtime.Data;
|
||||
|
||||
/// <summary>
|
||||
/// Launches and manages the Electron app process.
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
namespace ElectronNET.Runtime.Services.ElectronProcess
|
||||
{
|
||||
using ElectronNET.Runtime.Data;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using ElectronNET.Runtime.Data;
|
||||
|
||||
/// <summary>
|
||||
/// Launches and manages the Electron app process.
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
namespace ElectronNET.Runtime.Services
|
||||
{
|
||||
using ElectronNET.Runtime.Data;
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Tasks;
|
||||
using ElectronNET.Runtime.Data;
|
||||
|
||||
public abstract class LifetimeServiceBase
|
||||
{
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
namespace ElectronNET.Runtime.Services.SocketBridge
|
||||
{
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using ElectronNET.API;
|
||||
using ElectronNET.Runtime.Data;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
internal class SocketBridgeService : LifetimeServiceBase
|
||||
{
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
namespace ElectronNET.Runtime
|
||||
{
|
||||
using ElectronNET.Runtime.Controllers;
|
||||
using ElectronNET.Runtime.Data;
|
||||
using ElectronNET.Runtime.Helpers;
|
||||
using System;
|
||||
using System.Collections.Immutable;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using ElectronNET.Runtime.Controllers;
|
||||
using ElectronNET.Runtime.Data;
|
||||
using ElectronNET.Runtime.Helpers;
|
||||
|
||||
internal class StartupManager
|
||||
{
|
||||
|
||||
34
src/ElectronNET.API/Serialization/ElectronJson.cs
Normal file
34
src/ElectronNET.API/Serialization/ElectronJson.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using ElectronNET.API.Entities;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace ElectronNET.API.Serialization
|
||||
{
|
||||
internal static class ElectronJson
|
||||
{
|
||||
public static readonly JsonSerializerOptions Options = new JsonSerializerOptions
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||
WriteIndented = false,
|
||||
Converters =
|
||||
{
|
||||
new JsonStringEnumConverter(JsonNamingPolicy.CamelCase)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Use source generation where feasible for hot paths
|
||||
[JsonSourceGenerationOptions(WriteIndented = false, PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
[JsonSerializable(typeof(TrayClickEventArgs))]
|
||||
[JsonSerializable(typeof(Rectangle))]
|
||||
[JsonSerializable(typeof(Display))]
|
||||
[JsonSerializable(typeof(UpdateInfo))]
|
||||
[JsonSerializable(typeof(ProgressInfo))]
|
||||
[JsonSerializable(typeof(UpdateCheckResult))]
|
||||
[JsonSerializable(typeof(SemVer))]
|
||||
internal partial class ElectronJsonContext : JsonSerializerContext
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace ElectronNET.IntegrationTests.Tests
|
||||
this.fx.MainWindow.SetPosition(134, 246);
|
||||
await Task.Delay(500);
|
||||
var pos = await this.fx.MainWindow.GetPositionAsync();
|
||||
pos.Should().BeEquivalentTo(new[] { 134, 246 });
|
||||
pos.Should().BeEquivalentTo([134, 246]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -134,7 +134,7 @@ namespace ElectronNET.IntegrationTests.Tests
|
||||
window.WebContents.OnDomReady += () => domReadyTcs.TrySetResult();
|
||||
await window.WebContents.LoadURLAsync("about:blank");
|
||||
await domReadyTcs.Task;
|
||||
await window.WebContents.ExecuteJavaScriptAsync("document.title='NewTitle';");
|
||||
await window.WebContents.ExecuteJavaScriptAsync<string>("document.title='NewTitle';");
|
||||
|
||||
// Wait for event up to a short timeout
|
||||
var completed2 = await Task.WhenAny(tcs.Task, Task.Delay(3000));
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace ElectronNET.IntegrationTests.Tests
|
||||
// Navigate to example.com so cookie domain matches
|
||||
await this.fx.MainWindow.WebContents.LoadURLAsync("https://example.com");
|
||||
// Set via renderer for now
|
||||
await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync("document.cookie='integration_cookie=1;path=/';");
|
||||
await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync<string>("document.cookie='integration_cookie=1;path=/';");
|
||||
await Task.Delay(500);
|
||||
changed.Should().BeTrue();
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace ElectronNET.IntegrationTests.Tests
|
||||
{
|
||||
var tcs = new TaskCompletionSource<string>();
|
||||
await Electron.IpcMain.On("ipc-on-test", obj => tcs.TrySetResult(obj?.ToString() ?? string.Empty));
|
||||
await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync("require('electron').ipcRenderer.send('ipc-on-test','payload123')");
|
||||
await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync<string>("require('electron').ipcRenderer.send('ipc-on-test','payload123')");
|
||||
var result = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5));
|
||||
result.Should().Be("payload123");
|
||||
}
|
||||
@@ -26,7 +26,7 @@ namespace ElectronNET.IntegrationTests.Tests
|
||||
{
|
||||
var count = 0;
|
||||
Electron.IpcMain.Once("ipc-once-test", _ => count++);
|
||||
await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync("const {ipcRenderer}=require('electron'); ipcRenderer.send('ipc-once-test','a'); ipcRenderer.send('ipc-once-test','b');");
|
||||
await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync<string>("const {ipcRenderer}=require('electron'); ipcRenderer.send('ipc-once-test','a'); ipcRenderer.send('ipc-once-test','b');");
|
||||
await Task.Delay(500);
|
||||
count.Should().Be(1);
|
||||
}
|
||||
@@ -37,7 +37,7 @@ namespace ElectronNET.IntegrationTests.Tests
|
||||
var fired = false;
|
||||
await Electron.IpcMain.On("ipc-remove-test", _ => fired = true);
|
||||
Electron.IpcMain.RemoveAllListeners("ipc-remove-test");
|
||||
await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync("require('electron').ipcRenderer.send('ipc-remove-test','x')");
|
||||
await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync<string>("require('electron').ipcRenderer.send('ipc-remove-test','x')");
|
||||
await Task.Delay(400);
|
||||
fired.Should().BeFalse();
|
||||
}
|
||||
@@ -45,12 +45,12 @@ namespace ElectronNET.IntegrationTests.Tests
|
||||
[Fact]
|
||||
public async Task Ipc_OnSync_returns_value()
|
||||
{
|
||||
Electron.IpcMain.OnSync("ipc-sync-test", obj =>
|
||||
Electron.IpcMain.OnSync("ipc-sync-test", (obj) =>
|
||||
{
|
||||
obj.Should().NotBeNull();
|
||||
return "pong";
|
||||
});
|
||||
var ret = await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync("require('electron').ipcRenderer.sendSync('ipc-sync-test','ping')");
|
||||
var ret = await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync<string>("require('electron').ipcRenderer.sendSync('ipc-sync-test','ping')");
|
||||
ret.Should().Be("pong");
|
||||
}
|
||||
|
||||
@@ -58,12 +58,12 @@ namespace ElectronNET.IntegrationTests.Tests
|
||||
public async Task Ipc_Send_from_main_reaches_renderer()
|
||||
{
|
||||
// Listener: store raw arg; if Electron packs differently we will normalize later
|
||||
await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync(@"(function(){ const {ipcRenderer}=require('electron'); ipcRenderer.once('main-to-render',(e,arg)=>{ globalThis.__mainToRender = arg;}); return 'ready'; })();");
|
||||
await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync<string>(@"(function(){ const {ipcRenderer}=require('electron'); ipcRenderer.once('main-to-render',(e,arg)=>{ globalThis.__mainToRender = arg;}); return 'ready'; })();");
|
||||
Electron.IpcMain.Send(this.fx.MainWindow, "main-to-render", "hello-msg");
|
||||
string value = "";
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
var jsVal = await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync("globalThis.__mainToRender === undefined ? '' : (typeof globalThis.__mainToRender === 'string' ? globalThis.__mainToRender : JSON.stringify(globalThis.__mainToRender))");
|
||||
var jsVal = await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync<string>("globalThis.__mainToRender === undefined ? '' : (typeof globalThis.__mainToRender === 'string' ? globalThis.__mainToRender : JSON.stringify(globalThis.__mainToRender))");
|
||||
value = jsVal?.ToString() ?? "";
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
{
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace ElectronNET.IntegrationTests.Tests
|
||||
};
|
||||
Electron.Menu.SetApplicationMenu(items);
|
||||
var targetId = items[0].Submenu[0].Id;
|
||||
await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync($"require('electron').ipcRenderer.send('integration-click-application-menu','{targetId}')");
|
||||
await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync<string>($"require('electron').ipcRenderer.send('integration-click-application-menu','{targetId}')");
|
||||
for (int i = 0; i < 20 && !clicked; i++)
|
||||
{
|
||||
await Task.Delay(100);
|
||||
@@ -48,7 +48,7 @@ namespace ElectronNET.IntegrationTests.Tests
|
||||
var ctxId = ctxItems[0].Id;
|
||||
// simulate popup then click
|
||||
Electron.Menu.ContextMenuPopup(win);
|
||||
await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync($"require('electron').ipcRenderer.send('integration-click-context-menu',{win.Id},'{ctxId}')");
|
||||
await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync<string>($"require('electron').ipcRenderer.send('integration-click-context-menu',{win.Id},'{ctxId}')");
|
||||
for (int i = 0; i < 20 && !ctxClicked; i++)
|
||||
{
|
||||
await Task.Delay(100);
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace ElectronNET.IntegrationTests.Tests
|
||||
{
|
||||
// Use renderer to fetch process info and round-trip
|
||||
var execPath = await Electron.WindowManager.CreateWindowAsync(new API.Entities.BrowserWindowOptions { Show = false });
|
||||
var result = await execPath.WebContents.ExecuteJavaScriptAsync("process.execPath && process.platform ? 'ok' : 'fail'");
|
||||
var result = await execPath.WebContents.ExecuteJavaScriptAsync<string>("process.execPath && process.platform ? 'ok' : 'fail'");
|
||||
result.Should().Be("ok");
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace ElectronNET.IntegrationTests.Tests
|
||||
{
|
||||
var wc = this.fx.MainWindow.WebContents;
|
||||
await wc.LoadURLAsync("https://example.com");
|
||||
var title = await wc.ExecuteJavaScriptAsync("document.title");
|
||||
var title = await wc.ExecuteJavaScriptAsync<string>("document.title");
|
||||
title.Should().NotBeNull();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ElectronNET.API;
|
||||
using System.Linq;
|
||||
using ElectronNET.API.Entities;
|
||||
using Newtonsoft.Json;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace ElectronNET.WebApp.Controllers
|
||||
{
|
||||
@@ -39,11 +39,11 @@ namespace ElectronNET.WebApp.Controllers
|
||||
{
|
||||
var nativeImage = await Electron.Clipboard.ReadImageAsync();
|
||||
var mainWindow = Electron.WindowManager.BrowserWindows.First();
|
||||
Electron.IpcMain.Send(mainWindow, "paste-image-from", JsonConvert.SerializeObject(nativeImage));
|
||||
Electron.IpcMain.Send(mainWindow, "paste-image-from", JsonSerializer.Serialize(nativeImage));
|
||||
});
|
||||
}
|
||||
|
||||
return View();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<template class="task-template">
|
||||
<template class="task-template">
|
||||
<section id="clipboard-section" class="section js-section u-category-system">
|
||||
<header class="section-header">
|
||||
<div class="section-wrapper">
|
||||
@@ -145,7 +145,7 @@ copyBtn.addEventListener('click', () => {
|
||||
{
|
||||
var nativeImage = await Electron.Clipboard.ReadImageAsync();
|
||||
var mainWindow = Electron.WindowManager.BrowserWindows.First();
|
||||
Electron.IpcMain.Send(mainWindow, "paste-image-from", JsonConvert.SerializeObject(nativeImage));
|
||||
Electron.IpcMain.Send(mainWindow, "paste-image-from", JSON.stringify(nativeImage));
|
||||
});</code></pre>
|
||||
<div class="demo-protip">
|
||||
<h2>ProTip</h2>
|
||||
@@ -295,3 +295,4 @@ copyBtn.addEventListener('click', () => {
|
||||
|
||||
</section>
|
||||
</template>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user