-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
62 lines (54 loc) · 1.69 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
const {
app,
BrowserWindow,
ipcMain,
Menu,
Dialog
} = require('electron')
const path = require('path')
const fs = require('fs')
process.env.NODE_ENV = 'development' //production or development
app.on('ready', () => {
// Initializing the database file
global.sharedLocation = {
userDataPath: app.getPath('userData')
}
const file = path.join(app.getPath('userData'), 'sjchess.db')
try {
if (!fs.existsSync(file)) {
const sqlite3 = require('sqlite3')
var db = new sqlite3.Database(file)
db.serialize(function() {
db.run('CREATE TABLE games( id INTEGER PRIMARY KEY AUTOINCREMENT, whitePlayerId INTEGER, blackPlayerId INTEGER, result INTERGER DEFAULT 0, date DATE, ts DATETIME DEFAULT CURRENT_TIMESTAMP)')
db.run('CREATE TABLE players( id INTEGER PRIMARY KEY AUTOINCREMENT, surname VARCHAR(128), name VARCHAR(128), sex CHAR, tournamentId INT)')
db.run('CREATE TABLE tournaments( id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR (128), date DATE, ts DATETIME DEFAULT CURRENT_TIMESTAMP , active BOOLEAN DEFAULT 1)')
})
}
} catch (err) {
console.error(err)
}
let mainWindow = new BrowserWindow({
frame: true,
height: 600,
width: 1000,
minWidth: 550,
minHeight: 450,
show: false,
icon: path.join(__dirname, 'build/icon.png'),
webPreferences: {
nodeIntegration: true
}
})
mainWindow.loadURL(path.join('file://', __dirname, '/src/index.html'))
mainWindow.once('ready-to-show', () => {
mainWindow.show()
})
if (process.env.NODE_ENV === 'production') {
mainWindow.setMenu(null)
} else {
mainWindow.openDevTools()
}
});
app.on('window-all-closed', () => {
app.quit()
})