-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
136 lines (120 loc) · 4.16 KB
/
Copy pathmain.js
File metadata and controls
136 lines (120 loc) · 4.16 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
const { app, BrowserWindow, ipcMain, dialog } = require('electron');
const path = require('path');
const nodeID3 = require('node-id3');
const fs = require('fs');
let mainWindow;
function createWindow() {
mainWindow = new BrowserWindow({
width: 1000,
height: 800,
minWidth: 1000,
minHeight: 800,
frame: false,
transparent: true,
resizable: true,
show: false,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
webSecurity: false,
devTools: true // Полностью отключаем инструменты разработчика
}
});
mainWindow.loadFile('index.html');
mainWindow.setMenu(null);
mainWindow.once('ready-to-show', () => {
mainWindow.show();
});
mainWindow.on('closed', () => {
mainWindow = null;
});
// Обработчики для кнопок управления окном
ipcMain.on('minimize-window', () => {
mainWindow.minimize();
});
ipcMain.on('maximize-window', () => {
if (mainWindow.isMaximized()) {
mainWindow.unmaximize();
} else {
mainWindow.maximize();
}
});
ipcMain.on('close-window', () => {
mainWindow.close();
});
// Обработчик для диалога выбора файлов
ipcMain.handle('show-open-dialog', async (event, options) => {
return await dialog.showOpenDialog(mainWindow, options);
});
// Обработчик для выбора папки
ipcMain.handle('show-directory-dialog', async () => {
const result = await dialog.showOpenDialog(mainWindow, {
properties: ['openDirectory']
});
return result;
});
// Обработчик для получения списка файлов из папки
ipcMain.handle('get-folder-files', async (event, folderPath) => {
try {
const files = [];
const readDir = (dir) => {
const items = fs.readdirSync(dir, { withFileTypes: true });
for (const item of items) {
const fullPath = path.join(dir, item.name);
if (item.isDirectory()) {
readDir(fullPath);
} else if (item.isFile() && item.name.toLowerCase().endsWith('.mp3')) {
files.push(fullPath);
}
}
};
readDir(folderPath);
return files;
} catch (error) {
console.error('Ошибка при чтении папки:', error);
return [];
}
});
ipcMain.handle('get-audio-metadata', async (event, filePath) => {
try {
const tags = nodeID3.read(filePath);
return {
title: tags.title || path.basename(filePath, path.extname(filePath)),
artist: tags.artist || 'Неизвестный исполнитель',
picture: tags.image ? {
data: tags.image.imageBuffer,
format: tags.image.mime
} : null
};
} catch (error) {
console.error('Ошибка при чтении метаданных:', error);
return {
title: path.basename(filePath, path.extname(filePath)),
artist: 'Неизвестный исполнитель',
picture: null
};
}
});
ipcMain.handle('get-file-stats', async (event, filePath) => {
try {
const stats = await fs.promises.stat(filePath);
return {
size: stats.size
};
} catch (error) {
console.error('Ошибка при получении статистики файла:', error);
throw error;
}
});
}
app.whenReady().then(createWindow);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});