diff --git a/packages/dui3/lib/accounts/composables/setup.ts b/packages/dui3/lib/accounts/composables/setup.ts index 31339278f..c301f67c5 100644 --- a/packages/dui3/lib/accounts/composables/setup.ts +++ b/packages/dui3/lib/accounts/composables/setup.ts @@ -54,8 +54,6 @@ export async function useAccountsSetup(): Promise { accounts.value = newAccs } - // Call this one first to initialize the account state - // QUESTION: could be flopped in a iife so as not to block and drop the asyncness of this setup function? await refreshAccounts() const defaultAccount = computed(() => diff --git a/packages/dui3/lib/bridge/generic.ts b/packages/dui3/lib/bridge/generic.ts index a3afa7b1a..a09199c90 100644 --- a/packages/dui3/lib/bridge/generic.ts +++ b/packages/dui3/lib/bridge/generic.ts @@ -11,9 +11,15 @@ export class GenericBridge extends BaseBridge { this.bridge = object } - public async create() { + public async create(): Promise { // NOTE: GetMethods is a call to the .NET side. - const availableMethodNames = await this.bridge.GetBindingsMethodNames() + let availableMethodNames = [] as string[] + + try { + availableMethodNames = await this.bridge.GetBindingsMethodNames() + } catch { + return false + } // NOTE: hoisting original calls as lowerCasedMethodNames, but using the UpperCasedName for the .NET call // This allows us to follow js convetions and keep .NET ones too (eg. bindings.sayHi('') => public string SayHi(string name) {} @@ -23,6 +29,8 @@ export class GenericBridge extends BaseBridge { hoistTarget[lowercasedMethodName] = (...args: unknown[]) => this.runMethod(methodName, args) } + + return true } private async runMethod(methodName: string, args: unknown[]): Promise { diff --git a/packages/dui3/lib/bridge/sketchup.ts b/packages/dui3/lib/bridge/sketchup.ts index 46566b2c5..f32aa7342 100644 --- a/packages/dui3/lib/bridge/sketchup.ts +++ b/packages/dui3/lib/bridge/sketchup.ts @@ -47,7 +47,9 @@ export class SketchupBridge extends BaseBridge { // NOTE: we need to hoist the bindings in global scope BEFORE we call sketchup exec get comands below. ;(globalThis as Record).bindings = this + } + public async create(): Promise { // Initialization continues in the receiveCommandsAndInitializeBridge function, // where we expect sketchup to return to us the command names for related bindings/views. // NOTE: as we want to have multiple sketchup bindings in the future, we will @@ -55,6 +57,13 @@ export class SketchupBridge extends BaseBridge { // eslint-disable-next-line camelcase // sketchup.exec({ name: 'getCommands', view_id: this.bindingsName }) sketchup.getCommands(this.bindingsName) + + try { + await this.isInitalized + return true + } catch { + return false + } } /** @@ -79,7 +88,6 @@ export class SketchupBridge extends BaseBridge { * @param message */ private rejectBindings(message: string) { - this.resolveIsInitializedPromise(false) this.rejectIsInitializedPromise(message) } diff --git a/packages/dui3/plugins/00.bindings.ts b/packages/dui3/plugins/00.bindings.ts index 59fb3f1ee..0a53352a4 100644 --- a/packages/dui3/plugins/00.bindings.ts +++ b/packages/dui3/plugins/00.bindings.ts @@ -22,6 +22,8 @@ declare let globalThis: Record & { export default defineNuxtPlugin(async () => { const baseBinding = await tryHoistBinding('baseBinding') + const nonExistantBindings = await tryHoistBinding('nonExistantBindings') + const rhinoRandomBinding = await tryHoistBinding( 'rhinoRandomBinding' ) @@ -45,24 +47,24 @@ export default defineNuxtPlugin(async () => { */ const tryHoistBinding = async (name: string) => { let bridge: GenericBridge | SketchupBridge | null = null + let tempBridge: GenericBridge | SketchupBridge | null = null if (globalThis.CefSharp) { await globalThis.CefSharp.BindObjectAsync(name) - bridge = new GenericBridge(globalThis[name] as unknown as IRawBridge) - await bridge.create() + tempBridge = new GenericBridge(globalThis[name] as unknown as IRawBridge) } - if (globalThis.chrome && globalThis.chrome.webview && !bridge) { - bridge = new GenericBridge(globalThis.chrome.webview.hostObjects[name]) - await bridge.create() + if (globalThis.chrome && globalThis.chrome.webview && !tempBridge) { + tempBridge = new GenericBridge(globalThis.chrome.webview.hostObjects[name]) } - if (globalThis.sketchup && !bridge) { - bridge = new SketchupBridge(name) - const res = await bridge.isInitalized - if (!res) bridge = null + if (globalThis.sketchup && !tempBridge) { + tempBridge = new SketchupBridge(name) } + const res = await tempBridge?.create() + if (res) bridge = tempBridge + if (!bridge) console.warn(`Failed to bind ${name} binding.`) globalThis[name] = bridge