mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
@@ -6,10 +6,7 @@ import type {
|
||||
events as mainEvents,
|
||||
handlers as mainHandlers,
|
||||
} from '@affine/electron/main/exposed';
|
||||
import type {
|
||||
affine as exposedAffineGlobal,
|
||||
appInfo as exposedAppInfo,
|
||||
} from '@affine/electron/preload/electron-api';
|
||||
import type { appInfo as exposedAppInfo } from '@affine/electron/preload/electron-api';
|
||||
import type { sharedStorage as exposedSharedStorage } from '@affine/electron/preload/shared-storage';
|
||||
|
||||
type MainHandlers = typeof mainHandlers;
|
||||
@@ -37,9 +34,7 @@ export const appInfo = (globalThis as any).appInfo as
|
||||
| null;
|
||||
export const apis = (globalThis as any).apis as ClientHandler | null;
|
||||
export const events = (globalThis as any).events as ClientEvents | null;
|
||||
export const affine = (globalThis as any).affine as
|
||||
| typeof exposedAffineGlobal
|
||||
| null;
|
||||
|
||||
export const sharedStorage = (globalThis as any).sharedStorage as
|
||||
| typeof exposedSharedStorage
|
||||
| null;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { contextBridge } from 'electron';
|
||||
|
||||
import { affine, appInfo, getElectronAPIs } from './electron-api';
|
||||
import { appInfo, getElectronAPIs } from './electron-api';
|
||||
import { sharedStorage } from './shared-storage';
|
||||
|
||||
const { apis, events } = getElectronAPIs();
|
||||
@@ -9,9 +9,3 @@ contextBridge.exposeInMainWorld('appInfo', appInfo);
|
||||
contextBridge.exposeInMainWorld('apis', apis);
|
||||
contextBridge.exposeInMainWorld('events', events);
|
||||
contextBridge.exposeInMainWorld('sharedStorage', sharedStorage);
|
||||
|
||||
try {
|
||||
contextBridge.exposeInMainWorld('affine', affine);
|
||||
} catch (error) {
|
||||
console.error('Failed to expose affine APIs to window object!', error);
|
||||
}
|
||||
|
||||
@@ -11,42 +11,6 @@ import type {
|
||||
RendererToHelper,
|
||||
} from '../shared/type';
|
||||
|
||||
export const affine = {
|
||||
ipcRenderer: {
|
||||
send(channel: string, ...args: any[]) {
|
||||
ipcRenderer.send(channel, ...args);
|
||||
},
|
||||
|
||||
invoke(channel: string, ...args: any[]) {
|
||||
return ipcRenderer.invoke(channel, ...args);
|
||||
},
|
||||
|
||||
on(
|
||||
channel: string,
|
||||
listener: (event: Electron.IpcRendererEvent, ...args: any[]) => void
|
||||
) {
|
||||
ipcRenderer.on(channel, listener);
|
||||
return this;
|
||||
},
|
||||
|
||||
once(
|
||||
channel: string,
|
||||
listener: (event: Electron.IpcRendererEvent, ...args: any[]) => void
|
||||
) {
|
||||
ipcRenderer.once(channel, listener);
|
||||
return this;
|
||||
},
|
||||
|
||||
removeListener(
|
||||
channel: string,
|
||||
listener: (event: Electron.IpcRendererEvent, ...args: any[]) => void
|
||||
) {
|
||||
ipcRenderer.removeListener(channel, listener);
|
||||
return this;
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export function getElectronAPIs() {
|
||||
const mainAPIs = getMainAPIs();
|
||||
const helperAPIs = getHelperAPIs();
|
||||
|
||||
Reference in New Issue
Block a user