mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-11 20:08:37 +00:00
feat: optimize electron macos header style (#1774)
Co-authored-by: himself65 <himself65@outlook.com>
This commit is contained in:
16
apps/electron/layers/preload/preload.d.ts
vendored
Normal file
16
apps/electron/layers/preload/preload.d.ts
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
interface Window {
|
||||
/**
|
||||
* After analyzing the `exposeInMainWorld` calls,
|
||||
* `packages/preload/exposedInMainWorld.d.ts` file will be generated.
|
||||
* It contains all interfaces.
|
||||
* `packages/preload/exposedInMainWorld.d.ts` file is required for TS is `renderer`
|
||||
*
|
||||
* @see https://github.com/cawa-93/dts-for-context-bridge
|
||||
*/
|
||||
readonly apis: {
|
||||
workspaceSync: (id: string) => Promise<any>;
|
||||
onThemeChange: (theme: string) => Promise<any>;
|
||||
onSidebarVisibilityChange: (visible: boolean) => Promise<any>;
|
||||
};
|
||||
readonly appInfo: { electron: boolean; isMacOS: boolean };
|
||||
}
|
||||
@@ -4,10 +4,7 @@
|
||||
|
||||
import { contextBridge, ipcRenderer } from 'electron';
|
||||
|
||||
import { sha256sum } from './sha256sum';
|
||||
|
||||
// Expose version number to renderer
|
||||
contextBridge.exposeInMainWorld('yerba', { version: 0.1 });
|
||||
import { isMacOS } from '../../utils';
|
||||
|
||||
/**
|
||||
* The "Main World" is the JavaScript context that your main renderer code runs in.
|
||||
@@ -25,17 +22,17 @@ contextBridge.exposeInMainWorld('yerba', { version: 0.1 });
|
||||
* @see https://github.com/cawa-93/dts-for-context-bridge
|
||||
*/
|
||||
|
||||
/**
|
||||
* Safe expose node.js API
|
||||
* @example
|
||||
* window.nodeCrypto('data')
|
||||
*/
|
||||
contextBridge.exposeInMainWorld('nodeCrypto', { sha256sum });
|
||||
|
||||
contextBridge.exposeInMainWorld('apis', {
|
||||
workspaceSync: (id: string) => ipcRenderer.invoke('workspaceSync', id),
|
||||
workspaceSync: (id: string) => ipcRenderer.invoke('octo:workspace-sync', id),
|
||||
// ui
|
||||
onThemeChange: (theme: string) =>
|
||||
ipcRenderer.invoke('ui:theme-change', theme),
|
||||
|
||||
onSidebarVisibilityChange: (visible: boolean) =>
|
||||
ipcRenderer.invoke('ui:sidebar-visibility-change', visible),
|
||||
});
|
||||
|
||||
contextBridge.exposeInMainWorld('appInfo', {
|
||||
electron: 1,
|
||||
electron: true,
|
||||
isMacOS: isMacOS(),
|
||||
});
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
import type { BinaryLike } from 'crypto';
|
||||
import { createHash } from 'crypto';
|
||||
|
||||
export function sha256sum(data: BinaryLike) {
|
||||
return createHash('sha256').update(data).digest('hex');
|
||||
}
|
||||
Reference in New Issue
Block a user