mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-25 06:18:45 +08:00
refactor(electron): create electron api package (#5334)
This commit is contained in:
@@ -1,10 +1,17 @@
|
||||
import path from 'node:path';
|
||||
|
||||
import type { apis } from '@affine/electron-api';
|
||||
import { test } from '@affine-test/kit/electron';
|
||||
import { clickSideBarCurrentWorkspaceBanner } from '@affine-test/kit/utils/sidebar';
|
||||
import { expect } from '@playwright/test';
|
||||
import fs from 'fs-extra';
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
apis: typeof apis;
|
||||
}
|
||||
}
|
||||
|
||||
test('check workspace has a DB file', async ({ appInfo, workspace }) => {
|
||||
const w = await workspace.current();
|
||||
const dbPath = path.join(
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
"devDependencies": {
|
||||
"@affine-test/fixtures": "workspace:*",
|
||||
"@affine-test/kit": "workspace:*",
|
||||
"@affine/electron-api": "workspace:*",
|
||||
"@playwright/test": "^1.39.0",
|
||||
"@types/fs-extra": "^11.0.2",
|
||||
"fs-extra": "^11.1.1",
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
},
|
||||
{
|
||||
"path": "../../tests/fixtures"
|
||||
},
|
||||
{
|
||||
"path": "../../packages/frontend/electron-api"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"./e2e-enhance/*": "./e2e-enhance/*.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@affine/electron-api": "workspace:*",
|
||||
"@node-rs/argon2": "^1.5.2",
|
||||
"@playwright/test": "^1.39.0",
|
||||
"express": "^4.18.2",
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
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);
|
||||
return window.affine?.ipcRenderer.invoke(channel, ...args);
|
||||
},
|
||||
{ channel, args }
|
||||
);
|
||||
@@ -14,7 +21,7 @@ export function ipcRendererInvoke(page: Page, channel: string, ...args: any[]) {
|
||||
export function ipcRendererSend(page: Page, channel: string, ...args: any[]) {
|
||||
return page.evaluate(
|
||||
({ channel, args }) => {
|
||||
window.affine.ipcRenderer.send(channel, ...args);
|
||||
window.affine?.ipcRenderer.send(channel, ...args);
|
||||
},
|
||||
{ channel, args }
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user