Repository navigation
Expand file tree
/
Copy pathmain.js
More file actions
145 lines (122 loc) · 3.96 KB
/
Copy pathmain.js
File metadata and controls
145 lines (122 loc) · 3.96 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
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
const { app, BrowserWindow, ipcMain, Tray, Menu, nativeImage } = require('electron');
const path = require('path');
app.disableHardwareAcceleration();
app.setAppUserModelId('com.klashain.omenfancontrol');
// Paketli ve gelistirme ortamlarinda ikon yollari
const windowIconPath = app.isPackaged
? path.join(process.resourcesPath, 'icons', 'icon.png')
: path.join(__dirname, 'build', 'icon.png');
const trayIconPath = app.isPackaged
? path.join(process.resourcesPath, 'icons', 'icon_32.png')
: path.join(__dirname, 'build', 'icon_32.png');
let tray = null;
let trayLang = 'tr';
let mainWindow = null;
function createWindow() {
mainWindow = new BrowserWindow({
width: 900,
height: 600, // Reduced height for compactness
backgroundColor: '#0D0D0D',
icon: windowIconPath,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
},
frame: false,
autoHideMenuBar: true
});
mainWindow.loadFile('index.html');
ipcMain.on('window-minimize', () => {
mainWindow.hide(); // Hide to system tray instead of minimize
});
ipcMain.on('window-close', () => {
mainWindow.close();
});
// Autostart via Task Scheduler (app runs elevated, Run-key autostart would fail)
const TASK_NAME = 'OMEN Fan Control Autostart';
ipcMain.on('get-autostart-status', (event) => {
exec(`schtasks /Query /TN "${TASK_NAME}"`, (err) => {
event.reply('autostart-status', !err);
});
});
ipcMain.on('set-autostart', (event, enable) => {
if (enable) {
const exePath = app.getPath('exe');
exec(`schtasks /Create /TN "${TASK_NAME}" /TR "\\"${exePath}\\"" /SC ONLOGON /RL HIGHEST /F`, () => {});
} else {
exec(`schtasks /Delete /TN "${TASK_NAME}" /F`, () => {});
}
});
// Renderer'dan gelen dil secimini tepside uygula
ipcMain.on('set-lang', (event, l) => {
trayLang = (l === 'en') ? 'en' : 'tr';
if (tray) {
const labels = trayLang === 'en'
? { show: 'Show (Open UI)', quit: 'Exit' }
: { show: 'Göster (Arayüzü Aç)', quit: 'Çıkış' };
tray.setContextMenu(Menu.buildFromTemplate([
{ label: labels.show, click: () => mainWindow.show() },
{ label: labels.quit, click: () => { app.isQuiting = true; app.quit(); } }
]));
}
});
}
const { spawn, exec } = require('child_process');
let backendProcess = null;
function startBackend() {
const isPackaged = app.isPackaged;
const backendPath = isPackaged
? path.join(process.resourcesPath, 'backend', 'tcp_server.exe')
: path.join(__dirname, 'backend', 'dist', 'tcp_server.exe');
// Kill any existing instances first
exec('taskkill /f /im tcp_server.exe', (err, stdout, stderr) => {
try {
backendProcess = spawn(backendPath, [], { detached: false, windowsHide: true });
backendProcess.on('error', (err) => {
console.error("Backend process failed to start:", err);
});
} catch (e) {
console.error(e);
}
});
}
app.on('will-quit', () => {
if (backendProcess) {
backendProcess.kill();
}
});
function createTray() {
const icon = nativeImage.createFromPath(trayIconPath);
tray = new Tray(icon);
const labels = trayLang === 'en'
? { show: 'Show (Open UI)', quit: 'Exit' }
: { show: 'Göster (Arayüzü Aç)', quit: 'Çıkış' };
const contextMenu = Menu.buildFromTemplate([
{ label: labels.show, click: () => mainWindow.show() },
{ label: labels.quit, click: () => {
app.isQuiting = true;
app.quit();
}
}
]);
tray.setToolTip('OMEN Fan Control');
tray.setContextMenu(contextMenu);
tray.on('click', () => {
if (mainWindow.isVisible()) {
mainWindow.hide();
} else {
mainWindow.show();
}
});
}
app.whenReady().then(() => {
startBackend();
createWindow();
createTray();
app.on('activate', function () {
if (BrowserWindow.getAllWindows().length === 0) createWindow();
});
});
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit();
});