2025-12-12 15:16:01 +01:00
|
|
|
import { app, BrowserWindow, ipcMain, dialog } from 'electron';
|
|
|
|
|
import * as path from 'path';
|
|
|
|
|
import * as fs from 'fs';
|
2025-12-12 14:05:16 +01:00
|
|
|
|
|
|
|
|
function createWindow() {
|
|
|
|
|
const win = new BrowserWindow({
|
|
|
|
|
width: 1000,
|
|
|
|
|
height: 800,
|
|
|
|
|
webPreferences: {
|
|
|
|
|
preload: path.join(__dirname, 'preload.js'),
|
|
|
|
|
nodeIntegration: false,
|
|
|
|
|
contextIsolation: true,
|
|
|
|
|
sandbox: true
|
|
|
|
|
},
|
|
|
|
|
// Modern dark theme background
|
|
|
|
|
backgroundColor: '#0f172a',
|
|
|
|
|
titleBarStyle: 'hiddenInset' // Looks cleaner on macOS, normal on others
|
|
|
|
|
});
|
|
|
|
|
|
2025-12-12 15:16:01 +01:00
|
|
|
win.loadFile(path.join(__dirname, '../index.html'));
|
|
|
|
|
// Note: index.html is in the root, dist/main.js is in dist/. So we need to go up one level.
|
2025-12-12 14:05:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app.whenReady().then(() => {
|
|
|
|
|
createWindow();
|
|
|
|
|
|
|
|
|
|
app.on('activate', () => {
|
|
|
|
|
if (BrowserWindow.getAllWindows().length === 0) {
|
|
|
|
|
createWindow();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.on('window-all-closed', () => {
|
|
|
|
|
if (process.platform !== 'darwin') {
|
|
|
|
|
app.quit();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ipcMain.handle('open-file-dialog', async () => {
|
|
|
|
|
const { canceled, filePaths } = await dialog.showOpenDialog({
|
|
|
|
|
properties: ['openFile'],
|
|
|
|
|
filters: [
|
|
|
|
|
{ name: 'Markdown', extensions: ['md', 'markdown', 'txt'] },
|
|
|
|
|
{ name: 'All Files', extensions: ['*'] }
|
|
|
|
|
]
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (canceled) {
|
|
|
|
|
return null;
|
|
|
|
|
} else {
|
|
|
|
|
return filePaths[0];
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2025-12-12 15:16:01 +01:00
|
|
|
ipcMain.handle('read-file', async (event, filePath: string) => {
|
2025-12-12 14:05:16 +01:00
|
|
|
try {
|
|
|
|
|
const content = fs.readFileSync(filePath, 'utf-8');
|
|
|
|
|
return content;
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error("Error reading file", err);
|
|
|
|
|
throw err;
|
|
|
|
|
}
|
|
|
|
|
});
|
2025-12-12 15:38:33 +01:00
|
|
|
|
|
|
|
|
const configPath = path.join(app.getPath('userData'), 'config.json');
|
|
|
|
|
|
|
|
|
|
ipcMain.handle('load-settings', async () => {
|
|
|
|
|
try {
|
|
|
|
|
if (fs.existsSync(configPath)) {
|
|
|
|
|
const data = fs.readFileSync(configPath, 'utf-8');
|
|
|
|
|
return JSON.parse(data);
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Failed to load settings:', error);
|
|
|
|
|
}
|
|
|
|
|
return {};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ipcMain.handle('save-settings', async (event, settings) => {
|
|
|
|
|
try {
|
|
|
|
|
fs.writeFileSync(configPath, JSON.stringify(settings, null, 2));
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Failed to save settings:', error);
|
|
|
|
|
}
|
|
|
|
|
});
|