ElectronNET API: Add platform support attributes

This commit is contained in:
softworkz
2025-11-14 09:44:01 +01:00
parent 8e8d88c48f
commit 0580942a59
11 changed files with 167 additions and 13 deletions

View File

@@ -2,6 +2,7 @@ using ElectronNET.API.Entities;
using ElectronNET.API.Extensions;
using System;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
@@ -259,6 +260,8 @@ namespace ElectronNET.API
/// screen readers, are enabled or disabled. See https://www.chromium.org/developers/design-documents/accessibility for more details.
/// </summary>
/// <returns><see langword="true"/> when Chrome's accessibility support is enabled, <see langword="false"/> otherwise.</returns>
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("Windows")]
public event Action<bool> AccessibilitySupportChanged
{
add => AddEvent(value, GetHashCode());
@@ -316,6 +319,7 @@ namespace ElectronNET.API
/// <para/>
/// On Windows, you have to parse the arguments using App.CommandLine to get the filepath.
/// </summary>
[SupportedOSPlatform("macOS")]
public event Action<string> OpenFile
{
add => AddEvent(value, GetHashCode());
@@ -327,6 +331,7 @@ namespace ElectronNET.API
/// Emitted when a MacOS user wants to open a URL with the application. Your application's Info.plist file must
/// define the URL scheme within the CFBundleURLTypes key, and set NSPrincipalClass to AtomApplication.
/// </summary>
[SupportedOSPlatform("macOS")]
public event Action<string> OpenUrl
{
add => AddEvent(value, GetHashCode());
@@ -481,6 +486,7 @@ namespace ElectronNET.API
/// <summary>
/// Hides all application windows without minimizing them.
/// </summary>
[SupportedOSPlatform("macOS")]
public void Hide()
{
this.CallMethod0();
@@ -489,6 +495,7 @@ namespace ElectronNET.API
/// <summary>
/// Shows application windows after they were hidden. Does not automatically focus them.
/// </summary>
[SupportedOSPlatform("macOS")]
public void Show()
{
this.CallMethod0();
@@ -586,6 +593,8 @@ namespace ElectronNET.API
/// list from the task bar, and on macOS you can visit it from dock menu.
/// </summary>
/// <param name="path">Path to add.</param>
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("Windows")]
public void AddRecentDocument(string path)
{
this.CallMethod1(path);
@@ -594,6 +603,8 @@ namespace ElectronNET.API
/// <summary>
/// Clears the recent documents list.
/// </summary>
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("Windows")]
public void ClearRecentDocuments()
{
this.CallMethod0();
@@ -709,6 +720,8 @@ namespace ElectronNET.API
/// <param name="protocol">The name of your protocol, without ://.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Whether the call succeeded.</returns>
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("Windows")]
public async Task<bool> RemoveAsDefaultProtocolClientAsync(string protocol, CancellationToken cancellationToken = default)
{
return await this.RemoveAsDefaultProtocolClientAsync(protocol, null, null, cancellationToken).ConfigureAwait(false);
@@ -722,6 +735,8 @@ namespace ElectronNET.API
/// <param name="path">Defaults to process.execPath.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Whether the call succeeded.</returns>
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("Windows")]
public async Task<bool> RemoveAsDefaultProtocolClientAsync(string protocol, string path, CancellationToken cancellationToken = default)
{
return await this.RemoveAsDefaultProtocolClientAsync(protocol, path, null, cancellationToken).ConfigureAwait(false);
@@ -736,6 +751,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>
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("Windows")]
public async Task<bool> RemoveAsDefaultProtocolClientAsync(string protocol, string path, string[] args, CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
@@ -826,6 +843,7 @@ 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>
[SupportedOSPlatform("Windows")]
public async Task<bool> SetUserTasksAsync(UserTask[] userTasks, CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
@@ -846,6 +864,7 @@ namespace ElectronNET.API
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Jump List settings.</returns>
[SupportedOSPlatform("Windows")]
public async Task<JumpListSettings> GetJumpListSettingsAsync(CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
@@ -868,6 +887,7 @@ namespace ElectronNET.API
/// omitted from the Jump List. The list of removed items can be obtained using <see cref="GetJumpListSettingsAsync"/>.
/// </summary>
/// <param name="categories">Array of <see cref="JumpListCategory"/> objects.</param>
[SupportedOSPlatform("Windows")]
public void SetJumpList(JumpListCategory[] categories)
{
this.CallMethod1(categories);
@@ -950,6 +970,7 @@ namespace ElectronNET.API
/// </summary>
/// <param name="type">Uniquely identifies the activity. Maps to <see href="https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSUserActivity_Class/index.html#//apple_ref/occ/instp/NSUserActivity/activityType">NSUserActivity.activityType</see>.</param>
/// <param name="userInfo">App-specific state to store for use by another device.</param>
[SupportedOSPlatform("macOS")]
public void SetUserActivity(string type, object userInfo)
{
SetUserActivity(type, userInfo, null);
@@ -967,6 +988,7 @@ namespace ElectronNET.API
/// <param name="webpageUrl">
/// The webpage to load in a browser if no suitable app is installed on the resuming device. The scheme must be http or https.
/// </param>
[SupportedOSPlatform("macOS")]
public void SetUserActivity(string type, object userInfo, string webpageUrl)
{
this.CallMethod3(type, userInfo, webpageUrl);
@@ -976,6 +998,7 @@ namespace ElectronNET.API
/// The type of the currently running activity.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
[SupportedOSPlatform("macOS")]
public async Task<string> GetCurrentActivityTypeAsync(CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
@@ -985,6 +1008,7 @@ namespace ElectronNET.API
/// <summary>
/// Invalidates the current <see href="https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/Handoff/HandoffFundamentals/HandoffFundamentals.html">Handoff</see> user activity.
/// </summary>
[SupportedOSPlatform("macOS")]
public void InvalidateCurrentActivity()
{
this.CallMethod0();
@@ -993,6 +1017,7 @@ namespace ElectronNET.API
/// <summary>
/// Marks the current <see href="https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/Handoff/HandoffFundamentals/HandoffFundamentals.html">Handoff</see> user activity as inactive without invalidating it.
/// </summary>
[SupportedOSPlatform("macOS")]
public void ResignCurrentActivity()
{
this.CallMethod0();
@@ -1002,6 +1027,7 @@ namespace ElectronNET.API
/// Changes the <see href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd378459(v=vs.85).aspx">Application User Model ID</see> to id.
/// </summary>
/// <param name="id">Model Id.</param>
[SupportedOSPlatform("Windows")]
public void SetAppUserModelId(string id)
{
this.CallMethod1(id);
@@ -1016,6 +1042,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>
[SupportedOSPlatform("Linux")]
public async Task<int> ImportCertificateAsync(ImportCertificateOptions options, CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
@@ -1067,6 +1094,8 @@ namespace ElectronNET.API
/// <param name="count">Counter badge.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Whether the call succeeded.</returns>
[SupportedOSPlatform("Linux")]
[SupportedOSPlatform("macOS")]
public async Task<bool> SetBadgeCountAsync(int count, CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
@@ -1086,6 +1115,8 @@ namespace ElectronNET.API
/// The current value displayed in the counter badge.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
[SupportedOSPlatform("Linux")]
[SupportedOSPlatform("macOS")]
public async Task<int> GetBadgeCountAsync(CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
@@ -1101,6 +1132,7 @@ namespace ElectronNET.API
/// Whether the current desktop environment is Unity launcher.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
[SupportedOSPlatform("Linux")]
public async Task<bool> IsUnityRunningAsync(CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
@@ -1111,6 +1143,8 @@ namespace ElectronNET.API
/// If you provided path and args options to <see cref="SetLoginItemSettings"/> then you need to pass the same
/// arguments here for <see cref="LoginItemSettings.OpenAtLogin"/> to be set correctly.
/// </summary>
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("Windows")]
public async Task<LoginItemSettings> GetLoginItemSettingsAsync(CancellationToken cancellationToken = default)
{
return await this.GetLoginItemSettingsAsync(null, cancellationToken).ConfigureAwait(false);
@@ -1122,6 +1156,8 @@ namespace ElectronNET.API
/// </summary>
/// <param name="options"></param>
/// <param name="cancellationToken">The cancellation token.</param>
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("Windows")]
public async Task<LoginItemSettings> GetLoginItemSettingsAsync(LoginItemSettingsOptions options, CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
@@ -1151,6 +1187,8 @@ namespace ElectronNET.API
/// you'll want to set the launch path to Update.exe, and pass arguments that specify your application name.
/// </summary>
/// <param name="loginSettings"></param>
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("Windows")]
public void SetLoginItemSettings(LoginSettings loginSettings)
{
this.CallMethod1(loginSettings);
@@ -1162,6 +1200,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 Chromes accessibility support is enabled, <see langword="false"/> otherwise.</returns>
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("Windows")]
public async Task<bool> IsAccessibilitySupportEnabledAsync(CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
@@ -1178,6 +1218,8 @@ namespace ElectronNET.API
/// Note: Rendering accessibility tree can significantly affect the performance of your app. It should not be enabled by default.
/// </summary>
/// <param name="enabled">Enable or disable <see href="https://developers.google.com/web/fundamentals/accessibility/semantics-builtin/the-accessibility-tree">accessibility tree</see> rendering.</param>
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("Windows")]
public void SetAccessibilitySupportEnabled(bool enabled)
{
this.CallMethod1(enabled);