-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
78 lines (71 loc) · 2.2 KB
/
app.js
File metadata and controls
78 lines (71 loc) · 2.2 KB
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
const {app, BrowserWindow} = require('electron')
const path = require('path')
const url = require('url')
const fs = require('fs')
const yaml = require('js-yaml');
let window = null
// Convenience Functions
function recFindByExt(base,ext,files,result)
{
files = files || fs.readdirSync(base)
result = result || []
files.forEach(
function (file) {
var newbase = path.join(base,file)
if ( fs.statSync(newbase).isDirectory() )
{
result = recFindByExt(newbase,ext,fs.readdirSync(newbase),result)
}
else
{
if ( file.substr(-1*(ext.length+1)) == '.' + ext )
{
result.push(newbase)
}
}
}
)
return result
}
// Code to update the files database
if (process.argv[2] == '--update-db')
{
const JsonDB = require('node-json-db/dist/JsonDB')
const DBConfig = require('node-json-db/dist/lib/JsonDBConfig')
var db = new JsonDB.JsonDB(new DBConfig.Config("database", true, true, ':'));
const files = recFindByExt('code/', 'yml');
files.forEach( item => {
let fileContents = fs.readFileSync(item, 'utf8');
let data = yaml.safeLoad(fileContents);
db.push(':'+item, {"path":item,"title":data.title, "description":data.description});
});
db.save();
app.exit();
}
// Wait until the app is ready
app.once('ready', () => {
// Create a new window
window = new BrowserWindow({
// Set the initial width to 800px
width: 800,
// Set the initial height to 600px
height: 600,
// Set the default background color of the window to match the CSS
// background color of the page, this prevents any white flickering
backgroundColor: "#D6D8DC",
frame: false,
title: "OpenFOAM Code Cheats",
// Don't show the window until it's ready, this prevents any white flickering
show: false
})
// Load a URL in the window to the local index.html path
window.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true
}))
// Show window when page is ready
window.once('ready-to-show', () => {
window.show()
})
})