简体   繁体   English

electron 自动更新 windows

[英]electron auto-update for windows

I am trying to create an electron app that will auto-update new releases from github.我正在尝试创建一个 electron 应用程序,它将自动更新 github 的新版本。 Trying to do this for mac and windows right now.现在正在尝试为 mac 和 windows 执行此操作。

I have been able to successfully create and sign a mac os.dmg programs by following this tutorial .按照本教程,我已经能够成功创建并签署一个 mac os.dmg 程序。 The result is an electron app that when I am on my mac laptop and run npm run deploy for a new version, it will build and package the program by running this command: electron-builder build --mac --win --publish always结果是一个 electron 应用程序,当我在我的 Mac 笔记本电脑上运行npm run deploy新版本时,它将构建 ZEFE90A8E604A7C840E88 --D03A67F6B7D8Z 程序, electron-builder build --mac --win --publish always

The mac os.dmg file works like the tutorial instructs, it checks for updates in my main.js file and if a new version is published it will prompt the user to restart the app. mac os.dmg 文件的工作方式与教程中的说明一样,它会检查我的 main.js 文件中的更新,如果发布了新版本,它将提示用户重新启动应用程序。

The tutorial is supposed to also work for windows, but the windows.exe that gets generated and upload to my github repo releases tab does not seem to auto-update.本教程应该也适用于 windows,但生成并上传到我的 github 存储库发布选项卡的 windows.exe 似乎不会自动更新。 I test this by running my app windows portable.exe file: electron-auto-updater-1.0.2 after I have already released v1.0.3, so it should autoupdate but never does, and doesnt throw any err in my electron app window console.在我已经发布 v1.0.3 之后,我通过运行我的应用程序 windowsportable.exe 文件: electron-auto-updater-1.0.2来对此进行测试,因此它应该自动更新但永远不会,并且不会在我的 Z1B85623431169FEDC9A20ECF24DF3F5476FBFDEF24 应用程序 Z05B85623431169FEDC9A20ECF24DF3F5476FBFDEF24 .

Do I need to sign my windows exe for electron in a different way?我是否需要以不同的方式为 electron 签署我的 windows exe? Ultimately I am trying to create a bare minimum electron app for windows 10 with auto-updating.最终,我正在尝试为 windows 10 创建一个具有自动更新功能的最低限度的 electron 应用程序。 I have been looking online and following various old tutorial blog posts, the one i linked seems like the most recent (2019), and I followed every instruction for the signing procedure on a mac os laptop, but my code is not working on windows:我一直在网上查看并关注各种旧的教程博客文章,我链接的那个似乎是最新的(2019 年),我遵循了 mac os 笔记本电脑上签名过程的每一条说明,但我的代码在 windows 上不起作用:

package.json package.json

{
  "name": "electron-auto-updater",
  "productName": "Electron tutorial app",
  "description": "Application for electron tutorials",
  "version": "1.0.4",
  "main": "main.js",
  "scripts": {
    "start": "electron .",
    "build": "electron-builder build --mac --win --publish never",
    "deploy": "electron-builder build --mac --win --publish always",
    "deploy-win": "electron-builder build --win --publish always",
    "build-win": "electron-builder build --win --publish never"
  },
  "build": {
    "appId": "yourAppId",
    "afterSign": "scripts/notarize.js",
    "mac": {
      "icon": "build/icon.png",
      "hardenedRuntime": true,
      "gatekeeperAssess": false,
      "entitlements": "build/entitlements.mac.plist",
      "entitlementsInherit": "build/entitlements.mac.plist",
      "target": [
        "dmg",
        "zip"
      ]
    },
    "dmg": {
      "sign": false
    },
    "linux": {
      "category": "TODO: fill here the category of your app",
      "icon": "build/icon.png",
      "target": [
        "AppImage",
        "deb"
      ]
    },
    "win": {
      "target": "portable",
      "icon": "build/icon.png"
    }
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "electron": "^11.0.3",
    "electron-builder": "^22.9.1",
    "electron-notarize": "^1.0.0",
    "electron-winstaller": "^4.0.1"
  },
  "dependencies": {
    "dotenv": "^8.2.0",
    "electron-updater": "^4.3.5"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/MartinBarker/electron-auto-updater.git"
  }
}

main.js main.js

const { app, BrowserWindow, ipcMain } = require('electron');
const { autoUpdater } = require('electron-updater');
require('dotenv').config();

let mainWindow;

function createWindow () {
  mainWindow = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: true,
    },
  });
  mainWindow.loadFile('index.html');
  mainWindow.on('closed', function () {
    mainWindow = null;
  });

  mainWindow.once('ready-to-show', () => {
    try{
      autoUpdater.checkForUpdatesAndNotify();
    }catch(err){
      console.log('autoUpdater.checkForUpdatesAndNotify(); err = ', err)
    }
  });
}

app.on('ready', () => {
  createWindow();
});

app.on('window-all-closed', function () {
  if (process.platform !== 'darwin') {
    app.quit();
  }
});

app.on('activate', function () {
  if (mainWindow === null) {
    createWindow();
  }
});

ipcMain.on('app_version', (event) => {
  event.sender.send('app_version', { version: app.getVersion() });
});

ipcMain.on('restart_app', () => {
    autoUpdater.quitAndInstall();
  });

autoUpdater.on('update-available', () => {
    mainWindow.webContents.send('update_available');
    console.log('update avail')
  });
  autoUpdater.on('update-downloaded', () => {
    console.log('update downlaoded')
    mainWindow.webContents.send('update_downloaded');
  });

If I build on command prompt on my wind 10 computer I get this output in ym console: no error messages:

$1.0.4 deploy-win C:\Users\marti\Documents\projects\electron-auto-updater
electron-builder build --win --publish always

electron-builder  version=22.9.1 os=10.0.18363
loaded configuration  file=package.json ("build" field)
writing effective config  file=dist\builder-effective-config.yaml
packaging       platform=win32 arch=x64 electron=11.0.3     appOutDir=dist\win-unpacked
building        target=portable file=dist\Electron tutorial app 1.0.4.exe archs=x64
  s

fixed for windows by removing "target": "portable", from my package.json file, turns out for windows electron.exe programs that auto-update they dont work as portable, and need to be an installer instead fixed for windows by removing "target": "portable", from my package.json file, turns out for windows electron.exe programs that auto-update they dont work as portable, and need to be an installer instead

You need to configure for windows;需要为windows配置; see thedocs .请参阅文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM