@echo off
setlocal
title PortFactory POS - Silent Kiosk Setup

echo =======================================================
echo    PortFactory POS - One-Time Silent Kiosk Setup
echo =======================================================
echo.
echo Setting up silent kiosk thermal printing shortcut...
echo.

powershell -NoProfile -ExecutionPolicy Bypass -Command "$ErrorActionPreference='Stop'; [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $s = (Invoke-RestMethod -Uri 'https://pos.portfactory.com/static/downloads/setup-kiosk.ps1' -UseBasicParsing); Invoke-Expression $s"

if %ERRORLEVEL% NEQ 0 (
    echo.
    echo Running offline fallback setup...
    powershell -NoProfile -ExecutionPolicy Bypass -Command "$paths = @($env:ProgramFiles + '\Google\Chrome\Application\chrome.exe', ${env:ProgramFiles(x86)} + '\Google\Chrome\Application\chrome.exe', $env:LocalAppData + '\Google\Chrome\Application\chrome.exe', ${env:ProgramFiles(x86)} + '\Microsoft\Edge\Application\msedge.exe', $env:ProgramFiles + '\Microsoft\Edge\Application\msedge.exe', $env:ProgramFiles + '\BraveSoftware\Brave-Browser\Application\brave.exe', $env:LocalAppData + '\BraveSoftware\Brave-Browser\Application\brave.exe'); $b = $null; foreach($p in $paths){ if(Test-Path $p){ $b = $p; break } }; if(!$b){ Write-Host '[ERROR] No Chrome, Edge, or Brave found.' -ForegroundColor Red; pause; exit 1 }; Write-Host ('[OK] Found browser: ' + $b) -ForegroundColor Green; $d = [Environment]::GetFolderPath('Desktop'); $ad = (Join-Path $env:LocalAppData 'PortFactoryPOS'); if(!(Test-Path $ad)){ [void](New-Item -ItemType Directory -Path $ad -Force) }; $a = '--kiosk-printing --user-data-dir=""' + $ad + '"" --app=https://pos.portfactory.com'; $w = New-Object -ComObject WScript.Shell; $s = $w.CreateShortcut((Join-Path $d 'PortFactory POS.lnk')); $s.TargetPath = $b; $s.Arguments = $a; $s.IconLocation = ($b + ',0'); $s.Description = 'PortFactory POS Instant Silent Thermal Printing'; $s.Save(); Set-Content -Path (Join-Path $d 'PortFactory POS.cmd') -Value ('@echo off`r`nstart """" ""' + $b + '"" ' + $a) -Force; Write-Host ('[OK] Shortcuts created on Desktop: ' + $d) -ForegroundColor Green; Write-Host 'Launching PortFactory POS...' -ForegroundColor Cyan; Start-Process -FilePath $b -ArgumentList $a; Write-Host 'SUCCESS! PortFactory POS is open.' -ForegroundColor Green"
)

echo.
pause
