mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-06 03:49:56 +08:00
feat(client): add octobase-node to electron (#1672)
Co-authored-by: Himself65 <himself65@outlook.com>
This commit is contained in:
@@ -1,2 +0,0 @@
|
||||
yarnPath: .yarn/releases/yarn-3.4.1.cjs
|
||||
nodeLinker: node-modules
|
||||
@@ -9,10 +9,13 @@ See https://github.com/electron/forge/issues/2633
|
||||
|
||||
```
|
||||
# in project root, start web app at :8080
|
||||
pnpm dev
|
||||
yarn dev
|
||||
|
||||
# build octobase-node
|
||||
yarn workspace @affine/octobase-node build
|
||||
|
||||
# in /apps/electron, start electron app
|
||||
pnpm dev
|
||||
yarn dev
|
||||
```
|
||||
|
||||
## Credits
|
||||
|
||||
@@ -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));
|
||||
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
"make-macos-arm64": "electron-forge make --platform=darwin --arch=arm64",
|
||||
"make-macos-x64": "electron-forge make --platform=darwin --arch=x64",
|
||||
"make-windows-x64": "electron-forge make --platform=win32 --arch=x64",
|
||||
"build:octobase-node": "yarn workspace @affine/octobase-node build",
|
||||
"postinstall": "ELECTRON_RUN_AS_NODE=1 electron scripts/update-electron-vendors.mjs"
|
||||
},
|
||||
"config": {
|
||||
@@ -21,6 +22,7 @@
|
||||
},
|
||||
"main": "./dist/layers/main/index.js",
|
||||
"devDependencies": {
|
||||
"@affine/octobase-node": "workspace:*",
|
||||
"@electron-forge/cli": "^6.0.5",
|
||||
"@electron-forge/core": "^6.0.5",
|
||||
"@electron-forge/core-utils": "^6.0.5",
|
||||
@@ -37,6 +39,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"cross-env": "7.0.3",
|
||||
"electron-window-state": "^5.0.3"
|
||||
"electron-window-state": "^5.0.3",
|
||||
"fs-extra": "^11.1.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,18 +27,18 @@ console.log('build with following dir', {
|
||||
|
||||
// step 0: clean up
|
||||
await cleanup();
|
||||
console.log('Clean up done');
|
||||
echo('Clean up done');
|
||||
|
||||
// step 1: build web (nextjs) dist
|
||||
cd(repoRootDir);
|
||||
await $`pnpm i -r`;
|
||||
await $`pnpm build`;
|
||||
await $`pnpm export`;
|
||||
await $`yarn add`;
|
||||
await $`yarn build`;
|
||||
await $`yarn export`;
|
||||
await fs.move(affineWebOutDir, publicAffineOutDir, { overwrite: true });
|
||||
|
||||
// step 2: build electron resources
|
||||
await buildLayers();
|
||||
console.log('Build layers done');
|
||||
echo('Build layers done');
|
||||
|
||||
/// --------
|
||||
/// --------
|
||||
|
||||
Reference in New Issue
Block a user