10 changed files with 95 additions and 37 deletions
@ -0,0 +1,12 @@ |
|||
export class JsExports { |
|||
public static resolvedExports?: any; |
|||
public static exportsPromise: Promise<any>; |
|||
} |
|||
async function resolveExports (): Promise<any> { |
|||
const runtimeApi = await globalThis.getDotnetRuntime(0); |
|||
if (runtimeApi == null) { return; } |
|||
JsExports.resolvedExports = await runtimeApi.getAssemblyExports("Avalonia.Browser.dll"); |
|||
return JsExports.resolvedExports; |
|||
} |
|||
|
|||
JsExports.exportsPromise = resolveExports(); |
|||
@ -1,12 +1,33 @@ |
|||
import { JsExports } from "./jsExports"; |
|||
|
|||
export class TimerHelper { |
|||
public static runAnimationFrames(renderFrameCallback: (timestamp: number) => boolean): void { |
|||
public static runAnimationFrames(): void { |
|||
function render(time: number) { |
|||
const next = renderFrameCallback(time); |
|||
if (next) { |
|||
self.requestAnimationFrame(render); |
|||
if (JsExports.resolvedExports != null) { |
|||
JsExports.resolvedExports.Avalonia.Browser.Interop.TimerHelper.JsExportOnAnimationFrame(time); |
|||
} |
|||
self.requestAnimationFrame(render); |
|||
} |
|||
|
|||
self.requestAnimationFrame(render); |
|||
} |
|||
|
|||
static onTimeout() { |
|||
if (JsExports.resolvedExports != null) { |
|||
JsExports.resolvedExports.Avalonia.Browser.Interop.TimerHelper.JsExportOnTimeout(); |
|||
} else { console.error("TimerHelper.onTimeout call while uninitialized"); } |
|||
} |
|||
|
|||
static onInterval() { |
|||
if (JsExports.resolvedExports != null) { |
|||
JsExports.resolvedExports.Avalonia.Browser.Interop.TimerHelper.JsExportOnInterval(); |
|||
} else { console.error("TimerHelper.onInterval call while uninitialized"); } |
|||
} |
|||
|
|||
public static setTimeout(interval: number): number { |
|||
return setTimeout(TimerHelper.onTimeout, interval); |
|||
} |
|||
|
|||
public static setInterval(interval: number): number { |
|||
return setInterval(TimerHelper.onInterval, interval); |
|||
} |
|||
} |
|||
|
|||
Loading…
Reference in new issue