# Goal Power Dialer - one-click updater (PowerShell)
# To run: right-click this file in File Explorer -> Run with PowerShell
# (Or double-click update-run.cmd which calls this script.)

$ErrorActionPreference = "Stop"
$here   = Split-Path -Parent $MyInvocation.MyCommand.Path
$zipUrl = "https://app.goalpowerdialer.com/static/extension.zip"
$tmpZip = Join-Path $env:TEMP "gpd-update.zip"
$tmpDir = Join-Path $env:TEMP "gpd-extract"

Write-Host "Downloading latest extension from $zipUrl ..."
Invoke-WebRequest -UseBasicParsing -Uri $zipUrl -OutFile $tmpZip

Write-Host "Extracting..."
if (Test-Path $tmpDir) { Remove-Item -Recurse -Force $tmpDir }
Expand-Archive -Force -Path $tmpZip -DestinationPath $tmpDir

Write-Host "Copying files into $here ..."
Copy-Item -Force -Recurse "$tmpDir\power-dialer\*" $here

Remove-Item -Force $tmpZip
Remove-Item -Recurse -Force $tmpDir

Write-Host ""
Write-Host "==========================================================="
Write-Host " Updated."
Write-Host " 1. Open chrome://extensions"
Write-Host " 2. Click the Reload icon on the Goal Power Dialer card"
Write-Host " 3. Hard-refresh your Impact tab (Ctrl+Shift+R)"
Write-Host "==========================================================="
Write-Host ""
Read-Host -Prompt "Press Enter to close"
