-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.js
More file actions
100 lines (84 loc) · 2.35 KB
/
main.js
File metadata and controls
100 lines (84 loc) · 2.35 KB
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
const { app, BrowserWindow, ipcMain } = require("electron");
const { loadWhatsApp, sendNotification } = require("./src/window");
const { createTrayIconFor } = require("./src/tray");
const { clearServiceWorkers } = require("./src/session");
const path = require("path");
const AutoLaunch = require("auto-launch");
let mainWindowInstance;
let tray;
const isFirstInstance = app.requestSingleInstanceLock();
app.disableHardwareAcceleration();
if (!isFirstInstance) {
app.quit();
return;
}
app.on("second-instance", () => {
if (mainWindowInstance) {
if (mainWindowInstance.isMinimized()) {
mainWindowInstance.restore();
}
mainWindowInstance.show();
mainWindowInstance.focus();
}
});
const createAndLoadMainWindow = () => {
const shouldStartHidden = process.argv.includes("--hidden");
mainWindowInstance = loadWhatsApp({ show: !shouldStartHidden });
tray = createTrayIconFor(mainWindowInstance, app);
};
app.whenReady().then(() => {
createAndLoadMainWindow();
const yourAppName = "WhatsappDesktop";
const autoLauncher = new AutoLaunch({
name: yourAppName,
path: app.getPath("exe"),
isHidden: true,
});
autoLauncher.isEnabled().then((isEnabled) => {
if (!isEnabled) {
autoLauncher
.enable()
.then(() => {
console.log("Auto-launch enabled successfully.");
})
.catch((err) => {
console.error("Failed to enable auto-launch:", err);
});
}
});
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0 && !mainWindowInstance) {
createAndLoadMainWindow();
} else if (mainWindowInstance) {
if (mainWindowInstance.isMinimized()) {
mainWindowInstance.restore();
}
mainWindowInstance.show();
mainWindowInstance.focus();
}
});
});
app.on("before-quit", clearServiceWorkers);
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});
ipcMain.on(
"whatsapp-notification-from-renderer",
(event, { title, body, icon }) => {
sendNotification(title, body, icon);
}
);
ipcMain.on("update-badge-count", (event, count) => {
if (app.isReady() && app.setBadgeCount) {
app.setBadgeCount(count);
if (
process.platform === "darwin" &&
count > 0 &&
!mainWindowInstance.isFocused()
) {
app.dock.bounce("informational");
}
}
});