This repository has been archived by the owner on May 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
main.js
69 lines (59 loc) · 1.39 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
const fs = require('fs');
const path = require('path');
const os = require('os');
const electron = require('electron');
const { app } = electron;
const { BrowserWindow } = electron;
let parentPath = os.homedir();
if (process.env.NODE_ENV === 'development') {
parentPath = './';
}
const dbPath = path.join(parentPath, '.wanna/db');
const dbExists = () => {
if (fs.existsSync(dbPath)) {
return true;
}
return false;
};
const createDatabase = () => {
const wannaDirectoryPath = path.join(parentPath, '.wanna');
fs.mkdirSync(wannaDirectoryPath);
const prefill = JSON.stringify({
tasks: [],
ideas: [],
appProperties: {
showNotYetTasks: true,
fullscreen: false,
calendarSystem: 'en-US',
firstDayOfWeek: 1,
startupTab: 'tasks',
},
});
fs.writeFileSync(dbPath, prefill);
};
const isFullscreen = () => {
const data = fs.readFileSync(dbPath, 'utf-8');
return JSON.parse(data).appProperties.fullscreen;
};
let win;
function createWindow() {
if (dbExists() === false) {
createDatabase();
}
let width = 1024;
let height = 768;
if (isFullscreen()) {
({ width, height } = electron.screen.getPrimaryDisplay().size);
}
win = new BrowserWindow({
minWidth: 800,
minHeight: 600,
width,
height,
icon: `${__dirname}/icon.png`,
});
win.loadURL('http://localhost:3000');
}
app.on('ready', () => {
createWindow();
});