Skip to content

Instantly share code, notes, and snippets.

@AlexVallat
Last active September 5, 2020 15:29
Show Gist options
  • Save AlexVallat/de0fc4f0ccde42ee751865d66f81a2cf to your computer and use it in GitHub Desktop.
Save AlexVallat/de0fc4f0ccde42ee751865d66f81a2cf to your computer and use it in GitHub Desktop.
Unpacks electron.asar, patches it to insert an app.setPath('downloads',...) line to override the downloads path, then repacks it.
$DownloadLocation = "$env:TEMP\TeamsDownload"
$ErrorActionPreference = 'Stop'
$DownloadLocation = $DownloadLocation -replace '\\', '/' #Electron wants paths with /
$teamsElectronAsar = "$env:LOCALAPPDATA\Microsoft\Teams\current\resources\electron.asar"
$tempFolderPath = Join-Path $env:TEMP $(New-Guid)
New-Item -Type Directory -Path $tempFolderPath | Out-Null
Push-Location $tempFolderPath
npm install asar --no-fund --no-audit --no-progress --loglevel=error
.\node_modules\.bin\asar extract $teamsElectronAsar .\electron
(Get-Content .\electron\browser\init.js) -replace 'app.setAppPath.*', "app.setPath('downloads','$DownloadLocation')`n$&" | Set-Content .\electron\browser\init.js
Rename-Item $teamsElectronAsar -NewName "electron.asar.$(Get-Date -Format FileDateTime).bak"
.\node_modules\.bin\asar pack .\electron $teamsElectronAsar
Pop-Location
Remove-Item $tempFolderPath -Force -Recurse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment