cocktailpeanut 1 lună în urmă
părinte
comite
5894d629d0
2 a modificat fișierele cu 60 adăugiri și 28 ștergeri
  1. 10 7
      package.json
  2. 50 21
      updater.js

+ 10 - 7
package.json

@@ -1,7 +1,7 @@
 {
   "name": "Pinokio",
   "private": true,
-  "version": "3.20.15",
+  "version": "3.20.16",
   "homepage": "https://pinokio.co",
   "description": "pinokio",
   "main": "main.js",
@@ -28,11 +28,13 @@
     "directories": {
       "output": "dist-${platform}"
     },
-    "publish": [{
-      "provider": "github",
-      "owner": "cocktailpeanutlabs",
-      "repo": "pdeploy"
-    }],
+    "publish": [
+      {
+        "provider": "github",
+        "owner": "cocktailpeanutlabs",
+        "repo": "pdeploy"
+      }
+    ],
     "asarUnpack": [
       "node_modules/go-get-folder-size/**/*",
       "node_modules/7zip-bin/**/*",
@@ -125,10 +127,11 @@
   },
   "license": "MIT",
   "dependencies": {
+    "electron-progressbar": "^2.2.1",
     "electron-store": "^8.1.0",
     "electron-updater": "^6.6.2",
     "electron-window-state": "^5.0.3",
-    "pinokiod": "^3.20.15"
+    "pinokiod": "^3.20.16"
   },
   "devDependencies": {
     "@electron/rebuild": "3.2.10",

+ 50 - 21
updater.js

@@ -1,20 +1,19 @@
 const { autoUpdater } = require("electron-updater");
-const { dialog } = require('electron')
+const ProgressBar = require('electron-progressbar');
+const { dialog } = require('electron');
 
 class Updater {
   run(mainWindow) {
+    let progressBar = null;
     autoUpdater.autoDownload = false;
 
-    // Called when checking for an update
     autoUpdater.on('checking-for-update', () => {
       console.log('Checking for update...');
     });
 
-    // Called when an update is available
     autoUpdater.on('update-available', (info) => {
       console.log('Update available:', info.version);
 
-      // Ask user if they want to download
       dialog.showMessageBox(mainWindow, {
         type: 'question',
         buttons: ['Yes', 'No'],
@@ -24,41 +23,71 @@ class Updater {
         message: `Version ${info.version} is available. Do you want to download it now?`
       }).then(result => {
         if (result.response === 0) {
+          if (progressBar) {
+            progressBar.close();
+            progressBar = null;
+          }
+          progressBar = new ProgressBar({
+            indeterminate: false,
+            text: "Downloading update...",
+            detail: "Please wait...",
+            browserWindow: {
+              parent: mainWindow,
+              modal: true,
+              closable: false,
+              minimizable: false,
+              maximizable: false,
+              width: 400,
+              height: 120
+            }
+          });
           autoUpdater.downloadUpdate();
         }
       });
-
     });
 
-    // Called when no update is found
     autoUpdater.on('update-not-available', () => {
       console.log('No update available.');
     });
 
-    // Called on download progress
-    autoUpdater.on('download-progress', (progress) => {
-      console.log(`Download speed: ${progress.bytesPerSecond}`);
+    autoUpdater.on("download-progress", (progress) => {
       console.log(`Downloaded ${Math.round(progress.percent)}%`);
+      if (progressBar && !progressBar.isCompleted()) {
+        progressBar.value = Math.floor(progress.percent);
+        progressBar.detail = `Downloaded ${Math.round(progress.percent)}% (${(progress.transferred / 1024 / 1024).toFixed(2)} MB of ${(progress.total / 1024 / 1024).toFixed(2)} MB)`;
+      }
     });
 
-    // Called when the update has been downloaded
-    autoUpdater.on('update-downloaded', (info) => {
-      console.log('Update downloaded:', info.version);
+    autoUpdater.on("update-downloaded", (info) => {
+      console.log("Update downloaded:", info.version);
+
+      if (progressBar && !progressBar.isCompleted()) {
+        progressBar.setCompleted();
+        progressBar = null;
+      }
 
-      // Ask user if they want to install now
       dialog.showMessageBox(mainWindow, {
-        type: 'info',
-        buttons: ['Restart Now', 'Later'],
-        title: 'Update Ready',
-        message: 'A new version has been downloaded. Restart the application to apply the updates?'
-      }).then(result => {
-        if (result.response === 0) { // Restart Now
+        type: "info",
+        buttons: ["Restart Now", "Later"],
+        title: "Update Ready",
+        message: "A new version has been downloaded. Restart the application to apply the updates?"
+      }).then((result) => {
+        if (result.response === 0) {
           autoUpdater.quitAndInstall();
         }
       });
     });
-    autoUpdater.checkForUpdatesAndNotify();
 
+    autoUpdater.on("error", (err) => {
+      console.error("Update error:", err);
+      if (progressBar && !progressBar.isCompleted()) {
+        progressBar.close();
+        progressBar = null;
+      }
+    });
+
+    autoUpdater.checkForUpdates();
   }
 }
-module.exports = Updater
+
+module.exports = Updater;