chore(electron): remove unused ipc code (#7636)

fix AF-1120
This commit is contained in:
pengx17
2024-07-30 04:12:06 +00:00
parent 157cc97a65
commit 4a2d400087
5 changed files with 3 additions and 152 deletions

View File

@@ -1,38 +0,0 @@
import os from 'node:os';
import { test } from '@affine-test/kit/electron';
import { shouldCallIpcRendererHandler } from '@affine-test/kit/utils/ipc';
test.describe.skip('behavior test', () => {
if (os.platform() === 'darwin') {
test('system button should hidden correctly', async ({
page,
electronApp,
}) => {
{
const promise = shouldCallIpcRendererHandler(
electronApp,
'ui:handleSidebarVisibilityChange'
);
await page
.locator(
'[data-testid=app-sidebar-arrow-button-collapse][data-show=true]'
)
.click();
await promise;
}
{
const promise = shouldCallIpcRendererHandler(
electronApp,
'ui:handleSidebarVisibilityChange'
);
await page
.locator(
'[data-testid=app-sidebar-arrow-button-expand][data-show=true]'
)
.click();
await promise;
}
});
}
});

View File

@@ -1,64 +0,0 @@
// TODO(@pengx17): remove
import type { affine } from '@affine/electron-api';
// Credit: https://github.com/spaceagetv/electron-playwright-helpers/blob/main/src/ipc_helpers.ts
import type { Page } from '@playwright/test';
import type { ElectronApplication } from 'playwright';
declare global {
interface Window {
affine: typeof affine;
}
}
export function ipcRendererInvoke(page: Page, channel: string, ...args: any[]) {
return page.evaluate(
({ channel, args }) => {
return window.affine?.ipcRenderer.invoke(channel, ...args);
},
{ channel, args }
);
}
export function ipcRendererSend(page: Page, channel: string, ...args: any[]) {
return page.evaluate(
({ channel, args }) => {
window.affine?.ipcRenderer.send(channel, ...args);
},
{ channel, args }
);
}
type IpcMainWithHandlers = Electron.IpcMain & {
_invokeHandlers: Map<
string,
(e: Electron.IpcMainInvokeEvent, ...args: unknown[]) => Promise<unknown>
>;
};
export function shouldCallIpcRendererHandler(
electronApp: ElectronApplication,
channel: string
) {
return electronApp.evaluate(
async ({ ipcMain }, { channel }) => {
const ipcMainWH = ipcMain as IpcMainWithHandlers;
// this is all a bit of a hack, so let's test as we go
if (!ipcMainWH._invokeHandlers) {
throw new Error(`Cannot access ipcMain._invokeHandlers`);
}
const handler = ipcMainWH._invokeHandlers.get(channel);
if (!handler) {
throw new Error(`No ipcMain handler registered for '${channel}'`);
}
return new Promise<void>(resolve => {
ipcMainWH._invokeHandlers.set(channel, async (e, ...args) => {
ipcMainWH._invokeHandlers.set(channel, handler);
resolve();
return handler(e, ...args);
});
});
},
{ channel }
);
}