-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
230 lines (195 loc) · 4.87 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/* INIT VARS */
const electron = require('electron')
const {
app,
ipcMain,
ipcRenderer,
BrowserWindow,
Tray,
Menu
} = require('electron')
var path = require('path')
let mainWindow
app.requestSingleInstanceLock()
app.on('second-instance', function(event, commandLine, workingDirectory) {
app.quit()
});
/* INIT PROGRAM*/
loadApp();
//DISPLAY WIDTH HEIGHT
let isQuiting = false;
var width = 0;
var height = 0;
/* FUNCTIONS */
function loadApp() {
app.on('ready', function() {
const {
widthX,
heightX
} = electron.screen.getPrimaryDisplay().workAreaSize;
width = widthX;
height = heightX;
if (width < defaultwidth) {
defaultwidth = width;
defaultheight = Math.trunc(defaultwidth / perception);
}
console.log(defaultwidth);
console.log(defaultheight);
createCallbacks();
setupTray();
createWindow();
})
app.on('uncaughtException', function(error) {
alert(error)
});
app.on('activate', function() {
if (mainWindow === null) {
createCallbacks();
setupTray();
createWindow()
}
})
app.on('window-all-closed', function(event) {
event.preventDefault();
app.exit();
})
}
console.log(path.join(__dirname, ''));
var temp_maximized = false;
function createCallbacks() {
console.log("Create Callbacks");
ipcMain.on('update-notify-value', function(event, arg) {
const notifier = require('node-notifier');
notifier.notify({
icon: path.join(__dirname, 'icon.png'),
title: 'Arionum Wallet',
message: arg,
appID: ""
});
});
ipcMain.on('changeWindowState', function(event, arg) {
temp_maximized ? mainWindow.unmaximize() : mainWindow.maximize()
temp_maximized = !temp_maximized;
});
}
var tray;
function setupTray() {
try {
const path = require('path');
const imgPath = path.join(__dirname, 'icon.ico')
console.log("Create Tray");
tray = new Tray(imgPath);
tray.on('double-click', (event, bounds) => {
mainWindow.show();
});
tray.on('click', (event, bounds) => {
mainWindow.show();
});
var contextMenu = Menu.buildFromTemplate([{
label: 'Show App',
click: function() {
loadSite();
tray.setToolTip('Showing');
mainWindow.show();
}
},
{
label: 'Quit',
click: function() {
app.isQuiting = true;
app.quit();
}
}
]);
tray.setContextMenu(contextMenu)
tray.setTooltip('Error getting market price.');
} catch (e) {
} finally {
}
}
function createWindow() {
mainWindow = new BrowserWindow({
webPreferences: {
webSecurity: false
},
height: 748,
width: 468,
transparent: true,
frame: false,
icon: path.join(__dirname, 'assets/icons/64x64.png')
});
mainWindow.on('show', function() {
try {
tray.setHighlightMode('always');
tray.setToolTip('Getting market price...');
} catch (e) {
app.isQuiting = true;
}
})
mainWindow.on('minimize', function(event) {
event.preventDefault();
mainWindow.hide();
});
mainWindow.on('close', function(event) {
if (!app.isQuiting) {
event.preventDefault();
mainWindow.minimize();
}
return false;
})
registerWindowEvents();
loadSite();
}
var defaultwidth = 1318;
var defaultheight = 790;
var perception = defaultwidth / defaultheight;
function loadSite() {
if (checkData("publickey") == "") {
mainWindow.loadFile('login.html');
mainWindow.center();
} else {
mainWindow.setResizable(true);
mainWindow.setSize(defaultwidth, defaultheight, true);
mainWindow.center();
mainWindow.loadFile('index.html');
mainWindow.setResizable(false);
}
}
function registerWindowEvents() {
mainWindow.onbeforeunload = (e) => {
e.returnValue = true;
};
mainWindow.webContents.on('will-navigate', function(event, newUrl) {
var new_site = newUrl.split("/")[newUrl.split("/").length - 1] + "";
new_site = new_site.replace(".html", "");
if (new_site == "index") {
//mainWindow.setResizable( true );
mainWindow.setResizable(true);
mainWindow.setSize(defaultwidth, defaultheight, true);
mainWindow.center();
mainWindow.setResizable(false);
}
if (new_site == "login") {
mainWindow.setResizable(true);
mainWindow.setSize(468, 748, true);
mainWindow.center();
mainWindow.setResizable(false);
}
});
}
function checkData(key) {
const electron = require('electron');
const fs = require('fs');
const userDataPath = (electron.app || electron.remote.app).getPath('userData');
var paths = path.join(userDataPath, "arionum-config" + '.json');
var data = parseDataFile(paths, key);
return data;
}
function parseDataFile(filePath, key) {
try {
const fs = require('fs');
return JSON.parse(fs.readFileSync(filePath))[key];
} catch (error) {
return "";
}
}