-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
69 lines (58 loc) · 1.87 KB
/
index.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
const {app, Notification, session} = require('electron')
const path = require('path')
const {createWindow} = require('./src/window')
const {createTray} = require('./src/tray')
const lock = app.requestSingleInstanceLock()
let windowSingleton
//console.log(process.versions);
const dnt = "1";
const secChUa = "Chromium\";v=\"92\", \" Not A;Brand\";v=\"99\", \"Google Chrome\";v=\"92\"";
const secChUaMobile = "?0";
const upgradeInsecureRequests = "1";
const overrideHeaders = () => {
session.defaultSession.webRequest.onBeforeSendHeaders((details, callback) => {
details.requestHeaders['DNT'] = dnt;
details.requestHeaders['sec-ch-ua'] = secChUa;
details.requestHeaders['sec-ch-ua-mobile'] = secChUaMobile;
details.requestHeaders['Upgrade-Insecure-Requests'] = upgradeInsecureRequests;
callback({cancel: false, requestHeaders: details.requestHeaders});
});
}
const start = () => {
createWindow().then((window)=>{
overrideHeaders()
if(!lock){
showNotification()
}
windowSingleton = window
createTray(window,app)
preventDestroy(window)
})
}
const showNotification = () => {
let icon = path.join(__dirname, './resources/icon48.png')
let title = "WhatApp"
let body = "Couldn't achieve SingleInstanceLock,\n" +
"so there may be more than one instance created!\n" +
"In that case, you have to close them manually"
const notification={
title,
body,
icon
}
new Notification(notification).show()
}
const preventDestroy = (window) => {
window.on('close', function (event) {
event.preventDefault()
window.hide()
return false
})
}
app.on('ready', start)
app.on('second-instance', () => {
if(windowSingleton){
windowSingleton.focus()
}
})
app.on('window-all-closed', () => app.quit())