未验证 提交 8517bd79 编写于 作者: E Elie Bariche 提交者: GitHub

Merge pull request #12489 from unoplatform/dev/eb/csp

perf: Misc bindings V
......@@ -60,6 +60,9 @@ namespace Windows.UI.Xaml
ObserveApplicationVisibility();
}
#if NET7_0_OR_GREATER
[JSExport]
#endif
public static int DispatchVisibilityChange(bool isVisible)
{
var application = Windows.UI.Xaml.Application.Current;
......
......@@ -39,6 +39,9 @@ internal partial class SystemFocusVisual : Control
#endif
}
#if NET7_0_OR_GREATER
[JSExport]
#endif
public static int DispatchNativePositionChange(int focusVisualId)
{
var element = UIElement.GetElementFromHandle(focusVisualId) as SystemFocusVisual;
......
......@@ -31,6 +31,8 @@ using Uno.UI.Xaml;
using System.Diagnostics.CodeAnalysis;
#if NET7_0_OR_GREATER
using System.Runtime.InteropServices.JavaScript;
using NativeMethods = __Windows.ApplicationModel.DataTransfer.DragDrop.Core.DragDropExtension.NativeMethods;
#endif
......@@ -39,7 +41,7 @@ using NativeMethods = __Windows.ApplicationModel.DataTransfer.DragDrop.Core.Drag
namespace Windows.ApplicationModel.DataTransfer.DragDrop.Core
{
internal class DragDropExtension : IDragDropExtension
internal partial class DragDropExtension : IDragDropExtension
{
private const long _textReadTimeoutTicks = 10 * TimeSpan.TicksPerSecond;
......@@ -124,6 +126,9 @@ namespace Windows.ApplicationModel.DataTransfer.DragDrop.Core
[Preserve]
[EditorBrowsable(EditorBrowsableState.Never)]
#if NET7_0_OR_GREATER
[JSExport]
#endif
public static string OnNativeDropEvent()
{
try
......
......@@ -9,6 +9,8 @@ using Uno.UI.DataBinding;
using Windows.Storage.Helpers;
#if NET7_0_OR_GREATER
using System.Runtime.InteropServices.JavaScript;
using NativeMethods = __Windows.UI.Xaml.Media.FontFamilyLoader.NativeMethods;
#endif
......@@ -17,7 +19,7 @@ namespace Windows.UI.Xaml.Media;
/// <summary>
/// WebAssembly-specific asynchronous font loader
/// </summary>
internal class FontFamilyLoader
internal partial class FontFamilyLoader
{
private static readonly Dictionary<FontFamily, FontFamilyLoader> _loaders = new(new FontFamilyComparer());
private static readonly Dictionary<string, FontFamilyLoader> _loadersFromCssName = new();
......@@ -61,6 +63,9 @@ internal class FontFamilyLoader
/// <summary>
/// Typescript-invoked method to notify that a font has been loaded properly
/// </summary>
#if NET7_0_OR_GREATER
[JSExport]
#endif
internal static void NotifyFontLoaded(string cssFontName)
{
if (_loadersFromCssName.TryGetValue(cssFontName, out var loader))
......@@ -101,6 +106,9 @@ internal class FontFamilyLoader
/// <summary>
/// Typescript-invoked method to notify that a font failed to load properly
/// </summary>
#if NET7_0_OR_GREATER
[JSExport]
#endif
internal static void NotifyFontLoadFailed(string cssFontName)
{
if (_loadersFromCssName.TryGetValue(cssFontName, out var loader))
......
......@@ -60,9 +60,13 @@ namespace Uno.Utils {
private static onClipboardChanged() {
if (!Clipboard.dispatchContentChanged) {
Clipboard.dispatchContentChanged =
(<any>Module).mono_bind_static_method(
"[Uno] Windows.ApplicationModel.DataTransfer.Clipboard:DispatchContentChanged");
if ((<any>globalThis).DotnetExports !== undefined) {
Clipboard.dispatchContentChanged = (<any>globalThis).DotnetExports.Uno.Windows.ApplicationModel.DataTransfer.Clipboard.DispatchContentChanged;
} else {
Clipboard.dispatchContentChanged =
(<any>Module).mono_bind_static_method(
"[Uno] Windows.ApplicationModel.DataTransfer.Clipboard:DispatchContentChanged");
}
}
Clipboard.dispatchContentChanged();
}
......
......@@ -15,7 +15,11 @@
public static enable(pArgs: number): void {
if (!DragDropExtension._dispatchDropEventMethod) {
DragDropExtension._dispatchDropEventMethod = (<any>Module).mono_bind_static_method("[Uno.UI] Windows.ApplicationModel.DataTransfer.DragDrop.Core.DragDropExtension:OnNativeDropEvent");
if ((<any>globalThis).DotnetExports !== undefined) {
DragDropExtension._dispatchDropEventMethod = (<any>globalThis).DotnetExports.UnoUI.Windows.ApplicationModel.DataTransfer.DragDrop.Core.DragDropExtension.OnNativeDropEvent;
} else {
DragDropExtension._dispatchDropEventMethod = (<any>Module).mono_bind_static_method("[Uno.UI] Windows.ApplicationModel.DataTransfer.DragDrop.Core.DragDropExtension:OnNativeDropEvent");
}
}
if (DragDropExtension._current) {
......
......@@ -17,7 +17,11 @@ namespace Windows.Devices.Sensors {
public static initialize(): boolean {
try {
if (typeof window.Gyroscope === "function") {
this.dispatchReading = (<any>Module).mono_bind_static_method("[Uno] Windows.Devices.Sensors.Gyrometer:DispatchReading");
if ((<any>globalThis).DotnetExports !== undefined) {
this.dispatchReading = (<any>globalThis).DotnetExports.Uno.Windows.Devices.Sensors.Gyrometer.DispatchReading;
} else {
this.dispatchReading = (<any>Module).mono_bind_static_method("[Uno] Windows.Devices.Sensors.Gyrometer:DispatchReading");
}
let GyroscopeClass: any = window.Gyroscope;
this.gyroscope = new GyroscopeClass({ referenceFrame: "device" });
return true;
......
......@@ -142,9 +142,13 @@
const currentDpi = window.devicePixelRatio;
if (Math.abs(DisplayInformation.lastDpi - currentDpi) > 0.001) {
if (DisplayInformation.dispatchDpiChanged == null) {
DisplayInformation.dispatchDpiChanged =
(<any>Module).mono_bind_static_method(
"[Uno] Windows.Graphics.Display.DisplayInformation:DispatchDpiChanged");
if ((<any>globalThis).DotnetExports !== undefined) {
DisplayInformation.dispatchDpiChanged = (<any>globalThis).DotnetExports.Uno.Windows.Graphics.Display.DisplayInformation.DispatchDpiChanged;
} else {
DisplayInformation.dispatchDpiChanged =
(<any>Module).mono_bind_static_method(
"[Uno] Windows.Graphics.Display.DisplayInformation:DispatchDpiChanged");
}
}
DisplayInformation.dispatchDpiChanged(currentDpi);
}
......@@ -153,9 +157,13 @@
private static onOrientationChange() {
if (DisplayInformation.dispatchOrientationChanged == null) {
DisplayInformation.dispatchOrientationChanged =
(<any>Module).mono_bind_static_method(
"[Uno] Windows.Graphics.Display.DisplayInformation:DispatchOrientationChanged");
if ((<any>globalThis).DotnetExports !== undefined) {
DisplayInformation.dispatchOrientationChanged = (<any>globalThis).DotnetExports.Uno.Windows.Graphics.Display.DisplayInformation.DispatchOrientationChanged;
} else {
DisplayInformation.dispatchOrientationChanged =
(<any>Module).mono_bind_static_method(
"[Uno] Windows.Graphics.Display.DisplayInformation:DispatchOrientationChanged");
}
}
DisplayInformation.dispatchOrientationChanged(window.screen.orientation.type);
}
......
......@@ -17,7 +17,11 @@ namespace Uno.Helpers.Theming {
public static observeSystemTheme() {
if (!SystemThemeHelper.dispatchThemeChange) {
SystemThemeHelper.dispatchThemeChange = (<any>Module).mono_bind_static_method("[Uno] Uno.Helpers.Theming.SystemThemeHelper:DispatchSystemThemeChange");
if ((<any>globalThis).DotnetExports !== undefined) {
SystemThemeHelper.dispatchThemeChange = (<any>globalThis).DotnetExports.Uno.Uno.Helpers.Theming.SystemThemeHelper.DispatchSystemThemeChange;
} else {
SystemThemeHelper.dispatchThemeChange = (<any>Module).mono_bind_static_method("[Uno] Uno.Helpers.Theming.SystemThemeHelper:DispatchSystemThemeChange");
}
}
if (window.matchMedia) {
......
......@@ -15,9 +15,13 @@
public static networkStatusChanged() {
if (NetworkInformation.dispatchStatusChanged == null) {
NetworkInformation.dispatchStatusChanged =
(<any>Module).mono_bind_static_method(
"[Uno] Windows.Networking.Connectivity.NetworkInformation:DispatchStatusChanged");
if ((<any>globalThis).DotnetExports !== undefined) {
NetworkInformation.dispatchStatusChanged = (<any>globalThis).DotnetExports.Uno.Windows.Networking.Connectivity.NetworkInformation.DispatchStatusChanged;
} else {
NetworkInformation.dispatchStatusChanged =
(<any>Module).mono_bind_static_method(
"[Uno] Windows.Networking.Connectivity.NetworkInformation:DispatchStatusChanged");
}
}
NetworkInformation.dispatchStatusChanged();
}
......
......@@ -75,7 +75,11 @@
private static generateGuids(count: number): string[] {
if (!NativeStorageItem.generateGuidBinding) {
NativeStorageItem.generateGuidBinding = (<any>Module).mono_bind_static_method("[Uno] Uno.Storage.NativeStorageItem:GenerateGuids");
if ((<any>globalThis).DotnetExports !== undefined) {
NativeStorageItem.generateGuidBinding = (<any>globalThis).DotnetExports.Uno.Uno.Storage.NativeStorageItem.GenerateGuids;
} else {
NativeStorageItem.generateGuidBinding = (<any>Module).mono_bind_static_method("[Uno] Uno.Storage.NativeStorageItem:GenerateGuids");
}
}
const guids = NativeStorageItem.generateGuidBinding(count);
......
......@@ -69,9 +69,13 @@ namespace Windows.Storage {
private static onStorageInitialized() {
if (!StorageFolder.dispatchStorageInitialized) {
StorageFolder.dispatchStorageInitialized =
(<any>Module).mono_bind_static_method(
"[Uno] Windows.Storage.StorageFolder:DispatchStorageInitialized");
if ((<any>globalThis).DotnetExports !== undefined) {
StorageFolder.dispatchStorageInitialized = (<any>globalThis).DotnetExports.Uno.Windows.Storage.StorageFolder.DispatchStorageInitialized;
} else {
StorageFolder.dispatchStorageInitialized =
(<any>Module).mono_bind_static_method(
"[Uno] Windows.Storage.StorageFolder:DispatchStorageInitialized");
}
}
StorageFolder.dispatchStorageInitialized();
}
......
......@@ -14,7 +14,9 @@
constructor() {
var that = this;
var dispatchBackRequest = (<any>Module).mono_bind_static_method("[Uno] Windows.UI.Core.SystemNavigationManager:DispatchBackRequest");
var dispatchBackRequest = (<any>globalThis).DotnetExports !== undefined ?
(<any>globalThis).DotnetExports.Uno.Windows.UI.Core.SystemNavigationManager.DispatchBackRequest :
(<any>Module).mono_bind_static_method("[Uno] Windows.UI.Core.SystemNavigationManager:DispatchBackRequest");
window.history.replaceState(0, document.title, null);
window.addEventListener("popstate", function (evt) {
......
......@@ -5,7 +5,11 @@
public static observeVisibility() {
if (!Application.dispatchVisibilityChange) {
Application.dispatchVisibilityChange = (<any>Module).mono_bind_static_method("[Uno.UI] Windows.UI.Xaml.Application:DispatchVisibilityChange");
if ((<any>globalThis).DotnetExports !== undefined) {
Application.dispatchVisibilityChange = (<any>globalThis).DotnetExports.UnoUI.Windows.UI.Xaml.Application.DispatchVisibilityChange;
} else {
Application.dispatchVisibilityChange = (<any>Module).mono_bind_static_method("[Uno.UI] Windows.UI.Xaml.Application:DispatchVisibilityChange");
}
}
if (document.onvisibilitychange !== undefined) {
......
......@@ -25,8 +25,12 @@
private static onDocumentScroll() {
if (!FocusVisual.dispatchPositionChange) {
FocusVisual.dispatchPositionChange = (<any>Module).mono_bind_static_method(
"[Uno.UI] Uno.UI.Xaml.Controls.SystemFocusVisual:DispatchNativePositionChange");
if ((<any>globalThis).DotnetExports !== undefined) {
FocusVisual.dispatchPositionChange = (<any>globalThis).DotnetExports.UnoUI.Uno.UI.Xaml.Controls.SystemFocusVisual.DispatchNativePositionChange;
} else {
FocusVisual.dispatchPositionChange = (<any>Module).mono_bind_static_method(
"[Uno.UI] Uno.UI.Xaml.Controls.SystemFocusVisual:DispatchNativePositionChange");
}
}
FocusVisual.updatePosition();
......
......@@ -49,8 +49,12 @@
private static notifyFontLoaded(fontFamilyName: string): void {
if (!FontFamily.managedNotifyFontLoaded) {
FontFamily.managedNotifyFontLoaded =
(<any>Module).mono_bind_static_method("[Uno.UI] Windows.UI.Xaml.Media.FontFamilyLoader:NotifyFontLoaded");
if ((<any>globalThis).DotnetExports !== undefined) {
FontFamily.managedNotifyFontLoaded = (<any>globalThis).DotnetExports.UnoUI.Windows.UI.Xaml.Media.FontFamilyLoader.NotifyFontLoaded;
} else {
FontFamily.managedNotifyFontLoaded =
(<any>Module).mono_bind_static_method("[Uno.UI] Windows.UI.Xaml.Media.FontFamilyLoader:NotifyFontLoaded");
}
}
FontFamily.managedNotifyFontLoaded(fontFamilyName);
......@@ -59,8 +63,12 @@
private static notifyFontLoadFailed(fontFamilyName: string): void {
if (!FontFamily.managedNotifyFontLoadFailed) {
FontFamily.managedNotifyFontLoadFailed =
(<any>Module).mono_bind_static_method("[Uno.UI] Windows.UI.Xaml.Media.FontFamilyLoader:NotifyFontLoadFailed");
if ((<any>globalThis).DotnetExports !== undefined) {
FontFamily.managedNotifyFontLoadFailed = (<any>globalThis).DotnetExports.UnoUI.Windows.UI.Xaml.Media.FontFamilyLoader.NotifyFontLoadFailed;
} else {
FontFamily.managedNotifyFontLoadFailed =
(<any>Module).mono_bind_static_method("[Uno.UI] Windows.UI.Xaml.Media.FontFamilyLoader:NotifyFontLoadFailed");
}
}
FontFamily.managedNotifyFontLoadFailed(fontFamilyName);
......
#if NET7_0_OR_GREATER
using System.Runtime.InteropServices.JavaScript;
namespace __Windows.ApplicationModel.Calls
{
internal partial class PhoneCallManager
{
internal static partial class NativeMethods
{
}
}
}
#endif
\ No newline at end of file
......@@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.Text;
#if NET7_0_OR_GREATER
using NativeMethods = __Windows.ApplicationModel.Calls.PhoneCallManager.NativeMethods;
using NativeMethods = __Windows.__System.Launcher.NativeMethods;
#endif
namespace Windows.ApplicationModel.Calls
......@@ -14,8 +14,13 @@ namespace Windows.ApplicationModel.Calls
private static void ShowPhoneCallUIImpl(string phoneNumber, string displayName)
{
var uri = new Uri($"tel:{phoneNumber}");
#if NET7_0_OR_GREATER
NativeMethods.Open(uri.AbsoluteUri);
#else
var command = $"Uno.UI.WindowManager.current.open(\"{uri.AbsoluteUri}\");";
Uno.Foundation.WebAssemblyRuntime.InvokeJS(command);
#endif
}
}
}
......
......@@ -9,6 +9,8 @@ using Uno.Foundation;
using System.Threading;
#if NET7_0_OR_GREATER
using System.Runtime.InteropServices.JavaScript;
using NativeMethods = __Windows.ApplicationModel.DataTransfer.Clipboard.NativeMethods;
#endif
......@@ -91,6 +93,9 @@ namespace Windows.ApplicationModel.DataTransfer
#endif
}
#if NET7_0_OR_GREATER
[JSExport]
#endif
public static int DispatchContentChanged()
{
OnContentChanged();
......
......@@ -7,7 +7,17 @@ namespace __Windows.Devices.Sensors
{
internal static partial class NativeMethods
{
private const string JsType = "globalThis.Windows.Devices.Sensors.Gyrometer";
[JSImport($"{JsType}.initialize")]
internal static partial bool Initialize();
[JSImport($"{JsType}.startReading")]
internal static partial void StartReading();
[JSImport($"{JsType}.stopReading")]
internal static partial void StopReading();
}
}
}
#endif
\ No newline at end of file
#endif
......@@ -5,6 +5,8 @@ using Uno;
using Uno.Devices.Sensors.Helpers;
#if NET7_0_OR_GREATER
using System.Runtime.InteropServices.JavaScript;
using NativeMethods = __Windows.Devices.Sensors.Gyrometer.NativeMethods;
#endif
......@@ -12,7 +14,9 @@ namespace Windows.Devices.Sensors
{
public partial class Gyrometer
{
#if !NET7_0_OR_GREATER
private const string JsType = "Windows.Devices.Sensors.Gyrometer";
#endif
private DateTimeOffset _lastReading = DateTimeOffset.MinValue;
......@@ -24,6 +28,9 @@ namespace Windows.Devices.Sensors
private static Gyrometer TryCreateInstance()
{
#if NET7_0_OR_GREATER
return NativeMethods.Initialize() ? new() : null;
#else
var command = $"{JsType}.initialize()";
var initialized = Uno.Foundation.WebAssemblyRuntime.InvokeJS(command);
if (bool.Parse(initialized) == true)
......@@ -31,18 +38,27 @@ namespace Windows.Devices.Sensors
return new Gyrometer();
}
return null;
#endif
}
private void StartReading()
{
#if NET7_0_OR_GREATER
NativeMethods.StartReading();
#else
var command = $"{JsType}.startReading()";
Uno.Foundation.WebAssemblyRuntime.InvokeJS(command);
#endif
}
private void StopReading()
{
#if NET7_0_OR_GREATER
NativeMethods.StopReading();
#else
var command = $"{JsType}.stopReading()";
Uno.Foundation.WebAssemblyRuntime.InvokeJS(command);
#endif
}
/// <summary>
......@@ -56,6 +72,9 @@ namespace Windows.Devices.Sensors
/// <param name="y">AngularVelocity Y in radians/s</param>
/// <param name="z">AngularVelocity Z in radians/s</param>
/// <returns>0 - needed to bind method from WASM</returns>
#if NET7_0_OR_GREATER
[JSExport]
#endif
public static int DispatchReading(float x, float y, float z)
{
if (_instance == null)
......
......@@ -7,7 +7,17 @@ namespace __Windows.Devices.Sensors
{
internal static partial class NativeMethods
{
private const string JsType = "globalThis.Windows.Devices.Sensors.LightSensor";
[JSImport($"{JsType}.initialize")]
internal static partial bool Initialize();
[JSImport($"{JsType}.startReading")]
internal static partial void StartReading();
[JSImport($"{JsType}.stopReading")]
internal static partial void StopReading();
}
}
}
#endif
\ No newline at end of file
#endif
......@@ -11,10 +11,15 @@ namespace Windows.Devices.Sensors
{
public partial class LightSensor
{
#if !NET7_0_OR_GREATER
private const string JsType = "Windows.Devices.Sensors.LightSensor";
#endif
private static LightSensor? TryCreateInstance()
{
#if NET7_0_OR_GREATER
return NativeMethods.Initialize() ? new() : null;
#else
var command = $"{JsType}.initialize()";
var initialized = Uno.Foundation.WebAssemblyRuntime.InvokeJS(command);
if (bool.Parse(initialized) == true)
......@@ -22,18 +27,27 @@ namespace Windows.Devices.Sensors
return new LightSensor();
}
return null;
#endif
}
private void StartReading()
{
#if NET7_0_OR_GREATER
NativeMethods.StartReading();
#else
var command = $"{JsType}.startReading()";
Uno.Foundation.WebAssemblyRuntime.InvokeJS(command);
#endif
}
private void StopReading()
{
#if NET7_0_OR_GREATER
NativeMethods.StopReading();
#else
var command = $"{JsType}.stopReading()";
Uno.Foundation.WebAssemblyRuntime.InvokeJS(command);
#endif
}
public static int DispatchReading(float lux)
......
......@@ -7,7 +7,18 @@ namespace __Windows.Devices.Sensors
{
internal static partial class NativeMethods
{
private const string JsType = "globalThis.Windows.Devices.Sensors.Magnetometer";
[JSImport($"{JsType}.initialize")]
internal static partial bool Initialize();
[JSImport($"{JsType}.startReading")]
internal static partial void StartReading();
[JSImport($"{JsType}.stopReading")]
internal static partial void StopReading();
}
}
}
#endif
\ No newline at end of file
#endif
......@@ -12,7 +12,9 @@ namespace Windows.Devices.Sensors
{
public partial class Magnetometer
{
#if !NET7_0_OR_GREATER
private const string JsType = "Windows.Devices.Sensors.Magnetometer";
#endif
private DateTimeOffset _lastReading = DateTimeOffset.MinValue;
......@@ -24,6 +26,9 @@ namespace Windows.Devices.Sensors
private static Magnetometer TryCreateInstance()
{
#if NET7_0_OR_GREATER
return NativeMethods.Initialize() ? new() : null;
#else
var command = $"{JsType}.initialize()";
var initialized = Uno.Foundation.WebAssemblyRuntime.InvokeJS(command);
if (bool.Parse(initialized) == true)
......@@ -31,18 +36,27 @@ namespace Windows.Devices.Sensors
return new Magnetometer();
}
return null;
#endif
}
private void StartReading()
{
#if NET7_0_OR_GREATER
NativeMethods.StartReading();
#else
var command = $"{JsType}.startReading()";
Uno.Foundation.WebAssemblyRuntime.InvokeJS(command);
#endif
}
private void StopReading()
{
#if NET7_0_OR_GREATER
NativeMethods.StopReading();
#else
var command = $"{JsType}.stopReading()";
Uno.Foundation.WebAssemblyRuntime.InvokeJS(command);
#endif
}
/// <summary>
......
......@@ -7,6 +7,8 @@ using Uno;
using Uno.Foundation;
#if NET7_0_OR_GREATER
using System.Runtime.InteropServices.JavaScript;
using NativeMethods = __Windows.Graphics.Display.DisplayInformation.NativeMethods;
#endif
......@@ -22,6 +24,9 @@ namespace Windows.Graphics.Display
private const string JsType = "Windows.Graphics.Display.DisplayInformation";
#endif
#if NET7_0_OR_GREATER
[JSExport]
#endif
public static int DispatchDpiChanged()
{
if (_lazyInstance.IsValueCreated)
......@@ -31,6 +36,9 @@ namespace Windows.Graphics.Display
return 0;
}
#if NET7_0_OR_GREATER
[JSExport]
#endif
public static int DispatchOrientationChanged()
{
if (_lazyInstance.IsValueCreated)
......
......@@ -7,9 +7,13 @@ using System.Web;
using Uno.Extensions;
using Uno.Foundation.Logging;
#if NET7_0_OR_GREATER
using System.Runtime.InteropServices.JavaScript;
#endif
namespace Uno.Helpers
{
public static class ProtocolActivation
public static partial class ProtocolActivation
{
internal const string QueryKey = "unoprotocolactivation";
......@@ -72,8 +76,12 @@ namespace Uno.Helpers
uriString += "%s";
// register scheme
#if NET7_0_OR_GREATER
NativeMethods.RegisterProtocolHandler(scheme, uriString, prompt);
#else
var initialized = Uno.Foundation.WebAssemblyRuntime.InvokeJS(
$"navigator.registerProtocolHandler('{scheme}', '{uriString}' , '{prompt.Replace("'", "\\'")}')");
#endif
}
internal static bool TryParseActivationUri(string queryArguments, out Uri uri)
......@@ -107,6 +115,14 @@ namespace Uno.Helpers
// arguments did not contain activation URI or it could not be parsed
return false;
}
#if NET7_0_OR_GREATER
internal static partial class NativeMethods
{
[JSImport("globalThis.navigator.registerProtocolHandler")]
internal static partial void RegisterProtocolHandler(string scheme, string uri, string prompt);
}
#endif
}
}
#endif
......@@ -6,6 +6,8 @@ using Uno.Foundation;
using Uno.Foundation.Logging;
#if NET7_0_OR_GREATER
using System.Runtime.InteropServices.JavaScript;
using NativeMethods = __Uno.Helpers.Theming.SystemThemeHelper.NativeMethods;
#endif
......@@ -54,6 +56,9 @@ internal static partial class SystemThemeHelper
#endif
}
#if NET7_0_OR_GREATER
[JSExport]
#endif
public static int DispatchSystemThemeChange()
{
RefreshSystemTheme();
......
......@@ -7,7 +7,14 @@ namespace __Windows.Networking.Connectivity
{
internal static partial class NativeMethods
{
private const string JsType = "globalThis.Windows.Networking.Connectivity.NetworkInformation";
[JSImport($"{JsType}.startStatusChanged")]
internal static partial void StartStatusChanged();
[JSImport($"{JsType}.stopStatusChanged")]
internal static partial void StopStatusChanged();
}
}
}
#endif
\ No newline at end of file
#endif
......@@ -7,6 +7,8 @@ using System.Threading.Tasks;
using Uno;
#if NET7_0_OR_GREATER
using System.Runtime.InteropServices.JavaScript;
using NativeMethods = __Windows.Networking.Connectivity.NetworkInformation.NativeMethods;
#endif
......@@ -14,20 +16,33 @@ namespace Windows.Networking.Connectivity
{
public partial class NetworkInformation
{
#if !NET7_0_OR_GREATER
private const string JsType = "Windows.Networking.Connectivity.NetworkInformation";
#endif
private static void StartNetworkStatusChanged()
{
#if NET7_0_OR_GREATER
NativeMethods.StartStatusChanged();
#else
var command = $"{JsType}.startStatusChanged()";
Uno.Foundation.WebAssemblyRuntime.InvokeJS(command);
#endif
}
private static void StopNetworkStatusChanged()
{
#if NET7_0_OR_GREATER
NativeMethods.StopStatusChanged();
#else
var command = $"{JsType}.stopStatusChanged()";
Uno.Foundation.WebAssemblyRuntime.InvokeJS(command);
#endif
}
#if NET7_0_OR_GREATER
[JSExport]
#endif
public static int DispatchStatusChanged()
{
OnNetworkStatusChanged();
......
......@@ -7,7 +7,14 @@ namespace __Windows.Phone.Devices.Notification
{
internal static partial class NativeMethods
{
private const string JsType = "globalThis.Windows.Phone.Devices.Notification.VibrationDevice";
[JSImport($"{JsType}.initialize")]
internal static partial bool Initialize();
[JSImport($"{JsType}.vibrate")]
internal static partial void Vibrate(string duration);
}
}
}
#endif
\ No newline at end of file
#endif
......@@ -11,7 +11,10 @@ namespace Windows.Phone.Devices.Notification
{
public partial class VibrationDevice
{
#if !NET7_0_OR_GREATER
private const string JsType = "Windows.Phone.Devices.Notification.VibrationDevice";
#endif
private static VibrationDevice _instance;
private static bool _initializationAttempted;
......@@ -23,12 +26,17 @@ namespace Windows.Phone.Devices.Notification
{
if (!_initializationAttempted && _instance == null)
{
#if NET7_0_OR_GREATER
_instance = NativeMethods.Initialize() ? new() : null;
#else
var command = $"{JsType}.initialize()";
var initialized = Uno.Foundation.WebAssemblyRuntime.InvokeJS(command);
if (bool.Parse(initialized) == true)
{
_instance = new VibrationDevice();
}
#endif
_initializationAttempted = true;
}
return _instance;
......@@ -42,8 +50,12 @@ namespace Windows.Phone.Devices.Notification
private void WasmVibrate(TimeSpan duration)
{
#if NET7_0_OR_GREATER
NativeMethods.Vibrate($"{(long)duration.TotalMilliseconds}");
#else
var command = $"{JsType}.vibrate(\"{(long)duration.TotalMilliseconds}\");";
Uno.Foundation.WebAssemblyRuntime.InvokeJS(command);
#endif
}
}
}
......
......@@ -7,7 +7,9 @@ namespace __Windows.Security.ExchangeActiveSyncProvisioning
{
internal static partial class NativeMethods
{
[JSImport("globalThis.Windows.System.Profile.AnalyticsVersionInfo.getUserAgent")]
internal static partial string GetUserAgent();
}
}
}
#endif
\ No newline at end of file
#endif
......@@ -9,7 +9,10 @@ namespace Windows.Security.ExchangeActiveSyncProvisioning
public partial class EasClientDeviceInformation
{
private const string BrowserVersionFallback = "Unknown";
#if !NET7_0_OR_GREATER
private const string JsType = "Windows.System.Profile.AnalyticsVersionInfo";
#endif
partial void Initialize()
{
......@@ -19,7 +22,13 @@ namespace Windows.Security.ExchangeActiveSyncProvisioning
private string GetUserAgent()
{
var userAgent = InvokeJS(JsType + ".getUserAgent()");
var userAgent =
#if NET7_0_OR_GREATER
NativeMethods.GetUserAgent();
#else
InvokeJS(JsType + ".getUserAgent()");
#endif
if (!string.IsNullOrEmpty(userAgent))
{
return userAgent;
......
......@@ -3,12 +3,19 @@
using System;
using System.Linq;
#if NET7_0_OR_GREATER
using System.Runtime.InteropServices.JavaScript;
#endif
namespace Uno.Storage
{
public class NativeStorageItem
public partial class NativeStorageItem
{
private const string GuidSplit = ";";
#if NET7_0_OR_GREATER
[JSExport]
#endif
public static string GenerateGuids(int count) => string.Join(GuidSplit, Enumerable.Range(0, count).Select(i => Guid.NewGuid().ToString()));
}
}
......@@ -9,6 +9,10 @@ using Uno.Extensions;
using System.Threading.Tasks;
using Uno.Foundation.Logging;
#if NET7_0_OR_GREATER
using System.Runtime.InteropServices.JavaScript;
#endif
namespace Windows.Storage
{
partial class StorageFolder
......@@ -54,6 +58,9 @@ namespace Windows.Storage
public string[] Paths;
}
#if NET7_0_OR_GREATER
[JSExport]
#endif
internal static void DispatchStorageInitialized()
{
if (typeof(StorageFolder).Log().IsEnabled(Uno.Foundation.Logging.LogLevel.Debug))
......
......@@ -7,7 +7,9 @@ namespace __Windows.__System
{
internal static partial class NativeMethods
{
[JSImport("globalThis.Uno.UI.WindowManager.current.open")]
internal static partial string Open(string url);
}
}
}
#endif
\ No newline at end of file
#endif
......@@ -13,8 +13,12 @@ namespace Windows.System
{
public static Task<bool> LaunchUriPlatformAsync(Uri uri)
{
#if NET7_0_OR_GREATER
var result = NativeMethods.Open(uri.OriginalString);
#else
var command = $"Uno.UI.WindowManager.current.open(\"{uri.OriginalString}\");";
var result = WebAssemblyRuntime.InvokeJS(command);
#endif
return Task.FromResult(result == "True");
}
}
......
......@@ -7,7 +7,12 @@ namespace __Windows.UI.Core
{
internal static partial class NativeMethods
{
[JSImport("globalThis.Windows.UI.Core.SystemNavigationManager.current.disable")]
internal static partial void Disable();
[JSImport("globalThis.Windows.UI.Core.SystemNavigationManager.current.enable")]
internal static partial void Enable();
}
}
}
#endif
\ No newline at end of file
#endif
......@@ -5,6 +5,8 @@ using Uno;
using Uno.Foundation;
#if NET7_0_OR_GREATER
using System.Runtime.InteropServices.JavaScript;
using NativeMethods = __Windows.UI.Core.SystemNavigationManager.NativeMethods;
#endif
......@@ -17,17 +19,28 @@ namespace Windows.UI.Core
switch (visibility)
{
case AppViewBackButtonVisibility.Visible:
#if NET7_0_OR_GREATER
NativeMethods.Enable();
#else
WebAssemblyRuntime.InvokeJS("Windows.UI.Core.SystemNavigationManager.current.enable();");
#endif
break;
case AppViewBackButtonVisibility.Collapsed:
default: // Disabled value is not present in currently supported UWP API, but should be mapped to collapsed
#if NET7_0_OR_GREATER
NativeMethods.Disable();
#else
WebAssemblyRuntime.InvokeJS("Windows.UI.Core.SystemNavigationManager.current.disable();");
#endif
break;
}
}
[Preserve]
#if NET7_0_OR_GREATER
[JSExport]
#endif
public static bool DispatchBackRequest() => GetForCurrentView().RequestBack();
}
}
......@@ -7,7 +7,9 @@ namespace __Windows.UI.Popups
{
internal static partial class NativeMethods
{
[JSImport("globalThis.alert")]
internal static partial void Alert(string message);
}
}
}
#endif
\ No newline at end of file
#endif
......@@ -23,8 +23,12 @@ public partial class MessageDialog
{
VisualTreeHelperProxy.CloseAllFlyouts();
#if NET7_0_OR_GREATER
NativeMethods.Alert(Content);
#else
var command = $"Uno.UI.WindowManager.current.alert(\"{Uno.Foundation.WebAssemblyRuntime.EscapeJs(Content)}\");";
Uno.Foundation.WebAssemblyRuntime.InvokeJS(command);
#endif
return AsyncOperation.FromTask<IUICommand>(
ct => Task.FromResult<IUICommand>(new UICommand("OK")) // TODO: Localize (PBI 28711)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册