-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
105 lines (92 loc) · 2.46 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
const {app, Tray, Menu, shell, BrowserWindow} = require("electron");
const path = require("path");
const url = require("url");
const iconPath = path.join(__dirname, "icon.png");
const fs = require("fs");
const filePath = path.join(__dirname, "settings.txt");
let tray = null;
let win = null;
let pref = null;
let abt = null;
var closeOnX = false;
var mySettings = [];
function readFile()
{
mySettings = fs.readFileSync(filePath,"utf8");
mySettings = (mySettings).split(" ");
}
function getCloseOnXPref()
{
readFile();
if (mySettings[0]==="true")
{
closeOnX = true;
}
else {
closeOnX = false;
}
return;
}
app.on("ready", function(){
win = new BrowserWindow({width: 600, height: 475, resizable: false});
win.setMenu(null);
win.loadURL(url.format({
pathname: path.join(__dirname, "index.html"),
protocol: "file:",
slashes: true
}));
getCloseOnXPref();
win.on("minimize",function(event){
event.preventDefault();
win.hide();
});
win.on("close", function (event) {
if (closeOnX)
{
app.quit();
}
else {
if( !app.isQuiting){
event.preventDefault();
win.hide();
}
}
});
tray = new Tray(iconPath);
var contextMenu = Menu.buildFromTemplate([
{ label: "Coffin", click: function(){
win.show();
} },
{ label: "About", click: function(){
abt = new BrowserWindow({width: 500, height: 600, resizable: false});
abt.setMenu(null);
abt.loadURL(url.format({
pathname: path.join(__dirname, "about.html"),
protocol: "file:",
slashes: true
}));
} },
{
label: "Preferences", click: function(){
pref = new BrowserWindow({width: 400, height: 650, resizable: false});
pref.setMenu(null);
pref.loadURL(url.format({
pathname: path.join(__dirname, "preferences.html"),
protocol: "file:",
slashes: true
}));
}
},
{
label: "Report a bug...", click: function(){
shell.openExternal("https://github.com/Frankcarvajal/Coffin/issues/new");
}
},
{ label: "Quit", click: function(){
app.isQuiting = true;
app.quit();
} }
]);
tray.setToolTip("Coffin");
tray.setContextMenu(contextMenu);
});