diff --git a/src/modules/launcher/PowerLauncher/App.xaml.cs b/src/modules/launcher/PowerLauncher/App.xaml.cs index a0c6b6c612..4ffff7be8a 100644 --- a/src/modules/launcher/PowerLauncher/App.xaml.cs +++ b/src/modules/launcher/PowerLauncher/App.xaml.cs @@ -29,6 +29,7 @@ namespace PowerLauncher private static int _powerToysPid; private Settings _settings; private MainViewModel _mainVM; + private MainWindow _mainWindow; private SettingWindowViewModel _settingsVM; private readonly Alphabet _alphabet = new Alphabet(); private StringMatcher _stringMatcher; @@ -78,11 +79,11 @@ namespace PowerLauncher ThemeManager themeManager = new ThemeManager(this); PluginManager.LoadPlugins(_settings.PluginSettings); _mainVM = new MainViewModel(_settings); - var window = new MainWindow(_settings, _mainVM); + _mainWindow = new MainWindow(_settings, _mainVM); API = new PublicAPIInstance(_settingsVM, _mainVM, _alphabet); PluginManager.InitializePlugins(API); - Current.MainWindow = window; + Current.MainWindow = _mainWindow; Current.MainWindow.Title = Constant.ExeFileName; // happlebao todo temp fix for instance code logic @@ -161,20 +162,40 @@ namespace PowerLauncher AppDomain.CurrentDomain.UnhandledException += ErrorReporting.UnhandledExceptionHandle; } - public void Dispose() - { - // if sessionending is called, exit proverbially be called when log off / shutdown - // but if sessionending is not called, exit won't be called when log off / shutdown - if (!_disposed) - { - API.SaveAppAllSettings(); - _disposed = true; - } - } - public void OnSecondAppStarted() { Current.MainWindow.Visibility = Visibility.Visible; } + + protected virtual void Dispose(bool disposing) + { + if (!_disposed) + { + if (disposing) + { + _mainWindow.Dispose(); + API.SaveAppAllSettings(); + _disposed = true; + } + + // TODO: free unmanaged resources (unmanaged objects) and override finalizer + // TODO: set large fields to null + _disposed = true; + } + } + + // // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources + // ~App() + // { + // // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method + // Dispose(disposing: false); + // } + + public void Dispose() + { + // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method + Dispose(disposing: true); + GC.SuppressFinalize(this); + } } } \ No newline at end of file diff --git a/src/modules/launcher/PowerLauncher/MainWindow.xaml.cs b/src/modules/launcher/PowerLauncher/MainWindow.xaml.cs index 988391a5f1..186987da74 100644 --- a/src/modules/launcher/PowerLauncher/MainWindow.xaml.cs +++ b/src/modules/launcher/PowerLauncher/MainWindow.xaml.cs @@ -16,9 +16,10 @@ using System.Timers; using Microsoft.PowerLauncher.Telemetry; using Microsoft.PowerToys.Telemetry; + namespace PowerLauncher { - public partial class MainWindow + public partial class MainWindow : IDisposable { #region Private Fields @@ -268,6 +269,8 @@ namespace PowerLauncher private const int millisecondsToWait = 100; private static DateTime s_lastTimeOfTyping; + private bool disposedValue = false; + private string ListView_FirstItem(String input) { if (!string.IsNullOrEmpty(input)) @@ -356,5 +359,34 @@ namespace PowerLauncher { Hide(); } + + protected virtual void Dispose(bool disposing) + { + if (!disposedValue) + { + if (disposing) + { + _firstDeleteTimer.Dispose(); + } + + // TODO: free unmanaged resources (unmanaged objects) and override finalizer + // TODO: set large fields to null + disposedValue = true; + } + } + + // // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources + // ~MainWindow() + // { + // // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method + // Dispose(disposing: false); + // } + + public void Dispose() + { + // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method + Dispose(disposing: true); + GC.SuppressFinalize(this); + } } }