-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
106 lines (92 loc) · 2.12 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
const { Tray, Menu, Notification } = require('electron');
const { app, BrowserWindow } = require('electron/main');
const path = require('node:path');
const quotes = require('./quotes');
let win;
let notificationTime = 3600000;
const gotTheLock = app.requestSingleInstanceLock();
if (!gotTheLock) {
app.quit();
} else {
app.on('second-instance', () => {
if (win) {
if (win.isMinimized()) win.restore();
win.focus();
}
});
}
function createWindow() {
win = new BrowserWindow({
width: 500,
height: 500,
icon: path.join(__dirname, 'logo.png'),
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
},
});
win.loadFile('index.html');
win.on('close', (event) => {
if (!app.isQuitting) {
event.preventDefault();
win.hide();
}
});
}
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
let tray = null;
app.whenReady().then(() => {
const iconPath = path.join(__dirname, 'logo.png');
tray = new Tray(iconPath);
const contextMenu = Menu.buildFromTemplate([
{
label: 'Open',
click: () => {
win.show();
},
},
{
label: 'Quit',
click: () => {
app.isQuitting = true;
app.quit();
},
},
]);
tray.setToolTip('Motivasiya');
tray.setContextMenu(contextMenu);
tray.on('click', () => {
win.isVisible() ? win.hide() : win.show();
});
tray.setContextMenu(contextMenu);
});
function showNotification() {
const message = getRandomMessage();
new Notification({
title: 'Xatırlatma',
body: message,
silent: false,
icon: path.join(__dirname, 'logo.png'),
timeoutType: 'never',
urgency: 'critical',
}).show();
}
app.whenReady().then(() => {
createWindow();
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
setTimeout(function run() {
showNotification();
setTimeout(run, notificationTime);
}, notificationTime);
});
function getRandomMessage() {
const randomIndex = Math.floor(Math.random() * quotes.length);
return quotes[randomIndex];
}