feat(client): add octobase-node to electron (#1672)

Co-authored-by: Himself65 <himself65@outlook.com>
This commit is contained in:
Peng Xiao
2023-03-27 14:59:36 +08:00
committed by GitHub
parent 449ffbc73f
commit c2b1a9b118
20 changed files with 1169 additions and 12 deletions
@@ -0,0 +1,21 @@
import * as os from 'node:os';
import path from 'node:path';
import { Storage } from '@affine/octobase-node';
import { ipcMain } from 'electron';
import fs from 'fs-extra';
const AFFINE_ROOT = path.join(os.homedir(), '.affine');
fs.ensureDirSync(AFFINE_ROOT);
// todo: rethink this
export const appState = {
storage: new Storage(path.join(AFFINE_ROOT, 'test.db')),
};
export const registerHandlers = () => {
ipcMain.handle('workspaceSync', async (_, id) => {
return appState.storage.sync(id, '');
});
};
+2
View File
@@ -2,6 +2,7 @@ import './security-restrictions';
import { app } from 'electron';
import { registerHandlers } from './app-state';
import { restoreOrCreateWindow } from './main-window';
import { registerProtocol } from './protocol';
@@ -41,6 +42,7 @@ app.on('activate', restoreOrCreateWindow);
app
.whenReady()
.then(registerProtocol)
.then(registerHandlers)
.then(restoreOrCreateWindow)
.catch(e => console.error('Failed create window:', e));
+9 -1
View File
@@ -2,7 +2,7 @@
* @module preload
*/
import { contextBridge } from 'electron';
import { contextBridge, ipcRenderer } from 'electron';
import { sha256sum } from './sha256sum';
@@ -31,3 +31,11 @@ contextBridge.exposeInMainWorld('yerba', { version: 0.1 });
* window.nodeCrypto('data')
*/
contextBridge.exposeInMainWorld('nodeCrypto', { sha256sum });
contextBridge.exposeInMainWorld('apis', {
workspaceSync: (id: string) => ipcRenderer.invoke('workspaceSync', id),
});
contextBridge.exposeInMainWorld('appInfo', {
electron: 1,
});