-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.js
More file actions
102 lines (87 loc) · 2.7 KB
/
Copy pathmain.js
File metadata and controls
102 lines (87 loc) · 2.7 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
const { app, BrowserWindow, dialog, ipcMain } = require('electron');
const path = require('path');
const fs = require('fs');
let mainWindow;
function createWindow() {
mainWindow = new BrowserWindow({
width: 1200,
height: 800,
icon: path.join(__dirname, 'assets', 'icon.icns'),
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
});
mainWindow.loadFile('index.html');
// Debug için Developer Tools'u aç
//mainWindow.webContents.openDevTools();
}
app.whenReady().then(createWindow);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
// Klasör seçme dialog'u
ipcMain.handle('select-folder', async () => {
const result = await dialog.showOpenDialog(mainWindow, {
properties: ['openDirectory']
});
if (!result.canceled) {
const folderPath = result.filePaths[0];
const imageFiles = fs.readdirSync(folderPath)
.filter(file => /\.(jpg|jpeg|png|bmp|gif)$/i.test(file))
.map(file => path.join(folderPath, file));
return { folderPath, imageFiles };
}
return null;
});
// Export fonksiyonu - dosya kaydetme
ipcMain.handle('save-file', async (event, data, fileName, fileExtension) => {
const filters = [];
// Set up file filters based on extension
switch (fileExtension) {
case 'json':
filters.push({ name: 'JSON Files', extensions: ['json'] });
break;
case 'txt':
filters.push({ name: 'Text Files', extensions: ['txt'] });
break;
case 'xml':
filters.push({ name: 'XML Files', extensions: ['xml'] });
break;
case 'zip':
filters.push({ name: 'ZIP Files', extensions: ['zip'] });
break;
default:
filters.push({ name: 'All Files', extensions: ['*'] });
}
filters.push({ name: 'All Files', extensions: ['*'] });
const result = await dialog.showSaveDialog(mainWindow, {
defaultPath: fileName,
filters: filters
});
if (!result.canceled) {
try {
// Ensure the file has the correct extension
let filePath = result.filePath;
if (!filePath.endsWith(`.${fileExtension}`)) {
filePath += `.${fileExtension}`;
}
// Handle different data types
if (fileExtension === 'zip') {
// For ZIP files, data is a Uint8Array - convert to Buffer properly
const buffer = Buffer.from(data);
fs.writeFileSync(filePath, buffer);
} else {
// For text files (JSON, XML, TXT)
fs.writeFileSync(filePath, data, 'utf8');
}
return { success: true, path: filePath };
} catch (error) {
console.error('File save error:', error);
return { success: false, error: error.message };
}
}
return { success: false, canceled: true };
});