mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-09-21 22:45:20 +00:00
replace remaining cases with OnResult, fix deserialization of json objects
This commit is contained in:
@@ -492,20 +492,7 @@ namespace ElectronNET.API
|
||||
/// should usually also specify a productName field, which is your application's full capitalized name, and
|
||||
/// which will be preferred over name by Electron.
|
||||
/// </summary>
|
||||
public Task<string> GetNameAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
|
||||
BridgeConnector.On<string>("appGetNameCompleted", (result) =>
|
||||
{
|
||||
BridgeConnector.Off("appGetNameCompleted");
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("appGetName");
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
public Task<string> GetNameAsync() => BridgeConnector.OnResult<string>("appGetName", "appGetNameCompleted");
|
||||
|
||||
|
||||
internal App()
|
||||
@@ -641,25 +628,7 @@ namespace ElectronNET.API
|
||||
/// <summary>
|
||||
/// The current application directory.
|
||||
/// </summary>
|
||||
public async Task<string> GetAppPathAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
using(cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.On<string>("appGetAppPathCompleted", (path) =>
|
||||
{
|
||||
BridgeConnector.Off("appGetAppPathCompleted");
|
||||
taskCompletionSource.SetResult(path);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("appGetAppPath");
|
||||
|
||||
return await taskCompletionSource.Task
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
public Task<string> GetAppPathAsync(CancellationToken cancellationToken = default) => BridgeConnector.OnResult<string>("appGetAppPath", "appGetAppPathCompleted", cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Sets or creates a directory your app's logs which can then be manipulated with <see cref="GetPathAsync"/>
|
||||
@@ -682,25 +651,8 @@ namespace ElectronNET.API
|
||||
/// <param name="pathName">Special directory.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>A path to a special directory or file associated with name.</returns>
|
||||
public async Task<string> GetPathAsync(PathName pathName, CancellationToken cancellationToken = default)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
public Task<string> GetPathAsync(PathName pathName, CancellationToken cancellationToken = default) => BridgeConnector.OnResult<string>("appGetPath", "appGetPathCompleted", cancellationToken, pathName.GetDescription());
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
using(cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.On<string>("appGetPathCompleted", (path) =>
|
||||
{
|
||||
BridgeConnector.Off("appGetPathCompleted");
|
||||
|
||||
taskCompletionSource.SetResult(path);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("appGetPath", pathName.GetDescription());
|
||||
|
||||
return await taskCompletionSource.Task.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the path to a special directory or file associated with name. If the path specifies a directory
|
||||
@@ -724,25 +676,7 @@ namespace ElectronNET.API
|
||||
/// the version of the current bundle or executable is returned.
|
||||
/// </summary>
|
||||
/// <returns>The version of the loaded application.</returns>
|
||||
public async Task<string> GetVersionAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
using(cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.On<string>("appGetVersionCompleted", (version) =>
|
||||
{
|
||||
BridgeConnector.Off("appGetVersionCompleted");
|
||||
taskCompletionSource.SetResult(version);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("appGetVersion");
|
||||
|
||||
return await taskCompletionSource.Task
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
public Task<string> GetVersionAsync(CancellationToken cancellationToken = default) => BridgeConnector.OnResult<string>("appGetVersion", "appGetVersionCompleted", cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// The current application locale. Possible return values are documented <see href="https://www.electronjs.org/docs/api/locales">here</see>.
|
||||
@@ -752,25 +686,7 @@ namespace ElectronNET.API
|
||||
/// Note: On Windows, you have to call it after the <see cref="Ready"/> events gets emitted.
|
||||
/// </summary>
|
||||
/// <returns>The current application locale.</returns>
|
||||
public async Task<string> GetLocaleAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.On<string>("appGetLocaleCompleted", (local) =>
|
||||
{
|
||||
BridgeConnector.Off("appGetLocaleCompleted");
|
||||
taskCompletionSource.SetResult(local);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("appGetLocale");
|
||||
|
||||
return await taskCompletionSource.Task
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
public Task<string> GetLocaleAsync(CancellationToken cancellationToken = default) => BridgeConnector.OnResult<string>("appGetLocale", "appGetLocaleCompleted", cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Adds path to the recent documents list. This list is managed by the OS. On Windows you can visit the
|
||||
@@ -878,25 +794,7 @@ namespace ElectronNET.API
|
||||
/// <param name="args">Arguments passed to the executable. Defaults to an empty array.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Whether the call succeeded.</returns>
|
||||
public async Task<bool> SetAsDefaultProtocolClientAsync(string protocol, string path, string[] args, CancellationToken cancellationToken = default)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.On<bool>("appSetAsDefaultProtocolClientCompleted", (success) =>
|
||||
{
|
||||
BridgeConnector.Off("appSetAsDefaultProtocolClientCompleted");
|
||||
taskCompletionSource.SetResult(success);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("appSetAsDefaultProtocolClient", protocol, path, args);
|
||||
|
||||
return await taskCompletionSource.Task
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
public Task<bool> SetAsDefaultProtocolClientAsync(string protocol, string path, string[] args, CancellationToken cancellationToken = default) => BridgeConnector.OnResult<bool>("appSetAsDefaultProtocolClient", "appSetAsDefaultProtocolClientCompleted", cancellationToken, protocol, path, args);
|
||||
|
||||
/// <summary>
|
||||
/// This method checks if the current executable as the default handler for a protocol (aka URI scheme).
|
||||
@@ -932,25 +830,8 @@ namespace ElectronNET.API
|
||||
/// <param name="args">Defaults to an empty array.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Whether the call succeeded.</returns>
|
||||
public async Task<bool> RemoveAsDefaultProtocolClientAsync(string protocol, string path, string[] args, CancellationToken cancellationToken = default)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
public Task<bool> RemoveAsDefaultProtocolClientAsync(string protocol, string path, string[] args, CancellationToken cancellationToken = default) => BridgeConnector.OnResult<bool>("appRemoveAsDefaultProtocolClient", "appRemoveAsDefaultProtocolClientCompleted", cancellationToken, protocol, path, args);
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.On<bool>("appRemoveAsDefaultProtocolClientCompleted", (success) =>
|
||||
{
|
||||
BridgeConnector.Off("appRemoveAsDefaultProtocolClientCompleted");
|
||||
taskCompletionSource.SetResult(success);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("appRemoveAsDefaultProtocolClient", protocol, path, args);
|
||||
|
||||
return await taskCompletionSource.Task
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method checks if the current executable is the default handler for a protocol (aka URI scheme).
|
||||
@@ -1004,25 +885,8 @@ namespace ElectronNET.API
|
||||
/// <param name="args">Defaults to an empty array.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Whether the current executable is the default handler for a protocol (aka URI scheme).</returns>
|
||||
public async Task<bool> IsDefaultProtocolClientAsync(string protocol, string path, string[] args, CancellationToken cancellationToken = default)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
public Task<bool> IsDefaultProtocolClientAsync(string protocol, string path, string[] args, CancellationToken cancellationToken = default) => BridgeConnector.OnResult<bool>("appIsDefaultProtocolClient", "appIsDefaultProtocolClientCompleted", cancellationToken, protocol, path, args);
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.On<bool>("appIsDefaultProtocolClientCompleted", (success) =>
|
||||
{
|
||||
BridgeConnector.Off("appIsDefaultProtocolClientCompleted");
|
||||
taskCompletionSource.SetResult(success);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("appIsDefaultProtocolClient", protocol, path, args);
|
||||
|
||||
return await taskCompletionSource.Task
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds tasks to the <see cref="UserTask"/> category of the JumpList on Windows.
|
||||
@@ -1032,50 +896,14 @@ namespace ElectronNET.API
|
||||
/// <param name="userTasks">Array of <see cref="UserTask"/> objects.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Whether the call succeeded.</returns>
|
||||
public async Task<bool> SetUserTasksAsync(UserTask[] userTasks, CancellationToken cancellationToken = default)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.On<bool>("appSetUserTasksCompleted", (success) =>
|
||||
{
|
||||
BridgeConnector.Off("appSetUserTasksCompleted");
|
||||
taskCompletionSource.SetResult(success);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("appSetUserTasks", JArray.FromObject(userTasks, _jsonSerializer));
|
||||
|
||||
return await taskCompletionSource.Task
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
public Task<bool> SetUserTasksAsync(UserTask[] userTasks, CancellationToken cancellationToken = default) => BridgeConnector.OnResult<bool>("appSetUserTasks", "appSetUserTasksCompleted", cancellationToken, JArray.FromObject(userTasks, _jsonSerializer));
|
||||
|
||||
/// <summary>
|
||||
/// Jump List settings for the application.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Jump List settings.</returns>
|
||||
public async Task<JumpListSettings> GetJumpListSettingsAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<JumpListSettings>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.On<JumpListSettings>("appGetJumpListSettingsCompleted", (jumpListSettings) =>
|
||||
{
|
||||
BridgeConnector.Off("appGetJumpListSettingsCompleted");
|
||||
taskCompletionSource.SetResult(jumpListSettings);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("appGetJumpListSettings");
|
||||
|
||||
return await taskCompletionSource.Task
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
public Task<JumpListSettings> GetJumpListSettingsAsync(CancellationToken cancellationToken = default) => BridgeConnector.OnResult<JumpListSettings>("appGetJumpListSettings", "appGetJumpListSettingsCompleted", cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Sets or removes a custom Jump List for the application. If categories is null the previously set custom
|
||||
@@ -1119,7 +947,7 @@ namespace ElectronNET.API
|
||||
/// should continue loading. And returns true if your process has sent its parameters to another instance, and
|
||||
/// you should immediately quit.
|
||||
/// </returns>
|
||||
public async Task<bool> RequestSingleInstanceLockAsync(Action<string[], string> newInstanceOpened, CancellationToken cancellationToken = default)
|
||||
public async Task<bool> RequestSingleInstanceLockAsync(Action<string[], string> newInstanceOpened, CancellationToken cancellationToken = default)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
@@ -1140,8 +968,7 @@ namespace ElectronNET.API
|
||||
|
||||
BridgeConnector.Emit("appRequestSingleInstanceLock");
|
||||
|
||||
return await taskCompletionSource.Task
|
||||
.ConfigureAwait(false);
|
||||
return await taskCompletionSource.Task.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1160,24 +987,7 @@ namespace ElectronNET.API
|
||||
/// <see cref="ReleaseSingleInstanceLock"/>.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
public async Task<bool> HasSingleInstanceLockAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.On<bool>("appHasSingleInstanceLockCompleted", (hasLock) =>
|
||||
{
|
||||
BridgeConnector.Off("appHasSingleInstanceLockCompleted");
|
||||
taskCompletionSource.SetResult(hasLock);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("appHasSingleInstanceLock");
|
||||
|
||||
return await taskCompletionSource.Task.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
public Task<bool> HasSingleInstanceLockAsync(CancellationToken cancellationToken = default) => BridgeConnector.OnResult<bool>("appHasSingleInstanceLock", "appHasSingleInstanceLockCompleted", cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Creates an NSUserActivity and sets it as the current activity. The activity is
|
||||
@@ -1212,24 +1022,8 @@ namespace ElectronNET.API
|
||||
/// The type of the currently running activity.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
public async Task<string> GetCurrentActivityTypeAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
public Task<string> GetCurrentActivityTypeAsync(CancellationToken cancellationToken = default) => BridgeConnector.OnResult<string>("appGetCurrentActivityType", "appGetCurrentActivityTypeCompleted", cancellationToken);
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.On<string>("appGetCurrentActivityTypeCompleted", (activityType) =>
|
||||
{
|
||||
BridgeConnector.Off("appGetCurrentActivityTypeCompleted");
|
||||
taskCompletionSource.SetResult(activityType);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("appGetCurrentActivityType");
|
||||
|
||||
return await taskCompletionSource.Task.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invalidates the current <see href="https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/Handoff/HandoffFundamentals/HandoffFundamentals.html">Handoff</see> user activity.
|
||||
@@ -1265,25 +1059,7 @@ namespace ElectronNET.API
|
||||
/// <param name="options"></param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Result of import. Value of 0 indicates success.</returns>
|
||||
public async Task<int> ImportCertificateAsync(ImportCertificateOptions options, CancellationToken cancellationToken = default)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<int>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.On<int>("appImportCertificateCompleted", (result) =>
|
||||
{
|
||||
BridgeConnector.Off("appImportCertificateCompleted");
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("appImportCertificate", JObject.FromObject(options, _jsonSerializer));
|
||||
|
||||
return await taskCompletionSource.Task
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
public Task<int> ImportCertificateAsync(ImportCertificateOptions options, CancellationToken cancellationToken = default) => BridgeConnector.OnResult<int>("appImportCertificate", "appImportCertificateCompleted", cancellationToken, JObject.FromObject(options, _jsonSerializer));
|
||||
|
||||
/// <summary>
|
||||
/// Memory and cpu usage statistics of all the processes associated with the app.
|
||||
@@ -1293,25 +1069,7 @@ namespace ElectronNET.API
|
||||
/// statistics of all the processes associated with the app.
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// </returns>
|
||||
public async Task<ProcessMetric[]> GetAppMetricsAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<ProcessMetric[]>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.On<ProcessMetric[]>("appGetAppMetricsCompleted", (result) =>
|
||||
{
|
||||
BridgeConnector.Off("appGetAppMetricsCompleted");
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("appGetAppMetrics");
|
||||
|
||||
return await taskCompletionSource.Task
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
public Task<ProcessMetric[]> GetAppMetricsAsync(CancellationToken cancellationToken = default) => BridgeConnector.OnResult<ProcessMetric[]>("appGetAppMetrics", "appGetAppMetricsCompleted", cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// The Graphics Feature Status from chrome://gpu/.
|
||||
@@ -1319,25 +1077,7 @@ namespace ElectronNET.API
|
||||
/// Note: This information is only usable after the gpu-info-update event is emitted.
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// </summary>
|
||||
public async Task<GPUFeatureStatus> GetGpuFeatureStatusAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<GPUFeatureStatus>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.On<GPUFeatureStatus>("appGetGpuFeatureStatusCompleted", (result) =>
|
||||
{
|
||||
BridgeConnector.Off("appGetGpuFeatureStatusCompleted");
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("appGetGpuFeatureStatus");
|
||||
|
||||
return await taskCompletionSource.Task
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
public Task<GPUFeatureStatus> GetGpuFeatureStatusAsync(CancellationToken cancellationToken = default) => BridgeConnector.OnResult<GPUFeatureStatus>("appGetGpuFeatureStatus", "appGetGpuFeatureStatusCompleted", cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the counter badge for current app. Setting the count to 0 will hide the badge.
|
||||
@@ -1349,49 +1089,13 @@ namespace ElectronNET.API
|
||||
/// <param name="count">Counter badge.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Whether the call succeeded.</returns>
|
||||
public async Task<bool> SetBadgeCountAsync(int count, CancellationToken cancellationToken = default)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.On<bool>("appSetBadgeCountCompleted", (success) =>
|
||||
{
|
||||
BridgeConnector.Off("appSetBadgeCountCompleted");
|
||||
taskCompletionSource.SetResult(success);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("appSetBadgeCount", count);
|
||||
|
||||
return await taskCompletionSource.Task
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
public Task<bool> SetBadgeCountAsync(int count, CancellationToken cancellationToken = default) => BridgeConnector.OnResult<bool>("appSetBadgeCount", "appSetBadgeCountCompleted", cancellationToken, count);
|
||||
|
||||
/// <summary>
|
||||
/// The current value displayed in the counter badge.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
public async Task<int> GetBadgeCountAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<int>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.On<int>("appGetBadgeCountCompleted", (count) =>
|
||||
{
|
||||
BridgeConnector.Off("appGetBadgeCountCompleted");
|
||||
taskCompletionSource.SetResult(count);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("appGetBadgeCount");
|
||||
|
||||
return await taskCompletionSource.Task
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
public Task<int> GetBadgeCountAsync(CancellationToken cancellationToken = default) => BridgeConnector.OnResult<int>("appGetBadgeCount", "appGetBadgeCountCompleted", cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="CommandLine"/> object that allows you to read and manipulate the command line arguments that Chromium uses.
|
||||
@@ -1402,25 +1106,7 @@ namespace ElectronNET.API
|
||||
/// Whether the current desktop environment is Unity launcher.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
public async Task<bool> IsUnityRunningAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.On<bool>("appIsUnityRunningCompleted", (isUnityRunning) =>
|
||||
{
|
||||
BridgeConnector.Off("appIsUnityRunningCompleted");
|
||||
taskCompletionSource.SetResult(isUnityRunning);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("appIsUnityRunning");
|
||||
|
||||
return await taskCompletionSource.Task
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
public Task<bool> IsUnityRunningAsync(CancellationToken cancellationToken = default) => BridgeConnector.OnResult<bool>("appIsUnityRunning", "appIsUnityRunningCompleted", cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// If you provided path and args options to <see cref="SetLoginItemSettings"/> then you need to pass the same
|
||||
@@ -1437,32 +1123,9 @@ namespace ElectronNET.API
|
||||
/// </summary>
|
||||
/// <param name="options"></param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
public async Task<LoginItemSettings> GetLoginItemSettingsAsync(LoginItemSettingsOptions options, CancellationToken cancellationToken = default)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<LoginItemSettings>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.On<LoginItemSettings>("appGetLoginItemSettingsCompleted", (result) =>
|
||||
{
|
||||
BridgeConnector.Off("appGetLoginItemSettingsCompleted");
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
|
||||
if (options == null)
|
||||
{
|
||||
BridgeConnector.Emit("appGetLoginItemSettings");
|
||||
}
|
||||
else
|
||||
{
|
||||
BridgeConnector.Emit("appGetLoginItemSettings", JObject.FromObject(options, _jsonSerializer));
|
||||
}
|
||||
|
||||
return await taskCompletionSource.Task
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
public Task<LoginItemSettings> GetLoginItemSettingsAsync(LoginItemSettingsOptions options, CancellationToken cancellationToken = default) =>
|
||||
options is null ? BridgeConnector.OnResult<LoginItemSettings>("appGetLoginItemSettings", "appGetLoginItemSettingsCompleted", cancellationToken)
|
||||
: BridgeConnector.OnResult<LoginItemSettings>("appGetLoginItemSettings", "appGetLoginItemSettingsCompleted", cancellationToken, JObject.FromObject(options, _jsonSerializer));
|
||||
|
||||
/// <summary>
|
||||
/// Set the app's login item settings.
|
||||
@@ -1481,25 +1144,8 @@ namespace ElectronNET.API
|
||||
/// See <see href="chromium.org/developers/design-documents/accessibility">Chromium's accessibility docs</see> for more details.
|
||||
/// </summary>
|
||||
/// <returns><see langword="true"/> if Chrome’s accessibility support is enabled, <see langword="false"/> otherwise.</returns>
|
||||
public async Task<bool> IsAccessibilitySupportEnabledAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
public Task<bool> IsAccessibilitySupportEnabledAsync(CancellationToken cancellationToken = default) => BridgeConnector.OnResult<bool>("appIsAccessibilitySupportEnabled", "appIsAccessibilitySupportEnabledCompleted", cancellationToken);
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.On<bool>("appIsAccessibilitySupportEnabledCompleted", (isAccessibilitySupportEnabled) =>
|
||||
{
|
||||
BridgeConnector.Off("appIsAccessibilitySupportEnabledCompleted");
|
||||
taskCompletionSource.SetResult(isAccessibilitySupportEnabled);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("appIsAccessibilitySupportEnabled");
|
||||
|
||||
return await taskCompletionSource.Task
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Manually enables Chrome's accessibility support, allowing to expose accessibility switch to users in application settings.
|
||||
@@ -1565,20 +1211,7 @@ namespace ElectronNET.API
|
||||
/// custom value as early as possible in your app's initialization to ensure that your overridden value
|
||||
/// is used.
|
||||
/// </summary>
|
||||
public Task<string> GetUserAgentFallbackAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
|
||||
BridgeConnector.On<string>("appGetUserAgentFallbackCompleted", (result) =>
|
||||
{
|
||||
BridgeConnector.Off("appGetUserAgentFallbackCompleted");
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("appGetUserAgentFallback");
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
public Task<string> GetUserAgentFallbackAsync() => BridgeConnector.OnResult<string>("appGetUserAgentFallback", "appGetUserAgentFallbackCompleted");
|
||||
|
||||
internal void PreventQuit()
|
||||
{
|
||||
@@ -1593,27 +1226,27 @@ namespace ElectronNET.API
|
||||
/// </summary>
|
||||
/// <param name="eventName">The event name</param>
|
||||
/// <param name="fn">The handler</param>
|
||||
public void On(string eventName, Action fn)
|
||||
=> Events.Instance.On(ModuleName, eventName, fn);
|
||||
public void On(string eventName, Action fn) => Events.Instance.On(ModuleName, eventName, fn);
|
||||
|
||||
/// <summary>
|
||||
/// Subscribe to an unmapped event on the <see cref="App"/> module.
|
||||
/// </summary>
|
||||
/// <param name="eventName">The event name</param>
|
||||
/// <param name="fn">The handler</param>
|
||||
public void On(string eventName, Action<object> fn) => Events.Instance.On(ModuleName, eventName, fn);
|
||||
|
||||
/// <summary>
|
||||
/// Subscribe to an unmapped event on the <see cref="App"/> module once.
|
||||
/// </summary>
|
||||
/// <param name="eventName">The event name</param>
|
||||
/// <param name="fn">The handler</param>
|
||||
public void Once(string eventName, Action fn)
|
||||
=> Events.Instance.Once(ModuleName, eventName, fn);
|
||||
public void Once(string eventName, Action fn) => Events.Instance.Once(ModuleName, eventName, fn);
|
||||
|
||||
/// <summary>
|
||||
/// Subscribe to an unmapped event on the <see cref="App"/> module once.
|
||||
/// </summary>
|
||||
/// <param name="eventName">The event name</param>
|
||||
/// <param name="fn">The handler</param>
|
||||
public void Once(string eventName, Action<object> fn)
|
||||
=> Events.Instance.Once(ModuleName, eventName, fn);
|
||||
public void Once(string eventName, Action<object> fn) => Events.Instance.Once(ModuleName, eventName, fn);
|
||||
}
|
||||
}
|
||||
@@ -16,40 +16,14 @@ namespace ElectronNET.API
|
||||
/// <summary>
|
||||
/// Whether to automatically download an update when it is found. (Default is true)
|
||||
/// </summary>
|
||||
public Task<bool> IsAutoDownloadEnabledAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
|
||||
BridgeConnector.On<bool>("autoUpdater-autoDownload-get-reply", (result) =>
|
||||
{
|
||||
BridgeConnector.Off("autoUpdater-autoDownload-get-reply");
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("autoUpdater-autoDownload-get");
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
public Task<bool> IsAutoDownloadEnabledAsync() => BridgeConnector.OnResult<bool>("autoUpdater-autoDownload-get", "autoUpdater-autoDownload-get-reply");
|
||||
|
||||
/// <summary>
|
||||
/// Whether to automatically install a downloaded update on app quit (if `QuitAndInstall` was not called before).
|
||||
///
|
||||
/// Applicable only on Windows and Linux.
|
||||
/// </summary>
|
||||
public Task<bool> IsAutoInstallOnAppQuitEnabledAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
|
||||
BridgeConnector.On<bool>("autoUpdater-autoInstallOnAppQuit-get-reply", (result) =>
|
||||
{
|
||||
BridgeConnector.Off("autoUpdater-autoInstallOnAppQuit-get-reply");
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("autoUpdater-autoInstallOnAppQuit-get");
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
public Task<bool> IsAutoInstallOnAppQuitEnabledAsync() => BridgeConnector.OnResult<bool>("autoUpdater-autoInstallOnAppQuit-get", "autoUpdater-autoInstallOnAppQuit-get-reply");
|
||||
|
||||
/// <summary>
|
||||
/// *GitHub provider only.* Whether to allow update to pre-release versions.
|
||||
@@ -57,54 +31,16 @@ namespace ElectronNET.API
|
||||
///
|
||||
/// If "true", downgrade will be allowed("allowDowngrade" will be set to "true").
|
||||
/// </summary>
|
||||
public Task<bool> IsAllowPrereleaseEnabledAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
|
||||
BridgeConnector.On<bool>("autoUpdater-allowPrerelease-get-reply", (result) =>
|
||||
{
|
||||
BridgeConnector.Off("autoUpdater-allowPrerelease-get-reply");
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("autoUpdater-allowPrerelease-get");
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
public Task<bool> IsAllowPrereleaseEnabledAsync() => BridgeConnector.OnResult<bool>("autoUpdater-allowPrerelease-get", "autoUpdater-allowPrerelease-get-reply");
|
||||
|
||||
/// <summary>
|
||||
/// *GitHub provider only.*
|
||||
/// Get all release notes (from current version to latest), not just the latest (Default is false).
|
||||
/// </summary>
|
||||
public Task<bool> IsFullChangeLogEnabledAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
public Task<bool> IsFullChangeLogEnabledAsync() => BridgeConnector.OnResult<bool>("autoUpdater-fullChangelog-get", "autoUpdater-fullChangelog-get-reply");
|
||||
|
||||
BridgeConnector.On<bool>("autoUpdater-fullChangelog-get-reply", (result) =>
|
||||
{
|
||||
BridgeConnector.Off("autoUpdater-fullChangelog-get-reply");
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("autoUpdater-fullChangelog-get");
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
public Task<bool> IsAllowDowngradeEnabledAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
|
||||
BridgeConnector.On<bool>("autoUpdater-allowDowngrade-get-reply", (result) =>
|
||||
{
|
||||
BridgeConnector.Off("autoUpdater-allowDowngrade-get-reply");
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("autoUpdater-allowDowngrade-get");
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
public Task<bool> IsAllowDowngradeEnabledAsync() => BridgeConnector.OnResult<bool>("autoUpdater-allowDowngrade-get", "autoUpdater-allowDowngrade-get-reply");
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Whether to automatically download an update when it is found. (Default is true)
|
||||
@@ -172,72 +108,23 @@ namespace ElectronNET.API
|
||||
/// <summary>
|
||||
/// For test only.
|
||||
/// </summary>
|
||||
public Task<string> GetUpdateConfigPathAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
|
||||
BridgeConnector.On<string>("autoUpdater-updateConfigPath-get-reply", (result) =>
|
||||
{
|
||||
BridgeConnector.Off("autoUpdater-updateConfigPath-get-reply");
|
||||
taskCompletionSource.SetResult(result.ToString());
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("autoUpdater-updateConfigPath-get");
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
public Task<string> GetUpdateConfigPathAsync() => BridgeConnector.OnResult<string>("autoUpdater-updateConfigPath-get", "autoUpdater-updateConfigPath-get-reply");
|
||||
|
||||
/// <summary>
|
||||
/// The current application version
|
||||
/// </summary>
|
||||
public Task<SemVer> GetCurrentVersionAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<SemVer>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
|
||||
BridgeConnector.On<SemVer>("autoUpdater-currentVersion-get-reply", (version) =>
|
||||
{
|
||||
BridgeConnector.Off("autoUpdater-currentVersion-get-reply");
|
||||
taskCompletionSource.SetResult(version);
|
||||
});
|
||||
BridgeConnector.Emit("autoUpdater-currentVersion-get");
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
public Task<SemVer> GetCurrentVersionAsync() => BridgeConnector.OnResult<SemVer>("autoUpdater-updateConcurrentVersionfigPath-get", "autoUpdater-currentVersion-get-reply");
|
||||
|
||||
/// <summary>
|
||||
/// Get the update channel. Not applicable for GitHub.
|
||||
/// Doesn’t return channel from the update configuration, only if was previously set.
|
||||
/// </summary>
|
||||
public Task<string> GetChannelAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
|
||||
BridgeConnector.On<string>("autoUpdater-channel-get-reply", (result) =>
|
||||
{
|
||||
BridgeConnector.Off("autoUpdater-channel-get-reply");
|
||||
taskCompletionSource.SetResult(result.ToString());
|
||||
});
|
||||
BridgeConnector.Emit("autoUpdater-channel-get");
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
|
||||
public Task<string> GetChannelAsync() => BridgeConnector.OnResult<string>("autoUpdater-channel-get", "autoUpdater-channel-get-reply");
|
||||
|
||||
/// <summary>
|
||||
/// The request headers.
|
||||
/// </summary>
|
||||
public Task<Dictionary<string, string>> GetRequestHeadersAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<Dictionary<string, string>>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
BridgeConnector.On<Dictionary<string, string>>("autoUpdater-requestHeaders-get-reply", (headers) =>
|
||||
{
|
||||
BridgeConnector.Off("autoUpdater-requestHeaders-get-reply");
|
||||
taskCompletionSource.SetResult(headers);
|
||||
});
|
||||
BridgeConnector.Emit("autoUpdater-requestHeaders-get");
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
public Task<Dictionary<string, string>> GetRequestHeadersAsync() => BridgeConnector.OnResult<Dictionary<string, string>>("autoUpdater-requestHeaders-get", "autoUpdater-requestHeaders-get-reply");
|
||||
|
||||
/// <summary>
|
||||
/// The request headers.
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using SocketIOClient;
|
||||
using SocketIOClient.JsonSerializer;
|
||||
using SocketIOClient.Newtonsoft.Json;
|
||||
|
||||
namespace ElectronNET.API
|
||||
@@ -235,7 +239,7 @@ namespace ElectronNET.API
|
||||
EIO = 3
|
||||
});
|
||||
|
||||
socket.JsonSerializer = new NewtonsoftJsonSerializer(socket.Options.EIO);
|
||||
socket.JsonSerializer = new CamelCaseNewtonsoftJsonSerializer(socket.Options.EIO);
|
||||
|
||||
|
||||
socket.OnConnected += (_, __) =>
|
||||
@@ -258,5 +262,20 @@ namespace ElectronNET.API
|
||||
return _socket;
|
||||
}
|
||||
}
|
||||
|
||||
private class CamelCaseNewtonsoftJsonSerializer : NewtonsoftJsonSerializer
|
||||
{
|
||||
public CamelCaseNewtonsoftJsonSerializer(int eio) : base(eio)
|
||||
{
|
||||
}
|
||||
|
||||
public override JsonSerializerSettings CreateOptions()
|
||||
{
|
||||
return new JsonSerializerSettings()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver()
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,21 +40,7 @@ namespace ElectronNET.API
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <returns>The content in the clipboard as plain text.</returns>
|
||||
public Task<string> ReadTextAsync(string type = "")
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
|
||||
BridgeConnector.On<string>("clipboard-readText-Completed", (text) =>
|
||||
{
|
||||
BridgeConnector.Off("clipboard-readText-Completed");
|
||||
|
||||
taskCompletionSource.SetResult(text);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("clipboard-readText", type);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
public Task<string> ReadTextAsync(string type = "") => BridgeConnector.OnResult<string>("clipboard-readText", "clipboard-readText-Completed", type);
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text into the clipboard as plain text.
|
||||
@@ -71,21 +57,7 @@ namespace ElectronNET.API
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
public Task<string> ReadHTMLAsync(string type = "")
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
|
||||
BridgeConnector.On<string>("clipboard-readHTML-Completed", (text) =>
|
||||
{
|
||||
BridgeConnector.Off("clipboard-readHTML-Completed");
|
||||
|
||||
taskCompletionSource.SetResult(text);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("clipboard-readHTML", type);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
public Task<string> ReadHTMLAsync(string type = "") => BridgeConnector.OnResult<string>("clipboard-readHTML", "clipboard-readHTML-Completed", type);
|
||||
|
||||
/// <summary>
|
||||
/// Writes markup to the clipboard.
|
||||
@@ -102,21 +74,8 @@ namespace ElectronNET.API
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
public Task<string> ReadRTFAsync(string type = "")
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
public Task<string> ReadRTFAsync(string type = "") => BridgeConnector.OnResult<string>("clipboard-readRTF", "clipboard-readRTF-Completed", type);
|
||||
|
||||
BridgeConnector.On<string>("clipboard-readRTF-Completed", (text) =>
|
||||
{
|
||||
BridgeConnector.Off("clipboard-readRTF-Completed");
|
||||
|
||||
taskCompletionSource.SetResult(text);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("clipboard-readRTF", type);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text into the clipboard in RTF.
|
||||
@@ -134,21 +93,7 @@ namespace ElectronNET.API
|
||||
/// be empty strings when the bookmark is unavailable.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<ReadBookmark> ReadBookmarkAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<ReadBookmark>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
|
||||
BridgeConnector.On<ReadBookmark>("clipboard-readBookmark-Completed", (bookmark) =>
|
||||
{
|
||||
BridgeConnector.Off("clipboard-readBookmark-Completed");
|
||||
|
||||
taskCompletionSource.SetResult(bookmark);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("clipboard-readBookmark");
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
public Task<ReadBookmark> ReadBookmarkAsync() => BridgeConnector.OnResult<ReadBookmark>("clipboard-readBookmark", "clipboard-readBookmark-Completed");
|
||||
|
||||
/// <summary>
|
||||
/// Writes the title and url into the clipboard as a bookmark.
|
||||
@@ -171,21 +116,7 @@ namespace ElectronNET.API
|
||||
/// find pasteboard whenever the application is activated.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<string> ReadFindTextAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
|
||||
BridgeConnector.On<string>("clipboard-readFindText-Completed", (text) =>
|
||||
{
|
||||
BridgeConnector.Off("clipboard-readFindText-Completed");
|
||||
|
||||
taskCompletionSource.SetResult(text);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("clipboard-readFindText");
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
public Task<string> ReadFindTextAsync() => BridgeConnector.OnResult<string>("clipboard-readFindText", "clipboard-readFindText-Completed");
|
||||
|
||||
/// <summary>
|
||||
/// macOS: Writes the text into the find pasteboard as plain text. This method uses
|
||||
@@ -211,21 +142,7 @@ namespace ElectronNET.API
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
public Task<string[]> AvailableFormatsAsync(string type = "")
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<string[]>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
|
||||
BridgeConnector.On<string[]>("clipboard-availableFormats-Completed", (formats) =>
|
||||
{
|
||||
BridgeConnector.Off("clipboard-availableFormats-Completed");
|
||||
|
||||
taskCompletionSource.SetResult(formats);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("clipboard-availableFormats", type);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
public Task<string[]> AvailableFormatsAsync(string type = "") => BridgeConnector.OnResult<string[]>("clipboard-availableFormats", "clipboard-availableFormats-Completed", type);
|
||||
|
||||
/// <summary>
|
||||
/// Writes data to the clipboard.
|
||||
@@ -242,21 +159,7 @@ namespace ElectronNET.API
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
public Task<NativeImage> ReadImageAsync(string type = "")
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<NativeImage>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
|
||||
BridgeConnector.On<NativeImage>("clipboard-readImage-Completed", (image) =>
|
||||
{
|
||||
BridgeConnector.Off("clipboard-readImage-Completed");
|
||||
|
||||
taskCompletionSource.SetResult(image);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("clipboard-readImage", type);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
public Task<NativeImage> ReadImageAsync(string type = "") => BridgeConnector.OnResult<NativeImage>("clipboard-readImage", "clipboard-readImage-Completed", type);
|
||||
|
||||
/// <summary>
|
||||
/// Writes an image to the clipboard.
|
||||
|
||||
@@ -66,24 +66,7 @@ namespace ElectronNET.API
|
||||
/// <param name="switchName">A command-line switch</param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns>Whether the command-line switch is present.</returns>
|
||||
public async Task<bool> HasSwitchAsync(string switchName, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.On<bool>("appCommandLineHasSwitchCompleted", (result) =>
|
||||
{
|
||||
BridgeConnector.Off("appCommandLineHasSwitchCompleted");
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("appCommandLineHasSwitch", switchName);
|
||||
|
||||
return await taskCompletionSource.Task.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
public Task<bool> HasSwitchAsync(string switchName, CancellationToken cancellationToken = default) => BridgeConnector.OnResult<bool>("appCommandLineHasSwitch", "appCommandLineHasSwitchCompleted", cancellationToken, switchName);
|
||||
|
||||
/// <summary>
|
||||
/// The command-line switch value.
|
||||
@@ -94,23 +77,6 @@ namespace ElectronNET.API
|
||||
/// <remarks>
|
||||
/// Note: When the switch is not present or has no value, it returns empty string.
|
||||
/// </remarks>
|
||||
public async Task<string> GetSwitchValueAsync(string switchName, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.On<string>("appCommandLineGetSwitchValueCompleted", (result) =>
|
||||
{
|
||||
BridgeConnector.Off("appCommandLineGetSwitchValueCompleted");
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("appCommandLineGetSwitchValue", switchName);
|
||||
|
||||
return await taskCompletionSource.Task.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
public Task<string> GetSwitchValueAsync(string switchName, CancellationToken cancellationToken = default) => BridgeConnector.OnResult<string>("appCommandLineGetSwitchValue", "appCommandLineGetSwitchValueCompleted", cancellationToken, switchName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,25 +153,7 @@ namespace ElectronNET.API
|
||||
/// TODO: Menu (macOS) still to be implemented
|
||||
/// Gets the application's dock menu.
|
||||
/// </summary>
|
||||
public async Task<Menu> GetMenu(CancellationToken cancellationToken = default)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<Menu>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.On<Menu>("dock-getMenu-completed", (menu) =>
|
||||
{
|
||||
BridgeConnector.Off("dock-getMenu-completed");
|
||||
taskCompletionSource.SetResult(menu);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("dock-getMenu");
|
||||
|
||||
return await taskCompletionSource.Task
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
public Task<Menu> GetMenu(CancellationToken cancellationToken = default) => BridgeConnector.OnResult<Menu>("dock-getMenu", "dock-getMenu-completed", cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the image associated with this dock icon.
|
||||
|
||||
@@ -41,7 +41,7 @@ This package contains the API to access the "native" electron API.</Description>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
<PackageReference Include="SocketIOClient" Version="2.2.4" />
|
||||
<PackageReference Include="SocketIOClient" Version="2.3.1" />
|
||||
<PackageReference Include="SocketIOClient.Newtonsoft.Json" Version="2.2.1" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -68,21 +68,8 @@ namespace ElectronNET.API
|
||||
/// since they don’t want applications to fight for global shortcuts.
|
||||
/// </summary>
|
||||
/// <returns>Whether this application has registered accelerator.</returns>
|
||||
public Task<bool> IsRegisteredAsync(string accelerator)
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
|
||||
BridgeConnector.On<bool>("globalShortcut-isRegisteredCompleted" + accelerator.GetHashCode(), (isRegistered) =>
|
||||
{
|
||||
BridgeConnector.Off("globalShortcut-isRegisteredCompleted" + accelerator.GetHashCode());
|
||||
public Task<bool> IsRegisteredAsync(string accelerator) => BridgeConnector.OnResult<bool>("globalShortcut-isRegistered", "globalShortcut-isRegisteredCompleted", accelerator);
|
||||
|
||||
taskCompletionSource.SetResult(isRegistered);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("globalShortcut-isRegistered", accelerator);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unregisters the global shortcut of accelerator.
|
||||
|
||||
@@ -101,51 +101,26 @@ namespace ElectronNET.API
|
||||
/// A <see cref="ThemeSourceMode"/> property that can be <see cref="ThemeSourceMode.System"/>, <see cref="ThemeSourceMode.Light"/> or <see cref="ThemeSourceMode.Dark"/>. It is used to override (<seealso cref="SetThemeSource"/>) and
|
||||
/// supercede the value that Chromium has chosen to use internally.
|
||||
/// </summary>
|
||||
public Task<ThemeSourceMode> GetThemeSourceAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<ThemeSourceMode>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
|
||||
BridgeConnector.On<string>("nativeTheme-themeSource-getCompleted", (themeSource) =>
|
||||
{
|
||||
BridgeConnector.Off("nativeTheme-themeSource-getCompleted");
|
||||
|
||||
var themeSourceValue = Enum.Parse<ThemeSourceMode>(themeSource, true);
|
||||
|
||||
taskCompletionSource.SetResult(themeSourceValue);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("nativeTheme-themeSource-get");
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
public async Task<ThemeSourceMode> GetThemeSourceAsync() => Enum.Parse<ThemeSourceMode>(await BridgeConnector.OnResult<string>("nativeTheme-themeSource-get", "nativeTheme-themeSource-getCompleted"), true);
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="bool"/> for if the OS / Chromium currently has a dark mode enabled or is
|
||||
/// being instructed to show a dark-style UI. If you want to modify this value you
|
||||
/// should use <see cref="SetThemeSource"/>.
|
||||
/// </summary>
|
||||
public Task<bool> ShouldUseDarkColorsAsync()
|
||||
{
|
||||
return BridgeConnector.OnResult<bool>("nativeTheme-shouldUseDarkColors", "nativeTheme-shouldUseDarkColors-completed");
|
||||
}
|
||||
public Task<bool> ShouldUseDarkColorsAsync() => BridgeConnector.OnResult<bool>("nativeTheme-shouldUseDarkColors", "nativeTheme-shouldUseDarkColors-completed");
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="bool"/> for if the OS / Chromium currently has high-contrast mode enabled or is
|
||||
/// being instructed to show a high-contrast UI.
|
||||
/// </summary>
|
||||
public Task<bool> ShouldUseHighContrastColorsAsync()
|
||||
{
|
||||
return BridgeConnector.OnResult<bool>("nativeTheme-shouldUseHighContrastColors", "nativeTheme-shouldUseHighContrastColors-completed");
|
||||
}
|
||||
public Task<bool> ShouldUseHighContrastColorsAsync() => BridgeConnector.OnResult<bool>("nativeTheme-shouldUseHighContrastColors", "nativeTheme-shouldUseHighContrastColors-completed");
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="bool"/> for if the OS / Chromium currently has an inverted color scheme or is
|
||||
/// being instructed to use an inverted color scheme.
|
||||
/// </summary>
|
||||
public Task<bool> ShouldUseInvertedColorSchemeAsync()
|
||||
{
|
||||
return BridgeConnector.OnResult<bool>("nativeTheme-shouldUseInvertedColorScheme", "nativeTheme-shouldUseInvertedColorScheme-completed");
|
||||
}
|
||||
public Task<bool> ShouldUseInvertedColorSchemeAsync() => BridgeConnector.OnResult<bool>("nativeTheme-shouldUseInvertedColorScheme", "nativeTheme-shouldUseInvertedColorScheme-completed");
|
||||
|
||||
/// <summary>
|
||||
/// Emitted when something in the underlying NativeTheme has changed. This normally means that either the value of <see cref="ShouldUseDarkColorsAsync"/>,
|
||||
|
||||
@@ -129,122 +129,40 @@ namespace ElectronNET.API
|
||||
/// The current absolute position of the mouse pointer.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<Point> GetCursorScreenPointAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<Point>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
|
||||
BridgeConnector.On<Point>("screen-getCursorScreenPointCompleted", (point) =>
|
||||
{
|
||||
BridgeConnector.Off("screen-getCursorScreenPointCompleted");
|
||||
|
||||
taskCompletionSource.SetResult(point);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("screen-getCursorScreenPoint");
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
public Task<Point> GetCursorScreenPointAsync() => BridgeConnector.OnResult<Point>("screen-getCursorScreenPoint", "screen-getCursorScreenPointCompleted");
|
||||
|
||||
/// <summary>
|
||||
/// macOS: The height of the menu bar in pixels.
|
||||
/// </summary>
|
||||
/// <returns>The height of the menu bar in pixels.</returns>
|
||||
public Task<int> GetMenuBarHeightAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<int>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
|
||||
BridgeConnector.On<int>("screen-getMenuBarHeightCompleted", (height) =>
|
||||
{
|
||||
BridgeConnector.Off("screen-getMenuBarHeightCompleted");
|
||||
|
||||
taskCompletionSource.SetResult(height);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("screen-getMenuBarHeight");
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
public Task<int> GetMenuBarHeightAsync() => BridgeConnector.OnResult<int>("screen-getMenuBarHeight", "screen-getMenuBarHeightCompleted");
|
||||
|
||||
/// <summary>
|
||||
/// The primary display.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<Display> GetPrimaryDisplayAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<Display>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
public Task<Display> GetPrimaryDisplayAsync() => BridgeConnector.OnResult<Display>("screen-getPrimaryDisplay", "screen-getPrimaryDisplayCompleted");
|
||||
|
||||
BridgeConnector.On<Display>("screen-getPrimaryDisplayCompleted", (display) =>
|
||||
{
|
||||
BridgeConnector.Off("screen-getPrimaryDisplayCompleted");
|
||||
|
||||
taskCompletionSource.SetResult(display);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("screen-getPrimaryDisplay");
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An array of displays that are currently available.
|
||||
/// </summary>
|
||||
/// <returns>An array of displays that are currently available.</returns>
|
||||
public Task<Display[]> GetAllDisplaysAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<Display[]>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
|
||||
BridgeConnector.On<Display[]>("screen-getAllDisplaysCompleted", (displays) =>
|
||||
{
|
||||
BridgeConnector.Off("screen-getAllDisplaysCompleted");
|
||||
|
||||
taskCompletionSource.SetResult(displays);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("screen-getAllDisplays");
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
public Task<Display[]> GetAllDisplaysAsync() => BridgeConnector.OnResult<Display[]>("screen-getAllDisplays", "screen-getAllDisplaysCompleted");
|
||||
|
||||
/// <summary>
|
||||
/// The display nearest the specified point.
|
||||
/// </summary>
|
||||
/// <returns>The display nearest the specified point.</returns>
|
||||
public Task<Display> GetDisplayNearestPointAsync(Point point)
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<Display>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
|
||||
BridgeConnector.On<Display>("screen-getDisplayNearestPointCompleted", (display) =>
|
||||
{
|
||||
BridgeConnector.Off("screen-getDisplayNearestPointCompleted");
|
||||
|
||||
taskCompletionSource.SetResult(display);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("screen-getDisplayNearestPoint", JObject.FromObject(point, _jsonSerializer));
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
public Task<Display> GetDisplayNearestPointAsync(Point point) => BridgeConnector.OnResult<Display>("screen-getDisplayNearestPoint", "screen-getDisplayNearestPointCompleted", JObject.FromObject(point, _jsonSerializer));
|
||||
|
||||
/// <summary>
|
||||
/// The display that most closely intersects the provided bounds.
|
||||
/// </summary>
|
||||
/// <param name="rectangle"></param>
|
||||
/// <returns>The display that most closely intersects the provided bounds.</returns>
|
||||
public Task<Display> GetDisplayMatchingAsync(Rectangle rectangle)
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<Display>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
public Task<Display> GetDisplayMatchingAsync(Rectangle rectangle) => BridgeConnector.OnResult<Display>("screen-getDisplayMatching", "screen-getDisplayMatching", JObject.FromObject(rectangle, _jsonSerializer));
|
||||
|
||||
BridgeConnector.On<Display>("screen-getDisplayMatching", (display) =>
|
||||
{
|
||||
BridgeConnector.Off("screen-getDisplayMatching");
|
||||
|
||||
taskCompletionSource.SetResult(display);
|
||||
});
|
||||
|
||||
BridgeConnector.Emit("screen-getDisplayMatching", JObject.FromObject(rectangle, _jsonSerializer));
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
private JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user