我正在尝试创建一个电子应用程序,它将自动更新来自github的新版本。现在想为mac和windows做这件事。
我已经能够成功地创建和签署一个mac os .dmg程序,通过遵循本教程。结果是一个电子应用程序,当我在mac笔记本电脑上运行新版本的npm run deploy时,它将通过运行以下命令来构建和打包程序:electron-builder build --mac --win --publish always。
mac os .dmg文件按照教程的指示工作,它检查我的main.js文件中的更新,如果发布了新版本,它将提示用户重新启动应用程序。
本教程也适用于windows,但是生成并上传到我的选项卡的windows.exe似乎不自动更新。我通过运行我的应用程序窗口可移植的.exe文件:在我已经发布了1.0.3版本之后运行electron-auto-updater-1.0.2来测试这个问题,所以它应该是自动更新的,但从来没有,并且不会在我的电子应用程序窗口控制台中抛出任何错误。
我是否需要以不同的方式签署我的windows exe的电子文件?最终,我试图为windows 10创建一个最低限度的电子应用程序,并进行自动更新。我一直在网上查找并关注各种旧的教程博客文章,我链接的这篇文章似乎是最近的(2019年),我遵循了mac os膝上型计算机上的签名过程的每一条指令,但我的代码并不适用于windows:
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
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发布于 2020-12-05 20:18:47
通过从我的"target": "portable",文件中删除package.json,修正了windows电子.exe程序,这些程序自动更新它们不是作为可移植的,而是需要安装程序。
https://stackoverflow.com/questions/65154564
复制相似问题