-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
95 lines (93 loc) · 2.42 KB
/
main.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
const { app, BrowserWindow, ipcMain, Tray, Menu, nativeImage } = require('electron');
const path = require('path');
const fs = require('fs');
const { exec } = require("child_process")
var mainWindow = null
function createWindow() {
mainWindow = new BrowserWindow({
width: 400,
height: 680,
icon: path.join(__dirname, 'ico.png'),
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
nodeIntegration: true,
contextIsolation: false
},
autoHideMenuBar: true,
titleBarOverlay: "Freedom Guard"
});
mainWindow.loadFile('index.html');
}
let tray
app.whenReady().then(() => {
const icon = nativeImage.createFromPath('ico.png')
tray = new Tray(icon)
const contextMenu = Menu.buildFromTemplate([
{
label: 'Show Application',
type: 'normal',
click: () => {
mainWindow.show();
}
},
{
label: 'Hide Application',
type: 'normal',
click: () => {
mainWindow.hide();
}
},
{
label: 'Close Application',
type: 'normal',
click: () => {
mainWindow.close();
app.exit();
}
},
]);
tray.setContextMenu(contextMenu);
tray.setToolTip('Freedom Guard')
tray.setTitle('VPN (Warp, Vibe , Psiphon)')
})
app.on('ready', createWindow);
app.on('before-quit', () => {
exec("taskkill /IM " + "HiddifyCli.exe" + " /F");
exec('reg add "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /F');
exec("taskkill /IM " + "warp-plus.exe" + " /F");
if (process.platform !== 'darwin') {
app.quit();
}
});
app.setUserTasks([
{
program: process.execPath,
arguments: '--new-window',
iconPath: process.execPath,
iconIndex: 0,
title: 'New Window',
description: 'Create a new window'
}
])
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
ipcMain.handle('write-json', async (event, filePath, data) => {
return new Promise((resolve, reject) => {
fs.writeFile(filePath, JSON.stringify(data, null, 2), (err) => {
if (err) reject(err);
else resolve('File written successfully');
});
});
});
// Handle read JSON file
ipcMain.handle('read-json', async (event, filePath) => {
return new Promise((resolve, reject) => {
fs.readFile(filePath, 'utf-8', (err, data) => {
if (err) reject(err);
else resolve(JSON.parse(data));
});
});
});