63 lines
1.9 KiB
TypeScript
63 lines
1.9 KiB
TypeScript
import { app, BrowserWindow, ipcMain } from "electron";
|
|
import { handleOpenFolder } from "./fileOperations";
|
|
import path from "node:path";
|
|
import started from "electron-squirrel-startup";
|
|
|
|
// Handle creating/removing shortcuts on Windows when installing/uninstalling.
|
|
if (started) {
|
|
app.quit();
|
|
}
|
|
|
|
const createWindow = () => {
|
|
// Create the browser window.
|
|
const mainWindow = new BrowserWindow({
|
|
width: 800,
|
|
height: 600,
|
|
webPreferences: {
|
|
preload: path.join(__dirname, "preload.js"),
|
|
},
|
|
});
|
|
|
|
// and load the index.html of the app.
|
|
if (MAIN_WINDOW_VITE_DEV_SERVER_URL) {
|
|
mainWindow.loadURL(MAIN_WINDOW_VITE_DEV_SERVER_URL);
|
|
} else {
|
|
mainWindow.loadFile(
|
|
path.join(
|
|
__dirname,
|
|
`../renderer/${MAIN_WINDOW_VITE_NAME}/index.html`,
|
|
),
|
|
);
|
|
}
|
|
|
|
// Open the DevTools.
|
|
mainWindow.webContents.openDevTools();
|
|
};
|
|
|
|
// This method will be called when Electron has finished
|
|
// initialization and is ready to create browser windows.
|
|
// Some APIs can only be used after this event occurs.
|
|
|
|
app.whenReady().then(() => {
|
|
ipcMain.handle("dialog:openFolder", async (event) => {
|
|
// Use the sender's window for correct dialog association
|
|
const senderWindow = BrowserWindow.fromWebContents(event.sender);
|
|
return await handleOpenFolder(senderWindow);
|
|
});
|
|
createWindow();
|
|
if (process.platform === "darwin") {
|
|
app.on("activate", function () {
|
|
if (BrowserWindow.getAllWindows().length === 0) createWindow();
|
|
});
|
|
}
|
|
});
|
|
|
|
// Quit when all windows are closed, except on macOS. There, it's common
|
|
// for applications and their menu bar to stay active until the user quits
|
|
// explicitly with Cmd + Q.
|
|
app.on("window-all-closed", () => {
|
|
if (process.platform !== "darwin") {
|
|
app.quit();
|
|
}
|
|
});
|