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:
bao-qian
2016-05-02 22:37:01 +01:00
parent a7a34ac6b2
commit c6aff8424c
12 changed files with 65 additions and 14 deletions

View File

@@ -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>

View File

@@ -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;
}
}
}
}

View File

@@ -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();