experiments(dui3): WIP - needs minor readjustments with the .net patterns

This commit is contained in:
Dimitrie Stefanescu
2023-07-12 19:39:15 +01:00
parent ca91ff8960
commit eb0f4402fb
5 changed files with 81 additions and 11 deletions
@@ -0,0 +1,76 @@
export interface IBaseBindings {
sayHi: (name: string) => Promise<string>
getAccounts: () => Promise<Account[]>
getSourceAppName: () => Promise<string>
getSourceAppVersion: () => Promise<string>
getDocumentInfo: () => Promise<DocumentInfo>
// TODO:
getFileState: () => Promise<FileState>
updateFileState: (state: FileState) => Promise<void>
/**
* Subscribe to messages from the host application.
* @param event
* @param callback
*/
on: <E extends keyof IBaseBindingsHostEvents>(
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<string,unknown>???
// report: Record<string,unknown>???
// progress: Record<string, unknown> // ??? 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
}
-1
View File
@@ -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
+2 -2
View File
@@ -10,7 +10,7 @@ type IWebView2 = {
}
type IRawBridge = {
GetMethods: () => string[]
GetBindingsMethodNames: () => string[]
RunMethod: (methodName: string, args: string) => Promise<string>
}
@@ -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) {}
+1 -1
View File
@@ -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(`
+2 -7
View File
@@ -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<string>
openDevTools: () => Promise<void>
getAccounts: () => Promise<Account[]>
getSourceAppName: () => Promise<string>
getSourceApplicationName: () => Promise<string>
getSourceApplicationVersion: () => Promise<string>
// getFileState: () => Promise<FileState>
// addModelCard(string modelId, string projectId), removeModelCard(...) // etc. etc.