refactor: enable updater on Windows only if uninstaller is found

This commit is contained in:
purocean
2024-07-02 22:21:48 +08:00
parent acad1415ed
commit 2e40ca9fee
+13 -1
View File
@@ -1,5 +1,7 @@
import type { RequestOptions } from 'http'
import { dialog, app, shell } from 'electron'
import { dirname } from 'path'
import { readdirSync } from 'fs'
import { autoUpdater, CancellationToken, UpdateInfo } from 'electron-updater'
import { resolveFiles } from 'electron-updater/out/providers/Provider'
import { GitHubProvider } from 'electron-updater/out/providers/GitHubProvider'
@@ -20,7 +22,7 @@ autoUpdater.logger = logger
let progressBar: any = null
const isAppx = app.getAppPath().indexOf('\\WindowsApps\\') > -1
const disabled = isAppx || (process as any).mas
let disabled = isAppx || (process as any).mas
class UpdateProvider extends GitHubProvider {
constructor (options: any, updater: any, runtimeOptions: any) {
@@ -87,6 +89,16 @@ const init = (call?: () => void) => {
return
}
if (process.platform === 'win32') {
const fileList = readdirSync(dirname(app.getPath('exe')))
const hasUninstall = fileList.some(x => x.includes('Uninstall'))
if (!hasUninstall) {
disabled = true
console.log('updater >', 'No uninstaller found, updater disabled')
return
}
}
autoUpdater.setFeedURL({ provider: 'custom', owner: 'purocean', repo: 'yn', updateProvider: UpdateProvider as any })
autoUpdater.autoDownload = false