feat: Migrate project to TypeScript by adding configuration, dependencies, and converting preload script.

This commit is contained in:
2025-12-12 15:16:01 +01:00
parent 87e5f5a72c
commit 8b83428803
8 changed files with 155 additions and 78 deletions
+64
View File
@@ -0,0 +1,64 @@
import { app, BrowserWindow, ipcMain, dialog } from 'electron';
import * as path from 'path';
import * as fs from 'fs';
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
});
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.
}
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];
}
});
ipcMain.handle('read-file', async (event, filePath: string) => {
try {
const content = fs.readFileSync(filePath, 'utf-8');
return content;
} catch (err) {
console.error("Error reading file", err);
throw err;
}
});