Sfoglia il codice sorgente

修复 Windows 更新校验文件选择和兼容提示

Samien 1 mese fa
parent
commit
ed24caec5f

+ 1 - 1
desktop/host-manager.mjs

@@ -119,7 +119,7 @@ export class DesktopHostManager {
    const value=await remoteExchange(config,{host:core.info(),results:core.takeResults()})
    this.backoff=400
    if(this.config!==config||this.core!==core)return
-   this.publish(process.platform==='win32'&&!value.capabilities?.desktopPlatforms?.includes('win32')
+   this.publish(process.platform==='win32'&&!(Array.isArray(value.capabilities?.desktopPlatforms)&&value.capabilities.desktopPlatforms.includes('win32'))
     ? '已连接;服务器尚不支持 Windows 电脑操作,请升级服务器(聊天可继续使用)'
     : `电脑已连接 ${new URL(config.serverURL).host}`)
    core.acceptCapabilities?.(value.capabilities)

+ 1 - 1
desktop/main.mjs

@@ -525,7 +525,7 @@ else {
         { id:'desktop-background', label:'登录启动时仅驻留菜单栏', type:'checkbox', checked:preferences.value.backgroundAtLogin,
           click:async item=>{try{await preferences.setBackgroundAtLogin(item.checked)}catch(error){item.checked=preferences.value.backgroundAtLogin;await dialog.showMessageBox(window,{type:'error',message:error.message})}} },
         { id:'desktop-update-check', label:'检查 App 更新…', click:showUpdates },
-        { id:'desktop-update-help', label:'App 更新与回退…', click:()=>dialog.showMessageBox(window,{type:'info',message:`夭夭 App ${packageVersion}`,detail:`App 构建:${String(buildInfo.commit).slice(0,12)}\n\n通过“检查 App 更新”下载新版,准备完成后点击“重启更新”。此操作只更新当前电脑的 App,不升级远程服务器;独立后台服务继续运行。开发运行时提供手动安装包下载。\n\n服务器模式下,首次启动同步较旧的本机 Web,已有较新的 Web 保留。Web 降级通过服务器的回滚入口处理;数据库结构不兼容时不能直接降级。\n\n数据目录:${home}`,buttons:['知道了','打开数据目录']}).then(result=>{if(result.response===1)shell.showItemInFolder(home)}) },
+        { id:'desktop-update-help', label:'App 更新与回退…', click:()=>dialog.showMessageBox(window,{type:'info',message:`夭夭 App ${packageVersion}`,detail:`App 构建:${String(buildInfo.commit).slice(0,12)}\n\n通过“检查 App 更新”下载新版,准备完成后点击“重启更新”。此操作只更新当前电脑的 App,不升级远程服务器。开发运行时提供手动安装包下载。${platform.server ? "\n\n独立后台服务继续运行。服务器模式下,首次启动同步较旧的本机 Web,已有较新的 Web 保留。Web 降级通过服务器的回滚入口处理;数据库结构不兼容时不能直接降级。" : ""}\n\n数据目录:${home}`,buttons:['知道了','打开数据目录']}).then(result=>{if(result.response===1)shell.showItemInFolder(home)}) },
         { type: 'separator' },
         { role: 'hide', label: '隐藏夭夭' }, { role: 'hideOthers', label: '隐藏其他' }, { role: 'unhide', label: '显示全部' },
         { type: 'separator' },

+ 2 - 1
desktop/update-manager.mjs

@@ -54,7 +54,8 @@ export class DesktopUpdateManager {
       this.release = release
       const version = release.manifest.webVersion
       this.asset = release.assets.find(asset => asset.name === (this.platform === 'win32' ? `Yaoyao-${version}-win-${this.arch}-setup.exe` : `Yaoyao-${version}-${this.arch}.dmg`))
-      this.checksum = release.assets.find(asset => asset.name === 'SHA256SUMS.txt')
+      this.checksum = (this.platform === 'win32' && release.assets.find(asset => asset.name === `SHA256SUMS-win-${this.arch}.txt`))
+        || release.assets.find(asset => asset.name === 'SHA256SUMS.txt')
       const newer = this.compare(version, this.version) > 0
       const supported = (this.platform === 'darwin' && ['arm64', 'x64'].includes(this.arch) || this.platform === 'win32' && this.arch === 'x64')
         && this.asset?.size > 0 && this.asset.size <= 2 * 1024 ** 3 && this.checksum?.size <= 65536

+ 14 - 0
desktop/update-manager.test.mjs

@@ -49,6 +49,20 @@ test('same version with a different commit and unsupported architectures never o
     assert.equal(f.calls.length, 0)
   } finally { await f.clean() }
 })
+test('Windows downloads an EXE using its platform checksum manifest', async () => {
+  const assetName = 'Yaoyao-0.4.2-win-x64-setup.exe'
+  const sums = Buffer.from(`${hash(data)}  ${assetName}\n`)
+  const f = await fixture({ platform: 'win32', arch: 'x64', fetchImpl: async url => new Response(url.endsWith('.exe') ? data : sums) })
+  try {
+    f.release.assets = [
+      { name: assetName, url: prefix + assetName, size: data.length },
+      { name: 'SHA256SUMS-win-x64.txt', url: prefix + 'SHA256SUMS-win-x64.txt', size: sums.length },
+    ]
+    assert.equal((await f.manager.check()).available, true)
+    assert.equal((await f.manager.download()).phase, 'ready')
+    assert.match(await f.manager.verifiedFile(), /win-x64-setup\.exe$/)
+  } finally { await f.clean() }
+})
 test('corrupt or missing checksum, wrong size, and failed image validation never expose a file', async () => {
   for (const failure of ['digest', 'size', 'checksum', 'image']) {
     const f = await fixture()