Skip to content

Commit

Permalink
feature: add function to launch iframe worker (#55)
Browse files Browse the repository at this point in the history
* feature: add function to launch iframe worker

* move code

* move code

* remove code

* move code

* use ts

* add get

* update preferences

* register command

* lint
  • Loading branch information
levivilet authored Dec 28, 2024
1 parent e9f2d5a commit ed2ce23
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
7 changes: 7 additions & 0 deletions packages/extension-host-worker/src/parts/Id/Id.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const state = {
id: 0,
}

export const create = () => {
return ++state.id
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const isProduction = false
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import * as ParentRpc from '../Rpc/Rpc.ts'

export const get = (key: string): Promise<string> => {
return ParentRpc.invoke('Preferences.get', key)
}

0 comments on commit ed2ce23

Please sign in to comment.