cocktailpeanut 1 månad sedan
förälder
incheckning
fc345c59d9
5 ändrade filer med 53 tillägg och 5 borttagningar
  1. 2 1
      full.js
  2. 0 1
      main.js
  3. 2 1
      minimal.js
  4. 2 2
      package.json
  5. 47 0
      updater.js

+ 2 - 1
full.js

@@ -4,6 +4,7 @@ const fs = require('fs')
 const path = require("path")
 const Pinokiod = require("pinokiod")
 const os = require('os')
+const Updater = require('./updater')
 const is_mac = process.platform.startsWith("darwin")
 const platform = os.platform()
 var mainWindow;
@@ -23,7 +24,7 @@ const filter = function (item) {
   return item.browserName === 'Chrome';
 };
 
-const updater = new global.Updater()
+const updater = new Updater()
 const pinokiod = new Pinokiod(config)
 const titleBarOverlay = (colors) => {
   if (is_mac) {

+ 0 - 1
main.js

@@ -1,6 +1,5 @@
 const Pinokiod = require("pinokiod")
 const config = require('./config')
-global.Updater = require('./updater')
 const pinokiod = new Pinokiod(config)
 let mode = pinokiod.kernel.store.get("mode") || "full"
 //iprocess.env.PINOKIO_MODE = process.env.PINOKIO_MODE || 'desktop';

+ 2 - 1
minimal.js

@@ -2,8 +2,9 @@ const { app, Tray, Menu, shell, nativeImage } = require('electron');
 const path = require('path')
 const Pinokiod = require("pinokiod")
 const config = require('./config')
+const Updater = require('./updater')
 const pinokiod = new Pinokiod(config)
-const updater = new global.Updater()
+const updater = new Updater()
 let tray
 app.whenReady().then(async () => {
   await pinokiod.start({

+ 2 - 2
package.json

@@ -1,7 +1,7 @@
 {
   "name": "Pinokio",
   "private": true,
-  "version": "3.20.8",
+  "version": "3.20.9",
   "homepage": "https://pinokio.co",
   "description": "pinokio",
   "main": "main.js",
@@ -128,7 +128,7 @@
     "electron-store": "^8.1.0",
     "electron-updater": "^6.6.2",
     "electron-window-state": "^5.0.3",
-    "pinokiod": "^3.20.8"
+    "pinokiod": "^3.20.9"
   },
   "devDependencies": {
     "@electron/rebuild": "3.2.10",

+ 47 - 0
updater.js

@@ -0,0 +1,47 @@
+const { autoUpdater } = require("electron-updater");
+const { dialog } = require('electron')
+
+class Updater {
+  run() {
+    // 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);
+    });
+
+    // 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}`);
+      console.log(`Downloaded ${Math.round(progress.percent)}%`);
+    });
+
+    // Called when the update has been downloaded
+    autoUpdater.on('update-downloaded', (info) => {
+      console.log('Update downloaded:', info.version);
+
+      // Ask user if they want to install now
+      dialog.showMessageBox(mainWindow, {
+        type: 'info',
+        buttons: ['Restart Now', 'Later'],
+        title: 'Update Available',
+        message: 'A new version has been downloaded. Restart the application to apply the updates?'
+      }).then(result => {
+        if (result.response === 0) { // Restart Now
+          autoUpdater.quitAndInstall();
+        }
+      });
+    });
+    autoUpdater.checkForUpdatesAndNotify();
+
+  }
+}
+module.exports = Updater