This repository has been archived by the owner on Jul 10, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
167 lines (120 loc) · 4.17 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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
const { app, BrowserWindow, ipcMain, Tray, Menu, Notification } = require('electron');
const path = require('path');
const fs = require('fs-extra');
const islam_bot = require('./src/Telegram/index.js');
let Path_Local = fs.existsSync(path.join(process.resourcesPath, '/index.js')) === true ? process.resourcesPath : __dirname
let Path_appDate = app.getPath("appData");
let mainWindow
let tray
let trayMenu
const createWindow = () => {
mainWindow = new BrowserWindow({
width: 550,
height: 340,
show: false,
center: true,
resizable: false, // قابل لتكبير والتصغير
frame: false, // ايطار البرنامج
title: 'islam_bot',
icon: path.join(Path_Local, '/build/icons/icon.png'),
webPreferences: {
preload: path.join(__dirname, 'preload.js')
}
});
mainWindow.loadFile('./src/index.html');
mainWindow.removeMenu()
mainWindow.once('ready-to-show', () => {
mainWindow.show();
});
mainWindow.on('minimize', (event) => {
event.preventDefault();
mainWindow.hide();
});
mainWindow.on("show", (event) => {
event.preventDefault();
});
mainWindow.on('closed', (event) => {
event.preventDefault();
if (fs.existsSync(path.join(Path_appDate, '/islam_bot/Settings.json'))) {
let Settings = fs.readJSONSync(path.join(Path_appDate, '/islam_bot/Settings.json'));
if (Settings.start === true) {
let data = Object.assign({}, Settings, { start: false })
fs.writeJSONSync(path.join(Path_appDate, '/islam_bot/Settings.json'), data, { spaces: '\t' })
}
}
tray = null
trayMenu = null
mainWindow = null
});
trayMenu = Menu.buildFromTemplate([
{
label: 'عرض التطبيق', click: function () {
mainWindow.show();
}
},
{
label: 'إغلاق', click: function () {
if (mainWindow !== null) {
mainWindow.close();
}
else if (mainWindow === null) createWindow()
app.isQuiting = true;
app.quit();
}
}
]);
tray = new Tray(path.join(Path_Local, '/build/icons/icon.png'));
tray.setContextMenu(trayMenu);
tray.setToolTip("islam_bot");
tray.on('click', () => {
mainWindow.isVisible() ? mainWindow.hide() : mainWindow.show()
});
}
app.whenReady().then(async () => {
createWindow();
if (process.argv.includes('--hidden')) {
mainWindow.hide()
}
if (fs.existsSync(path.join(Path_appDate, '/islam_bot/Settings.json'))) {
let Settings = fs.readJSONSync(path.join(Path_appDate, '/islam_bot/Settings.json'));
if (Settings.start === true && Settings.off_on === 'on') {
islam_bot(app.getPath("appData"), Path_Local, Notification);
}
}
setInterval(async () => {
if (fs.existsSync(path.join(Path_appDate, '/islam_bot/Settings.json'))) {
let Settings = fs.readJSONSync(path.join(Path_appDate, '/islam_bot/Settings.json'));
if (Settings.start === false && Settings.off_on === 'on') {
islam_bot(app.getPath("appData"), Path_Local, Notification);
let data = Object.assign({}, Settings, { start: true })
fs.writeJSONSync(path.join(Path_appDate, '/islam_bot/Settings.json'), data, { spaces: '\t' });
}
}
}, 1000);
});
app.on('ready', (e) => {
e.preventDefault();
app.setAppUserModelId("org.IslamBot.rn0x");
ipcMain.on('minimize', () => {
mainWindow.minimize()
});
ipcMain.on('close', () => {
mainWindow.close()
});
ipcMain.handle('Path_appDate', async () => {
return Path_appDate // Path Files
});
});
app.on('before-quit', function () {
tray.destroy();
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
});
app.setLoginItemSettings({
openAtLogin: true,
path: path.join(process.resourcesPath, '../islam_bot.exe'),
args: ['--hidden']
})