mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 02:36:19 +02:00
Removing update logic from PowerLuanch App.xaml.cs as was done in Wox project.
This commit is contained in:
@@ -1,163 +1,141 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Timers;
|
using System.Timers;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using Wox;
|
using Wox;
|
||||||
using Wox.Core;
|
using Wox.Core;
|
||||||
using Wox.Core.Plugin;
|
using Wox.Core.Plugin;
|
||||||
using Wox.Core.Resource;
|
using Wox.Core.Resource;
|
||||||
using Wox.Helper;
|
using Wox.Helper;
|
||||||
using Wox.Infrastructure;
|
using Wox.Infrastructure;
|
||||||
using Wox.Infrastructure.Http;
|
using Wox.Infrastructure.Http;
|
||||||
using Wox.Infrastructure.Image;
|
using Wox.Infrastructure.Image;
|
||||||
using Wox.Infrastructure.Logger;
|
using Wox.Infrastructure.Logger;
|
||||||
using Wox.Infrastructure.UserSettings;
|
using Wox.Infrastructure.UserSettings;
|
||||||
using Wox.ViewModel;
|
using Wox.ViewModel;
|
||||||
using Stopwatch = Wox.Infrastructure.Stopwatch;
|
using Stopwatch = Wox.Infrastructure.Stopwatch;
|
||||||
|
|
||||||
namespace PowerLauncher
|
namespace PowerLauncher
|
||||||
{
|
{
|
||||||
public partial class App : IDisposable, ISingleInstanceApp
|
public partial class App : IDisposable, ISingleInstanceApp
|
||||||
{
|
{
|
||||||
public static PublicAPIInstance API { get; private set; }
|
public static PublicAPIInstance API { get; private set; }
|
||||||
private const string Unique = "Wox_Unique_Application_Mutex";
|
private const string Unique = "Wox_Unique_Application_Mutex";
|
||||||
private static bool _disposed;
|
private static bool _disposed;
|
||||||
private Settings _settings;
|
private Settings _settings;
|
||||||
private MainViewModel _mainVM;
|
private MainViewModel _mainVM;
|
||||||
private SettingWindowViewModel _settingsVM;
|
private SettingWindowViewModel _settingsVM;
|
||||||
private readonly Updater _updater = new Updater(PowerLauncher.Properties.Settings.Default.GithubRepo);
|
private readonly Alphabet _alphabet = new Alphabet();
|
||||||
private readonly Alphabet _alphabet = new Alphabet();
|
private StringMatcher _stringMatcher;
|
||||||
private StringMatcher _stringMatcher;
|
|
||||||
|
[STAThread]
|
||||||
[STAThread]
|
public static void Main()
|
||||||
public static void Main()
|
{
|
||||||
{
|
if (SingleInstance<App>.InitializeAsFirstInstance(Unique))
|
||||||
if (SingleInstance<App>.InitializeAsFirstInstance(Unique))
|
{
|
||||||
{
|
using (var application = new App())
|
||||||
using (var application = new App())
|
{
|
||||||
{
|
application.InitializeComponent();
|
||||||
application.InitializeComponent();
|
application.Run();
|
||||||
application.Run();
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
private void OnStartup(object sender, StartupEventArgs e)
|
||||||
private void OnStartup(object sender, StartupEventArgs e)
|
{
|
||||||
{
|
Stopwatch.Normal("|App.OnStartup|Startup cost", () =>
|
||||||
Stopwatch.Normal("|App.OnStartup|Startup cost", () =>
|
{
|
||||||
{
|
Log.Info("|App.OnStartup|Begin Wox startup ----------------------------------------------------");
|
||||||
Log.Info("|App.OnStartup|Begin Wox startup ----------------------------------------------------");
|
Log.Info($"|App.OnStartup|Runtime info:{ErrorReporting.RuntimeInfo()}");
|
||||||
Log.Info($"|App.OnStartup|Runtime info:{ErrorReporting.RuntimeInfo()}");
|
RegisterAppDomainExceptions();
|
||||||
RegisterAppDomainExceptions();
|
RegisterDispatcherUnhandledException();
|
||||||
RegisterDispatcherUnhandledException();
|
|
||||||
|
ImageLoader.Initialize();
|
||||||
ImageLoader.Initialize();
|
|
||||||
|
_settingsVM = new SettingWindowViewModel();
|
||||||
_settingsVM = new SettingWindowViewModel(_updater);
|
_settings = _settingsVM.Settings;
|
||||||
_settings = _settingsVM.Settings;
|
|
||||||
|
_alphabet.Initialize(_settings);
|
||||||
_alphabet.Initialize(_settings);
|
_stringMatcher = new StringMatcher(_alphabet);
|
||||||
_stringMatcher = new StringMatcher(_alphabet);
|
StringMatcher.Instance = _stringMatcher;
|
||||||
StringMatcher.Instance = _stringMatcher;
|
_stringMatcher.UserSettingSearchPrecision = _settings.QuerySearchPrecision;
|
||||||
_stringMatcher.UserSettingSearchPrecision = _settings.QuerySearchPrecision;
|
|
||||||
|
PluginManager.LoadPlugins(_settings.PluginSettings);
|
||||||
PluginManager.LoadPlugins(_settings.PluginSettings);
|
_mainVM = new MainViewModel(_settings);
|
||||||
_mainVM = new MainViewModel(_settings);
|
var window = new MainWindow(_settings, _mainVM);
|
||||||
var window = new MainWindow(_settings, _mainVM);
|
API = new PublicAPIInstance(_settingsVM, _mainVM, _alphabet);
|
||||||
API = new PublicAPIInstance(_settingsVM, _mainVM, _alphabet);
|
PluginManager.InitializePlugins(API);
|
||||||
PluginManager.InitializePlugins(API);
|
Log.Info($"|App.OnStartup|Dependencies Info:{ErrorReporting.DependenciesInfo()}");
|
||||||
Log.Info($"|App.OnStartup|Dependencies Info:{ErrorReporting.DependenciesInfo()}");
|
|
||||||
|
Current.MainWindow = window;
|
||||||
Current.MainWindow = window;
|
Current.MainWindow.Title = Constant.Wox;
|
||||||
Current.MainWindow.Title = Constant.Wox;
|
|
||||||
|
// happlebao todo temp fix for instance code logic
|
||||||
// happlebao todo temp fix for instance code logic
|
// load plugin before change language, because plugin language also needs be changed
|
||||||
// load plugin before change language, because plugin language also needs be changed
|
InternationalizationManager.Instance.Settings = _settings;
|
||||||
InternationalizationManager.Instance.Settings = _settings;
|
InternationalizationManager.Instance.ChangeLanguage(_settings.Language);
|
||||||
InternationalizationManager.Instance.ChangeLanguage(_settings.Language);
|
// main windows needs initialized before theme change because of blur settigns
|
||||||
// main windows needs initialized before theme change because of blur settigns
|
ThemeManager.Instance.Settings = _settings;
|
||||||
ThemeManager.Instance.Settings = _settings;
|
ThemeManager.Instance.ChangeTheme(_settings.Theme);
|
||||||
ThemeManager.Instance.ChangeTheme(_settings.Theme);
|
|
||||||
|
Http.Proxy = _settings.Proxy;
|
||||||
Http.Proxy = _settings.Proxy;
|
|
||||||
|
RegisterExitEvents();
|
||||||
RegisterExitEvents();
|
|
||||||
|
|
||||||
AutoStartup();
|
_mainVM.MainWindowVisibility = _settings.HideOnStartup ? Visibility.Hidden : Visibility.Visible;
|
||||||
AutoUpdates();
|
Log.Info("|App.OnStartup|End Wox startup ---------------------------------------------------- ");
|
||||||
|
|
||||||
_mainVM.MainWindowVisibility = _settings.HideOnStartup ? Visibility.Hidden : Visibility.Visible;
|
|
||||||
Log.Info("|App.OnStartup|End Wox startup ---------------------------------------------------- ");
|
|
||||||
});
|
//[Conditional("RELEASE")]
|
||||||
}
|
// check udpate every 5 hours
|
||||||
|
|
||||||
|
// check updates on startup
|
||||||
private void AutoStartup()
|
});
|
||||||
{
|
}
|
||||||
}
|
|
||||||
|
private void RegisterExitEvents()
|
||||||
//[Conditional("RELEASE")]
|
{
|
||||||
private void AutoUpdates()
|
AppDomain.CurrentDomain.ProcessExit += (s, e) => Dispose();
|
||||||
{
|
Current.Exit += (s, e) => Dispose();
|
||||||
Task.Run(async () =>
|
Current.SessionEnding += (s, e) => Dispose();
|
||||||
{
|
}
|
||||||
if (_settings.AutoUpdates)
|
|
||||||
{
|
/// <summary>
|
||||||
// check udpate every 5 hours
|
/// let exception throw as normal is better for Debug
|
||||||
var timer = new Timer(1000 * 60 * 60 * 5);
|
/// </summary>
|
||||||
timer.Elapsed += async (s, e) =>
|
[Conditional("RELEASE")]
|
||||||
{
|
private void RegisterDispatcherUnhandledException()
|
||||||
await _updater.UpdateApp();
|
{
|
||||||
};
|
DispatcherUnhandledException += ErrorReporting.DispatcherUnhandledException;
|
||||||
timer.Start();
|
}
|
||||||
|
|
||||||
// check updates on startup
|
|
||||||
await _updater.UpdateApp();
|
/// <summary>
|
||||||
}
|
/// let exception throw as normal is better for Debug
|
||||||
});
|
/// </summary>
|
||||||
}
|
[Conditional("RELEASE")]
|
||||||
|
private static void RegisterAppDomainExceptions()
|
||||||
private void RegisterExitEvents()
|
{
|
||||||
{
|
AppDomain.CurrentDomain.UnhandledException += ErrorReporting.UnhandledExceptionHandle;
|
||||||
AppDomain.CurrentDomain.ProcessExit += (s, e) => Dispose();
|
}
|
||||||
Current.Exit += (s, e) => Dispose();
|
|
||||||
Current.SessionEnding += (s, e) => Dispose();
|
public void Dispose()
|
||||||
}
|
{
|
||||||
|
// if sessionending is called, exit proverbially be called when log off / shutdown
|
||||||
/// <summary>
|
// but if sessionending is not called, exit won't be called when log off / shutdown
|
||||||
/// let exception throw as normal is better for Debug
|
if (!_disposed)
|
||||||
/// </summary>
|
{
|
||||||
[Conditional("RELEASE")]
|
API.SaveAppAllSettings();
|
||||||
private void RegisterDispatcherUnhandledException()
|
_disposed = true;
|
||||||
{
|
}
|
||||||
DispatcherUnhandledException += ErrorReporting.DispatcherUnhandledException;
|
}
|
||||||
}
|
|
||||||
|
public void OnSecondAppStarted()
|
||||||
|
{
|
||||||
/// <summary>
|
Current.MainWindow.Visibility = Visibility.Visible;
|
||||||
/// let exception throw as normal is better for Debug
|
}
|
||||||
/// </summary>
|
}
|
||||||
[Conditional("RELEASE")]
|
|
||||||
private static void RegisterAppDomainExceptions()
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user