-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
73 lines (58 loc) · 1.5 KB
/
Copy pathmain.js
File metadata and controls
73 lines (58 loc) · 1.5 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
const { app, BrowserWindow, Tray, Menu } = require('electron')
const path = require('path')
let mainWindow, tray;
let isQuiting = false;
function createTray(iconPath) {
tray = new Tray(iconPath)
tray.setToolTip('Diet Analyzer')
tray.on('double-click', () => { mainWindow.show() })
const contextMenu = Menu.buildFromTemplate([
{
label: 'Quit', click: () => {
isQuiting = true
app.quit()
}
}
])
tray.setContextMenu(contextMenu)
}
function createWindow() {
const path = require('path');
const iconPath = path.join(__dirname, 'assets/food.jpg');
console.log(iconPath);
// Basic Methods
mainWindow = new BrowserWindow({
width: 1000, height: 800,
minWidth: 800, minHeight: 600,
webPreferences: { nodeIntegration: true },
icon: iconPath,
title: "Diet Analyzer"
})
mainWindow.loadFile('./dist/Diet-Analyzer/index.html')
mainWindow.on('closed', () => { mainWindow = null })
// Setting NULL MenuBar
mainWindow.setMenu(null);
// Creating Tray
createTray(iconPath)
// Configuring Options
mainWindow.on('minimize', (event) => {
event.preventDefault();
mainWindow.hide();
});
mainWindow.on('close', (event) => {
if (!isQuiting) {
event.preventDefault();
mainWindow.hide();
}
return false;
});
}
app.on('ready', () => {
createWindow()
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit()
})
app.on('activate', () => {
if (mainWindow === null) createWindow()
})