Skip to content

Commit d4f186d

Browse files
committed
Update itt.ps1
1 parent 2005f4a commit d4f186d

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

itt.ps1

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3033,31 +3033,35 @@ $h.AutomaticDecompression = [System.Net.DecompressionMethods] 'GZip,Deflate'
30333033
$c = [System.Net.Http.HttpClient]::new($h)
30343034
$appsUrl = "https://raw.githubusercontent.com/emadadeldev/ittea/refs/heads/main/static/Database/Applications.json"
30353035
$tweaksUrl = "https://raw.githubusercontent.com/emadadeldev/ittea/refs/heads/main/static/Database/Tweaks.json"
3036-
while ($true) {
3036+
function Get-JsonFromUrl($url) {
30373037
try {
3038-
Write-Host "[i] Fetching data from GitHub..." -ForegroundColor Cyan
3039-
$aTask, $tTask = $c.GetStringAsync($appsUrl), $c.GetStringAsync($tweaksUrl)
3040-
[Threading.Tasks.Task]::WaitAll($aTask, $tTask)
3041-
$appsRaw = [System.Text.Encoding]::UTF8.GetString([System.Text.Encoding]::UTF8.GetBytes($aTask.Result)).Trim([char]0xFEFF)
3042-
$tweaksRaw = [System.Text.Encoding]::UTF8.GetString([System.Text.Encoding]::UTF8.GetBytes($tTask.Result)).Trim([char]0xFEFF)
3043-
$appsData = $appsRaw | ConvertFrom-Json
3044-
$tweaksData = $tweaksRaw | ConvertFrom-Json
3038+
$response = $c.GetAsync($url).Result
3039+
if (-not $response.IsSuccessStatusCode) {
3040+
throw "HTTP $($response.StatusCode)"
3041+
}
3042+
$bytes = $response.Content.ReadAsByteArrayAsync().Result
3043+
$jsonString = [System.Text.Encoding]::UTF8.GetString($bytes).Trim([char]0xFEFF)
3044+
return ($jsonString | ConvertFrom-Json)
3045+
}
3046+
catch {
3047+
Write-Host "[x] Failed to load $url -> $($_.Exception.Message)" -ForegroundColor Red
3048+
return $null
3049+
}
3050+
}
3051+
while ($true) {
3052+
$appsData = Get-JsonFromUrl $appsUrl
3053+
$tweaksData = Get-JsonFromUrl $tweaksUrl
30453054
if ($appsData -and $tweaksData) {
30463055
$itt.AppsListView.ItemsSource = $appsData
30473056
$itt.TweaksListView.ItemsSource = $tweaksData
30483057
Write-Host "[✓] Data loaded successfully." -ForegroundColor Green
30493058
break
30503059
}
30513060
else {
3052-
Write-Host "[!] Data not ready, retrying..." -ForegroundColor Yellow
3053-
}
3054-
}
3055-
catch {
3056-
Write-Host "[x] Error: $($_.Exception.Message)" -ForegroundColor Red
30573061
Write-Host "[!] Retrying in 8 seconds..." -ForegroundColor Yellow
3058-
}
30593062
Start-Sleep 8
30603063
}
3064+
}
30613065
$MainXaml.SelectNodes("//*[@Name]") | ForEach-Object {
30623066
$name = $_.Name
30633067
$element = $itt["window"].FindName($name)

0 commit comments

Comments
 (0)