diff --git a/packages/dui3/lib/bindings/definitions/baseBindings.ts b/packages/dui3/lib/bindings/definitions/baseBindings.ts new file mode 100644 index 000000000..83971e527 --- /dev/null +++ b/packages/dui3/lib/bindings/definitions/baseBindings.ts @@ -0,0 +1,76 @@ +export interface IBaseBindings { + sayHi: (name: string) => Promise + getAccounts: () => Promise + getSourceAppName: () => Promise + getSourceAppVersion: () => Promise + getDocumentInfo: () => Promise + + // TODO: + getFileState: () => Promise + updateFileState: (state: FileState) => Promise + + /** + * Subscribe to messages from the host application. + * @param event + * @param callback + */ + on: ( + event: E, + callback: IBaseBindingsHostEvents[E] + ) => void +} + +export interface IBaseBindingsHostEvents { + displayToastNotification: (args: ToastInfo) => void + documentChanged: () => void + selectionChanged: (args: SelectionChangedInfo) => void +} + +export type Account = { + id: string + isDefault: boolean + token: string + serverInfo: { + name: string + url: string + } + userInfo: { + id: string + avatar: string + email: string + name: string + commits: { totalCount: number } + streams: { totalCount: number } + } +} + +export type FileState = { + models: ModelCard[] +} + +export type ModelCard = { + serverUrl: string // we need to select the correct account + modelId: string // we need to assemble the gql query properly + projectId: string + type: 'sender' | 'receiver' + status?: 'idle' | 'inprogress' | 'error' | 'warning' | 'disabled' | 'expired' //??? + // settings: Record??? + // report: Record??? + // progress: Record // ??? send status, receive status +} +export type DocumentInfo = { + location: string + name: string + id: string +} + +export type ToastInfo = { + text: string + details?: string + type: 'info' | 'error' | 'warning' +} + +export type SelectionChangedInfo = { + objectIds: string[] + humanReadableSummary?: string +} diff --git a/packages/dui3/lib/bridge/base.ts b/packages/dui3/lib/bridge/base.ts index f8d904fbf..ae0c6ddf3 100644 --- a/packages/dui3/lib/bridge/base.ts +++ b/packages/dui3/lib/bridge/base.ts @@ -3,7 +3,6 @@ import { createNanoEvents, Emitter } from 'nanoevents' /** * A simple (typed) event emitter base class that host applications can use to send messages (and data) to the web ui, * e.g. via `browser.executeScriptAsync("myBindings.on('eventName', serializedData)")`. - */ export class BaseBridge { private emitter: Emitter diff --git a/packages/dui3/lib/bridge/webview.ts b/packages/dui3/lib/bridge/webview.ts index 7adfc86e3..7878a5b0b 100644 --- a/packages/dui3/lib/bridge/webview.ts +++ b/packages/dui3/lib/bridge/webview.ts @@ -10,7 +10,7 @@ type IWebView2 = { } type IRawBridge = { - GetMethods: () => string[] + GetBindingsMethodNames: () => string[] RunMethod: (methodName: string, args: string) => Promise } @@ -25,7 +25,7 @@ export class WebView2Bridge extends BaseBridge { // NOTE: GetMethods is a call to the .NET side. const availableMethodNames = - chrome.webview.hostObjects.sync[bridgeName].GetMethods() + chrome.webview.hostObjects.sync[bridgeName].GetBindingsMethodNames() // 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) {} diff --git a/packages/dui3/pages/index.vue b/packages/dui3/pages/index.vue index 09218cef4..f7f574c0c 100644 --- a/packages/dui3/pages/index.vue +++ b/packages/dui3/pages/index.vue @@ -38,7 +38,7 @@ import { graphql } from '~/lib/common/generated/gql' import { ServerInfoTestQuery } from '~/lib/common/generated/gql/graphql' const { $bindings } = useNuxtApp() -const appName = await $bindings.getSourceAppName() +const appName = await $bindings.getSourceApplicationName() const { accounts, refreshAccounts, defaultAccount } = await useAccountsSetup() const versionQuery = graphql(` diff --git a/packages/dui3/types/index.ts b/packages/dui3/types/index.ts index a7ecd09ab..de7a9a41c 100644 --- a/packages/dui3/types/index.ts +++ b/packages/dui3/types/index.ts @@ -44,19 +44,14 @@ type TestData = { // .NET/Host App -> JS export interface HostAppEvents { test: (data: TestData) => void - documentChanged: (data: { x: number; y: boolean }) => void - selectionChanged: () => void - documentClosed: () => void - updateModelCardState: () => void - displayToastNotification: () => void // bla bla bla } // JS -> asks for something form host app export interface IWebUiBinding { - sayHi: (name: string) => Promise openDevTools: () => Promise getAccounts: () => Promise - getSourceAppName: () => Promise + getSourceApplicationName: () => Promise + getSourceApplicationVersion: () => Promise // getFileState: () => Promise // addModelCard(string modelId, string projectId), removeModelCard(...) // etc. etc.