Skip to content

Commit

Permalink
new functions, undo redo reload
Browse files Browse the repository at this point in the history
all have hotkeys, reload needs an icon button
  • Loading branch information
toddtarsi committed Apr 4, 2024
1 parent 0968f8c commit ae1f9ad
Show file tree
Hide file tree
Showing 23 changed files with 206 additions and 166 deletions.
2 changes: 1 addition & 1 deletion packages/selenium-ide/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "selenium-ide",
"version": "4.0.1-beta.4",
"version": "4.0.1-beta.5",
"private": false,
"description": "Selenium IDE electron app",
"author": "Todd <[email protected]>",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ import {
ExpandedMutationObserver,
} from 'browser/types'
import initFindSelect from './find-select'
import { RecordNewCommandInput, RecorderPreprocessor } from '@seleniumhq/side-api'
import {
RecordNewCommandInput,
RecorderPreprocessor,
} from '@seleniumhq/side-api'
import LocatorBuilders from './locator-builders'

export interface RecordingState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,20 @@
// specific language governing permissions and limitations
// under the License.

import { RecordNewCommandInput, RecorderPreprocessor } from '@seleniumhq/side-api'
import {
RecordNewCommandInput,
RecorderPreprocessor,
} from '@seleniumhq/side-api'
import initFindSelect from 'browser/windows/PlaybackWindow/preload/find-select'
import LocatorBuilders from 'browser/windows/PlaybackWindow/preload/locator-builders'
import { attach, detach } from 'browser/windows/PlaybackWindow/preload/prompt-injector'
import { handlers, observers } from 'browser/windows/PlaybackWindow/preload/record-handlers'
import {
attach,
detach,
} from 'browser/windows/PlaybackWindow/preload/prompt-injector'
import {
handlers,
observers,
} from 'browser/windows/PlaybackWindow/preload/record-handlers'
import {
EventHandler,
ExpandedMessageEvent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ export interface MiniProjectShape {
}

const SettingsWrapper: FC = () =>
useContext(context) === 'project' ? (
<ProjectSettings />
) : (
<SystemSettings />
)
useContext(context) === 'project' ? <ProjectSettings /> : <SystemSettings />

const ProjectTab: React.FC<Pick<SIDEMainProps, 'setTab' | 'tab'>> = () => (
<Box className="fill flex flex-col">
Expand Down
18 changes: 10 additions & 8 deletions packages/selenium-ide/src/main/api/classes/DriverEventListener.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { ipcMain, WebContents } from 'electron'
import { BaseListener, EventMutator, ListenerFn, VariadicArgs } from '@seleniumhq/side-api'
import {
BaseListener,
EventMutator,
ListenerFn,
VariadicArgs,
} from '@seleniumhq/side-api'
import { Session } from 'main/types'
import getCore from '../helpers/getCore'
import { COLOR_CYAN, vdebuglog } from 'main/util'

const apiDebugLog = vdebuglog('api', COLOR_CYAN)

const baseListener = <ARGS extends VariadicArgs>(
path: string,
Expand All @@ -14,19 +16,19 @@ const baseListener = <ARGS extends VariadicArgs>(
const listeners: any[] = []
return {
addListener(listener) {
apiDebugLog('Listener added', path)
session.system.loggers.api('Listener added', path)
listeners.push(listener)
},
async dispatchEvent(...args) {
apiDebugLog('Dispatch event', path, args)
session.system.loggers.api('Dispatch event', path, args)
if (mutator) {
const newState = mutator(getCore(session), args)
session.projects.project = newState.project
session.state.state = newState.state
session.api.state.onMutate.dispatchEvent(path, args)
}
const results = await Promise.all(listeners.map((fn) => fn(...args)))
return results;
return results
},
hasListener(listener) {
return listeners.includes(listener)
Expand All @@ -37,7 +39,7 @@ const baseListener = <ARGS extends VariadicArgs>(
if (index === -1) {
throw new Error(`Unable to remove listener for ${path} ${listener}`)
}
apiDebugLog('Listener removed', path)
session.system.loggers.api('Listener removed', path)
listeners.splice(index, 1)
},
}
Expand Down
17 changes: 4 additions & 13 deletions packages/selenium-ide/src/main/api/classes/DriverHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@ import {
Mutator,
} from '@seleniumhq/side-api'
import noop from 'lodash/fp/noop'
import { COLOR_CYAN, vdebuglog } from 'main/util'
import getCore from '../helpers/getCore'
import { Session, SessionControllerKeys } from '../../types'

const apiDebugLog = vdebuglog('api', COLOR_CYAN)

export type AsyncHandler<HANDLER extends ApiHandler> = (
...args: Parameters<HANDLER>
) => Promise<ReturnType<HANDLER>>
Expand Down Expand Up @@ -52,19 +48,14 @@ const Handler =
const handler = factory(path, session)
const doAPI = async (...params: Parameters<HANDLER>) => {
const result = await handler(...params)
if (mutator) {
const { project, state } = mutator(getCore(session), { params, result })
session.projects.project = project
session.state.state = state
session.api.state.onMutate.dispatchEvent(path, { params, result })
}
await session.state.mutate(mutator, params, result, path)
return result
}
ipcMain.handle(path, async (_event, ...args) => {
apiDebugLog('Received API Request', path, args)
session.system.loggers.api('Received API Request', path, args)
const result = await doAPI(...(args as Parameters<HANDLER>))
apiDebugLog('Resolved API Request', path, result)
return result;
session.system.loggers.api('Resolved API Request', path, result)
return result
})
return doAPI
}
Expand Down
29 changes: 7 additions & 22 deletions packages/selenium-ide/src/main/api/classes/DriverRawHandler.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { Mutator } from '@seleniumhq/side-api'
import { ipcMain } from 'electron'
import noop from 'lodash/fp/noop'
import { COLOR_CYAN, vdebuglog } from 'main/util'
import { AsyncHandler, HandlerFactory } from './Handler'
import getCore from '../helpers/getCore'
import { Session, SessionControllerKeys } from '../../types'

const apiDebugLog = vdebuglog('api', COLOR_CYAN)

export type ParametersExceptFirst<F> = F extends (
arg0: any,
...rest: infer R
Expand Down Expand Up @@ -50,28 +46,17 @@ const Handler =
const handler = factory(path, session)
const doAPI = async (...params: Parameters<HANDLER>) => {
const result = await handler(...params)
if (mutator) {
const serializableParams = params.slice(
1
) as ParametersExceptFirst<HANDLER>
const newState = mutator(getCore(session), {
params: serializableParams,
result,
})
session.projects.project = newState.project
session.state.state = newState.state
session.api.state.onMutate.dispatchEvent(path, {
params: serializableParams,
result,
})
}
const serializableParams = params.slice(
1
) as ParametersExceptFirst<HANDLER>
await session.state.mutate(mutator, serializableParams, result, path)
return result
}
ipcMain.handle(path, async (...args) => {
apiDebugLog('Received API Request', path, args.slice(1))
session.system.loggers.api('Received API Request', path, args.slice(1))
const result = await doAPI(...(args as Parameters<HANDLER>))
apiDebugLog('Resolved API Request', path, result)
return result;
session.system.loggers.api('Resolved API Request', path, result)
return result
})
return doAPI
}
Expand Down
11 changes: 4 additions & 7 deletions packages/selenium-ide/src/main/api/classes/EventListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ import {
} from '@seleniumhq/side-api'
import { Session } from 'main/types'
import getCore from '../helpers/getCore'
import { COLOR_CYAN, vdebuglog } from 'main/util'

const apiDebugLog = vdebuglog('api', COLOR_CYAN)

export type MainListener<
ARGS extends VariadicArgs,
Expand All @@ -26,11 +23,11 @@ const baseListener = <ARGS extends VariadicArgs, RESULT extends any>(
const listeners: any[] = []
return {
addListener(listener) {
apiDebugLog('Listener added', path)
session.system.loggers.api('Listener added', path)
listeners.push(listener)
},
async dispatchEvent(...args) {
apiDebugLog('Dispatch event', path, args)
session.system.loggers.api('Dispatch event', path, args)
if (mutator) {
session.api.state.onMutate.dispatchEvent(path, args)
const newState = mutator(getCore(session), args)
Expand All @@ -40,7 +37,7 @@ const baseListener = <ARGS extends VariadicArgs, RESULT extends any>(
return await Promise.all<RESULT>(listeners.map((fn) => fn(...args)))
},
async dispatchEventAsync(...args) {
apiDebugLog('Dispatch event async', path, args)
session.system.loggers.api('Dispatch event async', path, args)
if (mutator) {
session.api.state.onMutate.dispatchEvent(path, args)
const newState = mutator(getCore(session), args)
Expand All @@ -61,7 +58,7 @@ const baseListener = <ARGS extends VariadicArgs, RESULT extends any>(
if (index === -1) {
throw new Error(`Unable to remove listener for ${path} ${listener}`)
}
apiDebugLog('Listener removed', path)
session.system.loggers.api('Listener removed', path)
listeners.splice(index, 1)
},
}
Expand Down
21 changes: 7 additions & 14 deletions packages/selenium-ide/src/main/api/classes/Handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@ import {
Mutator,
} from '@seleniumhq/side-api'
import noop from 'lodash/fp/noop'
import { COLOR_CYAN, vdebuglog } from 'main/util'
import getCore from '../helpers/getCore'
import { Session, SessionControllerKeys } from '../../types'

const apiDebugLog = vdebuglog('api', COLOR_CYAN)

export type AsyncHandler<HANDLER extends ApiHandler> = (
...args: Parameters<HANDLER>
) => Promise<ReturnType<HANDLER>>
Expand All @@ -31,7 +27,9 @@ const defaultHandler = <HANDLER extends ApiHandler>(
// @ts-expect-error
return controller[method].bind(controller) as AsyncHandler<HANDLER>
}
apiDebugLog(`Missing method for path ${path}, using passthrough`)
session.system.loggers.api(
`Missing method for path ${path}, using passthrough`
)
return noop as unknown as AsyncHandler<HANDLER>
}

Expand All @@ -52,19 +50,14 @@ const Handler =
const handler = factory(path, session)
const doAPI = async (...params: Parameters<HANDLER>) => {
const result = await handler(...params)
if (mutator) {
const { project, state } = mutator(getCore(session), { params, result })
session.projects.project = project
session.state.state = state
session.api.state.onMutate.dispatchEvent(path, { params, result })
}
await session.state.mutate(mutator, params, result, path)
return result
}
ipcMain.handle(path, async (_event, ...args) => {
apiDebugLog('Received API Request', path, args)
session.system.loggers.api('Received API Request', path, args)
const result = await doAPI(...(args as Parameters<HANDLER>))
apiDebugLog('Resolved API Request', path, result)
return result;
session.system.loggers.api('Resolved API Request', path, result)
return result
})
return doAPI
}
Expand Down
29 changes: 7 additions & 22 deletions packages/selenium-ide/src/main/api/classes/RawHandler.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { Mutator } from '@seleniumhq/side-api'
import { ipcMain } from 'electron'
import noop from 'lodash/fp/noop'
import { COLOR_CYAN, vdebuglog } from 'main/util'
import { AsyncHandler, HandlerFactory } from './Handler'
import getCore from '../helpers/getCore'
import { Session, SessionControllerKeys } from '../../types'

const apiDebugLog = vdebuglog('api', COLOR_CYAN)

export type ParametersExceptFirst<F> = F extends (
arg0: any,
...rest: infer R
Expand Down Expand Up @@ -50,28 +46,17 @@ const Handler =
const handler = factory(path, session)
const doAPI = async (...params: Parameters<HANDLER>) => {
const result = await handler(...params)
if (mutator) {
const serializableParams = params.slice(
1
) as ParametersExceptFirst<HANDLER>
const newState = mutator(getCore(session), {
params: serializableParams,
result,
})
session.projects.project = newState.project
session.state.state = newState.state
session.api.state.onMutate.dispatchEvent(path, {
params: serializableParams,
result,
})
}
const serializableParams = params.slice(
1
) as ParametersExceptFirst<HANDLER>
await session.state.mutate(mutator, serializableParams, result, path)
return result
}
ipcMain.handle(path, async (...args) => {
apiDebugLog('Received API Request', path, args.slice(1))
session.system.loggers.api('Received API Request', path, args.slice(1))
const result = await doAPI(...(args as Parameters<HANDLER>))
apiDebugLog('Resolved API Request', path, result)
return result;
session.system.loggers.api('Resolved API Request', path, result)
return result
})
return doAPI
}
Expand Down
5 changes: 2 additions & 3 deletions packages/selenium-ide/src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ app.commandLine.appendSwitch('remote-debugging-port', '8315')
const log = configureLogging()
autoUpdater.logger = log


// Capture and show unhandled exceptions
process.on('unhandledRejection', function handleWarning(reason) {
console.log('[PROCESS] Unhandled Promise Rejection')
Expand Down Expand Up @@ -59,7 +58,7 @@ app.on('ready', async () => {
app.exit(0)
}
})

app.on('window-all-closed', async () => {
allWindowsClosed = true
if (process.platform === 'darwin') {
Expand All @@ -68,7 +67,7 @@ app.on('ready', async () => {
await session.system.quit()
}
})

app.on(
'certificate-error',
(event, _webContents, _url, _error, _certificate, callback) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export const commands: MenuComponent = (session: Session) => () =>
{
label: '&Edit',
submenu: [
...(editBasicsCommands(session)()),
...(testEditorCommands(session)()),
...editBasicsCommands(session)(),
...testEditorCommands(session)(),
],
},
{
Expand All @@ -50,4 +50,4 @@ export const commands: MenuComponent = (session: Session) => () =>
},
]

export default menuFactoryFromCommandFactory(commands)
export default menuFactoryFromCommandFactory(commands)
Loading

0 comments on commit ae1f9ad

Please sign in to comment.