From 84504f734f8c30430d1c15c3b374daf85a7b755b Mon Sep 17 00:00:00 2001 From: DJ2LS Date: Thu, 29 Feb 2024 16:36:56 +0100 Subject: [PATCH] removed updater, auto start server --- gui/electron/main/index.ts | 149 ++++--------------- gui/electron/preload/index.ts | 81 +--------- gui/src/components/settings.vue | 31 +--- gui/src/components/settings_updater.vue | 16 -- gui/src/components/settings_updater_core.vue | 102 ------------- 5 files changed, 34 insertions(+), 345 deletions(-) delete mode 100644 gui/src/components/settings_updater.vue delete mode 100644 gui/src/components/settings_updater_core.vue diff --git a/gui/electron/main/index.ts b/gui/electron/main/index.ts index cf4e9636..11f02846 100644 --- a/gui/electron/main/index.ts +++ b/gui/electron/main/index.ts @@ -1,7 +1,6 @@ import { app, BrowserWindow, shell, ipcMain } from "electron"; import { release, platform } from "node:os"; import { join } from "node:path"; -import { autoUpdater } from "electron-updater"; import { existsSync } from "fs"; import { spawn } from "child_process"; @@ -40,7 +39,7 @@ if (!app.requestSingleInstanceLock()) { // process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true' // set daemon process var -var daemonProcess = null; +var serverProcess = null; let win: BrowserWindow | null = null; // Here, you can also use other preload const preload = join(__dirname, "../preload/index.js"); @@ -87,12 +86,7 @@ async function createWindow() { // win.webContents.on('will-navigate', (event, url) => { }) #344 win.once("ready-to-show", () => { - //autoUpdater.logger = log.scope("updater"); - //autoUpdater.channel = config.update_channel; - autoUpdater.autoInstallOnAppQuit = false; - autoUpdater.autoDownload = true; - autoUpdater.checkForUpdatesAndNotify(); - //autoUpdater.quitAndInstall(); + // }); } @@ -102,64 +96,51 @@ app.whenReady().then(() => { console.log(platform()); //Generate daemon binary path - var daemonPath = ""; + var serverPath = ""; switch (platform().toLowerCase()) { - case "darwin": - daemonPath = join(process.resourcesPath, "modem", "freedata-server"); - case "linux": - daemonPath = join(process.resourcesPath, "modem", "freedata-server"); - break; + //case "darwin": + // serverPath = join(process.resourcesPath, "modem", "freedata-server"); + //case "linux": + // serverPath = join(process.resourcesPath, "modem", "freedata-server"); + // break; case "win32": - daemonPath = join(process.resourcesPath, "modem", "freedata-server.exe"); - break; case "win64": - daemonPath = join(process.resourcesPath, "modem", "freedata-server.exe"); - break; + serverPath = join(process.env.LOCALAPPDATA, "FreeDATA", "freedata-server", "freedata-server.exe"); + break; default: console.log("Unhandled OS Platform: ", platform()); break; } //Start daemon binary if it exists - if (existsSync(daemonPath)) { + if (existsSync(serverPath)) { console.log("Starting freedata-server binary"); - console.log("daemonPath:", daemonPath); - console.log("CWD:", join(daemonPath, "..")); - /* - var daemonProcess = spawn("freedata-server", [], { - cwd: join(process.env.DIST, "modem"), - shell: true - }); -*/ - /* -daemonProcess = spawn(daemonPath, [], { - shell: true - }); - console.log(daemonProcess) -*/ - daemonProcess = spawn(daemonPath, [], {}); + console.log("serverPath:", serverPath); + console.log("CWD:", join(serverPath, "..")); + + serverProcess = spawn(serverPath, [], { shell: true }); // return process messages - daemonProcess.on("error", (err) => { - //daemonProcessLog.error(`error when starting daemon: ${err}`); + serverProcess.on("error", (err) => { + //serverProcessLog.error(`error when starting daemon: ${err}`); console.log(err); }); - daemonProcess.on("message", () => { - // daemonProcessLog.info(`${data}`); + serverProcess.on("message", () => { + // serverProcessLog.info(`${data}`); }); - daemonProcess.stdout.on("data", () => { - // daemonProcessLog.info(`${data}`); + serverProcess.stdout.on("data", () => { + // serverProcessLog.info(`${data}`); }); - daemonProcess.stderr.on("data", (data) => { - // daemonProcessLog.info(`${data}`); + serverProcess.stderr.on("data", (data) => { + // serverProcessLog.info(`${data}`); console.log(data); }); - daemonProcess.on("close", (code) => { - // daemonProcessLog.warn(`daemonProcess exited with code ${code}`); + serverProcess.on("close", (code) => { + // serverProcessLog.warn(`serverProcess exited with code ${code}`); }); } else { - daemonProcess = null; - daemonPath = null; + serverProcess = null; + serverPath = null; console.log("Daemon binary doesn't exist--normal for dev environments."); } @@ -205,101 +186,31 @@ ipcMain.handle("open-win", (_, arg) => { } }); -//restart and install udpate -ipcMain.on("request-restart-and-install-update", (event, data) => { - close_sub_processes(); - autoUpdater.quitAndInstall(); -}); -// LISTENER FOR UPDATER EVENTS -autoUpdater.on("update-available", (info) => { - process.env.FDUpdateAvail = "1"; - console.log("update available"); - - let arg = { - status: "update-available", - info: info, - }; - win.webContents.send("action-updater", arg); -}); - -autoUpdater.on("update-not-available", (info) => { - console.log("update not available"); - let arg = { - status: "update-not-available", - info: info, - }; - win.webContents.send("action-updater", arg); -}); - -autoUpdater.on("update-downloaded", (info) => { - process.env.FDUpdateAvail = "1"; - console.log("update downloaded"); - let arg = { - status: "update-downloaded", - info: info, - }; - win.webContents.send("action-updater", arg); - // we need to call this at this point. - // if an update is available and we are force closing the app - // the entire screen crashes... - //console.log('quit application and install update'); - //autoUpdater.quitAndInstall(); -}); - -autoUpdater.on("checking-for-update", () => { - console.log("checking for update"); - let arg = { - status: "checking-for-update", - version: app.getVersion(), - }; - win.webContents.send("action-updater", arg); -}); - -autoUpdater.on("download-progress", (progress) => { - let arg = { - status: "download-progress", - progress: progress, - }; - win.webContents.send("action-updater", arg); -}); - -autoUpdater.on("error", (error) => { - console.log("update error"); - let arg = { - status: "error", - progress: error, - }; - win.webContents.send("action-updater", arg); - console.log("AUTO UPDATER : " + error); -}); function close_sub_processes() { console.log("closing sub processes"); // closing the modem binary if not closed when closing application and also our daemon which has been started by the gui try { - if (daemonProcess != null) { - daemonProcess.kill(); + if (serverProcess != null) { + serverProcess.kill(); } } catch (e) { console.log(e); } - console.log("closing modem and daemon"); + console.log("closing freedata server process"); try { if (platform() == "win32") { - spawn("Taskkill", ["/IM", "freedata-modem.exe", "/F"]); spawn("Taskkill", ["/IM", "freedata-server.exe", "/F"]); } if (platform() == "linux") { - spawn("pkill", ["-9", "freedata-modem"]); spawn("pkill", ["-9", "freedata-server"]); } if (platform() == "darwin") { - spawn("pkill", ["-9", "freedata-modem"]); spawn("pkill", ["-9", "freedata-server"]); } } catch (e) { diff --git a/gui/electron/preload/index.ts b/gui/electron/preload/index.ts index 69e18a1e..03708df3 100644 --- a/gui/electron/preload/index.ts +++ b/gui/electron/preload/index.ts @@ -111,83 +111,4 @@ window.onmessage = (ev) => { ev.data.payload === "removeLoading" && removeLoading(); }; -setTimeout(removeLoading, 4999); - -// IPC ACTION FOR AUTO UPDATER -ipcRenderer.on("action-updater", (event, arg) => { - if (arg.status == "download-progress") { - var progressinfo = - "(" + - Math.round(arg.progress.transferred / 1024) + - "kB /" + - Math.round(arg.progress.total / 1024) + - "kB)" + - " @ " + - Math.round(arg.progress.bytesPerSecond / 1024) + - "kByte/s"; - document.getElementById("UpdateProgressInfo").innerHTML = progressinfo; - - document - .getElementById("UpdateProgressBar") - .setAttribute("aria-valuenow", arg.progress.percent); - document - .getElementById("UpdateProgressBar") - .setAttribute("style", "width:" + arg.progress.percent + "%;"); - } - - if (arg.status == "checking-for-update") { - //document.title = document.title + ' - v' + arg.version; - //updateTitle( - // config.myCall, - // config.tnc_host, - // config.tnc_port, - // " -v " + arg.version, - //); - document.getElementById("updater_status").innerHTML = - ''; - - document.getElementById("updater_status").className = - "btn btn-secondary btn-sm"; - document.getElementById("update_and_install").style.display = "none"; - } - if (arg.status == "update-downloaded") { - document.getElementById("update_and_install").removeAttribute("style"); - document.getElementById("updater_status").innerHTML = - ''; - document.getElementById("updater_status").className = - "btn btn-success btn-sm"; - - // HERE WE NEED TO RUN THIS SOMEHOW... - //mainLog.info('quit application and install update'); - //autoUpdater.quitAndInstall(); - } - if (arg.status == "update-not-available") { - document.getElementById("updater_last_version").innerHTML = - arg.info.releaseName; - document.getElementById("updater_last_update").innerHTML = - arg.info.releaseDate; - document.getElementById("updater_release_notes").innerHTML = - arg.info.releaseNotes; - - document.getElementById("updater_status").innerHTML = - ''; - document.getElementById("updater_status").className = - "btn btn-success btn-sm"; - document.getElementById("update_and_install").style.display = "none"; - } - if (arg.status == "update-available") { - document.getElementById("updater_status").innerHTML = - ''; - document.getElementById("updater_status").className = - "btn btn-warning btn-sm"; - document.getElementById("update_and_install").style.display = "none"; - } - - if (arg.status == "error") { - document.getElementById("updater_status").innerHTML = - ''; - document.getElementById("updater_status").className = - "btn btn-danger btn-sm"; - document.getElementById("update_and_install").style.display = "none"; - } -}); +setTimeout(removeLoading, 3999); diff --git a/gui/src/components/settings.vue b/gui/src/components/settings.vue index 718e660e..f230bf97 100644 --- a/gui/src/components/settings.vue +++ b/gui/src/components/settings.vue @@ -1,5 +1,4 @@ - - diff --git a/gui/src/components/settings_updater_core.vue b/gui/src/components/settings_updater_core.vue deleted file mode 100644 index b83cd823..00000000 --- a/gui/src/components/settings_updater_core.vue +++ /dev/null @@ -1,102 +0,0 @@ - - -