$ErrorActionPreference = "Stop" $repositoryPath = "D:\Main-Repository-V2\Main-Repository-V2" $heartbeatUrl = "https://git.seed2action.org/api/connector/heartbeat" $installDir = Join-Path $env:ProgramData "Seed2Action\GitConnector" if (-not (Test-Path $repositoryPath -PathType Container)) { throw "Authorized repository folder was not found: $repositoryPath" } if (-not (Get-Command git -ErrorAction SilentlyContinue)) { throw "Git is not installed or is not available in PATH." } if (-not (Get-Command node -ErrorAction SilentlyContinue)) { throw "Node.js is not installed or is not available in PATH." } New-Item -Path $installDir -ItemType Directory -Force | Out-Null Copy-Item (Join-Path $PSScriptRoot "Seed2ActionConnectorDaemon.mjs") (Join-Path $installDir "Seed2ActionConnectorDaemon.mjs") -Force Copy-Item (Join-Path $PSScriptRoot "Seed2ActionDaemonLauncher.vbs") (Join-Path $installDir "Seed2ActionDaemonLauncher.vbs") -Force Copy-Item (Join-Path $PSScriptRoot "Seed2ActionConnector.ps1") (Join-Path $installDir "Seed2ActionConnector.ps1") -Force @{ RepositoryPath=$repositoryPath; HeartbeatUrl=$heartbeatUrl } | ConvertTo-Json | Set-Content (Join-Path $installDir "config.json") # Clean up any legacy recurring polling tasks (stop the 90-second cycle) Unregister-ScheduledTask -TaskName "Seed2Action Connector Periodic" -Confirm:$false -ErrorAction SilentlyContinue | Out-Null Unregister-ScheduledTask -TaskName "Seed2Action Periodic Connector" -Confirm:$false -ErrorAction SilentlyContinue | Out-Null # Only prompt for token if credential.dat does not already exist if (-not (Test-Path (Join-Path $installDir "credential.dat"))) { $token = Read-Host "Paste a Gitea personal access token with read:user permission" -AsSecureString $token | ConvertFrom-SecureString | Set-Content (Join-Path $installDir "credential.dat") -NoNewline } # Install Scheduled Task to start the silent daemon once at logon (zero recurring console popups) $action = New-ScheduledTaskAction -Execute "wscript.exe" -Argument "`"$installDir\Seed2ActionDaemonLauncher.vbs`"" $trigger = New-ScheduledTaskTrigger -AtLogOn $principal = New-ScheduledTaskPrincipal -UserId ([System.Security.Principal.WindowsIdentity]::GetCurrent().Name) -LogonType Interactive -RunLevel Limited $settings = New-ScheduledTaskSettingsSet -MultipleInstances IgnoreNew -ExecutionTimeLimit (New-TimeSpan -Days 365) -StartWhenAvailable Register-ScheduledTask -TaskName "Seed2Action Git Connector" -Action $action -Trigger $trigger -Principal $principal -Settings $settings -Force | Out-Null # Launch the daemon now silently Start-Process -FilePath "wscript.exe" -ArgumentList "`"$installDir\Seed2ActionDaemonLauncher.vbs`"" -WindowStyle Hidden Write-Host "Seed2Action desktop connector daemon installed on 127.0.0.1:43127 and running silently." -ForegroundColor Green Write-Host "Recurring 90-second polling tasks removed. The daemon operates on-demand with zero recurring console popups." -ForegroundColor Cyan