1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | document.addEventListener('DOMContentLoaded', () => {
|
10 |
|
11 |
|
12 |
|
13 | injectScripts();
|
14 | });
|
15 |
|
16 |
|
17 | import { ipcRenderer } from 'electron';
|
18 | import path from 'path';
|
19 | import fs from 'fs';
|
20 |
|
21 | const INJECT_JS_PATH = path.join(__dirname, '../../', 'inject/inject.js');
|
22 | const log = require('loglevel');
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 | function setNotificationCallback(createCallback, clickCallback) {
|
31 | const OldNotify = window.Notification;
|
32 | const newNotify = (title, opt) => {
|
33 | createCallback(title, opt);
|
34 | const instance = new OldNotify(title, opt);
|
35 | instance.addEventListener('click', clickCallback);
|
36 | return instance;
|
37 | };
|
38 | newNotify.requestPermission = OldNotify.requestPermission.bind(OldNotify);
|
39 | Object.defineProperty(newNotify, 'permission', {
|
40 | get: () => OldNotify.permission,
|
41 | });
|
42 |
|
43 | window.Notification = newNotify;
|
44 | }
|
45 |
|
46 | function injectScripts() {
|
47 | const needToInject = fs.existsSync(INJECT_JS_PATH);
|
48 | if (!needToInject) {
|
49 | return;
|
50 | }
|
51 |
|
52 |
|
53 | require(INJECT_JS_PATH);
|
54 | }
|
55 |
|
56 | function notifyNotificationCreate(title, opt) {
|
57 | ipcRenderer.send('notification', title, opt);
|
58 | }
|
59 | function notifyNotificationClick() {
|
60 | ipcRenderer.send('notification-click');
|
61 | }
|
62 |
|
63 | setNotificationCallback(notifyNotificationCreate, notifyNotificationClick);
|
64 |
|
65 | ipcRenderer.on('params', (event, message) => {
|
66 | const appArgs = JSON.parse(message);
|
67 | log.info('nativefier.json', appArgs);
|
68 | });
|
69 |
|
70 | ipcRenderer.on('debug', (event, message) => {
|
71 |
|
72 | log.info('debug:', message);
|
73 | });
|