-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.js
More file actions
235 lines (206 loc) ยท 5.96 KB
/
main.js
File metadata and controls
235 lines (206 loc) ยท 5.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
const { app, BrowserWindow, Tray, Menu, ipcMain, nativeImage, dialog } = require('electron');
const path = require('path');
const fs = require('fs');
let mainWindow = null;
let tray = null;
// Auto-start on Windows boot
let autoLauncher = null;
try {
const AutoLaunch = require('auto-launch');
autoLauncher = new AutoLaunch({
name: 'MIC Processor Pro',
path: app.getPath('exe'),
});
} catch (e) {
console.log('Auto-launch not available in dev mode');
}
function createWindow() {
mainWindow = new BrowserWindow({
width: 1200,
height: 800,
minWidth: 900,
minHeight: 600,
frame: false,
transparent: false,
backgroundColor: '#0a0a0f',
icon: path.join(__dirname, 'assets', 'icon.png'),
webPreferences: {
nodeIntegration: true,
contextIsolation: false
},
show: false
});
// Load from Vite dev server or production build
if (process.env.NODE_ENV === 'development' || !app.isPackaged) {
mainWindow.loadURL('http://localhost:5173');
// mainWindow.webContents.openDevTools();
} else {
mainWindow.loadFile(path.join(__dirname, 'dist', 'index.html'));
}
// Show window when ready
mainWindow.once('ready-to-show', () => {
mainWindow.show();
});
// Minimize to tray instead of closing
mainWindow.on('close', (event) => {
if (!app.isQuitting) {
event.preventDefault();
mainWindow.hide();
}
});
// Handle minimize to tray
mainWindow.on('minimize', () => {
mainWindow.hide();
});
}
function createTray() {
// Create a simple colored icon
const icon = createDefaultIcon();
tray = new Tray(icon);
const contextMenu = Menu.buildFromTemplate([
{
label: '๐๏ธ Open MIC Processor Pro',
click: () => {
mainWindow.show();
mainWindow.focus();
}
},
{ type: 'separator' },
{
label: '๐ Audio Active',
enabled: false
},
{ type: 'separator' },
{
label: 'โ๏ธ Start with Windows',
type: 'checkbox',
checked: false,
click: async (menuItem) => {
if (autoLauncher) {
if (menuItem.checked) {
await autoLauncher.enable();
} else {
await autoLauncher.disable();
}
}
}
},
{ type: 'separator' },
{
label: 'โ Quit',
click: () => {
app.isQuitting = true;
app.quit();
}
}
]);
// Check current autostart status
if (autoLauncher) {
autoLauncher.isEnabled().then((isEnabled) => {
contextMenu.items[4].checked = isEnabled;
}).catch(() => { });
}
tray.setToolTip('MIC Processor Pro');
tray.setContextMenu(contextMenu);
// Double-click to show window
tray.on('double-click', () => {
mainWindow.show();
mainWindow.focus();
});
}
function createDefaultIcon() {
// Create a 16x16 purple icon
const size = 16;
const buffer = Buffer.alloc(size * size * 4);
for (let y = 0; y < size; y++) {
for (let x = 0; x < size; x++) {
const i = (y * size + x) * 4;
// Create a circular purple icon
const cx = size / 2, cy = size / 2;
const dist = Math.sqrt((x - cx) ** 2 + (y - cy) ** 2);
if (dist < size / 2 - 1) {
buffer[i] = 99; // R
buffer[i + 1] = 102; // G
buffer[i + 2] = 241; // B
buffer[i + 3] = 255; // A
} else {
buffer[i + 3] = 0; // Transparent
}
}
}
return nativeImage.createFromBuffer(buffer, { width: size, height: size });
}
// IPC handlers for window controls
ipcMain.on('minimize-window', () => {
if (mainWindow) mainWindow.minimize();
});
ipcMain.on('maximize-window', () => {
if (mainWindow) {
if (mainWindow.isMaximized()) {
mainWindow.unmaximize();
} else {
mainWindow.maximize();
}
}
});
ipcMain.on('close-window', () => {
if (mainWindow) mainWindow.hide();
});
// Device change notification (Plug and Play)
ipcMain.on('devices-changed', (event, devices) => {
if (tray && devices.currentInput) {
tray.setToolTip(`MIC Processor Pro\n๐ค ${devices.currentInput}`);
}
});
// VST folder selection
ipcMain.handle('select-vst-folder', async () => {
const result = await dialog.showOpenDialog(mainWindow, {
title: 'Select VST Plugins Folder',
properties: ['openDirectory'],
defaultPath: 'C:\\Program Files\\VSTPlugins'
});
if (result.canceled || result.filePaths.length === 0) {
return null;
}
const folder = result.filePaths[0];
// Scan for VST plugins
let plugins = [];
try {
const files = fs.readdirSync(folder);
plugins = files.filter(file =>
file.endsWith('.vst3') ||
file.endsWith('.dll') ||
file.endsWith('.vst')
);
} catch (err) {
console.error('Error scanning VST folder:', err);
}
return { folder, plugins };
});
app.whenReady().then(() => {
createWindow();
createTray();
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
// Prevent multiple instances
const gotTheLock = app.requestSingleInstanceLock();
if (!gotTheLock) {
app.quit();
} else {
app.on('second-instance', () => {
if (mainWindow) {
if (mainWindow.isMinimized()) mainWindow.restore();
mainWindow.show();
mainWindow.focus();
}
});
}