From a30f727c95d7aa01e4a05091601067367e3b795b Mon Sep 17 00:00:00 2001 From: Ethan Mick Date: Mon, 15 Sep 2025 12:33:08 -0400 Subject: initial commit --- src/main/index.ts | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main/preload.ts | 1 + 2 files changed, 64 insertions(+) create mode 100644 src/main/index.ts create mode 100644 src/main/preload.ts (limited to 'src/main') diff --git a/src/main/index.ts b/src/main/index.ts new file mode 100644 index 0000000..b164f15 --- /dev/null +++ b/src/main/index.ts @@ -0,0 +1,63 @@ +import Database from 'better-sqlite3' +import { app, BrowserWindow } from 'electron' +import fs from 'node:fs' +import path from 'node:path' + +const isDev = !app.isPackaged // reliable dev/prod switch. [oai_citation:2‡Electron](https://electronjs.org/docs/latest/api/app?utm_source=chatgpt.com) + +function createWindow() { + const win = new BrowserWindow({ + width: 800, + height: 600, + show: false, + webPreferences: { + contextIsolation: true, + nodeIntegration: false, + preload: path.join(__dirname, 'preload.js'), + }, + }) + + if (isDev) { + const url = process.env.VITE_DEV_SERVER_URL ?? 'http://localhost:5173' + win.loadURL(url).finally(() => { + win.show() + win.webContents.openDevTools({ mode: 'detach' }) + }) + } else { + const indexHtml = path.join( + app.getAppPath(), + 'renderer', + 'dist', + 'index.html' + ) + win.loadFile(indexHtml).finally(() => win.show()) + } +} + +function initDb() { + const dbDir = app.getPath('userData') + if (!fs.existsSync(dbDir)) fs.mkdirSync(dbDir, { recursive: true }) + const dbPath = path.join(dbDir, 'app.db') + + const db = new Database(dbPath) + db.pragma('journal_mode = WAL') + db.prepare('CREATE TABLE IF NOT EXISTS messages (text TEXT)').run() + db.prepare('INSERT INTO messages (text) VALUES (?)').run( + 'hello from better-sqlite3' + ) + const row = db.prepare('SELECT text FROM messages LIMIT 1').get() + console.log('Selected row:', row) + db.close() +} + +app.whenReady().then(() => { + initDb() + createWindow() + app.on( + 'activate', + () => BrowserWindow.getAllWindows().length === 0 && createWindow() + ) +}) +app.on('window-all-closed', () => { + if (process.platform !== 'darwin') app.quit() +}) diff --git a/src/main/preload.ts b/src/main/preload.ts new file mode 100644 index 0000000..0b39d91 --- /dev/null +++ b/src/main/preload.ts @@ -0,0 +1 @@ +// Expose nothing for now; keep the door open for future IPC-safe APIs. -- cgit v1.2.3