mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 11:46:30 +02:00
Save when exit
1. fix image cache 2. fix save when exit since destructor won't be called 3. fix #583 #582 (partially) #581 (partially) #580
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
<Application x:Class="Wox.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Exit="OnExit"
|
||||
SessionEnding="OnSessionEnding">
|
||||
<Application.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
|
||||
@@ -13,11 +13,12 @@ using Stopwatch = Wox.Infrastructure.Stopwatch;
|
||||
|
||||
namespace Wox
|
||||
{
|
||||
public partial class App : Application, ISingleInstanceApp
|
||||
public partial class App : ISingleInstanceApp
|
||||
{
|
||||
private const string Unique = "Wox_Unique_Application_Mutex";
|
||||
public static MainWindow Window { get; private set; }
|
||||
public static PublicAPIInstance API { get; private set; }
|
||||
private bool _saved;
|
||||
|
||||
[STAThread]
|
||||
public static void Main()
|
||||
@@ -71,5 +72,29 @@ namespace Wox
|
||||
CommandArgsFactory.Execute(args);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnExit(object sender, ExitEventArgs e)
|
||||
{
|
||||
Save();
|
||||
}
|
||||
|
||||
private void OnSessionEnding(object sender, SessionEndingCancelEventArgs e)
|
||||
{
|
||||
Save();
|
||||
}
|
||||
|
||||
private void Save()
|
||||
{
|
||||
// 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 (!_saved)
|
||||
{
|
||||
var vm = (MainViewModel) Window.DataContext;
|
||||
vm.Save();
|
||||
PluginManager.Save();
|
||||
ImageLoader.Save();
|
||||
_saved = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ using Wox.Storage;
|
||||
|
||||
namespace Wox.ViewModel
|
||||
{
|
||||
public class MainViewModel : BaseViewModel
|
||||
public class MainViewModel : BaseViewModel, ISavable
|
||||
{
|
||||
#region Private Fields
|
||||
|
||||
@@ -81,7 +81,7 @@ namespace Wox.ViewModel
|
||||
InitializeKeyCommands();
|
||||
}
|
||||
|
||||
~MainViewModel()
|
||||
public void Save()
|
||||
{
|
||||
_settingsStorage.Save();
|
||||
_queryHistoryStorage.Save();
|
||||
|
||||
Reference in New Issue
Block a user