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

View File

@@ -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, '');
});
};

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));