-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
146 lines (121 loc) · 3.46 KB
/
main.js
File metadata and controls
146 lines (121 loc) · 3.46 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
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
const electron = require('electron');
const url = require('url');
const path = require('path');
const storage = require('electron-json-storage');
const secretInfo = require('./secretInfo');
const backColor = "#e8eaf6";
//SET ENV
//process.env.NODE_ENV = 'production'; //DESCOMENTAR QUANDO FOR UTILIZAR
//Descontructors
const {app, BrowserWindow, Menu, Tray} = electron;
//Shared object, can be acessed from the console
const API = secretInfo.apiKey
global.sharedObj = {
//You can put your API KEY directly here
apiKey: secretInfo.apiKey
};
let iconPath = path.join(__dirname, '/assets/icons/png/leagueIconRecording.png');
let mainWindow;
let welcomeWindow;
let trayMenu = null; //Making so that trayMenu is not collected by the GC
//Listen for the app to be ready
app.on('ready', function(){
//Create new mainWindow
const {width, height} = electron.screen.getPrimaryDisplay().workAreaSize
let realWidth = width - 25;
let realHeight = height - 25;
mainWindow = new BrowserWindow({
width: realWidth,
height: realHeight,
dragable: true,
//transparent: true,
frame: false,
resizable: true
});
//Load the HTML file into window
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'liveMatch.html'),
procol: 'file:',
slashes: true
}));
//Set the color
mainWindow.setBackgroundColor(backColor);
//Hides the mainWindow while not loaded and/or not closed the welcomeWindow
mainWindow.hide();
// OVERLAY TESTING
/*
mainWindow.setAlwaysOnTop(true, "floating");
mainWindow.setVisibleOnAllWorkspaces(true);
mainWindow.setFullScreenable(false);*/
//Create the welcome page
let welcomeWidth = realWidth / 100 * 80;
welcomeWindow = new BrowserWindow({
width: welcomeWidth,
height: 500,
dragable: false,
transparent: true,
frame: false,
resizable: false
})
//Load the HTML file into window
welcomeWindow.loadURL(url.format({
pathname: path.join(__dirname, 'welcomeWindow.html'),
procol: 'file:',
slashes: true
}));
//Set the color
welcomeWindow.setBackgroundColor(backColor);
//When the welcomeWindow is closed, shows the mainWindow
welcomeWindow.on('close', () => mainWindow.show())
// Tray configuration \\
trayMenu = new Tray(iconPath);
trayMenu.setToolTip("LiveTracker")
//Tray menu
var trayContextMenu = Menu.buildFromTemplate([
{
label: 'LiveTracker Super Tray',
enabled: false
},
{
type: 'separator',
enabled: false
},
{
label: 'Show LiveTracker',
click: function(){
mainWindow.show();
}
},
{
label: 'Quit',
click: function(){
mainWindow.isQuiting = true;
mainWindow.close();
}
}
]);
trayMenu.setContextMenu(trayContextMenu)
trayMenu.on('click', function(event){
event.preventDefault();
mainWindow.show();
});
//When trying to minimize, hide to tray instead
mainWindow.on('minimize',function(event){
event.preventDefault();
mainWindow.hide();
});
//See if we need to close or to minimize when clicking in the exit button
storage.get('playerPreferences', function(error, data) {
if (error) throw error;
//If the player chose not to close when clicking to exit, hide the window
if (!data.finishAtExit){
mainWindow.on('close', function (event) {
if(!mainWindow.isQuiting){
event.preventDefault();
mainWindow.hide();
}
return false;
});
}
});
});