Closed lichangwei123 closed 7 months ago
electron-builder.yml
appId: cn.tiven.app
productName: electron-test2
copyright: Copyright © 2023 ${author}
asar: false
directories:
buildResources: build
output: dist
files:
- '!**/.vscode/*'
- '!dist2/*'
- '!node_modules/*'
- '!electron.vite.config.{js,ts,mjs,cjs}'
- '!{.eslintignore,.eslintrc.cjs,.prettierignore,.prettierrc.yaml,dev-app-update.yml,[CHANGELOG.md](http://changelog.md/),[README.md](http://readme.md/)}'
- '!{.env,.env.*,.npmrc,pnpm-lock.yaml}'
asarUnpack:
- resources/**
win:
certificateFile: build/****.pfx
certificatePassword: 123456
executableName: electron-test2
icon: resources/icon.ico
publisherName: tiven
verifyUpdateCodeSignature: false
requestedExecutionLevel: highestAvailable #// 权限
signingHashAlgorithms: [sha256]
signDlls: true #// dll文件是否签名
rfc3161TimeStampServer: http://timestamp.digicert.com/ #http://timestamp.comodoca.com/rfc3161 #// 时间戳"http://timestamp.globalsign.com/scripts/timestamp.dll" "http://timestamp.digicert.com/" "http://timestamp.comodoca.com/rfc3161" "http://sha256timestamp.ws.symantec.com/sha256/timestamp"
target:
- nsis
- squirrel
nsis:
oneClick: false
allowElevation: true
artifactName: ${name}-${version}-setup.${ext}
shortcutName: ${productName}
uninstallDisplayName: ${productName}
createDesktopShortcut: always
perMachine: false
allowToChangeInstallationDirectory: true
squirrelWindows: #此处不可缺少
loadingGif: resources/111.gif
iconUrl: https://tiven.cn/static/img/net-stats.ico
mac:
category: public.app-category.developer-tools
entitlementsInherit: build/entitlements.mac.plist
extendInfo:
- NSCameraUsageDescription: Application requests access to the device's camera.
- NSMicrophoneUsageDescription: Application requests access to the device's microphone.
- NSDocumentsFolderUsageDescription: Application requests access to the user's Documents folder.
- NSDownloadsFolderUsageDescription: Application requests access to the user's Downloads folder.
dmg:
artifactName: ${name}-${version}.${ext}
linux:
target:
- AppImage
- snap
- deb
maintainer: [electronjs.org](http://electronjs.org/)
category: Utility
appImage:
artifactName: ${name}-${version}.${ext}
npmRebuild: false
publish:
provider: generic
url: https://lawdawn-download.oss-cn-beijing.aliyuncs.com/win-2023-11-04-1/
Please help me.
main.js
const { app, BrowserWindow, ipcMain } = require('electron')
const { autoUpdater } = require('electron-updater')
const os = require('os')
const logger = require('electron-log')
//打印log到本地
logger.transports.file.maxSize = 1002430 // 10M
logger.transports.file.format =
'[{y}-{m}-{d} {h}:{i}:{s}.{ms}] [{level}]{scope} {text}'
logger.transports.file.resolvePath = () => './operation.log' //打印在你安装的软件位置,
autoUpdater.autoDownload = false //这个必须写成false,写成true时,我这会报没权限更新,也没清楚什么原因
// 将创建窗口独立成一个函数
function createWindow() {
let mainWin = new BrowserWindow({
x: 100,
y: 100, // 设置窗口显示的位置,相对于当前屏幕的左上角
show: false, // 默认情况下创建一个窗口对象之后就会显示,设置为false 就不会显示了
width: 800,
height: 400,
// maxHeight: 600,
// maxWidth: 1000,
minHeight: 200,
minWidth: 300, // 可以通过 min max 来设置当前应用窗口的最大和最小尺寸
resizable: true, // 是否允许缩放应用的窗口大小
title: 'electron-tester',
webPreferences: {
enableWebSQL: false,
webSecurity: false,
spellcheck: false,
nativeWindowOpen: true,
nodeIntegration: true,
contextIsolation: false,
},
experimentalDarkMode: true,
})
mainWin.loadFile('./src/index.html')
//忽略无关代码
ipcMain.on('checkUpdate', () => {
console.log('checkUpdate-->')
//处理更新操作
const returnData = {
error: {
status: -1,
msg: '更新时发生意外,无法进行正常更新!',
},
checking: {
status: 0,
msg: '正在检查更新……',
},
updateAva: {
status: 1,
msg: '正在升级……',
},
updateNotAva: {
status: 2,
msg: '当前没有可用的更新...',
},
}
let platform =
os.platform() === 'darwin'
? process.arch === 'x64'
? 'darwin'
: 'darwin-arm64'
: 'win32'
let commitId = 'ab4f3c131bfec65670dd265549646b725f8ee649'
//更新连接
autoUpdater.setFeedURL(
// `[https://devxz.dafenqi.law/lawdawn-api/api/update/${platform}/${commitId}](https://devxz.dafenqi.law/lawdawn-api/api/update/$%7Bplatform%7D/$%7BcommitId%7D)`
'https://lawdawn-download.oss-cn-beijing.aliyuncs.com/win-2023-11-04-1'
)
logger.error(['检查更新'])
//更新错误事件
autoUpdater.on('error', function (error) {
console.log('err-->', error)
logger.error(['检查更新失败', error])
sendUpdateMessage(returnData.error)
})
//检查事件
autoUpdater.on('checking-for-update', function () {
sendUpdateMessage(returnData.checking)
})
//发现新版本
autoUpdater.on('update-available', function (info) {
console.log('info22-->', info)
logger.info(['发现新版本', info])
sendUpdateMessage(returnData.updateAva)
autoUpdater.downloadUpdate()
})
//当前版本为最新版本
autoUpdater.on('update-not-available', function (info) {
console.log('info11-->', info)
setTimeout(function () {
sendUpdateMessage(returnData.updateNotAva)
}, 1000)
问题解决了吗,我也遇到这个问题
我也遇到了这个问题,临时解决方案:默认安装至C盘,不可选择安装目录,自动更新后安装就没有再遇到这个问题了。有其他解决方案辛苦回复下,谢谢。
我也遇到了,看起来是文件被占用,但实际测试并没有,可以将整个安装目录直接重命名。 卸载再安装就可以,覆盖安装就报这个错,个别案例。
https://github.com/electron-userland/electron-builder/issues/6865 我遇到的似乎是文件名过长,最长的文件名接近250,由于用户名有长有短,所以看起来是有的用户有问题,有的没问题
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days.
This issue was closed because it has been stalled for 30 days with no activity.
It fails halfway through the update, and various approaches have been tried many times