1
0
mirror of https://github.com/upscayl/upscayl.git synced 2024-11-24 15:40:21 +01:00
upscayl/main/index.js
2022-08-15 15:42:48 +05:30

57 lines
1.4 KiB
JavaScript

// Native
const { join } = require("path");
const { format } = require("url");
const { exec } = require("child_process");
const fs = require("fs");
// Packages
const { BrowserWindow, app, ipcMain, dialog } = require("electron");
const isDev = require("electron-is-dev");
const prepareNext = require("electron-next");
// Prepare the renderer once the app is ready
app.on("ready", async () => {
await prepareNext("./renderer");
const mainWindow = new BrowserWindow({
width: 1100,
height: 700,
webPreferences: {
autoHideMenuBar: true,
nodeIntegration: false,
preload: join(__dirname, "preload.js"),
},
});
const url = isDev
? "http://localhost:8000"
: format({
pathname: join(__dirname, "../renderer/out/index.html"),
protocol: "file:",
slashes: true,
});
mainWindow.setMenuBarVisibility(false);
mainWindow.maximize();
mainWindow.loadURL(url);
});
// Quit the app once all windows are closed
app.on("window-all-closed", app.quit);
// ! DONT FORGET TO RESTART THE APP WHEN YOU CHANGE CODE HERE
ipcMain.on("sendMessage", (_, message) => {
console.log(message);
});
ipcMain.handle("open", async () => {
const {canceled, filePaths} = await dialog.showOpenDialog({ properties: ['openFile', 'multiSelections'] })
if (canceled) {
console.log('operation cancelled')
return("cancelled")
}
else {
console.log(filePaths[0])
return(filePaths[0])
}
})