提交 09be506b 编写于 作者: E Elie Bariche

feat: Initialize WindowManager asynchronously

上级 d010280f
......@@ -13,6 +13,7 @@ using Uno.Foundation;
using Uno.Extensions;
using Uno.Foundation.Logging;
using System.Threading;
using System.Threading.Tasks;
using Uno.UI;
using Uno.UI.Xaml;
using Uno;
......@@ -84,19 +85,31 @@ namespace Windows.UI.Xaml
return 0;
}
static partial void StartPartial(ApplicationInitializationCallback callback)
static async partial void StartPartial(ApplicationInitializationCallback callback)
{
_startInvoked = true;
try
{
_startInvoked = true;
SynchronizationContext.SetSynchronizationContext(
new CoreDispatcherSynchronizationContext(CoreDispatcher.Main, CoreDispatcherPriority.Normal)
);
var isLoadEventsEnabled = !FeatureConfiguration.FrameworkElement.WasmUseManagedLoadedUnloaded;
WindowManagerInterop.Init(isLoadEventsEnabled);
Windows.Storage.ApplicationData.Init();
var isLoadEventsEnabled = !FeatureConfiguration.FrameworkElement.WasmUseManagedLoadedUnloaded;
SynchronizationContext.SetSynchronizationContext(
new CoreDispatcherSynchronizationContext(CoreDispatcher.Main, CoreDispatcherPriority.Normal)
);
await WindowManagerInterop.InitAsync(isLoadEventsEnabled);
callback(new ApplicationInitializationCallbackParams());
Windows.Storage.ApplicationData.Init();
callback(new ApplicationInitializationCallbackParams());
}
catch (Exception exception)
{
if (typeof(Application).Log().IsEnabled(LogLevel.Error))
{
typeof(Application).Log().LogError("Application initialization failed.", exception);
}
}
}
partial void ObserveSystemThemeChanges()
......
......@@ -27,25 +27,13 @@ namespace Uno.UI.Xaml
//When users set double.MaxValue to scroll to the end of the page Javascript doesn't scroll.
private const double MAX_SCROLLING_OFFSET = 1_000_000_000_000_000_000;
#region Init
internal static void Init(bool isLoadEventsEnabled)
{
var parms = new WindowManagerInitParams
{
IsLoadEventsEnabled = isLoadEventsEnabled
};
TSInteropMarshaller.InvokeJS("UnoStatic:initNative", parms);
}
[TSInteropMessage]
[StructLayout(LayoutKind.Sequential, Pack = 4)]
private struct WindowManagerInitParams
{
public bool IsLoadEventsEnabled;
}
#endregion
internal static Task InitAsync(bool isLoadEventsEnabled)
=>
#if NET7_0_OR_GREATER
NativeMethods.InitAsync(isLoadEventsEnabled);
#else
WebAssemblyRuntime.InvokeAsync($"Uno.UI.WindowManager.init({(isLoadEventsEnabled ? "true" : "false")})");
#endif
internal static string FindLaunchArguments()
=>
......@@ -1314,6 +1302,9 @@ namespace Uno.UI.Xaml
[JSImport("globalThis.Uno.UI.WindowManager.current.getProperty")]
internal static partial string GetProperty(IntPtr htmlId, string name);
[JSImport("globalThis.Uno.UI.WindowManager.init")]
internal static partial Task InitAsync(bool isLoadEventsEnabled);
[JSImport("globalThis.Uno.UI.WindowManager.current.measureViewNativeFast")]
internal static partial void MeasureView(IntPtr htmlId, double availableWidth, double availableHeight, bool measureContent, IntPtr pReturn);
......
......@@ -29,7 +29,6 @@ namespace MonoSupport {
}
else {
if (!jsCallDispatcher._isUnoRegistered) {
jsCallDispatcher.registerScope("UnoStatic", Uno.UI.WindowManager);
jsCallDispatcher.registerScope("UnoStatic_Windows_Storage_StorageFolder", Windows.Storage.StorageFolder);
jsCallDispatcher.registerScope("UnoStatic_Windows_Storage_ApplicationDataContainer", Windows.Storage.ApplicationDataContainer);
jsCallDispatcher.registerScope("UnoStatic_Windows_ApplicationModel_DataTransfer_DragDrop_Core_DragDropExtension", Windows.ApplicationModel.DataTransfer.DragDrop.Core.DragDropExtension);
......
......@@ -20,17 +20,16 @@ namespace Uno.UI {
private static readonly unoUnarrangedClassName = "uno-unarranged";
private static readonly unoCollapsedClassName = "uno-visibility-collapsed";
private static _cctor = (() => {
WindowManager.initMethods();
HtmlDom.initPolyfills();
})();
/**
* Initialize the WindowManager
* @param containerElementId The ID of the container element for the Xaml UI
* @param loadingElementId The ID of the loading element to remove once ready
*/
public static init(isLoadEventsEnabled: boolean, containerElementId: string = "uno-body", loadingElementId: string = "uno-loading"): void {
public static async init(isLoadEventsEnabled: boolean, containerElementId: string = "uno-body", loadingElementId: string = "uno-loading") {
HtmlDom.initPolyfills();
await WindowManager.initMethods();
WindowManager._isLoadEventsEnabled = isLoadEventsEnabled;
......@@ -48,7 +47,7 @@ namespace Uno.UI {
private static buildReadyPromise(): Promise<boolean> {
return new Promise<boolean>(resolve => {
Promise.all(
[WindowManager.buildSplashScreen(), ExportManager.initialize()]
[WindowManager.buildSplashScreen()]
).then(() => resolve(true))
});
}
......@@ -112,20 +111,6 @@ namespace Uno.UI {
});
}
/**
* Initialize the WindowManager
* @param containerElementId The ID of the container element for the Xaml UI
* @param loadingElementId The ID of the loading element to remove once ready
*/
public static initNative(pParams: number): boolean {
const params = WindowManagerInitParams.unmarshal(pParams);
WindowManager.init(params.IsLoadEventsEnabled);
return true;
}
private containerElement: HTMLDivElement;
private rootElement: HTMLElement;
......@@ -1582,7 +1567,10 @@ namespace Uno.UI {
);
}
private static initMethods() {
private static async initMethods() {
await ExportManager.initialize();
if (!WindowManager.resizeMethod) {
WindowManager.resizeMethod = (<any>Module).mono_bind_static_method("[Uno.UI] Windows.UI.Xaml.Window:Resize");
}
......
/* TSBindingsGenerator Generated code -- this code is regenerated on each build */
class WindowManagerInitParams
{
/* Pack=4 */
public IsLoadEventsEnabled : boolean;
public static unmarshal(pData:number) : WindowManagerInitParams
{
const ret = new WindowManagerInitParams();
{
ret.IsLoadEventsEnabled = Boolean(Module.getValue(pData + 0, "i32"));
}
return ret;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册