-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathrenderer.js
92 lines (79 loc) · 3.18 KB
/
renderer.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
// This file is required by the index.html file and will
// be executed in the renderer process for that window.
// No Node.js APIs are available in this process because
// `nodeIntegration` is turned off. Use `preload.js` to
// selectively enable features needed in the rendering
// process.
// A little helper tool to wrap your functions if you want to build same app on web and electron.
// Use this function to use electron apis only when running inside electron.
// const isRunningInElectron = () => {
// const userAgent = navigator.userAgent.toLowerCase();
// return userAgent.indexOf(" electron/") > -1;
// };
const { ipcRenderer } = require ('electron')
const {
START_NOTIFICATION_SERVICE,
NOTIFICATION_SERVICE_STARTED,
NOTIFICATION_SERVICE_ERROR,
NOTIFICATION_RECEIVED,
TOKEN_UPDATED,
} = require ('electron-push-receiver/src/constants')
// Listen for service successfully started
ipcRenderer.on(NOTIFICATION_SERVICE_STARTED, (_, token) => {
console.log('service successfully started', token)
})
// Handle notification errors
ipcRenderer.on(NOTIFICATION_SERVICE_ERROR, (_, error) => {
console.log('notification error', error)
})
// Send FCM token to backend
ipcRenderer.on(TOKEN_UPDATED, (_, token) => {
console.log('token updated', token)
})
// Display notification
ipcRenderer.on(NOTIFICATION_RECEIVED, (_, serverNotificationPayload) => {
// check to see if payload contains a body string, if it doesn't consider it a silent push
if (serverNotificationPayload.notification.body){
// payload has a body, so show it to the user
console.log('display notification', serverNotificationPayload)
let myNotification = new Notification(serverNotificationPayload.notification.title, {
body: serverNotificationPayload.notification.body
})
myNotification.onclick = () => {
console.log('Notification clicked')
}
} else {
// payload has no body, so consider it silent (and just consider the data portion)
console.log('do something with the key/value pairs in the data', serverNotificationPayload.data)
}
})
// Start service
const senderId = '672237316015' // <-- replace with FCM sender ID from FCM web admin under Settings->Cloud Messaging
// console.log('starting service and registering a client')
ipcRenderer.send(START_NOTIFICATION_SERVICE, senderId)
window.addEventListener("DOMContentLoaded", () => {
const menuButton = document.getElementById("menu-btn");
const minimizeButton = document.getElementById("minimize-btn");
const maxUnmaxButton = document.getElementById("max-unmax-btn");
const closeButton = document.getElementById("close-btn");
menuButton.addEventListener("click", e => {
window.openMenu(e.x, e.y);
});
minimizeButton.addEventListener("click", e => {
window.minimizeWindow();
});
maxUnmaxButton.addEventListener("click", e => {
const icon = maxUnmaxButton.querySelector("i.far");
window.maxUnmaxWindow();
if (window.isWindowMaximized()) {
icon.classList.remove("fa-square");
icon.classList.add("fa-clone");
} else {
icon.classList.add("fa-square");
icon.classList.remove("fa-clone");
}
});
closeButton.addEventListener("click", e => {
window.closeWindow();
});
});