-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
78 lines (68 loc) · 2.02 KB
/
app.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
const {app, BrowserWindow, ipcMain, Tray, Menu} = require('electron');
const request = require('request');
const path = require('path');
const Positioner = require('electron-positioner');
process.setMaxListeners(0);
let mainWindow;
// Quit when all windows are closed.
app.on('window-all-closed', () => {
if (process.platform != 'darwin')
app.quit();
});
// This method will be called when Electron has done everything
// initialization and ready for creating browser windows.
app.on('ready', () => {
// Create the browser window.
mainWindow = new BrowserWindow(
{
title: "Currency",
width: 115,
height: 410,
alwaysOnTop: true,
resizable: false,
movable: true,
frame: false,
icon: './public/icons/tray-ico.png',
}
);
//mainWindow.openDevTools();
let iconPath = path.join(__dirname, 'public/icons/tray-ico.png');
tray = new Tray(iconPath);
const contextMenu = Menu.buildFromTemplate([
{
label: 'Quit',
type: 'normal',
click: function() {
app.quit();
}
}
]);
tray.setToolTip('Welcome')
tray.setContextMenu(contextMenu)
// and load the index.html of the app.
mainWindow.loadURL('file://' + __dirname + '/views/index.html');
var data = '';
ipcMain.on('get-currency', (event,arg) => {
if (arg === true){
request('https://altin.doviz.com/api/v1/header', (error, response, body) => {
if (error){
event.sender.send('currency-reply', false);
}else{
if (arg === true){
data = JSON.parse(body).splice(0,3);
event.sender.send('currency-reply', data);
}
}
});
}
});
var positioner = new Positioner(mainWindow);
positioner.move('center')
// Emitted when the window is closed.
mainWindow.on('closed', () => {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null;
});
});