From 93ea9382e38a7e356dc1dce6a8af11f35034c7ac Mon Sep 17 00:00:00 2001 From: hishitetsu <66369541+hishitetsu@users.noreply.github.com> Date: Wed, 23 Aug 2023 12:02:12 +0900 Subject: [PATCH 01/14] Cache main window --- src/Files.App/MainWindow.xaml | 1 + src/Files.App/MainWindow.xaml.cs | 26 ++++++++++++++++++- src/Files.App/Program.cs | 13 ++++++++++ .../Settings/GeneralSettingsService.cs | 6 +++++ src/Files.App/Strings/en-US/Resources.resw | 3 +++ .../ViewModels/Settings/AdvancedViewModel.cs | 14 ++++++++++ .../Views/Settings/AdvancedPage.xaml | 11 ++++++++ .../Settings/IGeneralSettingsService.cs | 5 ++++ 8 files changed, 78 insertions(+), 1 deletion(-) diff --git a/src/Files.App/MainWindow.xaml b/src/Files.App/MainWindow.xaml index 54015a29c704..77e69a29cd9e 100644 --- a/src/Files.App/MainWindow.xaml +++ b/src/Files.App/MainWindow.xaml @@ -6,4 +6,5 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:winuiex="using:WinUIEx" + Closed="MainWindow_Closed" mc:Ignorable="d" /> diff --git a/src/Files.App/MainWindow.xaml.cs b/src/Files.App/MainWindow.xaml.cs index 3dc0aa7315b9..95128bbb217b 100644 --- a/src/Files.App/MainWindow.xaml.cs +++ b/src/Files.App/MainWindow.xaml.cs @@ -4,11 +4,11 @@ using Files.App.UserControls.MultitaskingControl; using Microsoft.UI; using Microsoft.UI.Windowing; +using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Media.Animation; using Microsoft.UI.Xaml.Navigation; using System.IO; -using System.Runtime.InteropServices; using Windows.ApplicationModel; using Windows.ApplicationModel.Activation; using Windows.Storage; @@ -285,5 +285,29 @@ async Task PerformNavigation(string payload, string selectItem = null) } } } + + private void MainWindow_Closed(object sender, WindowEventArgs args) + { + if (!Ioc.Default.GetRequiredService()?.GeneralSettingsService.LeaveAppRunning ?? true) + return; + + AppWindow.Hide(); + + // Save and clear all tabs + App.SaveSessionTabs(); + MainPageViewModel.AppInstances.ForEach(tabItem => tabItem.Unload()); + MainPageViewModel.AppInstances.Clear(); + + args.Handled = true; + Program.Pool = new(0, 1, "Files-Instance"); + Thread.Yield(); + if (Program.Pool.WaitOne()) + { + Program.Pool.Dispose(); + AppWindow.Show(); + Activate(); + EnsureWindowIsInitialized().Navigate(typeof(MainPage), null, new SuppressNavigationTransitionInfo()); + } + } } } diff --git a/src/Files.App/Program.cs b/src/Files.App/Program.cs index 31fbf6c315fa..6e3b9b6a2016 100644 --- a/src/Files.App/Program.cs +++ b/src/Files.App/Program.cs @@ -14,6 +14,19 @@ namespace Files.App { internal class Program { + public static Semaphore Pool; + + static Program() + { + Pool = new(0, 1, "Files-Instance", out var isNew); + if (!isNew) + { + Pool.Release(); + Environment.Exit(0); + } + Pool.Dispose(); + } + // Note: // We can't declare Main to be async because in a WinUI app // This prevents Narrator from reading XAML elements diff --git a/src/Files.App/Services/Settings/GeneralSettingsService.cs b/src/Files.App/Services/Settings/GeneralSettingsService.cs index 9b1a8d05f9d7..e5f34f10ba10 100644 --- a/src/Files.App/Services/Settings/GeneralSettingsService.cs +++ b/src/Files.App/Services/Settings/GeneralSettingsService.cs @@ -208,6 +208,12 @@ public bool ShowOpenInNewPane set => Set(value); } + public bool LeaveAppRunning + { + get => Get(false); + set => Set(value); + } + public FileNameConflictResolveOptionType ConflictsResolveOption { get => (FileNameConflictResolveOptionType)Get((long)FileNameConflictResolveOptionType.GenerateNewName); diff --git a/src/Files.App/Strings/en-US/Resources.resw b/src/Files.App/Strings/en-US/Resources.resw index 34c02fa84c1b..6045b7e2f870 100644 --- a/src/Files.App/Strings/en-US/Resources.resw +++ b/src/Files.App/Strings/en-US/Resources.resw @@ -3447,4 +3447,7 @@ Due to platform limitations, drag and drop isn't available when running Files as administrator. + + Leave app running in the background when the window is closed + \ No newline at end of file diff --git a/src/Files.App/ViewModels/Settings/AdvancedViewModel.cs b/src/Files.App/ViewModels/Settings/AdvancedViewModel.cs index 2991c5469b6c..1949c1417b54 100644 --- a/src/Files.App/ViewModels/Settings/AdvancedViewModel.cs +++ b/src/Files.App/ViewModels/Settings/AdvancedViewModel.cs @@ -297,6 +297,20 @@ public bool CanOpenOnWindowsStartup set => SetProperty(ref canOpenOnWindowsStartup, value); } + public bool LeaveAppRunning + { + get => UserSettingsService.GeneralSettingsService.LeaveAppRunning; + set + { + if (value != UserSettingsService.GeneralSettingsService.LeaveAppRunning) + { + UserSettingsService.GeneralSettingsService.LeaveAppRunning = value; + + OnPropertyChanged(); + } + } + } + public async Task OpenFilesOnWindowsStartup() { var stateMode = await ReadState(); diff --git a/src/Files.App/Views/Settings/AdvancedPage.xaml b/src/Files.App/Views/Settings/AdvancedPage.xaml index 72f67ea6d68e..6ae3e10728df 100644 --- a/src/Files.App/Views/Settings/AdvancedPage.xaml +++ b/src/Files.App/Views/Settings/AdvancedPage.xaml @@ -98,6 +98,17 @@ + + + + + + + + bool ShowSendToMenu { get; set; } + /// + /// Gets or sets a value indicating whether or not to leave app running in the background. + /// + bool LeaveAppRunning { get; set; } + /// /// Gets or sets a value indicating the default option to resolve conflicts. /// From 6e509cd3468c121bfa33c6f1eb0633861a7a7c00 Mon Sep 17 00:00:00 2001 From: hishitetsu <66369541+hishitetsu@users.noreply.github.com> Date: Wed, 23 Aug 2023 19:52:34 +0900 Subject: [PATCH 02/14] Update --- src/Files.App/App.xaml.cs | 26 +++++++++++++++++++ .../Multitasking/MultitaskingContext.cs | 6 ++--- src/Files.App/Data/Models/AppModel.cs | 18 +++++-------- src/Files.App/MainWindow.xaml | 1 - src/Files.App/MainWindow.xaml.cs | 26 +------------------ 5 files changed, 35 insertions(+), 42 deletions(-) diff --git a/src/Files.App/App.xaml.cs b/src/Files.App/App.xaml.cs index 0005b87a43cb..f7774ec30322 100644 --- a/src/Files.App/App.xaml.cs +++ b/src/Files.App/App.xaml.cs @@ -21,6 +21,7 @@ using Microsoft.Extensions.Logging; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Media.Animation; using Microsoft.Windows.AppLifecycle; using System.IO; using System.Text; @@ -300,6 +301,31 @@ private async void Window_Closed(object sender, WindowEventArgs args) return; } + if (Ioc.Default.GetRequiredService().GeneralSettingsService.LeaveAppRunning) + { + // Cache the window istead of closing it + MainWindow.Instance.AppWindow.Hide(); + args.Handled = true; + + // Save and close all tabs + SaveSessionTabs(); + MainPageViewModel.AppInstances.ForEach(tabItem => tabItem.Unload()); + MainPageViewModel.AppInstances.Clear(); + await Task.Delay(100); + + Program.Pool = new(0, 1, "Files-Instance"); + Thread.Yield(); + if (Program.Pool.WaitOne()) + { + Program.Pool.Dispose(); + MainWindow.Instance.AppWindow.Show(); + MainWindow.Instance.Activate(); + MainWindow.Instance.EnsureWindowIsInitialized().Navigate(typeof(MainPage), null, new SuppressNavigationTransitionInfo()); + } + + return; + } + // Method can take a long time, make sure the window is hidden await Task.Yield(); diff --git a/src/Files.App/Data/Contexts/Multitasking/MultitaskingContext.cs b/src/Files.App/Data/Contexts/Multitasking/MultitaskingContext.cs index 3dd85e43e55c..3611cc0b8044 100644 --- a/src/Files.App/Data/Contexts/Multitasking/MultitaskingContext.cs +++ b/src/Files.App/Data/Contexts/Multitasking/MultitaskingContext.cs @@ -1,13 +1,10 @@ // Copyright (c) 2023 Files Community // Licensed under the MIT License. See the LICENSE. -using CommunityToolkit.Mvvm.ComponentModel; using Files.App.UserControls.MultitaskingControl; -using Files.App.ViewModels; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Input; using System.Collections.Specialized; -using System.ComponentModel; namespace Files.App.Data.Contexts { @@ -46,7 +43,8 @@ private void AppInstances_CollectionChanged(object? sender, NotifyCollectionChan } private void AppModel_PropertyChanged(object? sender, PropertyChangedEventArgs e) { - UpdateCurrentTabIndex(); + if (e.PropertyName is nameof(AppModel.TabStripSelectedIndex)) + UpdateCurrentTabIndex(); } private void BaseMultitaskingControl_OnLoaded(object? sender, IMultitaskingControl control) { diff --git a/src/Files.App/Data/Models/AppModel.cs b/src/Files.App/Data/Models/AppModel.cs index 07ca46926daa..5d6585cca232 100644 --- a/src/Files.App/Data/Models/AppModel.cs +++ b/src/Files.App/Data/Models/AppModel.cs @@ -33,19 +33,13 @@ public int TabStripSelectedIndex get => tabStripSelectedIndex; set { - if (value >= 0) - { - if (tabStripSelectedIndex != value) - { - SetProperty(ref tabStripSelectedIndex, value); - } + SetProperty(ref tabStripSelectedIndex, value); - if (value < MainPageViewModel.AppInstances.Count) - { - Frame rootFrame = (Frame)MainWindow.Instance.Content; - var mainView = (MainPage)rootFrame.Content; - mainView.ViewModel.SelectedTabItem = MainPageViewModel.AppInstances[value]; - } + if (value >= 0 && value < MainPageViewModel.AppInstances.Count) + { + Frame rootFrame = (Frame)MainWindow.Instance.Content; + var mainView = (MainPage)rootFrame.Content; + mainView.ViewModel.SelectedTabItem = MainPageViewModel.AppInstances[value]; } } } diff --git a/src/Files.App/MainWindow.xaml b/src/Files.App/MainWindow.xaml index 77e69a29cd9e..54015a29c704 100644 --- a/src/Files.App/MainWindow.xaml +++ b/src/Files.App/MainWindow.xaml @@ -6,5 +6,4 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:winuiex="using:WinUIEx" - Closed="MainWindow_Closed" mc:Ignorable="d" /> diff --git a/src/Files.App/MainWindow.xaml.cs b/src/Files.App/MainWindow.xaml.cs index 95128bbb217b..4109bddadbf4 100644 --- a/src/Files.App/MainWindow.xaml.cs +++ b/src/Files.App/MainWindow.xaml.cs @@ -176,7 +176,7 @@ public async Task InitializeApplication(object activatedEventArgs) rootFrame.Navigate(typeof(MainPage), null, new SuppressNavigationTransitionInfo()); } - private Frame EnsureWindowIsInitialized() + public Frame EnsureWindowIsInitialized() { // NOTE: // Do not repeat app initialization when the Window already has content, @@ -285,29 +285,5 @@ async Task PerformNavigation(string payload, string selectItem = null) } } } - - private void MainWindow_Closed(object sender, WindowEventArgs args) - { - if (!Ioc.Default.GetRequiredService()?.GeneralSettingsService.LeaveAppRunning ?? true) - return; - - AppWindow.Hide(); - - // Save and clear all tabs - App.SaveSessionTabs(); - MainPageViewModel.AppInstances.ForEach(tabItem => tabItem.Unload()); - MainPageViewModel.AppInstances.Clear(); - - args.Handled = true; - Program.Pool = new(0, 1, "Files-Instance"); - Thread.Yield(); - if (Program.Pool.WaitOne()) - { - Program.Pool.Dispose(); - AppWindow.Show(); - Activate(); - EnsureWindowIsInitialized().Navigate(typeof(MainPage), null, new SuppressNavigationTransitionInfo()); - } - } } } From 6b7d8515e3997a973572ff662e8d7fd3efdcd24b Mon Sep 17 00:00:00 2001 From: hishitetsu <66369541+hishitetsu@users.noreply.github.com> Date: Wed, 23 Aug 2023 22:15:39 +0900 Subject: [PATCH 03/14] Fix properties window freeze --- src/Files.App/App.xaml.cs | 5 ++++- .../Storage/Helpers/FilePropertiesHelpers.cs | 22 ++++++++++++++++++- .../Properties/MainPropertiesPage.xaml.cs | 15 +++++-------- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/Files.App/App.xaml.cs b/src/Files.App/App.xaml.cs index f7774ec30322..c07b25692caf 100644 --- a/src/Files.App/App.xaml.cs +++ b/src/Files.App/App.xaml.cs @@ -41,7 +41,7 @@ public partial class App : Application private static bool ShowErrorNotification = false; public static string OutputPath { get; set; } public static CommandBarFlyout? LastOpenedFlyout { get; set; } - public static TaskCompletionSource? SplashScreenLoadingTCS { get; set; } + public static TaskCompletionSource? SplashScreenLoadingTCS { get; private set; } public static StorageHistoryWrapper HistoryWrapper { get; } = new(); public static AppModel AppModel { get; private set; } @@ -313,6 +313,9 @@ private async void Window_Closed(object sender, WindowEventArgs args) MainPageViewModel.AppInstances.Clear(); await Task.Delay(100); + // Wait for all properties windows to close + await FilePropertiesHelpers.WaitClosingAll(); + Program.Pool = new(0, 1, "Files-Instance"); Thread.Yield(); if (Program.Pool.WaitOne()) diff --git a/src/Files.App/Utils/Storage/Helpers/FilePropertiesHelpers.cs b/src/Files.App/Utils/Storage/Helpers/FilePropertiesHelpers.cs index 5dfbf15d4eff..fa9915450952 100644 --- a/src/Files.App/Utils/Storage/Helpers/FilePropertiesHelpers.cs +++ b/src/Files.App/Utils/Storage/Helpers/FilePropertiesHelpers.cs @@ -31,6 +31,8 @@ public static class FilePropertiesHelpers public static nint GetWindowHandle(Window w) => WinRT.Interop.WindowNative.GetWindowHandle(w); + private static int WindowCount = 0; + private static TaskCompletionSource? PropertiesWindowsClosingTCS; private static BlockingCollection WindowCache = new(); /// @@ -140,8 +142,10 @@ public static void OpenPropertiesWindow(object item, IShellPage associatedInstan + Math.Max(0, Math.Min(displayArea.WorkArea.Height - appWindow.Size.Height, pointerPosition.Y - displayArea.WorkArea.Y)), }; - appWindow.Move(appWindowPos); + if (Interlocked.Increment(ref WindowCount) == 1) + PropertiesWindowsClosingTCS = new(); + appWindow.Move(appWindowPos); appWindow.Show(); } @@ -156,9 +160,19 @@ private static void PropertiesWindow_Closed(object sender, WindowEventArgs args) window.AppWindow.Hide(); window.Content = null; WindowCache.Add(window); + + if (Interlocked.Decrement(ref WindowCount) == 0) + { + PropertiesWindowsClosingTCS!.TrySetResult(); + PropertiesWindowsClosingTCS = null; + } } } + /// + /// Destroy all cached properties windows + /// + /// public static void DestroyCachedWindows() { while (WindowCache.TryTake(out var window)) @@ -167,5 +181,11 @@ public static void DestroyCachedWindows() window.Close(); } } + + /// + /// Returns task to wait for all properties windows to close + /// + /// Task to wait + public static Task WaitClosingAll() => PropertiesWindowsClosingTCS?.Task ?? Task.CompletedTask; } } diff --git a/src/Files.App/Views/Properties/MainPropertiesPage.xaml.cs b/src/Files.App/Views/Properties/MainPropertiesPage.xaml.cs index f59fdc1b93aa..b8f2233ea386 100644 --- a/src/Files.App/Views/Properties/MainPropertiesPage.xaml.cs +++ b/src/Files.App/Views/Properties/MainPropertiesPage.xaml.cs @@ -1,11 +1,6 @@ // Copyright (c) 2023 Files Community // Licensed under the MIT License. See the LICENSE. -using CommunityToolkit.Mvvm.DependencyInjection; -using CommunityToolkit.WinUI; -using Files.App.Data.Parameters; -using Files.App.Helpers; -using Files.App.ViewModels; using Files.App.ViewModels.Properties; using Microsoft.UI; using Microsoft.UI.Windowing; @@ -13,8 +8,6 @@ using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Input; using Microsoft.UI.Xaml.Navigation; -using System; -using System.Threading.Tasks; using Windows.System; using Windows.UI; @@ -45,9 +38,6 @@ protected override void OnNavigatedTo(NavigationEventArgs e) AppWindow = parameter.AppWindow; Window = parameter.Window; - AppSettings = Ioc.Default.GetRequiredService(); - AppSettings.ThemeModeChanged += AppSettings_ThemeModeChanged; - base.OnNavigatedTo(e); MainPropertiesViewModel = new(Window, AppWindow, MainContentFrame, BaseProperties, parameter); @@ -55,6 +45,8 @@ protected override void OnNavigatedTo(NavigationEventArgs e) private void Page_Loaded(object sender, RoutedEventArgs e) { + AppSettings = Ioc.Default.GetRequiredService(); + AppSettings.ThemeModeChanged += AppSettings_ThemeModeChanged; Window.Closed += Window_Closed; UpdatePageLayout(); @@ -89,6 +81,9 @@ private void UpdatePageLayout() private async void AppSettings_ThemeModeChanged(object? sender, EventArgs e) { + if (Parent is null) + return; + await DispatcherQueue.EnqueueOrInvokeAsync(() => { ((Frame)Parent).RequestedTheme = ThemeHelper.RootTheme; From 025bb2b6320ca04048168fc69f378450722b0b99 Mon Sep 17 00:00:00 2001 From: hishitetsu <66369541+hishitetsu@users.noreply.github.com> Date: Wed, 23 Aug 2023 23:54:31 +0900 Subject: [PATCH 04/14] Cache one window only --- src/Files.App/App.xaml.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Files.App/App.xaml.cs b/src/Files.App/App.xaml.cs index c07b25692caf..c3a7fa52ca3a 100644 --- a/src/Files.App/App.xaml.cs +++ b/src/Files.App/App.xaml.cs @@ -301,7 +301,8 @@ private async void Window_Closed(object sender, WindowEventArgs args) return; } - if (Ioc.Default.GetRequiredService().GeneralSettingsService.LeaveAppRunning) + if (Ioc.Default.GetRequiredService().GeneralSettingsService.LeaveAppRunning && + !Process.GetProcessesByName("Files").Any(x => x.Id != Process.GetCurrentProcess().Id)) { // Cache the window istead of closing it MainWindow.Instance.AppWindow.Hide(); From a85f61844992893b36aa8b80e6f548259d2413fe Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Wed, 23 Aug 2023 17:38:20 -0400 Subject: [PATCH 05/14] Close open content dialogs --- src/Files.App/App.xaml.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Files.App/App.xaml.cs b/src/Files.App/App.xaml.cs index c3a7fa52ca3a..f23bbd3b9a52 100644 --- a/src/Files.App/App.xaml.cs +++ b/src/Files.App/App.xaml.cs @@ -21,6 +21,7 @@ using Microsoft.Extensions.Logging; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Media; using Microsoft.UI.Xaml.Media.Animation; using Microsoft.Windows.AppLifecycle; using System.IO; @@ -317,6 +318,12 @@ private async void Window_Closed(object sender, WindowEventArgs args) // Wait for all properties windows to close await FilePropertiesHelpers.WaitClosingAll(); + // Close open content dialogs + var contentDialogs = VisualTreeHelper.GetOpenPopups(Window.Current); + foreach (var popup in contentDialogs) + if (popup.Child is ContentDialog) + ((ContentDialog)popup.Child).Hide(); + Program.Pool = new(0, 1, "Files-Instance"); Thread.Yield(); if (Program.Pool.WaitOne()) From 6017c7e41e62578d65366f0b0daab37400c443e7 Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Wed, 23 Aug 2023 17:41:31 -0400 Subject: [PATCH 06/14] Default to true --- src/Files.App/Services/Settings/GeneralSettingsService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Files.App/Services/Settings/GeneralSettingsService.cs b/src/Files.App/Services/Settings/GeneralSettingsService.cs index e5f34f10ba10..c9b4119eca3f 100644 --- a/src/Files.App/Services/Settings/GeneralSettingsService.cs +++ b/src/Files.App/Services/Settings/GeneralSettingsService.cs @@ -210,7 +210,7 @@ public bool ShowOpenInNewPane public bool LeaveAppRunning { - get => Get(false); + get => Get(true); set => Set(value); } From 1704bcc22ec4d133852d47080232e56b773c3bfc Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Wed, 23 Aug 2023 17:45:20 -0400 Subject: [PATCH 07/14] Update App.xaml.cs --- src/Files.App/App.xaml.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Files.App/App.xaml.cs b/src/Files.App/App.xaml.cs index f23bbd3b9a52..9d54497cc55e 100644 --- a/src/Files.App/App.xaml.cs +++ b/src/Files.App/App.xaml.cs @@ -305,6 +305,12 @@ private async void Window_Closed(object sender, WindowEventArgs args) if (Ioc.Default.GetRequiredService().GeneralSettingsService.LeaveAppRunning && !Process.GetProcessesByName("Files").Any(x => x.Id != Process.GetCurrentProcess().Id)) { + // Close open content dialogs + var contentDialogs = VisualTreeHelper.GetOpenPopups(Window.Current); + foreach (var popup in contentDialogs) + if (popup.Child is ContentDialog) + ((ContentDialog)popup.Child).Hide(); + // Cache the window istead of closing it MainWindow.Instance.AppWindow.Hide(); args.Handled = true; @@ -318,12 +324,6 @@ private async void Window_Closed(object sender, WindowEventArgs args) // Wait for all properties windows to close await FilePropertiesHelpers.WaitClosingAll(); - // Close open content dialogs - var contentDialogs = VisualTreeHelper.GetOpenPopups(Window.Current); - foreach (var popup in contentDialogs) - if (popup.Child is ContentDialog) - ((ContentDialog)popup.Child).Hide(); - Program.Pool = new(0, 1, "Files-Instance"); Thread.Yield(); if (Program.Pool.WaitOne()) From 0d87a6011796056dbc38691dae3639703698da3e Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Wed, 23 Aug 2023 17:49:44 -0400 Subject: [PATCH 08/14] Update App.xaml.cs --- src/Files.App/App.xaml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Files.App/App.xaml.cs b/src/Files.App/App.xaml.cs index 9d54497cc55e..78278eeadfac 100644 --- a/src/Files.App/App.xaml.cs +++ b/src/Files.App/App.xaml.cs @@ -306,7 +306,7 @@ private async void Window_Closed(object sender, WindowEventArgs args) !Process.GetProcessesByName("Files").Any(x => x.Id != Process.GetCurrentProcess().Id)) { // Close open content dialogs - var contentDialogs = VisualTreeHelper.GetOpenPopups(Window.Current); + var contentDialogs = VisualTreeHelper.GetOpenPopups(MainWindow.Instance); foreach (var popup in contentDialogs) if (popup.Child is ContentDialog) ((ContentDialog)popup.Child).Hide(); From e4bf47648b208e902e0b8c5bae990ff53f98fb07 Mon Sep 17 00:00:00 2001 From: hishitetsu <66369541+hishitetsu@users.noreply.github.com> Date: Thu, 24 Aug 2023 08:33:23 +0900 Subject: [PATCH 09/14] App Center --- src/Files.App/Services/Settings/GeneralSettingsService.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Files.App/Services/Settings/GeneralSettingsService.cs b/src/Files.App/Services/Settings/GeneralSettingsService.cs index c9b4119eca3f..641091bb1d82 100644 --- a/src/Files.App/Services/Settings/GeneralSettingsService.cs +++ b/src/Files.App/Services/Settings/GeneralSettingsService.cs @@ -260,6 +260,7 @@ protected override void RaiseOnSettingChangedEvent(object sender, SettingChanged case nameof(ShowOpenInNewTab): case nameof(ShowOpenInNewWindow): case nameof(ShowOpenInNewPane): + case nameof(LeaveAppRunning): case nameof(ConflictsResolveOption): case nameof(ShowHashesDictionary): Analytics.TrackEvent($"Set {e.SettingName} to {e.NewValue}"); From fe069653eb4ac660c8cfafaa8f598edfd330aae8 Mon Sep 17 00:00:00 2001 From: hishitetsu <66369541+hishitetsu@users.noreply.github.com> Date: Thu, 24 Aug 2023 11:03:04 +0900 Subject: [PATCH 10/14] Check for updates --- src/Files.App/App.xaml.cs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Files.App/App.xaml.cs b/src/Files.App/App.xaml.cs index 78278eeadfac..5b1fe6c8e6eb 100644 --- a/src/Files.App/App.xaml.cs +++ b/src/Files.App/App.xaml.cs @@ -178,12 +178,7 @@ await Task.WhenAll( FileTagsHelper.UpdateTagsDb(); }); - // Check for required updates - var updateService = Ioc.Default.GetRequiredService(); - await updateService.CheckForUpdates(); - await updateService.DownloadMandatoryUpdates(); - await updateService.CheckAndUpdateFilesLauncherAsync(); - await updateService.CheckLatestReleaseNotesAsync(); + await CheckForRequiredUpdates(); static async Task OptionalTask(Task task, bool condition) { @@ -192,6 +187,15 @@ static async Task OptionalTask(Task task, bool condition) } } + private static async Task CheckForRequiredUpdates() + { + var updateService = Ioc.Default.GetRequiredService(); + await updateService.CheckForUpdates(); + await updateService.DownloadMandatoryUpdates(); + await updateService.CheckAndUpdateFilesLauncherAsync(); + await updateService.CheckLatestReleaseNotesAsync(); + } + /// /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. @@ -331,6 +335,9 @@ private async void Window_Closed(object sender, WindowEventArgs args) Program.Pool.Dispose(); MainWindow.Instance.AppWindow.Show(); MainWindow.Instance.Activate(); + + _ = CheckForRequiredUpdates(); + MainWindow.Instance.EnsureWindowIsInitialized().Navigate(typeof(MainPage), null, new SuppressNavigationTransitionInfo()); } From 2a4ebdb457970773627111183c1602fed3e57775 Mon Sep 17 00:00:00 2001 From: hishitetsu <66369541+hishitetsu@users.noreply.github.com> Date: Thu, 24 Aug 2023 11:16:00 +0900 Subject: [PATCH 11/14] Fix close open content dialogs --- src/Files.App/App.xaml.cs | 6 ++---- src/Files.App/Helpers/UI/UIHelpers.cs | 12 +----------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/src/Files.App/App.xaml.cs b/src/Files.App/App.xaml.cs index 5b1fe6c8e6eb..ddeb8a3be6c1 100644 --- a/src/Files.App/App.xaml.cs +++ b/src/Files.App/App.xaml.cs @@ -3,6 +3,7 @@ using CommunityToolkit.WinUI.Helpers; using CommunityToolkit.WinUI.Notifications; +using Files.App.Helpers; using Files.App.Services.DateTimeFormatter; using Files.App.Services.Settings; using Files.App.Storage.FtpStorage; @@ -310,10 +311,7 @@ private async void Window_Closed(object sender, WindowEventArgs args) !Process.GetProcessesByName("Files").Any(x => x.Id != Process.GetCurrentProcess().Id)) { // Close open content dialogs - var contentDialogs = VisualTreeHelper.GetOpenPopups(MainWindow.Instance); - foreach (var popup in contentDialogs) - if (popup.Child is ContentDialog) - ((ContentDialog)popup.Child).Hide(); + UIHelpers.CloseAllDialogs(); // Cache the window istead of closing it MainWindow.Instance.AppWindow.Hide(); diff --git a/src/Files.App/Helpers/UI/UIHelpers.cs b/src/Files.App/Helpers/UI/UIHelpers.cs index 6a5fad871b5e..83dce59f37f0 100644 --- a/src/Files.App/Helpers/UI/UIHelpers.cs +++ b/src/Files.App/Helpers/UI/UIHelpers.cs @@ -2,20 +2,10 @@ // Licensed under the MIT License. See the LICENSE. using CommunityToolkit.WinUI.Notifications; -using Files.App.Extensions; -using Files.App.Utils.Shell; -using Files.Core.ViewModels.Dialogs; -using Files.Shared; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Media; using Microsoft.UI.Xaml.Media.Imaging; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Diagnostics; using System.IO; -using System.Linq; -using System.Threading.Tasks; using Windows.UI.Notifications; namespace Files.App.Helpers @@ -130,7 +120,7 @@ private static ContentDialog SetContentDialogRoot(ContentDialog contentDialog) public static void CloseAllDialogs() { - var openedDialogs = VisualTreeHelper.GetOpenPopups(MainWindow.Instance); + var openedDialogs = VisualTreeHelper.GetOpenPopupsForXamlRoot(MainWindow.Instance.Content.XamlRoot); foreach (var item in openedDialogs) { From 68867e2b80dfb69b888e452992a51db88742d7fa Mon Sep 17 00:00:00 2001 From: hishitetsu <66369541+hishitetsu@users.noreply.github.com> Date: Thu, 24 Aug 2023 11:17:03 +0900 Subject: [PATCH 12/14] Fix typo Co-authored-by: Yair <39923744+yaira2@users.noreply.github.com> --- src/Files.App/App.xaml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Files.App/App.xaml.cs b/src/Files.App/App.xaml.cs index ddeb8a3be6c1..b330d8f1c442 100644 --- a/src/Files.App/App.xaml.cs +++ b/src/Files.App/App.xaml.cs @@ -313,7 +313,7 @@ private async void Window_Closed(object sender, WindowEventArgs args) // Close open content dialogs UIHelpers.CloseAllDialogs(); - // Cache the window istead of closing it + // Cache the window instead of closing it MainWindow.Instance.AppWindow.Hide(); args.Handled = true; From a9474f130fe221ecd8dd1d31ab4453600ab6f4f3 Mon Sep 17 00:00:00 2001 From: hishitetsu <66369541+hishitetsu@users.noreply.github.com> Date: Thu, 24 Aug 2023 11:22:55 +0900 Subject: [PATCH 13/14] Added comments --- src/Files.App/App.xaml.cs | 2 ++ src/Files.App/Program.cs | 1 + 2 files changed, 3 insertions(+) diff --git a/src/Files.App/App.xaml.cs b/src/Files.App/App.xaml.cs index ddeb8a3be6c1..cd00ff2d0c5b 100644 --- a/src/Files.App/App.xaml.cs +++ b/src/Files.App/App.xaml.cs @@ -326,10 +326,12 @@ private async void Window_Closed(object sender, WindowEventArgs args) // Wait for all properties windows to close await FilePropertiesHelpers.WaitClosingAll(); + // Sleep current instance Program.Pool = new(0, 1, "Files-Instance"); Thread.Yield(); if (Program.Pool.WaitOne()) { + // Resume the instance Program.Pool.Dispose(); MainWindow.Instance.AppWindow.Show(); MainWindow.Instance.Activate(); diff --git a/src/Files.App/Program.cs b/src/Files.App/Program.cs index 6e3b9b6a2016..81be191d6cc6 100644 --- a/src/Files.App/Program.cs +++ b/src/Files.App/Program.cs @@ -21,6 +21,7 @@ static Program() Pool = new(0, 1, "Files-Instance", out var isNew); if (!isNew) { + // Resume cached instance Pool.Release(); Environment.Exit(0); } From b9a1f5db675a81f2325c4d87258c8102a829b42d Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Thu, 24 Aug 2023 10:12:51 -0400 Subject: [PATCH 14/14] Update src/Files.App/Views/Settings/AdvancedPage.xaml --- src/Files.App/Views/Settings/AdvancedPage.xaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Files.App/Views/Settings/AdvancedPage.xaml b/src/Files.App/Views/Settings/AdvancedPage.xaml index 6ae3e10728df..bc1dda4d903c 100644 --- a/src/Files.App/Views/Settings/AdvancedPage.xaml +++ b/src/Files.App/Views/Settings/AdvancedPage.xaml @@ -101,7 +101,7 @@ - +