forked from elkuku/electron-bootstrap-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderer.js
113 lines (91 loc) · 3.26 KB
/
renderer.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
$(function () {
const
{dialog} = require('electron').remote,
Conf = require('conf'),
config = new Conf(),
fs = require('fs'),
path = require('path'),
ejs = require('ejs'),
pjson = require('./package.json')
setup()
function setup() {
// Check if "Wheit" (Light) theme is selected
if ('Bläk' == config.get('theme')) {
$('head link#styleSheet').attr('href', 'css/example_dark.css');
}
$('.header.row.navi').html(loadTemplate('cmdBox', {}));
$('footer').prepend('<img src="img/logo.png" height="24px"/> ' + pjson.productName + ' ' + pjson.version + ' - ');
initContent()
// Setup buttons
var cmdBox = $('.cmdBoxNavi');
cmdBox.find('[data-toggle=config]').on('click', function () {
showConfig();
});
cmdBox.find('[data-toggle=reload]').on('click', function () {
//reload();
initContent(loadTemplate('alert', {type:'info', message:'Reload finished.'}));
});
cmdBox.find('[data-toggle=theme]').on('click', function () {
var e = $('head link#styleSheet');
if (e.attr('href').indexOf('dark') > 0) {
e.attr('href', 'css/example.css');
} else {
e.attr('href', 'css/example_dark.css');
}
});
}
/**
* Load a ejs template.
*
* @param name
* @param object
*
* @returns {String}
*/
function loadTemplate(name, object) {
var tpl = fs.readFileSync(__dirname + '/partials/' + name + '.ejs');
return ejs.render(tpl.toString(), object);
}
function initContent(message) {
$('#header').html('<h2><img src="img/logo.png" height="70px"/> ' + pjson.productName + ' <code>' + pjson.version + '</code></h2>');
$('#content').html(loadTemplate('alert', {type:'info', message:'Hey there…'}));
if (message) {
$('#console').html(message);
}
}
/**
* Show the configuration.
*/
function showConfig() {
$('#header').html('<h3><img src="img/logo.png" height="70px"/> Configuration</h3>');
$('#content').html(loadTemplate('config', {o:config}));
$('#console').html('');
$('#btnSaveConfig').on('click', function () {
saveConfig();
});
$('#cfgTheme').on('change', function () {
var e = $('head link#styleSheet');
if ('Bläk' == $(this).val()) {
e.attr('href', 'css/example_dark.css');
} else {
e.attr('href', 'css/example.css');
}
});
}
/**
* Save the configuration.
*/
function saveConfig() {
var examplePath = $('#cfgExample').val(),
theme = $('#cfgTheme').val(),
debug = $('#cfgDebug').is(':checked') ? true : false;
if (false == fs.existsSync(examplePath)) {
dialog.showErrorBox('Invalid Path', 'The example directory path is invalid');
return;
}
config.set('examplePath', examplePath);
config.set('debug', debug);
config.set('theme', theme);
initContent(loadTemplate('alert', {type:'info', message:'Config saved.'}));
}
});