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

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