1 | import renderer from '@platform/electron/lib/renderer';
|
2 | import dbRenderer from '@platform/fsdb.electron/lib/renderer';
|
3 | import * as React from 'react';
|
4 |
|
5 | import { log, t } from './common';
|
6 | import { Test } from './components/Test';
|
7 |
|
8 | const { app } = require('electron').remote;
|
9 | const DIR = app.getPath('userData');
|
10 | const FILE = 'test.db';
|
11 | const CONN = `nedb:${DIR}/${FILE}`;
|
12 |
|
13 | log.group('Database');
|
14 | log.info('path:', `${DIR}/${FILE}`);
|
15 | log.info('conn:', CONN);
|
16 | log.groupEnd();
|
17 |
|
18 | class Renderer extends React.PureComponent {
|
19 | public static contextType = renderer.Context;
|
20 | public context!: t.ILocalContext;
|
21 | public render() {
|
22 | return <Test db={this.context.db} />;
|
23 | }
|
24 | }
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | renderer
|
30 | .render(<Renderer />, 'root', {
|
31 | getContext: async e => {
|
32 | const { ipc } = e.context;
|
33 | const databases: t.DbFactory = dbRenderer.init({ ipc }).factory;
|
34 | const db = databases(CONN);
|
35 | return { db };
|
36 | },
|
37 | })
|
38 | .then(context => context.log.info('renderer loaded!'));
|