todoist-electron-app/src/main/main.ts
devaine 6c8ea122cd
feat: finally set up electron and vite together for build and live dev.
essentially vite and electron now can work together for live development
of an app without dealing with possible dimension issues or any of the
works
2026-10-28 18:16:43 -05:00

39 lines
931 B
TypeScript

import { app, BrowserWindow } from "electron"
import { fileURLToPath, format } from "node:url"
import path from "node:path"
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const distRendererPath = path.join(__dirname, "../../release/app/dist/renderer/")
//console.log(distRendererPath)
// Reference: https://www.electronjs.org/docs/latest/api/browser-window
const fileURL = format({
protocol: "file",
slashes: true,
pathname: path.join(distRendererPath, "index.html")
})
const mainWindowInit = () => {
const window = new BrowserWindow({
width: 1280,
height: 720
})
window.loadURL("http://localhost:5173").then(
// NOTE: On reject...
() => {
console.log("Using vite server...")
}),
// NOTE: On fulfill...
() => {
console.log("No vite server found!\nUsing dist files...")
window.loadURL(fileURL)
}
}
app.whenReady().then(() => {
mainWindowInit()
})