-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
85 lines (66 loc) · 1.93 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
const { app, BrowserWindow, ipcMain } = require('electron');
const url = require('url');
const path = require('path');
if (require('electron-squirrel-startup')) return app.quit();
let mainWindow;
function createWindow() {
mainWindow = new BrowserWindow({
width: 700,
height: 600,
maxWidth: 700,
maxHeight: 600,
minHeight: 500,
minWidth: 550,
webPreferences: {
contextIsolation: true, // protect against prototype pollution
enableRemoteModule: false, // turn off remote
preload: __dirname + '/preload.js',
devTools: true,
sandbox: true,
},
title: 'Digit',
icon: 'favicon.ico',
titleBarStyle: 'hidden',
titleBarOverlay: {
color: '#f5f5f5',
}
});
mainWindow.loadFile(
'./dist/index.html'
);
// Open the DevTools.
//mainWindow.webContents.openDevTools();
mainWindow.on('closed', function () {
mainWindow = null
});
}
//notification function
function timerNotify() {
const { Notification } = require('electron');
if (!Notification.isSupported()) {
console.log("Notifications are not supported in OS");
}
let newNotif = new Notification({ title: 'Break time!', body: 'Blink. Look. Walk.', timeoutType: 'never' });
newNotif.on('click', (event, arg) => {
mainWindow.maximize();
console.log("clicked");
});
newNotif.show();
}
if (process.platform === 'win32')
{
app.setAppUserModelId(app.name);
}
app.whenReady().then(() => {
createWindow();
app.on('activate', function () {
if (BrowserWindow.getAllWindows().length === 0) createWindow();
})
});
app.setAppUserModelId("digit.app");
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit();
});
ipcMain.on('onTimerNotify', (event, args) => {
timerNotify();
});