From 8dac2ce3fc56fb095eab26c30ce57cb56ffff361 Mon Sep 17 00:00:00 2001 From: emielvdveen Date: Fri, 8 Dec 2023 00:38:07 +0100 Subject: [PATCH] Added locale parameter and support for CommandSystemExit --- public/port-0.0.0-py3-none-any.whl | Bin 5363 -> 5454 bytes src/fake_bridge.ts | 22 ++++++++++ src/fake_storage.ts | 16 ------- src/framework/assembly.ts | 6 +-- src/framework/command_router.ts | 10 ++--- .../py/dist/port-0.0.0-py3-none-any.whl | Bin 5363 -> 5454 bytes .../processing/py/port/api/commands.py | 15 +++++++ src/framework/processing/py/port/script.py | 6 ++- src/framework/types/commands.ts | 12 +++++- src/framework/types/modules.ts | 2 +- src/index.tsx | 21 +++++----- src/live_bridge.ts | 36 ++++++++++++++++ src/live_storage.ts | 39 ------------------ 13 files changed, 108 insertions(+), 77 deletions(-) create mode 100644 src/fake_bridge.ts delete mode 100644 src/fake_storage.ts create mode 100644 src/live_bridge.ts delete mode 100644 src/live_storage.ts diff --git a/public/port-0.0.0-py3-none-any.whl b/public/port-0.0.0-py3-none-any.whl index 4b6f4ac8baeb11dfa0fc4c207279c476f92455b7..5ca4492929a8d60ef03192fc0aa0fabee5e15b4a 100644 GIT binary patch delta 2655 zcmV-l3ZV7#Db6a8p$Z(+y*3d6005u^k*gYiwUEI|#4r$s?|F)llM7`ZK=9;x@T%-d zWGKyaiMGkoj9?Mp-I-Kk8oJ;?bLi0d|4HWmx}l9x--dB)y*=JPptm?(E6oQW4uK+o zzR~8~p3tb&x7f4hyd!|Ch(q6KQFqIf9BJ;Q$CFZi<|rIoM`^0?Tkf&-<8#${G5|Dx zpAo=3%L>(!rZT4u#h72;f4{cN&I##l@@YUR)s@*F=SVmnf^P{o^1tG28f{);@DOQo z{&blJdmCLiYcj0!mHb_|iwTyCzdyxS=ByD)$V{-@Z;{LJ*;elPYs`1=jy527!J<%h zz7Lo2imTD$slkfE_efa_VrD_gKfsg|G&RZ;B|}hHWa?kQ*auF$e8D(y$lcxLz}D_ zh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I+Te$FNr8%JxLj1Im* zb|WU2L8WBs}&0$kw&!9+a+j$O9RDwipbMNrYZTTDV@K>=Tmx&eK-=8SA{euS5ZwQ z`leK;iat?ca%jl?UQgSQ4Vs9$*iyhxakX4JSE3Hz5vLRFS;sh!>vA({Y?HOF#njD` zY4z8&>ki66CQ>%q=(fo$nRP6B#4b~###c`J^^9G$wp_P0#x=nkz&_@q!FJNPPbU3} zGV%>`IAiiJvuF>i0R{TtnfRuY7!fLevM>OK;eD?KS`-4f=z=qfC^%HQhm`qO0mv`(izz66Mk$)@#Pq29W>SbKoi>bKMsxP3sf>wTXW zNU3bdPDdDdRTWQ+qzqiOpTVww4`$r0L2m=i5ESL-BVIC0`v)bEt^Ug5VLNFzc`OII zBj2K>E-l7Va=#xqNhU?9-6FP%1)z++Q$*?YYg^2F5x0Bt7CNb68>#WDPW>^Bf*#r~ zzhEOZJEJD7u9U9Z44xa#+7i}1uNUrE7i4Yp9EHB)%zs5UymSd}vJVs`X*a3R)|rUH zQkNOHpUj+FS=4BACYiib1YLg)t{iK*vIXJgACu)0kP4CY6`$7t003bElYbLZ0i2W4 z6FvbklMxgj8-sD&rl$q~04Nmz01f~E00000000000HlFClS>pk0uB$8ArTjopA<3z z9uSiu5f_u{6crr$;F void): void { - this.system.send(command) + this.bridge.send(command) resolve({ __type__: 'Response', command, payload: { __type__: 'PayloadVoid', value: undefined } }) } diff --git a/src/framework/processing/py/dist/port-0.0.0-py3-none-any.whl b/src/framework/processing/py/dist/port-0.0.0-py3-none-any.whl index 4b6f4ac8baeb11dfa0fc4c207279c476f92455b7..5ca4492929a8d60ef03192fc0aa0fabee5e15b4a 100644 GIT binary patch delta 2655 zcmV-l3ZV7#Db6a8p$Z(+y*3d6005u^k*gYiwUEI|#4r$s?|F)llM7`ZK=9;x@T%-d zWGKyaiMGkoj9?Mp-I-Kk8oJ;?bLi0d|4HWmx}l9x--dB)y*=JPptm?(E6oQW4uK+o zzR~8~p3tb&x7f4hyd!|Ch(q6KQFq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4Q3M85&mD}$j3@xacgF+0W!;0uu*p) ze`dd;MO+dL#(&N*pG&~$szh{D%X5P;fM#$?P=m4+SY5Mv$%D!CuEd0a-KCOU%% zL_0?G@G)x%8oCPbU?fGt`(?(&CRHNz@ zoq|8DQOEO0)}H6U4IVsHj>joSuvBd&m0fHOjMbIvlME$?C2OS&GzXOqL9L>rB5HLU zPvJ%+L~T3>s&WMwkQGXJrmB+YkDCbBoZC73#W8Y4lpI+Te$FNr8%JxLj1Im* zb|WU2L8WBs}&0$kw&!9+a+j$O9RDwipbMNrYZTTDV@K>=Tmx&eK-=8SA{euS5ZwQ z`leK;iat?ca%jl?UQgSQ4Vs9$*iyhxakX4JSE3Hz5vLRFS;sh!>vA({Y?HOF#njD` zY4z8&>ki66CQ>%q=(fo$nRP6B#4b~###c`J^^9G$wp_P0#x=nkz&_@q!FJNPPbU3} zGV%>`IAiiJvuF>i0R{TtnfRuY7!fLevM>OK;eD?KS`-4f=z=qfC^%HQhm`qO0mv`(izz66Mk$)@#Pq29W>SbKoi>bKMsxP3sf>wTXW zNU3bdPDdDdRTWQ+qzqiOpTVww4`$r0L2m=i5ESL-BVIC0`v)bEt^Ug5VLNFzc`OII zBj2K>E-l7Va=#xqNhU?9-6FP%1)z++Q$*?YYg^2F5x0Bt7CNb68>#WDPW>^Bf*#r~ zzhEOZJEJD7u9U9Z44xa#+7i}1uNUrE7i4Yp9EHB)%zs5UymSd}vJVs`X*a3R)|rUH zQkNOHpUj+FS=4BACYiib1YLg)t{iK*vIXJgACu)0kP4CY6`$7t003bElYbLZ0i2W4 z6FvbklMxgj8-sD&rl$q~04Nmz01f~E00000000000HlFClS>pk0uB$8ArTjopA<3z z9uSiu5f_u{6crr$;F(arg, 'CommandSystemExit', ['code', 'info']) +} + export type CommandUI = CommandUIRender diff --git a/src/framework/types/modules.ts b/src/framework/types/modules.ts index ccf10358..f460b30d 100644 --- a/src/framework/types/modules.ts +++ b/src/framework/types/modules.ts @@ -12,7 +12,7 @@ export interface VisualisationEngine { terminate: () => void } -export interface Storage { +export interface Bridge { send: (command: CommandSystem) => void } diff --git a/src/index.tsx b/src/index.tsx index acf5e1b9..2aef6ce7 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,30 +1,29 @@ import './fonts.css' import './framework/styles.css' import Assembly from './framework/assembly' -import { Storage } from './framework/types/modules' -import LiveStorage from './live_storage' -import FakeStorage from './fake_storage' +import { Bridge } from './framework/types/modules' +import LiveBridge from './live_bridge' +import FakeBridge from './fake_bridge' const rootElement = document.getElementById('root') as HTMLElement -const locale = 'en' const workerFile = new URL('./framework/processing/py_worker.js', import.meta.url) const worker = new Worker(workerFile) let assembly: Assembly -const run = (system: Storage): void => { - assembly = new Assembly(worker, system) +const run = (bridge: Bridge, locale: string): void => { + assembly = new Assembly(worker, bridge) assembly.visualisationEngine.start(rootElement, locale) assembly.processingEngine.start() } -if (process.env.REACT_APP_BUILD!=='standalone' && process.env.NODE_ENV === 'production') { +if (process.env.REACT_APP_BUILD !== 'standalone' && process.env.NODE_ENV === 'production') { // Setup embedded mode (requires to be embedded in iFrame) - console.log('Initializing storage system') - LiveStorage.create(window, run) + console.log('Initializing bridge system') + LiveBridge.create(window, run) } else { // Setup local development mode - console.log('Running with fake storage') - run(new FakeStorage()) + console.log('Running with fake bridge') + run(new FakeBridge(), 'en') } diff --git a/src/live_bridge.ts b/src/live_bridge.ts new file mode 100644 index 00000000..4aa16d4d --- /dev/null +++ b/src/live_bridge.ts @@ -0,0 +1,36 @@ +import { CommandSystem, isCommandSystem } from './framework/types/commands' +import { Bridge } from './framework/types/modules' + +export default class LiveBridge implements Bridge { + port: MessagePort + + constructor (port: MessagePort) { + this.port = port + } + + static create (window: Window, callback: (bridge: Bridge, locale: string) => void): void { + window.addEventListener('message', (event) => { + console.log('MESSAGE RECEIVED', event) + // Skip webpack messages + if (event.data.action === 'live-init') { + const bridge = new LiveBridge(event.ports[0]) + const locale = event.data.locale + console.log('LOCALE', locale) + callback(bridge, locale) + } + }) + } + + send (command: CommandSystem): void { + if (isCommandSystem(command)) { + this.port.postMessage(command) + } else { + this.log('error', 'received unknown command', command) + } + } + + private log (level: 'info' | 'error', ...message: any[]): void { + const logger = level === 'info' ? console.log : console.error + logger(`[${this.constructor.name}]`, ...message) + } +} diff --git a/src/live_storage.ts b/src/live_storage.ts deleted file mode 100644 index c1f05d4b..00000000 --- a/src/live_storage.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { CommandSystem, CommandSystemDonate, isCommandSystemDonate } from './framework/types/commands' -import { Storage } from './framework/types/modules' - -export default class LiveStorage implements Storage { - port: MessagePort - - constructor (port: MessagePort) { - this.port = port - } - - static create (window: Window, callback: (system: Storage) => void): void { - window.addEventListener('message', (event) => { - console.log('MESSAGE RECEIVED', event) - // Skip webpack messages - if (event.ports.length === 0) { - return - } - const system = new LiveStorage(event.ports[0]) - callback(system) - }) - } - - send (command: CommandSystem): void { - if (isCommandSystemDonate(command)) { - this.port.postMessage(command) - } else { - this.log('error', 'received unknown command', command) - } - } - - handleDonation (command: CommandSystemDonate): void { - this.log('info', `received donation: ${command.key}=${command.json_string}`) - } - - private log (level: 'info' | 'error', ...message: any[]): void { - const logger = level === 'info' ? console.log : console.error - logger(`[${this.constructor.name}]`, ...message) - } -}