From a579aa9c2a78a8e27bf9eea7f689f509006bab93 Mon Sep 17 00:00:00 2001 From: Elie Bariche <33458222+ebariche@users.noreply.github.com> Date: Sun, 21 May 2023 15:31:44 -0400 Subject: [PATCH] perf: Add ApplicationView bindings --- .../ViewManagement/ApplicationView.Interop.wasm.cs | 11 ++++++++++- .../UI/ViewManagement/ApplicationView.wasm.cs | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/Uno.UWP/UI/ViewManagement/ApplicationView.Interop.wasm.cs b/src/Uno.UWP/UI/ViewManagement/ApplicationView.Interop.wasm.cs index 17942fd6756e..263192a053ed 100644 --- a/src/Uno.UWP/UI/ViewManagement/ApplicationView.Interop.wasm.cs +++ b/src/Uno.UWP/UI/ViewManagement/ApplicationView.Interop.wasm.cs @@ -1,4 +1,5 @@ #if NET7_0_OR_GREATER +using System; using System.Runtime.InteropServices.JavaScript; namespace __Windows.UI.ViewManagement @@ -7,7 +8,15 @@ internal partial class ApplicationView { internal static partial class NativeMethods { + [JSImport("globalThis.Uno.UI.WindowManager.current.getWindowTitle")] + internal static partial string GetWindowTitle(); + + [JSImport("globalThis.Windows.UI.ViewManagement.ApplicationView.setFullScreenMode")] + internal static partial bool SetFullScreenMode(bool turnOn); + + [JSImport("globalThis.Uno.UI.WindowManager.current.setWindowTitle")] + internal static partial void SetWindowTitle(string title); } } } -#endif \ No newline at end of file +#endif diff --git a/src/Uno.UWP/UI/ViewManagement/ApplicationView.wasm.cs b/src/Uno.UWP/UI/ViewManagement/ApplicationView.wasm.cs index 4ce1a05c7f2e..8749a898c783 100644 --- a/src/Uno.UWP/UI/ViewManagement/ApplicationView.wasm.cs +++ b/src/Uno.UWP/UI/ViewManagement/ApplicationView.wasm.cs @@ -13,20 +13,30 @@ namespace Windows.UI.ViewManagement { partial class ApplicationView { +#if !NET7_0_OR_GREATER private const string ApplicationViewTsType = "Windows.UI.ViewManagement.ApplicationView"; +#endif public string Title { get { +#if NET7_0_OR_GREATER + return NativeMethods.GetWindowTitle(); +#else const string command = "Uno.UI.WindowManager.current.getWindowTitle()"; return WebAssemblyRuntime.InvokeJS(command); +#endif } set { +#if NET7_0_OR_GREATER + NativeMethods.SetWindowTitle(value); +#else var escapedValue = WebAssemblyRuntime.EscapeJs(value); var command = "Uno.UI.WindowManager.current.setWindowTitle(\"" + escapedValue + "\");"; WebAssemblyRuntime.InvokeJS(command); +#endif } } @@ -36,9 +46,13 @@ public string Title private bool SetFullScreenMode(bool turnOn) { +#if NET7_0_OR_GREATER + return NativeMethods.SetFullScreenMode(turnOn); +#else var jsEval = $"{ApplicationViewTsType}.setFullScreenMode({turnOn.ToString(CultureInfo.InvariantCulture).ToLowerInvariant()})"; var result = WebAssemblyRuntime.InvokeJS(jsEval); return bool.TryParse(result, out var modeSwitchSuccessful) && modeSwitchSuccessful; +#endif } } }