Save more

This commit is contained in:
bao-qian
2017-03-01 23:47:50 +00:00
parent 886e35477e
commit 6e3bc5e65d
3 changed files with 23 additions and 21 deletions

View File

@@ -22,6 +22,8 @@ namespace Wox
private const string Unique = "Wox_Unique_Application_Mutex";
private static bool _disposed;
private Settings _settings;
private MainViewModel _mainVM;
private SettingWindowViewModel _settingsVM;
[STAThread]
public static void Main()
@@ -48,13 +50,13 @@ namespace Wox
ImageLoader.Initialize();
Alphabet.Initialize();
var settingVM = new SettingWindowViewModel();
_settings = settingVM.Settings;
_settingsVM = new SettingWindowViewModel();
_settings = _settingsVM.Settings;
PluginManager.LoadPlugins(_settings.PluginSettings);
var mainVM = new MainViewModel(_settings);
var window = new MainWindow(_settings, mainVM);
API = new PublicAPIInstance(settingVM, mainVM);
_mainVM = new MainViewModel(_settings);
var window = new MainWindow(_settings, _mainVM);
API = new PublicAPIInstance(_settingsVM, _mainVM);
PluginManager.InitializePlugins(API);
Current.MainWindow = window;
@@ -75,7 +77,7 @@ namespace Wox
AutoStartup();
AutoUpdates();
mainVM.MainWindowVisibility = _settings.HideOnStartup ? Visibility.Hidden : Visibility.Visible;
_mainVM.MainWindowVisibility = _settings.HideOnStartup ? Visibility.Hidden : Visibility.Visible;
Log.Info("|App.OnStartup|End Wox startup ---------------------------------------------------- ");
});
}
@@ -98,16 +100,14 @@ namespace Wox
{
// check udpate every 5 hours
var timer = new Timer(1000 * 60 * 60 * 5);
timer.Elapsed += (s, e) =>
{
Updater.UpdateApp();
};
timer.Elapsed += (s, e) => { Updater.UpdateApp(); };
timer.Start();
// check updates on startup
Updater.UpdateApp();
}
}
private void RegisterExitEvents()
{
AppDomain.CurrentDomain.ProcessExit += (s, e) => Dispose();
@@ -125,19 +125,15 @@ namespace Wox
}
/// <summary>
/// let exception throw as normal is better for Debug
/// </summary>
[Conditional("RELEASE")]
private static void RegisterAppDomainExceptions()
{
AppDomain.CurrentDomain.UnhandledException += ErrorReporting.UnhandledExceptionHandle;
AppDomain.CurrentDomain.FirstChanceException += (s, e) =>
{
Log.Exception("|App.RegisterAppDomainExceptions|First Chance Exception:", e.Exception);
};
AppDomain.CurrentDomain.FirstChanceException +=
(s, e) => { Log.Exception("|App.RegisterAppDomainExceptions|First Chance Exception:", e.Exception); };
}
public void Dispose()
@@ -146,7 +142,8 @@ namespace Wox
// but if sessionending is not called, exit won't be called when log off / shutdown
if (!_disposed)
{
Current.Dispatcher.Invoke(() => ((MainViewModel)Current.MainWindow?.DataContext)?.Save());
_mainVM.Save();
_settingsVM.Save();
PluginManager.Save();
ImageLoader.Save();

View File

@@ -11,12 +11,10 @@ using Wox.Helper;
using Wox.Infrastructure.UserSettings;
using Wox.ViewModel;
using Screen = System.Windows.Forms.Screen;
using ContextMenu = System.Windows.Forms.ContextMenu;
using ContextMenuStrip = System.Windows.Forms.ContextMenuStrip;
using DataFormats = System.Windows.DataFormats;
using DragEventArgs = System.Windows.DragEventArgs;
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
using MenuItem = System.Windows.Forms.MenuItem;
using MessageBox = System.Windows.MessageBox;
using NotifyIcon = System.Windows.Forms.NotifyIcon;

View File

@@ -8,7 +8,9 @@ using Squirrel;
using Wox.Core.Plugin;
using Wox.Core.Resource;
using Wox.Helper;
using Wox.Infrastructure;
using Wox.Infrastructure.Hotkey;
using Wox.Infrastructure.Image;
using Wox.Plugin;
using Wox.ViewModel;
@@ -53,11 +55,16 @@ namespace Wox
public void RestarApp()
{
_mainVM.MainWindowVisibility = Visibility.Hidden;
// we must manually save
// UpdateManager.RestartApp() will call Environment.Exit(0)
// which will cause ungraceful exit
var vm = (MainViewModel) Application.Current.MainWindow.DataContext;
vm.Save();
_mainVM.Save();
_settingsVM.Save();
PluginManager.Save();
ImageLoader.Save();
Alphabet.Save();
UpdateManager.RestartApp();
}