ytDownloader/main.js

105 lines
2.5 KiB
JavaScript
Raw Normal View History

const { app, BrowserWindow, dialog, ipcMain } = require("electron");
2022-07-31 12:45:09 +06:00
const { autoUpdater } = require("electron-updater");
2022-08-27 12:02:54 +06:00
let win, secondaryWindow;
2022-07-31 12:45:09 +06:00
function createWindow() {
2022-08-02 23:27:08 +06:00
let isTransparent = false;
if (process.platform == "linux") {
isTransparent = true;
}
2022-08-05 17:37:17 +06:00
win = new BrowserWindow({
2022-07-31 12:45:09 +06:00
show: false,
icon: __dirname + "/public/icon.png",
2022-08-02 23:27:08 +06:00
spellcheck: false,
transparent: isTransparent,
webPreferences: {
2022-08-05 17:37:17 +06:00
nodeIntegration: true,
contextIsolation: false,
},
2022-07-31 12:45:09 +06:00
});
2022-08-05 17:37:17 +06:00
win.loadFile("html/index.html");
2022-07-31 12:45:09 +06:00
win.maximize();
2022-08-27 21:19:29 +06:00
// win.setMenu(null)
2022-07-31 12:45:09 +06:00
win.show();
2022-08-05 18:16:42 +06:00
// win.webContents.openDevTools();
2022-08-02 23:27:08 +06:00
autoUpdater.checkForUpdatesAndNotify();
2022-07-25 22:15:38 +06:00
}
app.whenReady().then(() => {
2022-07-31 12:45:09 +06:00
createWindow();
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
if (process.platform === "win32") {
app.setAppUserModelId(app.name);
}
});
2022-07-25 22:15:38 +06:00
2022-08-27 12:02:54 +06:00
ipcMain.on("load-page", (event, file) => {
secondaryWindow = new BrowserWindow({
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
},
parent: win,
modal: true,
show: false,
});
// win.loadFile(file);
secondaryWindow.loadFile(file);
2022-08-27 13:07:12 +06:00
secondaryWindow.setMenu(null)
2022-08-27 12:02:54 +06:00
secondaryWindow.maximize();
secondaryWindow.show();
});
ipcMain.on("close-secondary", () => {
secondaryWindow.close();
secondaryWindow = null;
2022-08-05 17:37:17 +06:00
});
2022-08-05 17:37:17 +06:00
ipcMain.on("select-location", () => {
2022-08-27 13:07:12 +06:00
const location = dialog.showOpenDialogSync(secondaryWindow, {
2022-08-05 17:37:17 +06:00
properties: ["openFile", "openDirectory"],
});
2022-08-05 17:37:17 +06:00
if (location) {
2022-08-27 13:07:12 +06:00
secondaryWindow.webContents.send("downloadPath", location);
}
2022-08-05 17:37:17 +06:00
});
2022-07-31 12:45:09 +06:00
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});
// Auto updater events
autoUpdater.on("update-available", (_event, releaseNotes, releaseName) => {
const dialogOpts = {
2022-08-02 23:27:08 +06:00
type: "info",
buttons: ["Ok"],
title: "Application Update",
message: process.platform === "win32" ? releaseNotes : releaseName,
detail: "A new version is being downloaded.",
};
dialog.showMessageBox(dialogOpts, (response) => {});
});
2022-07-31 12:45:09 +06:00
autoUpdater.on("update-downloaded", (_event, releaseNotes, releaseName) => {
const dialogOpts = {
2022-08-02 23:27:08 +06:00
type: "info",
buttons: ["Restart", "Later"],
title: "Application Update",
message: process.platform === "win32" ? releaseNotes : releaseName,
detail: "A new version has been downloaded. Restart the application to apply the updates.",
2022-07-31 12:45:09 +06:00
};
dialog.showMessageBox(dialogOpts).then((returnValue) => {
2022-08-02 23:27:08 +06:00
if (returnValue.response === 0) autoUpdater.quitAndInstall();
});
2022-07-31 19:14:15 +06:00
});