73 lines
1.7 KiB
JavaScript
73 lines
1.7 KiB
JavaScript
const { app, BrowserWindow, dialog, ipcMain } = require('electron');
|
|
const path = require('path');
|
|
|
|
const { processFolder } = require('./services/folderProcessor');
|
|
const { processZip } = require('./services/zipProcessor');
|
|
const { loadConfig } = require('./services/configService');
|
|
|
|
let config;
|
|
|
|
function createWindow() {
|
|
const win = new BrowserWindow({
|
|
width: 900,
|
|
height: 640,
|
|
webPreferences: {
|
|
preload: path.join(__dirname, 'preload.js'),
|
|
contextIsolation: true,
|
|
nodeIntegration: false,
|
|
},
|
|
});
|
|
|
|
win.loadFile(path.join(__dirname, 'renderer', 'index.html'));
|
|
}
|
|
|
|
async function initConfig() {
|
|
config = await loadConfig();
|
|
}
|
|
|
|
app.whenReady().then(async () => {
|
|
await initConfig();
|
|
createWindow();
|
|
|
|
app.on('activate', () => {
|
|
if (BrowserWindow.getAllWindows().length === 0) {
|
|
createWindow();
|
|
}
|
|
});
|
|
});
|
|
|
|
app.on('window-all-closed', () => {
|
|
if (process.platform !== 'darwin') app.quit();
|
|
});
|
|
|
|
ipcMain.handle('select-folder', async () => {
|
|
const result = await dialog.showOpenDialog({
|
|
properties: ['openDirectory'],
|
|
});
|
|
|
|
if (result.canceled || !result.filePaths[0]) {
|
|
return { canceled: true };
|
|
}
|
|
|
|
const routingResult = await processFolder(result.filePaths[0], config);
|
|
return { canceled: false, ...routingResult };
|
|
});
|
|
|
|
ipcMain.handle('select-zip', async () => {
|
|
const result = await dialog.showOpenDialog({
|
|
properties: ['openFile'],
|
|
filters: [{ name: 'Zip', extensions: ['zip'] }],
|
|
});
|
|
|
|
if (result.canceled || !result.filePaths[0]) {
|
|
return { canceled: true };
|
|
}
|
|
|
|
const routingResult = await processZip(result.filePaths[0], config);
|
|
return { canceled: false, ...routingResult };
|
|
});
|
|
|
|
ipcMain.handle('get-config-path', async () => ({
|
|
configPath: loadConfig.getConfigPath(),
|
|
}));
|