mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 05:14:54 +00:00
feat(client): add octobase-node to electron (#1672)
Co-authored-by: Himself65 <himself65@outlook.com>
This commit is contained in:
21
apps/electron/layers/main/src/app-state/index.ts
Normal file
21
apps/electron/layers/main/src/app-state/index.ts
Normal 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, '');
|
||||
});
|
||||
};
|
||||
@@ -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));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user