diff --git a/src/Files.App/App.xaml.cs b/src/Files.App/App.xaml.cs index f7d8cb49fca2..06ead247de72 100644 --- a/src/Files.App/App.xaml.cs +++ b/src/Files.App/App.xaml.cs @@ -160,7 +160,7 @@ async Task ActivateAsync() public async Task OnActivatedAsync(AppActivationArguments activatedEventArgs) { var activatedEventArgsData = activatedEventArgs.Data; - + // Logger may not be initialized yet due to race condition during startup if (Logger is not null) Logger.LogInformation($"The app is being activated. Activation type: {activatedEventArgsData.GetType().Name}"); @@ -175,6 +175,8 @@ await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(() /// private void Window_Activated(object sender, WindowActivatedEventArgs args) { + Logger.LogInformation($"Window_Activated: State={args?.WindowActivationState.ToString()}"); + AppModel.IsMainWindowClosed = false; // TODO(s): Is this code still needed? diff --git a/src/Files.App/Helpers/LogPathHelper.cs b/src/Files.App/Helpers/LogPathHelper.cs new file mode 100644 index 000000000000..86b6354a86b2 --- /dev/null +++ b/src/Files.App/Helpers/LogPathHelper.cs @@ -0,0 +1,45 @@ +// Copyright (c) Files Community +// Licensed under the MIT License. + +using System.IO; + +namespace Files.App.Helpers +{ + /// + /// Provides helper methods for formatting paths in logs. + /// + public static class LogPathHelper + { + public static string GetFileName(string? path) + { + if (string.IsNullOrEmpty(path)) + return "[Empty]"; + + try + { + return Path.GetFileName(path) ?? "?"; + } + catch + { + return "?"; + } + } + + public static string GetDirectoryName(string? path) + { + if (string.IsNullOrEmpty(path)) + return "[Empty]"; + + try + { + // Trim trailing separators to ensure we get the last directory name + var trimmedPath = path.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); + return Path.GetFileName(trimmedPath) ?? "?"; + } + catch + { + return "?"; + } + } + } +} diff --git a/src/Files.App/ViewModels/ShellViewModel.cs b/src/Files.App/ViewModels/ShellViewModel.cs index e5bd26e0a617..d32c70065a9d 100644 --- a/src/Files.App/ViewModels/ShellViewModel.cs +++ b/src/Files.App/ViewModels/ShellViewModel.cs @@ -1694,6 +1694,8 @@ private async Task RapidAddItemsToCollectionAsync(string? path, LibraryItem? lib public void CloseWatcher() { + App.Logger.LogInformation($"CloseWatcher: aProcessQueueAction={aProcessQueueAction?.Status.ToString()}, gitProcessQueueAction={gitProcessQueueAction?.Status.ToString()}"); + watcher?.Dispose(); watcher = null; @@ -2771,6 +2773,8 @@ public void CancelSearch() public void UpdateDateDisplay(bool isFormatChange) { + App.Logger.LogDebug($"UpdateDateDisplay: isFormatChange={isFormatChange}, itemCount={filesAndFolders?.Count}"); + filesAndFolders.ToList().AsParallel().ForAll(async item => { // Reassign values to update date display @@ -2792,6 +2796,8 @@ public void UpdateDateDisplay(bool isFormatChange) public void Dispose() { CancelLoadAndClearFiles(); + App.Logger.LogInformation($"ShellViewModel.Dispose: CurrentFolder={LogPathHelper.GetDirectoryName(CurrentFolder?.ItemPath)}"); + StorageTrashBinService.Watcher.ItemAdded -= RecycleBinItemCreatedAsync; StorageTrashBinService.Watcher.ItemDeleted -= RecycleBinItemDeletedAsync; StorageTrashBinService.Watcher.RefreshRequested -= RecycleBinRefreshRequestedAsync; diff --git a/src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs b/src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs index 2fec9e72573a..fc119b6efc82 100644 --- a/src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs +++ b/src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs @@ -115,7 +115,13 @@ public bool ShowCloudItemButton public UIElement PreviewPaneContent { get => previewPaneContent; - set => SetProperty(ref previewPaneContent, value); + set + { + var oldType = previewPaneContent?.GetType()?.Name; + var newType = value?.GetType()?.Name; + App.Logger.LogDebug($"PreviewPaneContent changing: {oldType} -> {newType}"); + SetProperty(ref previewPaneContent, value); + } } public bool LoadTagsList diff --git a/src/Files.App/ViewModels/UserControls/Previews/ShellPreviewViewModel.cs b/src/Files.App/ViewModels/UserControls/Previews/ShellPreviewViewModel.cs index 233b514b6996..15986549fcd8 100644 --- a/src/Files.App/ViewModels/UserControls/Previews/ShellPreviewViewModel.cs +++ b/src/Files.App/ViewModels/UserControls/Previews/ShellPreviewViewModel.cs @@ -1,7 +1,9 @@ // Copyright (c) Files Community // Licensed under the MIT License. +using Files.App.Helpers; using Files.App.ViewModels.Properties; +using Microsoft.Extensions.Logging; using Microsoft.UI.Content; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Hosting; @@ -127,6 +129,8 @@ private unsafe LRESULT WndProc(HWND hwnd, uint msg, WPARAM wParam, LPARAM lParam public unsafe void LoadPreview(UIElement presenter) { + App.Logger.LogInformation($"ShellPreview.LoadPreview: Item={LogPathHelper.GetFileName(Item?.ItemPath)}"); + var parent = MainWindow.Instance.WindowHandle; var hInst = PInvoke.GetModuleHandle(default(PWSTR)); var szClassName = $"{nameof(ShellPreviewViewModel)}-{Guid.NewGuid()}"; @@ -251,7 +255,13 @@ private unsafe bool ChildWindowToXaml(nint parent, UIElement presenter) public void UnloadPreview() { if (_hWnd != HWND.Null) + { PInvoke.DestroyWindow(_hWnd); + App.Logger.LogInformation($"ShellPreview.UnloadPreview: HWND={((nint)_hWnd)}, Item={LogPathHelper.GetFileName(Item?.ItemPath)}"); + } + else + App.Logger.LogInformation($"ShellPreview.UnloadPreview: HWND=, Item={LogPathHelper.GetFileName(Item?.ItemPath)}"); + _contentExternalOutputLink?.Dispose(); _contentExternalOutputLink = null; diff --git a/src/Files.App/Views/MainPage.xaml.cs b/src/Files.App/Views/MainPage.xaml.cs index 02fe6b441a07..0835decaca56 100644 --- a/src/Files.App/Views/MainPage.xaml.cs +++ b/src/Files.App/Views/MainPage.xaml.cs @@ -313,6 +313,8 @@ private void UpdateDateDisplayTimer_Tick(object sender, object e) { if (!App.AppModel.IsMainWindowClosed) InfoPane?.ViewModel.UpdateDateDisplay(); + else + App.Logger.LogWarning("UpdateDateDisplayTimer_Tick: Timer firing after window closed!"); } private void Page_SizeChanged(object sender, SizeChangedEventArgs e) diff --git a/src/Files.App/Views/ShellPanesPage.xaml.cs b/src/Files.App/Views/ShellPanesPage.xaml.cs index 293e61616f42..879ea628048c 100644 --- a/src/Files.App/Views/ShellPanesPage.xaml.cs +++ b/src/Files.App/Views/ShellPanesPage.xaml.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using Files.App.Controls; +using Microsoft.Extensions.Logging; using Microsoft.UI.Input; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; @@ -766,6 +767,8 @@ private void NotifyPropertyChanged([CallerMemberName] string propertyName = "") public void Dispose() { + App.Logger.LogInformation($"ShellPanesPage.Dispose: PaneCount={GetPaneCount()}, ActivePane={LogPathHelper.GetDirectoryName(ActivePane?.TabBarItemParameter?.NavigationParameter?.ToString())}"); + MainWindow.Instance.SizeChanged -= MainWindow_SizeChanged; // Dispose panes