Skip to content

Commit

Permalink
fix(win): Windows update fails for custom paths that require admin ri…
Browse files Browse the repository at this point in the history
  • Loading branch information
hvuntokrul committed Jul 24, 2021
1 parent 72ffc25 commit 45fc0a0
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions packages/electron-updater/src/BaseUpdater.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import fs from 'fs';
import path from 'path';
import { AllPublishOptions } from "builder-util-runtime"
import { AppAdapter } from "./AppAdapter"
import { AppUpdater, DownloadExecutorTask } from "./AppUpdater"
Expand Down Expand Up @@ -55,12 +57,24 @@ export abstract class BaseUpdater extends AppUpdater {
this.quitAndInstallCalled = true

try {
this._logger.info(`Install: isSilent: ${isSilent}, isForceRunAfter: ${isForceRunAfter}`)
let installPathRequiresElevation = false
if (process.platform === "win32") {
try {
const accessTestPath = path.join(path.dirname(process.execPath), `access-${Math.floor(Math.random() * 100)}.tmp`)
fs.writeFileSync(accessTestPath, " ")
fs.rmSync(accessTestPath)
} catch(err) {
// Require admin rights if needed
installPathRequiresElevation = true
}
}

this._logger.info(`Install: isSilent: ${isSilent}, isForceRunAfter: ${isForceRunAfter}, installPathRequiresElevation: ${installPathRequiresElevation}`)
return this.doInstall({
installerPath,
isSilent,
isForceRunAfter,
isAdminRightsRequired: downloadedFileInfo.isAdminRightsRequired,
isAdminRightsRequired: installPathRequiresElevation || downloadedFileInfo.isAdminRightsRequired,
})
} catch (e) {
this.dispatchError(e)
Expand Down

0 comments on commit 45fc0a0

Please sign in to comment.