-
-
Notifications
You must be signed in to change notification settings - Fork 776
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
making preload plugin scripts work again
- Loading branch information
Showing
15 changed files
with
134 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
import { processApi } from '@seleniumhq/side-api' | ||
import { ApiHoist as Api } from '@seleniumhq/side-api' | ||
|
||
type FunctionKeys<T extends Record<string, {mutator?: Function}>> = { | ||
[K in keyof T as T[K]['mutator'] extends Function ? K : never]: T[K]['mutator']; | ||
}; | ||
|
||
/** | ||
* This Converts the chrome API type to something usable | ||
* from the front end | ||
*/ | ||
export type BrowserApiMutatorMapper = { | ||
[Namespace in keyof Api]: { | ||
[Handler in keyof Api[Namespace]]: Api[Namespace][Handler]['mutator'] | ||
} | ||
export type BrowserApiMutators = { | ||
[Namespace in keyof Api]: FunctionKeys<Api[Namespace]> | ||
} | ||
|
||
export default processApi<BrowserApiMutatorMapper>( | ||
export default processApi<BrowserApiMutators>( | ||
(_, handler) => handler.mutator | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,67 @@ | ||
import { contextBridge } from 'electron' | ||
import api from 'browser/api' | ||
import apiMutators from 'browser/api/mutator' | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
import { PluginPreloadOutputShape } from '@seleniumhq/side-api' | ||
import api, { Api, BrowserApiMutators } from 'browser/api' | ||
import mutators from 'browser/api/mutator' | ||
import { contextBridge, ipcRenderer } from 'electron' | ||
|
||
/** | ||
* Binds our API on initialization | ||
*/ | ||
process.once('loaded', async () => { | ||
/** | ||
* Expose it in the main context | ||
*/ | ||
contextBridge.exposeInMainWorld('sideAPI', { ...api, mutators: apiMutators }) | ||
}) | ||
export default ( | ||
apiSubset: Partial<Api> & { mutators: Partial<BrowserApiMutators> } = { | ||
...api, | ||
mutators, | ||
} | ||
) => | ||
new Promise<(PluginPreloadOutputShape | null)[]>((resolve) => { | ||
const loadPluginFromPath = ([pluginPath, preloadPath]: [ | ||
string, | ||
string | ||
]): PluginPreloadOutputShape | null => { | ||
try { | ||
const pluginPreload = __non_webpack_require__(preloadPath) | ||
const pluginHandler = | ||
typeof pluginPreload === 'function' | ||
? pluginPreload | ||
: pluginPreload.default | ||
return pluginHandler((...args: any[]) => | ||
ipcRenderer.send(`message-${pluginPath}`, ...args) | ||
) | ||
} catch (e) { | ||
console.error(e) | ||
return null | ||
} | ||
} | ||
|
||
window.sideAPI = apiSubset as Api & { mutators: BrowserApiMutators } | ||
|
||
/** | ||
* Binds our API on initialization | ||
*/ | ||
process.once('loaded', async () => { | ||
/** | ||
* Expose it in the main context | ||
*/ | ||
contextBridge.exposeInMainWorld('sideAPI', window.sideAPI) | ||
const pluginPaths = await api.plugins.list() | ||
const preloadPaths = await api.plugins.listPreloadPaths() | ||
const richPlugins: [string, string][] = pluginPaths.map((p, i) => [ | ||
p, | ||
preloadPaths[i], | ||
]) | ||
const plugins = richPlugins.map(loadPluginFromPath) | ||
resolve(plugins) | ||
}) | ||
}) |
4 changes: 3 additions & 1 deletion
4
packages/selenium-ide/src/browser/windows/Chromedriver/preload.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
import '../../helpers/preload' | ||
import preload from '../../helpers/preload' | ||
|
||
preload() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
import '../../helpers/preload' | ||
import preload from '../../helpers/preload' | ||
|
||
preload() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
packages/selenium-ide/src/browser/windows/ProjectEditor/preload.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
import '../../helpers/preload' | ||
import preload from '../../helpers/preload' | ||
|
||
preload() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
import '../../helpers/preload' | ||
import preload from '../../helpers/preload' | ||
|
||
preload() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@seleniumhq/side-api", | ||
"version": "4.0.0-alpha.33", | ||
"version": "4.0.0-alpha.34", | ||
"private": false, | ||
"description": "Selenium IDE API command shapes and such", | ||
"author": "Todd Tarsi <[email protected]>", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,8 @@ | ||
import { EditorStateShape } from '../../models/state' | ||
import { Mutator } from '../../types/base' | ||
|
||
/** | ||
* Removes selected command indexes. Called when test editor closes. | ||
*/ | ||
export type Shape = () => Promise<void> | ||
export type EditorUpdates = Pick<EditorStateShape, 'selectedCommandIndexes'> | ||
export type StateUpdates = { editor: EditorUpdates } | ||
|
||
export const mutator: Mutator = (session) => session |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,8 @@ | ||
import { EditorStateShape } from '../../models/state' | ||
import { Mutator } from '../../types/base' | ||
|
||
export type Shape = () => Promise<void> | ||
/** | ||
* Called whenever test editor opens. Assigns command indexes | ||
*/ | ||
export type EditorUpdates = Pick<EditorStateShape, 'selectedCommandIndexes'> | ||
export type StateUpdates = { editor: EditorUpdates } | ||
|
||
export const mutator: Mutator = (session) => session |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.