Skip to content

Commit 81a34fc

Browse files
committed
fix: repair url path in local file manager
1 parent cc61452 commit 81a34fc

2 files changed

Lines changed: 56 additions & 18 deletions

File tree

TelegramDownloader/Pages/Partials/impl/FileManagerImpl.razor

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,19 @@
204204
fm.Path = "/";
205205
await fm.RefreshFilesAsync();
206206
}
207+
208+
// Navigate to path from URL after components are rendered
209+
if (_pendingPathNavigation)
210+
{
211+
_pendingPathNavigation = false;
212+
// Small delay to ensure components are fully initialized
213+
await Task.Delay(100);
214+
await NavigateToPathFromUrl();
215+
}
207216
}
208217

218+
private bool _pendingPathNavigation = false;
219+
209220
private async Task DetectMobileView()
210221
{
211222
try
@@ -229,10 +240,8 @@
229240
finally
230241
{
231242
_viewportDetected = true;
243+
_pendingPathNavigation = true;
232244
StateHasChanged();
233-
234-
// After viewport is detected, navigate to path from URL if present
235-
await NavigateToPathFromUrl();
236245
}
237246
}
238247

@@ -244,15 +253,25 @@
244253
var query = System.Web.HttpUtility.ParseQueryString(uri.Query);
245254
var pathFromUrl = query["path"];
246255

247-
if (!string.IsNullOrEmpty(pathFromUrl) && mobileFileManager != null)
248-
{
249-
// Decode the path and ensure it ends with /
250-
var decodedPath = Uri.UnescapeDataString(pathFromUrl);
251-
if (!decodedPath.EndsWith("/"))
252-
decodedPath += "/";
256+
if (string.IsNullOrEmpty(pathFromUrl))
257+
return;
258+
259+
// Decode the path and ensure it ends with /
260+
var decodedPath = Uri.UnescapeDataString(pathFromUrl);
261+
if (!decodedPath.EndsWith("/"))
262+
decodedPath += "/";
253263

264+
// Handle mobile file manager
265+
if (_isMobileView && mobileFileManager != null)
266+
{
254267
await mobileFileManager.NavigateToPathSilent(decodedPath);
255268
}
269+
// Handle desktop file manager
270+
else if (!_isMobileView && fm != null)
271+
{
272+
fm.Path = decodedPath;
273+
await fm.RefreshFilesAsync();
274+
}
256275
}
257276
catch (Exception ex)
258277
{

TelegramDownloader/Pages/Partials/impl/LocalFileManagerImpl.razor

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,15 @@
185185
}
186186

187187
}
188+
189+
// Navigate to path from URL after components are rendered
190+
if (_pendingPathNavigation)
191+
{
192+
_pendingPathNavigation = false;
193+
// Small delay to ensure components are fully initialized
194+
await Task.Delay(100);
195+
await NavigateToPathFromUrl();
196+
}
188197
}
189198

190199
private async Task DetectMobileView()
@@ -210,13 +219,13 @@
210219
finally
211220
{
212221
_viewportDetected = true;
222+
_pendingPathNavigation = true;
213223
StateHasChanged();
214-
215-
// After viewport is detected, navigate to path from URL if present
216-
await NavigateToPathFromUrl();
217224
}
218225
}
219226

227+
private bool _pendingPathNavigation = false;
228+
220229
private async Task NavigateToPathFromUrl()
221230
{
222231
try
@@ -225,15 +234,25 @@
225234
var query = HttpUtility.ParseQueryString(uri.Query);
226235
var pathFromUrl = query["path"];
227236

228-
if (!string.IsNullOrEmpty(pathFromUrl) && mobileFileManager != null)
229-
{
230-
// Decode the path and ensure it ends with /
231-
var decodedPath = Uri.UnescapeDataString(pathFromUrl);
232-
if (!decodedPath.EndsWith("/"))
233-
decodedPath += "/";
237+
if (string.IsNullOrEmpty(pathFromUrl))
238+
return;
234239

240+
// Decode the path and ensure it ends with /
241+
var decodedPath = Uri.UnescapeDataString(pathFromUrl);
242+
if (!decodedPath.EndsWith("/"))
243+
decodedPath += "/";
244+
245+
// Handle mobile file manager
246+
if (_isMobileView && mobileFileManager != null)
247+
{
235248
await mobileFileManager.NavigateToPathSilent(decodedPath);
236249
}
250+
// Handle desktop file manager
251+
else if (!_isMobileView && FileManager != null)
252+
{
253+
FileManager.Path = decodedPath;
254+
await FileManager.RefreshFilesAsync();
255+
}
237256
}
238257
catch (Exception ex)
239258
{

0 commit comments

Comments
 (0)