Skip to content

Commit

Permalink
chore: address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
kyungeunni committed Feb 8, 2023
1 parent c248f7e commit 9d70d94
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 26 deletions.
6 changes: 4 additions & 2 deletions common/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,17 @@ export type GenerateCodeOptions = {
actions: Steps;
isProject: boolean;
};

export type ActionGeneratedCallback = (event: IpcRendererEvent, actions: ActionContext[]) => void;
export interface IElectronAPI {
exportScript: (string) => Promise<boolean>;
recordJourney: (url: string) => Promise<void>;
stopRecording: () => void;
pauseRecording: () => Promise<void>;
resumeRecording: () => Promise<void>;
onActionGenerated: (
addActionGeneratedListener(
callback: (event: IpcRendererEvent, actions: ActionContext[]) => void
) => () => void;
): () => void;
generateCode: (params: GenerateCodeOptions) => Promise<string>;
openExternalLink: (url: string) => Promise<void>;
runTest: (
Expand Down
2 changes: 1 addition & 1 deletion electron/api/recordJourney.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export async function recordJourney(

// Listen to actions from Playwright recording session
const actionsHandler = (actions: ActionInContext[]) => {
browserWindow.webContents.send('change', actions);
browserWindow.webContents.send('actions-generated', actions);
};
actionListener.on('actions', actionsHandler);

Expand Down
29 changes: 9 additions & 20 deletions electron/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,8 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
import type {
ActionContext,
GenerateCodeOptions,
IElectronAPI,
RunJourneyOptions,
TestEvent,
} from '../common/types';
import { contextBridge, ipcRenderer, IpcRendererEvent } from 'electron';
import type { IElectronAPI } from '../common/types';
import { contextBridge, ipcRenderer } from 'electron';

const electronAPI: IElectronAPI = {
exportScript: async contents => {
Expand All @@ -46,25 +40,20 @@ const electronAPI: IElectronAPI = {
resumeRecording: async () => {
await ipcRenderer.invoke('set-mode', 'recording');
},
onActionGenerated: (
callback: (_event: IpcRendererEvent, actions: ActionContext[]) => void
): (() => void) => {
ipcRenderer.on('change', callback);
addActionGeneratedListener: listener => {
ipcRenderer.on('actions-generated', listener);
return () => {
ipcRenderer.removeAllListeners('change');
ipcRenderer.removeAllListeners('actions-generated');
};
},
generateCode: async (params: GenerateCodeOptions) => {
generateCode: async params => {
return ipcRenderer.invoke('actions-to-code', params);
},
openExternalLink: async (url: string) => {
openExternalLink: async url => {
await ipcRenderer.invoke('open-external-link', url);
},
runTest: async (
params: RunJourneyOptions,
callback: (_event: IpcRendererEvent, data: TestEvent) => void
) => {
ipcRenderer.on('test-event', callback);
runTest: async (params, listener) => {
ipcRenderer.on('test-event', listener);
await ipcRenderer.invoke('run-journey', params);
},
removeOnTestListener: () => {
Expand Down
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default function App() {
return generateMergedIR(prevSteps, nextSteps);
});
};
const removeListener = electronAPI.onActionGenerated(listener);
const removeListener = electronAPI.addActionGeneratedListener(listener);
return removeListener;
}, [electronAPI, setSteps]);

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/test/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const getCommunicationContextDefaults = (): ICommunicationContext => ({
stopRecording: jest.fn(),
pauseRecording: jest.fn(),
resumeRecording: jest.fn(),
onActionGenerated: jest.fn(),
addActionGeneratedListener: jest.fn(),
generateCode: jest.fn(),
openExternalLink: jest.fn(),
runTest: jest.fn(),
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/test/mockApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function getMockElectronApi(overrides?: Partial<IElectronAPI>): IElectron
stopRecording: jest.fn(),
pauseRecording: jest.fn(),
resumeRecording: jest.fn(),
onActionGenerated: jest.fn(),
addActionGeneratedListener: jest.fn(),
generateCode: jest.fn(),
openExternalLink: jest.fn(),
runTest: jest.fn(),
Expand Down

0 comments on commit 9d70d94

Please sign in to comment.