Add supported OS platform annotations

This commit is contained in:
rafael-aero
2021-08-26 14:22:54 +02:00
parent 7ad6803671
commit 224bc1ef65
16 changed files with 294 additions and 13 deletions

View File

@@ -7,8 +7,11 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Threading.Tasks;
//TODO: Add setTrafficLightPosition and getTrafficLightPosition: https://www.electronjs.org/docs/api/browser-window#winsettrafficlightpositionposition-macos
namespace ElectronNET.API
{
/// <summary>
@@ -146,6 +149,7 @@ namespace ElectronNET.API
/// <summary>
/// Emitted when window session is going to end due to force shutdown or machine restart or session log off.
/// </summary>
[SupportedOSPlatform("windows")]
public event Action OnSessionEnd
{
add
@@ -465,6 +469,8 @@ namespace ElectronNET.API
/// <summary>
/// Emitted when the window is being resized.
/// </summary>
[SupportedOSPlatform("macos")]
[SupportedOSPlatform("windows")]
public event Action OnResize
{
add
@@ -496,6 +502,8 @@ namespace ElectronNET.API
///
/// Note: On macOS this event is just an alias of moved.
/// </summary>
[SupportedOSPlatform("macos")]
[SupportedOSPlatform("windows")]
public event Action OnMove
{
add
@@ -523,8 +531,10 @@ namespace ElectronNET.API
private event Action _move;
/// <summary>
/// macOS: Emitted once when the window is moved to a new position.
/// Emitted once when the window is moved to a new position.
/// </summary>
[SupportedOSPlatform("macos")]
[SupportedOSPlatform("windows")]
public event Action OnMoved
{
add
@@ -676,6 +686,8 @@ namespace ElectronNET.API
/// and the APPCOMMAND_ prefix is stripped off.e.g.APPCOMMAND_BROWSER_BACKWARD
/// is emitted as browser-backward.
/// </summary>
[SupportedOSPlatform("macos")]
[SupportedOSPlatform("windows")]
public event Action<string> OnAppCommand
{
add
@@ -705,6 +717,7 @@ namespace ElectronNET.API
/// <summary>
/// Emitted when scroll wheel event phase has begun.
/// </summary>
[SupportedOSPlatform("macos")]
public event Action OnScrollTouchBegin
{
add
@@ -734,6 +747,7 @@ namespace ElectronNET.API
/// <summary>
/// Emitted when scroll wheel event phase has ended.
/// </summary>
[SupportedOSPlatform("macos")]
public event Action OnScrollTouchEnd
{
add
@@ -763,6 +777,7 @@ namespace ElectronNET.API
/// <summary>
/// Emitted when scroll wheel event phase filed upon reaching the edge of element.
/// </summary>
[SupportedOSPlatform("macos")]
public event Action OnScrollTouchEdge
{
add
@@ -792,6 +807,7 @@ namespace ElectronNET.API
/// <summary>
/// Emitted on 3-finger swipe. Possible directions are up, right, down, left.
/// </summary>
[SupportedOSPlatform("macos")]
public event Action<string> OnSwipe
{
add
@@ -821,6 +837,7 @@ namespace ElectronNET.API
/// <summary>
/// Emitted when the window opens a sheet.
/// </summary>
[SupportedOSPlatform("macos")]
public event Action OnSheetBegin
{
add
@@ -850,6 +867,7 @@ namespace ElectronNET.API
/// <summary>
/// Emitted when the window has closed a sheet.
/// </summary>
[SupportedOSPlatform("macos")]
public event Action OnSheetEnd
{
add
@@ -879,6 +897,7 @@ namespace ElectronNET.API
/// <summary>
/// Emitted when the native new tab button is clicked.
/// </summary>
[SupportedOSPlatform("macos")]
public event Action OnNewWindowForTab
{
add
@@ -1080,17 +1099,41 @@ namespace ElectronNET.API
/// </summary>
/// <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)
{
BridgeConnector.Emit("browserWindowSetAspectRatio", Id, aspectRatio, new Size() { Height = 0, Width = 0 });
}
/// <summary>
/// This will make a window maintain an aspect ratio. The extra size allows a developer to have space,
/// specified in pixels, not included within the aspect ratio calculations. This API already takes into
/// account the difference between a windows size and its content size.
///
/// Consider a normal window with an HD video player and associated controls.Perhaps there are 15 pixels
/// of controls on the left edge, 25 pixels of controls on the right edge and 50 pixels of controls below
/// the player. In order to maintain a 16:9 aspect ratio (standard aspect ratio for HD @1920x1080) within
/// the player itself we would call this function with arguments of 16/9 and[40, 50]. The second argument
/// doesnt care where the extra width and height are within the content viewonly that they exist. Just
/// sum any extra width and height areas you have within the overall content view.
/// </summary>
/// <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>
[SupportedOSPlatform("macos")]
public void SetAspectRatio(int aspectRatio, Size extraSize)
{
BridgeConnector.Emit("browserWindowSetAspectRatio", Id, aspectRatio, extraSize);
}
/// <summary>
/// Uses Quick Look to preview a file at a given path.
/// </summary>
/// <param name="path">The absolute path to the file to preview with QuickLook. This is important as
/// Quick Look uses the file name and file extension on the path to determine the content type of the
/// file to open.</param>
[SupportedOSPlatform("macos")]
public void PreviewFile(string path)
{
BridgeConnector.Emit("browserWindowPreviewFile", Id, path);
@@ -1104,6 +1147,7 @@ namespace ElectronNET.API
/// file to open.</param>
/// <param name="displayname">The name of the file to display on the Quick Look modal view. This is
/// purely visual and does not affect the content type of the file. Defaults to path.</param>
[SupportedOSPlatform("macos")]
public void PreviewFile(string path, string displayname)
{
BridgeConnector.Emit("browserWindowPreviewFile", Id, path, displayname);
@@ -1112,6 +1156,7 @@ namespace ElectronNET.API
/// <summary>
/// Closes the currently open Quick Look panel.
/// </summary>
[SupportedOSPlatform("macos")]
public void CloseFilePreview()
{
BridgeConnector.Emit("browserWindowCloseFilePreview", Id);
@@ -1131,6 +1176,7 @@ namespace ElectronNET.API
/// </summary>
/// <param name="bounds"></param>
/// <param name="animate"></param>
[SupportedOSPlatform("macos")]
public void SetBounds(Rectangle bounds, bool animate)
{
BridgeConnector.Emit("browserWindowSetBounds", Id, bounds, animate);
@@ -1159,6 +1205,7 @@ namespace ElectronNET.API
/// </summary>
/// <param name="bounds"></param>
/// <param name="animate"></param>
[SupportedOSPlatform("macos")]
public void SetContentBounds(Rectangle bounds, bool animate)
{
BridgeConnector.Emit("browserWindowSetContentBounds", Id, bounds, animate);
@@ -1189,6 +1236,7 @@ namespace ElectronNET.API
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="animate"></param>
[SupportedOSPlatform("macos")]
public void SetSize(int width, int height, bool animate)
{
BridgeConnector.Emit("browserWindowSetSize", Id, width, height, animate);
@@ -1219,6 +1267,7 @@ namespace ElectronNET.API
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="animate"></param>
[SupportedOSPlatform("macos")]
public void SetContentSize(int width, int height, bool animate)
{
BridgeConnector.Emit("browserWindowSetContentSize", Id, width, height, animate);
@@ -1293,6 +1342,8 @@ namespace ElectronNET.API
/// Sets whether the window can be moved by user. On Linux does nothing.
/// </summary>
/// <param name="movable"></param>
[SupportedOSPlatform("windows")]
[SupportedOSPlatform("macos")]
public void SetMovable(bool movable)
{
BridgeConnector.Emit("browserWindowSetMovable", Id, movable);
@@ -1300,10 +1351,10 @@ namespace ElectronNET.API
/// <summary>
/// Whether the window can be moved by user.
///
/// On Linux always returns true.
/// </summary>
/// <returns>On Linux always returns true.</returns>
[SupportedOSPlatform("windows")]
[SupportedOSPlatform("macos")]
public Task<bool> IsMovableAsync()
{
return BridgeConnector.OnResult<bool>("browserWindowIsMovable", "browserWindow-isMovable-completed" + Id, Id);
@@ -1313,6 +1364,8 @@ namespace ElectronNET.API
/// Sets whether the window can be manually minimized by user. On Linux does nothing.
/// </summary>
/// <param name="minimizable"></param>
[SupportedOSPlatform("windows")]
[SupportedOSPlatform("macos")]
public void SetMinimizable(bool minimizable)
{
BridgeConnector.Emit("browserWindowSetMinimizable", Id, minimizable);
@@ -1320,10 +1373,10 @@ namespace ElectronNET.API
/// <summary>
/// Whether the window can be manually minimized by user.
///
/// On Linux always returns true.
/// </summary>
/// <returns>On Linux always returns true.</returns>
[SupportedOSPlatform("windows")]
[SupportedOSPlatform("macos")]
public Task<bool> IsMinimizableAsync()
{
return BridgeConnector.OnResult<bool>("browserWindowIsMinimizable", "browserWindow-isMinimizable-completed" + Id, Id);
@@ -1333,6 +1386,8 @@ namespace ElectronNET.API
/// Sets whether the window can be manually maximized by user. On Linux does nothing.
/// </summary>
/// <param name="maximizable"></param>
[SupportedOSPlatform("windows")]
[SupportedOSPlatform("macos")]
public void SetMaximizable(bool maximizable)
{
BridgeConnector.Emit("browserWindowSetMaximizable", Id, maximizable);
@@ -1340,10 +1395,10 @@ namespace ElectronNET.API
/// <summary>
/// Whether the window can be manually maximized by user.
///
/// On Linux always returns true.
/// </summary>
/// <returns>On Linux always returns true.</returns>
[SupportedOSPlatform("windows")]
[SupportedOSPlatform("macos")]
public Task<bool> IsMaximizableAsync()
{
return BridgeConnector.OnResult<bool>("browserWindowIsMaximizable", "browserWindow-isMaximizable-completed" + Id, Id);
@@ -1371,6 +1426,8 @@ namespace ElectronNET.API
/// Sets whether the window can be manually closed by user. On Linux does nothing.
/// </summary>
/// <param name="closable"></param>
[SupportedOSPlatform("windows")]
[SupportedOSPlatform("macos")]
public void SetClosable(bool closable)
{
BridgeConnector.Emit("browserWindowSetClosable", Id, closable);
@@ -1378,10 +1435,10 @@ namespace ElectronNET.API
/// <summary>
/// Whether the window can be manually closed by user.
///
/// On Linux always returns true.
/// </summary>
/// <returns>On Linux always returns true.</returns>
[SupportedOSPlatform("windows")]
[SupportedOSPlatform("macos")]
public Task<bool> IsClosableAsync()
{
return BridgeConnector.OnResult<bool>("browserWindowIsClosable", "browserWindow-isClosable-completed" + Id, Id);
@@ -1407,6 +1464,8 @@ namespace ElectronNET.API
/// <param name="level">Values include normal, floating, torn-off-menu, modal-panel, main-menu,
/// status, pop-up-menu and screen-saver. The default is floating.
/// See the macOS docs</param>
[SupportedOSPlatform("windows")]
[SupportedOSPlatform("macos")]
public void SetAlwaysOnTop(bool flag, OnTopLevel level)
{
BridgeConnector.Emit("browserWindowSetAlwaysOnTop", Id, flag, level.GetDescription());
@@ -1423,6 +1482,7 @@ namespace ElectronNET.API
/// See the macOS docs</param>
/// <param name="relativeLevel">The number of layers higher to set this window relative to the given level.
/// The default is 0. Note that Apple discourages setting levels higher than 1 above screen-saver.</param>
[SupportedOSPlatform("macos")]
public void SetAlwaysOnTop(bool flag, OnTopLevel level, int relativeLevel)
{
BridgeConnector.Emit("browserWindowSetAlwaysOnTop", Id, flag, level.GetDescription(), relativeLevel);
@@ -1468,6 +1528,7 @@ namespace ElectronNET.API
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="animate"></param>
[SupportedOSPlatform("macos")]
public void SetPosition(int x, int y, bool animate)
{
// Workaround Windows 10 / Electron Bug
@@ -1482,7 +1543,7 @@ namespace ElectronNET.API
private bool isWindows10()
{
return RuntimeInformation.OSDescription.Contains("Windows 10");
return OperatingSystem.IsWindowsVersionAtLeast(10);
}
/// <summary>
@@ -1520,6 +1581,7 @@ namespace ElectronNET.API
/// but you may want to display them beneath a HTML-rendered toolbar.
/// </summary>
/// <param name="offsetY"></param>
[SupportedOSPlatform("macos")]
public void SetSheetOffset(float offsetY)
{
BridgeConnector.Emit("browserWindowSetSheetOffset", Id, offsetY);
@@ -1532,6 +1594,7 @@ namespace ElectronNET.API
/// </summary>
/// <param name="offsetY"></param>
/// <param name="offsetX"></param>
[SupportedOSPlatform("macos")]
public void SetSheetOffset(float offsetY, float offsetX)
{
BridgeConnector.Emit("browserWindowSetSheetOffset", Id, offsetY, offsetX);
@@ -1587,6 +1650,7 @@ namespace ElectronNET.API
/// and the icon of the file will show in windows title bar.
/// </summary>
/// <param name="filename"></param>
[SupportedOSPlatform("macos")]
public void SetRepresentedFilename(string filename)
{
BridgeConnector.Emit("browserWindowSetRepresentedFilename", Id, filename);
@@ -1596,6 +1660,7 @@ namespace ElectronNET.API
/// The pathname of the file the window represents.
/// </summary>
/// <returns></returns>
[SupportedOSPlatform("macos")]
public Task<string> GetRepresentedFilenameAsync()
{
return BridgeConnector.OnResult<string>("browserWindowGetRepresentedFilename", "browserWindow-getRepresentedFilename-completed" + Id, Id);
@@ -1606,6 +1671,7 @@ namespace ElectronNET.API
/// and the icon in title bar will become gray when set to true.
/// </summary>
/// <param name="edited"></param>
[SupportedOSPlatform("macos")]
public void SetDocumentEdited(bool edited)
{
BridgeConnector.Emit("browserWindowSetDocumentEdited", Id, edited);
@@ -1615,6 +1681,7 @@ namespace ElectronNET.API
/// Whether the windows document has been edited.
/// </summary>
/// <returns></returns>
[SupportedOSPlatform("macos")]
public Task<bool> IsDocumentEditedAsync()
{
return BridgeConnector.OnResult<bool>("browserWindowIsDocumentEdited", "browserWindow-isDocumentEdited-completed" + Id, Id);
@@ -1679,6 +1746,8 @@ namespace ElectronNET.API
/// setting it to null will remove the menu bar.
/// </summary>
/// <param name="menuItems"></param>
[SupportedOSPlatform("windows")]
[SupportedOSPlatform("linux")]
public void SetMenu(MenuItem[] menuItems)
{
menuItems.AddMenuItemsId();
@@ -1696,6 +1765,8 @@ namespace ElectronNET.API
/// <summary>
/// Remove the window's menu bar.
/// </summary>
[SupportedOSPlatform("windows")]
[SupportedOSPlatform("linux")]
public void RemoveMenu()
{
BridgeConnector.Emit("browserWindowRemoveMenu", Id);
@@ -1729,6 +1800,7 @@ namespace ElectronNET.API
/// </summary>
/// <param name="progress"></param>
/// <param name="progressBarOptions"></param>
[SupportedOSPlatform("windows")]
public void SetProgressBar(double progress, ProgressBarOptions progressBarOptions)
{
BridgeConnector.Emit("browserWindowSetProgressBar", Id, progress, progressBarOptions);
@@ -1776,6 +1848,7 @@ namespace ElectronNET.API
/// </summary>
/// <param name="thumbarButtons"></param>
/// <returns>Whether the buttons were added successfully.</returns>
[SupportedOSPlatform("windows")]
public Task<bool> SetThumbarButtonsAsync(ThumbarButton[] thumbarButtons)
{
var taskCompletionSource = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
@@ -1808,6 +1881,7 @@ namespace ElectronNET.API
/// an empty region: {x: 0, y: 0, width: 0, height: 0}.
/// </summary>
/// <param name="rectangle"></param>
[SupportedOSPlatform("windows")]
public void SetThumbnailClip(Rectangle rectangle)
{
BridgeConnector.Emit("browserWindowSetThumbnailClip", Id, rectangle);
@@ -1817,6 +1891,7 @@ namespace ElectronNET.API
/// Sets the toolTip that is displayed when hovering over the window thumbnail in the taskbar.
/// </summary>
/// <param name="tooltip"></param>
[SupportedOSPlatform("windows")]
public void SetThumbnailToolTip(string tooltip)
{
BridgeConnector.Emit("browserWindowSetThumbnailToolTip", Id, tooltip);
@@ -1829,6 +1904,7 @@ namespace ElectronNET.API
/// If one of those properties is not set, then neither will be used.
/// </summary>
/// <param name="options"></param>
[SupportedOSPlatform("windows")]
public void SetAppDetails(AppDetailsOptions options)
{
BridgeConnector.Emit("browserWindowSetAppDetails", Id, options);
@@ -1837,6 +1913,7 @@ namespace ElectronNET.API
/// <summary>
/// Same as webContents.showDefinitionForSelection().
/// </summary>
[SupportedOSPlatform("macos")]
public void ShowDefinitionForSelection()
{
BridgeConnector.Emit("browserWindowShowDefinitionForSelection", Id);
@@ -1868,6 +1945,8 @@ namespace ElectronNET.API
/// users can still bring up the menu bar by pressing the single Alt key.
/// </summary>
/// <param name="visible"></param>
[SupportedOSPlatform("windows")]
[SupportedOSPlatform("linux")]
public void SetMenuBarVisibility(bool visible)
{
BridgeConnector.Emit("browserWindowSetMenuBarVisibility", Id, visible);
@@ -1877,6 +1956,8 @@ namespace ElectronNET.API
/// Whether the menu bar is visible.
/// </summary>
/// <returns></returns>
[SupportedOSPlatform("windows")]
[SupportedOSPlatform("linux")]
public Task<bool> IsMenuBarVisibleAsync()
{
return BridgeConnector.OnResult<bool>("browserWindowIsMenuBarVisible", "browserWindow-isMenuBarVisible-completed" + Id, Id);
@@ -1923,6 +2004,8 @@ namespace ElectronNET.API
/// On Windows it calls SetWindowDisplayAffinity with WDA_MONITOR.
/// </summary>
/// <param name="enable"></param>
[SupportedOSPlatform("windows")]
[SupportedOSPlatform("macos")]
public void SetContentProtection(bool enable)
{
BridgeConnector.Emit("browserWindowSetContentProtection", Id, enable);
@@ -1932,6 +2015,8 @@ namespace ElectronNET.API
/// Changes whether the window can be focused.
/// </summary>
/// <param name="focusable"></param>
[SupportedOSPlatform("windows")]
[SupportedOSPlatform("macos")]
public void SetFocusable(bool focusable)
{
BridgeConnector.Emit("browserWindowSetFocusable", Id, focusable);
@@ -1971,6 +2056,7 @@ namespace ElectronNET.API
/// Controls whether to hide cursor when typing.
/// </summary>
/// <param name="autoHide"></param>
[SupportedOSPlatform("macos")]
public void SetAutoHideCursor(bool autoHide)
{
BridgeConnector.Emit("browserWindowSetAutoHideCursor", Id, autoHide);
@@ -1983,6 +2069,7 @@ namespace ElectronNET.API
/// <param name="type">Can be appearance-based, light, dark, titlebar, selection,
/// menu, popover, sidebar, medium-light or ultra-dark.
/// See the macOS documentation for more details.</param>
[SupportedOSPlatform("macos")]
public void SetVibrancy(Vibrancy type)
{
BridgeConnector.Emit("browserWindowSetVibrancy", Id, type.GetDescription());