diff --git a/packages/extension-host-worker/src/parts/CommandMap/CommandMap.ts b/packages/extension-host-worker/src/parts/CommandMap/CommandMap.ts index 0c37802..c41087e 100644 --- a/packages/extension-host-worker/src/parts/CommandMap/CommandMap.ts +++ b/packages/extension-host-worker/src/parts/CommandMap/CommandMap.ts @@ -30,6 +30,7 @@ import * as HandleBeforeUnload from '../HandleBeforeUnload/HandleBeforeUnload.ts import * as HandleMessagePort from '../HandleMessagePort/HandleMessagePort.ts' import * as IndexedDb from '../IndexedDb/IndexedDb.ts' import * as IndexedDbKeyValueStorage from '../IndexedDbKeyValueStorage/IndexedDbKeyValueStorage.ts' +import * as LaunchIframeWorker from '../LaunchIframeWorker/LaunchIframeWorker.ts' import * as LoadWebView from '../LoadWebView/LoadWebView.ts' import * as SaveState from '../SaveState/SaveState.ts' import * as SearchFileWithFetch from '../SearchFileWithFetch/SearchFileWithFetch.ts' @@ -38,6 +39,7 @@ import * as TextSearchFetch from '../TextSearchFetch/TextSearchFetch.ts' import * as TextSearchHtml from '../TextSearchHtml/TextSearchHtml.ts' export const commandMap = { + 'ExtensionHost.launchIframeWorker': LaunchIframeWorker.launchIframeWorker, 'ExtensionHostRename.executeprepareRenameProvider': ExtensionHostRename.executeprepareRenameProvider, 'ExtensionHostRename.executeRenameProvider': ExtensionHostRename.executeRenameProvider, 'IndexedDb.addHandle': IndexedDb.addHandle, diff --git a/packages/extension-host-worker/src/parts/GetConfiguredIframeWorkerUrl/GetConfiguredIframeWorkerUrl.ts b/packages/extension-host-worker/src/parts/GetConfiguredIframeWorkerUrl/GetConfiguredIframeWorkerUrl.ts new file mode 100644 index 0000000..2315d3c --- /dev/null +++ b/packages/extension-host-worker/src/parts/GetConfiguredIframeWorkerUrl/GetConfiguredIframeWorkerUrl.ts @@ -0,0 +1,15 @@ +import * as IframeWorkerUrl from '../IframeWorkerUrl/IframeWorkerUrl.ts' +import * as IsProduction from '../IsProduction/IsProduction.ts' +import * as Preferences from '../Preferences/Preferences.ts' + +export const getConfiguredIframeWorkerUrl = async () => { + let configuredWorkerUrl = (await Preferences.get('develop.iframeWorkerPath')) || '' + if (configuredWorkerUrl) { + configuredWorkerUrl = '/remote' + configuredWorkerUrl + } + configuredWorkerUrl = configuredWorkerUrl || IframeWorkerUrl.iframeWorkerUrl + if (IsProduction.isProduction) { + configuredWorkerUrl = IframeWorkerUrl.iframeWorkerUrl + } + return configuredWorkerUrl +} diff --git a/packages/extension-host-worker/src/parts/Id/Id.ts b/packages/extension-host-worker/src/parts/Id/Id.ts new file mode 100644 index 0000000..cbad7a3 --- /dev/null +++ b/packages/extension-host-worker/src/parts/Id/Id.ts @@ -0,0 +1,7 @@ +export const state = { + id: 0, +} + +export const create = () => { + return ++state.id +} diff --git a/packages/extension-host-worker/src/parts/IsProduction/IsProduction.ts b/packages/extension-host-worker/src/parts/IsProduction/IsProduction.ts new file mode 100644 index 0000000..a5f2670 --- /dev/null +++ b/packages/extension-host-worker/src/parts/IsProduction/IsProduction.ts @@ -0,0 +1 @@ +export const isProduction = false diff --git a/packages/extension-host-worker/src/parts/LaunchIframeWorker/LaunchIframeWorker.ts b/packages/extension-host-worker/src/parts/LaunchIframeWorker/LaunchIframeWorker.ts new file mode 100644 index 0000000..734785d --- /dev/null +++ b/packages/extension-host-worker/src/parts/LaunchIframeWorker/LaunchIframeWorker.ts @@ -0,0 +1,19 @@ +import * as GetConfiguredIframeWorkerUrl from '../GetConfiguredIframeWorkerUrl/GetConfiguredIframeWorkerUrl.ts' +import * as HandleIpc from '../HandleIpc/HandleIpc.ts' +import * as Id from '../Id/Id.ts' +import * as IpcParent from '../IpcParent/IpcParent.ts' +import * as IpcParentType from '../IpcParentType/IpcParentType.ts' + +export const launchIframeWorker = async () => { + const configuredWorkerUrl = GetConfiguredIframeWorkerUrl.getConfiguredIframeWorkerUrl() + const name = 'Iframe Worker' + const id = Id.create() + const ipc = await IpcParent.create({ + method: IpcParentType.ModuleWorkerAndWorkaroundForChromeDevtoolsBug, + name, + url: configuredWorkerUrl, + id, + }) + HandleIpc.handleIpc(ipc) + return ipc +} diff --git a/packages/extension-host-worker/src/parts/Preferences/Preferences.ts b/packages/extension-host-worker/src/parts/Preferences/Preferences.ts new file mode 100644 index 0000000..d7ac333 --- /dev/null +++ b/packages/extension-host-worker/src/parts/Preferences/Preferences.ts @@ -0,0 +1,5 @@ +import * as ParentRpc from '../Rpc/Rpc.ts' + +export const get = (key: string): Promise => { + return ParentRpc.invoke('Preferences.get', key) +}