Skip to content

Commit 4787c6d

Browse files
committed
Update xaml.ps1
1 parent eccf96a commit 4787c6d

File tree

1 file changed

+90
-78
lines changed

1 file changed

+90
-78
lines changed

Initialize/xaml.ps1

Lines changed: 90 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#===========================================================================
2-
#region initialize Runspace & Window
2+
#region initialize Runspace
33
#===========================================================================
44
# Max threads = number of logical processors
55
$MaxThreads = [int]$env:NUMBER_OF_PROCESSORS
@@ -11,10 +11,12 @@ $HashVars = New-Object System.Management.Automation.Runspaces.SessionStateVariab
1111
# Create the initial session state
1212
$InitialSessionState = [System.Management.Automation.Runspaces.InitialSessionState]::CreateDefault()
1313
$InitialSessionState.Variables.Add($HashVars)
14-
14+
#===========================================================================
15+
#endregion initialize Runspace
16+
#===========================================================================
1517

1618
# ================================
17-
# Function Injection
19+
#region Function Injection
1820
# ================================
1921

2022
# List of functions to include in the runspace environment
@@ -37,10 +39,25 @@ foreach ($Func in $Functions) {
3739
# Debug end
3840
}
3941
}
42+
# ================================
43+
#endregion Function Injection
44+
# ================================
45+
46+
# ================================
47+
#region Runspace Pool Creation
48+
# ================================
4049

50+
$itt.Runspace = [RunspaceFactory]::CreateRunspacePool(
51+
1, $MaxThreads, $InitialSessionState, $Host
52+
)
4153

54+
$itt.Runspace.Open()
4255
# ================================
43-
# UI Initialization
56+
#endregion Runspace Pool Creation
57+
# ================================
58+
59+
# ================================
60+
#region UI Windows Initialization
4461
# ================================
4562

4663
try {
@@ -54,18 +71,35 @@ catch {
5471
Write-Output "Error initializing UI: $($_.Exception.Message)"
5572
}
5673

74+
# ==================================
75+
#endregion UI Windows Initialization
76+
# ==================================
5777

58-
# ================================
59-
# Runspace Pool Creation
60-
# ================================
78+
#===========================================================================
79+
#region Initialize WPF Controls
80+
#===========================================================================
81+
# List Views
82+
$itt.CurrentList
83+
$itt.CurrentCategory
84+
$itt.TabControl = $itt["window"].FindName("taps")
85+
$itt.AppsListView = $itt["window"].FindName("AppsListView")
86+
$itt.TweaksListView = $itt["window"].FindName("TweaksListView")
87+
$itt.searchInput = $itt["window"].FindName("searchInput")
88+
$itt.SettingsListView = $itt["window"].FindName("SettingsList")
6189

62-
$itt.Runspace = [RunspaceFactory]::CreateRunspacePool(
63-
1, $MaxThreads, $InitialSessionState, $Host
64-
)
90+
# Buttons and Inputs
91+
$itt.Description = $itt["window"].FindName("description")
92+
$itt.Statusbar = $itt["window"].FindName("statusbar")
93+
$itt.InstallBtn = $itt["window"].FindName("installBtn")
94+
$itt.ApplyBtn = $itt["window"].FindName("applyBtn")
95+
$itt.installText = $itt["window"].FindName("installText")
96+
$itt.installIcon = $itt["window"].FindName("installIcon")
97+
$itt.applyText = $itt["window"].FindName("applyText")
98+
$itt.applyIcon = $itt["window"].FindName("applyIcon")
99+
$itt.QuoteIcon = $itt["window"].FindName("QuoteIcon")
65100

66-
$itt.Runspace.Open()
67101
#===========================================================================
68-
#endregion initialize Runspace & Window
102+
#endregion Initialize WPF Controls
69103
#===========================================================================
70104

71105
#===========================================================================
@@ -105,8 +139,52 @@ try {
105139
New-ItemProperty -Path $itt.registryPath -Name "locales" -Value "default" -PropertyType String -Force *> $Null
106140
New-ItemProperty -Path $itt.registryPath -Name "backup" -Value 0 -PropertyType DWORD -Force *> $Null
107141
New-ItemProperty -Path $itt.registryPath -Name "source" -Value "auto" -PropertyType String -Force *> $Null
142+
}
143+
144+
145+
#===========================================================================
146+
#region Fetch Data
147+
#===========================================================================
148+
$h = [System.Net.Http.HttpClientHandler]::new()
149+
$h.AutomaticDecompression = [System.Net.DecompressionMethods] 'GZip,Deflate'
150+
$c = [System.Net.Http.HttpClient]::new($h)
108151

152+
$appsUrl = "http://127.0.0.1:5500/static/Database/Applications.json"
153+
$tweaksUrl = "http://127.0.0.1:5500/static/Database/Tweaks.json"
154+
$localsUrl = "http://127.0.0.1:5500/static/Database/locales.json"
155+
156+
157+
while ($true) {
158+
try {
159+
$aTask, $tTask = $c.GetStringAsync($appsUrl), $c.GetStringAsync($tweaksUrl)
160+
[Threading.Tasks.Task]::WaitAll($aTask, $tTask)
161+
162+
$appsData = $aTask.Result | ConvertFrom-Json
163+
$tweaksData = $tTask.Result | ConvertFrom-Json
164+
#$localsUrl = $lTask.Result | ConvertFrom-Json
165+
166+
167+
if ($appsData -and $tweaksData) {
168+
$itt.AppsListView.ItemsSource = $appsData
169+
$itt.TweaksListView.ItemsSource = $tweaksData
170+
$splash.Close()
171+
break
172+
}
173+
else {
174+
Write-Host "Still loading data..." -ForegroundColor Yellow
175+
}
176+
}
177+
catch {
178+
Write-Host "Unstable internet connection detected. Retrying in 10 seconds..." -ForegroundColor Yellow
179+
}
180+
181+
Start-Sleep 10
109182
}
183+
#===========================================================================
184+
#endregion Fetch Data
185+
#===========================================================================
186+
187+
110188
#===========================================================================
111189
#region Set Language based on culture
112190
#===========================================================================
@@ -184,70 +262,4 @@ catch {
184262
}
185263
#===========================================================================
186264
#endregion Create default keys
187-
#===========================================================================
188-
189-
#===========================================================================
190-
#region Initialize WPF Controls
191-
#===========================================================================
192-
193-
# List Views
194-
$itt.CurrentList
195-
$itt.CurrentCategory
196-
$itt.TabControl = $itt["window"].FindName("taps")
197-
$itt.AppsListView = $itt["window"].FindName("AppsListView")
198-
$itt.TweaksListView = $itt["window"].FindName("TweaksListView")
199-
$itt.searchInput = $itt["window"].FindName("searchInput")
200-
$itt.SettingsListView = $itt["window"].FindName("SettingsList")
201-
202-
# Buttons and Inputs
203-
$itt.Description = $itt["window"].FindName("description")
204-
$itt.Statusbar = $itt["window"].FindName("statusbar")
205-
$itt.InstallBtn = $itt["window"].FindName("installBtn")
206-
$itt.ApplyBtn = $itt["window"].FindName("applyBtn")
207-
$itt.installText = $itt["window"].FindName("installText")
208-
$itt.installIcon = $itt["window"].FindName("installIcon")
209-
$itt.applyText = $itt["window"].FindName("applyText")
210-
$itt.applyIcon = $itt["window"].FindName("applyIcon")
211-
$itt.QuoteIcon = $itt["window"].FindName("QuoteIcon")
212-
213-
#===========================================================================
214-
#endregion Initialize WPF Controls
215-
#===========================================================================
216-
217-
#===========================================================================
218-
#region Fetch Data
219-
#===========================================================================
220-
$h = [System.Net.Http.HttpClientHandler]::new()
221-
$h.AutomaticDecompression = [System.Net.DecompressionMethods] 'GZip,Deflate'
222-
$c = [System.Net.Http.HttpClient]::new($h)
223-
224-
$appsUrl = "https://raw.githubusercontent.com/emadadeldev/ittea/refs/heads/main/static/Database/Applications.json"
225-
$tweaksUrl = "https://raw.githubusercontent.com/emadadeldev/ittea/refs/heads/main/static/Database/Tweaks.json"
226-
227-
while ($true) {
228-
try {
229-
$aTask, $tTask = $c.GetStringAsync($appsUrl), $c.GetStringAsync($tweaksUrl)
230-
[Threading.Tasks.Task]::WaitAll($aTask, $tTask)
231-
232-
$appsData = $aTask.Result | ConvertFrom-Json
233-
$tweaksData = $tTask.Result | ConvertFrom-Json
234-
235-
if ($appsData -and $tweaksData) {
236-
$itt.AppsListView.ItemsSource = $appsData
237-
$itt.TweaksListView.ItemsSource = $tweaksData
238-
$splash.Close()
239-
break
240-
}
241-
else {
242-
Write-Host "Still loading data..." -ForegroundColor Yellow
243-
}
244-
}
245-
catch {
246-
Write-Host "Unstable internet connection detected. Retrying in 10 seconds..." -ForegroundColor Yellow
247-
}
248-
249-
Start-Sleep 10
250-
}
251-
#===========================================================================
252-
#endregion Fetch Data
253265
#===========================================================================

0 commit comments

Comments
 (0)