-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
main.js
83 lines (65 loc) · 2.24 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const electron = require('electron');
const path = require('path');
const { addRxPlugin } = require('rxdb');
const { getRxStorageMemory } = require('rxdb/plugins/storage-memory');
const { exposeIpcMainRxStorage } = require('rxdb/plugins/electron');
const { wrappedValidateAjvStorage } = require('rxdb/plugins/validate-ajv');
const { getDatabase } = require('./shared');
/**
* @link https://github.com/electron/electron/issues/19775#issuecomment-834649057
*/
process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true';
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
const windows = [];
function createWindow() {
const width = 600;
const height = 600;
const w = new BrowserWindow({
width,
height,
webPreferences: {
contextIsolation: false,
nodeIntegration: true,
preload: path.join(__dirname, 'preload.js')
}
});
w.loadFile('index.html');
const x = windows.length * width;
const y = 0;
w.setPosition(x, y);
windows.push(w);
// use this to debug by automatically opening the devtools.
// w.webContents.openDevTools();
}
app.on('ready', async function () {
const dbSuffix = new Date().getTime(); // we add a random timestamp in dev-mode to reset the database on each start
electron.ipcMain.handle('getDBSuffix', () => dbSuffix);
const storage = wrappedValidateAjvStorage({ storage: getRxStorageMemory() });
exposeIpcMainRxStorage({
key: 'main-storage',
storage,
ipcMain: electron.ipcMain
});
// const db = await getDatabase(
// 'heroesdb' + dbSuffix,
// storage
// );
// // show heroes table in console
// db.heroes.find().sort('name').$.subscribe(heroDocs => {
// console.log('### got heroes(' + heroDocs.length + '):');
// heroDocs.forEach(doc => console.log(
// doc.name + ' | ' + doc.color
// ));
// });
/**
* Here we create two windows, just to play around and test the cross-tab behavior.
* In your production app you likely only want one window.
*/
createWindow();
createWindow();
});
app.on('window-all-closed', function () {
if (process.platform !== 'darwin')
app.quit();
});