From a98cbc3a9da3e96b42c710bbaf2622c30cd5aeaf Mon Sep 17 00:00:00 2001 From: ryanbodrug-microsoft <56318517+ryanbodrug-microsoft@users.noreply.github.com> Date: Tue, 7 Apr 2020 14:39:12 -0700 Subject: [PATCH] Removing update logic from PowerLuanch App.xaml.cs as was done in Wox project. --- .../launcher/PowerLauncher/App.xaml.cs | 302 ++++++++---------- 1 file changed, 140 insertions(+), 162 deletions(-) diff --git a/src/modules/launcher/PowerLauncher/App.xaml.cs b/src/modules/launcher/PowerLauncher/App.xaml.cs index 09c7646fcb..86d1da4532 100644 --- a/src/modules/launcher/PowerLauncher/App.xaml.cs +++ b/src/modules/launcher/PowerLauncher/App.xaml.cs @@ -1,163 +1,141 @@ -using System; -using System.Diagnostics; -using System.Threading.Tasks; -using System.Timers; -using System.Windows; -using Wox; -using Wox.Core; -using Wox.Core.Plugin; -using Wox.Core.Resource; -using Wox.Helper; -using Wox.Infrastructure; -using Wox.Infrastructure.Http; -using Wox.Infrastructure.Image; -using Wox.Infrastructure.Logger; -using Wox.Infrastructure.UserSettings; -using Wox.ViewModel; -using Stopwatch = Wox.Infrastructure.Stopwatch; - -namespace PowerLauncher -{ - public partial class App : IDisposable, ISingleInstanceApp - { - public static PublicAPIInstance API { get; private set; } - private const string Unique = "Wox_Unique_Application_Mutex"; - private static bool _disposed; - private Settings _settings; - private MainViewModel _mainVM; - private SettingWindowViewModel _settingsVM; - private readonly Updater _updater = new Updater(PowerLauncher.Properties.Settings.Default.GithubRepo); - private readonly Alphabet _alphabet = new Alphabet(); - private StringMatcher _stringMatcher; - - [STAThread] - public static void Main() - { - if (SingleInstance.InitializeAsFirstInstance(Unique)) - { - using (var application = new App()) - { - application.InitializeComponent(); - application.Run(); - } - } - } - - private void OnStartup(object sender, StartupEventArgs e) - { - Stopwatch.Normal("|App.OnStartup|Startup cost", () => - { - Log.Info("|App.OnStartup|Begin Wox startup ----------------------------------------------------"); - Log.Info($"|App.OnStartup|Runtime info:{ErrorReporting.RuntimeInfo()}"); - RegisterAppDomainExceptions(); - RegisterDispatcherUnhandledException(); - - ImageLoader.Initialize(); - - _settingsVM = new SettingWindowViewModel(_updater); - _settings = _settingsVM.Settings; - - _alphabet.Initialize(_settings); - _stringMatcher = new StringMatcher(_alphabet); - StringMatcher.Instance = _stringMatcher; - _stringMatcher.UserSettingSearchPrecision = _settings.QuerySearchPrecision; - - PluginManager.LoadPlugins(_settings.PluginSettings); - _mainVM = new MainViewModel(_settings); - var window = new MainWindow(_settings, _mainVM); - API = new PublicAPIInstance(_settingsVM, _mainVM, _alphabet); - PluginManager.InitializePlugins(API); - Log.Info($"|App.OnStartup|Dependencies Info:{ErrorReporting.DependenciesInfo()}"); - - Current.MainWindow = window; - Current.MainWindow.Title = Constant.Wox; - - // happlebao todo temp fix for instance code logic - // load plugin before change language, because plugin language also needs be changed - InternationalizationManager.Instance.Settings = _settings; - InternationalizationManager.Instance.ChangeLanguage(_settings.Language); - // main windows needs initialized before theme change because of blur settigns - ThemeManager.Instance.Settings = _settings; - ThemeManager.Instance.ChangeTheme(_settings.Theme); - - Http.Proxy = _settings.Proxy; - - RegisterExitEvents(); - - AutoStartup(); - AutoUpdates(); - - _mainVM.MainWindowVisibility = _settings.HideOnStartup ? Visibility.Hidden : Visibility.Visible; - Log.Info("|App.OnStartup|End Wox startup ---------------------------------------------------- "); - }); - } - - - private void AutoStartup() - { - } - - //[Conditional("RELEASE")] - private void AutoUpdates() - { - Task.Run(async () => - { - if (_settings.AutoUpdates) - { - // check udpate every 5 hours - var timer = new Timer(1000 * 60 * 60 * 5); - timer.Elapsed += async (s, e) => - { - await _updater.UpdateApp(); - }; - timer.Start(); - - // check updates on startup - await _updater.UpdateApp(); - } - }); - } - - private void RegisterExitEvents() - { - AppDomain.CurrentDomain.ProcessExit += (s, e) => Dispose(); - Current.Exit += (s, e) => Dispose(); - Current.SessionEnding += (s, e) => Dispose(); - } - - /// - /// let exception throw as normal is better for Debug - /// - [Conditional("RELEASE")] - private void RegisterDispatcherUnhandledException() - { - DispatcherUnhandledException += ErrorReporting.DispatcherUnhandledException; - } - - - /// - /// let exception throw as normal is better for Debug - /// - [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; - } - } +using System; +using System.Diagnostics; +using System.Threading.Tasks; +using System.Timers; +using System.Windows; +using Wox; +using Wox.Core; +using Wox.Core.Plugin; +using Wox.Core.Resource; +using Wox.Helper; +using Wox.Infrastructure; +using Wox.Infrastructure.Http; +using Wox.Infrastructure.Image; +using Wox.Infrastructure.Logger; +using Wox.Infrastructure.UserSettings; +using Wox.ViewModel; +using Stopwatch = Wox.Infrastructure.Stopwatch; + +namespace PowerLauncher +{ + public partial class App : IDisposable, ISingleInstanceApp + { + public static PublicAPIInstance API { get; private set; } + private const string Unique = "Wox_Unique_Application_Mutex"; + private static bool _disposed; + private Settings _settings; + private MainViewModel _mainVM; + private SettingWindowViewModel _settingsVM; + private readonly Alphabet _alphabet = new Alphabet(); + private StringMatcher _stringMatcher; + + [STAThread] + public static void Main() + { + if (SingleInstance.InitializeAsFirstInstance(Unique)) + { + using (var application = new App()) + { + application.InitializeComponent(); + application.Run(); + } + } + } + + private void OnStartup(object sender, StartupEventArgs e) + { + Stopwatch.Normal("|App.OnStartup|Startup cost", () => + { + Log.Info("|App.OnStartup|Begin Wox startup ----------------------------------------------------"); + Log.Info($"|App.OnStartup|Runtime info:{ErrorReporting.RuntimeInfo()}"); + RegisterAppDomainExceptions(); + RegisterDispatcherUnhandledException(); + + ImageLoader.Initialize(); + + _settingsVM = new SettingWindowViewModel(); + _settings = _settingsVM.Settings; + + _alphabet.Initialize(_settings); + _stringMatcher = new StringMatcher(_alphabet); + StringMatcher.Instance = _stringMatcher; + _stringMatcher.UserSettingSearchPrecision = _settings.QuerySearchPrecision; + + PluginManager.LoadPlugins(_settings.PluginSettings); + _mainVM = new MainViewModel(_settings); + var window = new MainWindow(_settings, _mainVM); + API = new PublicAPIInstance(_settingsVM, _mainVM, _alphabet); + PluginManager.InitializePlugins(API); + Log.Info($"|App.OnStartup|Dependencies Info:{ErrorReporting.DependenciesInfo()}"); + + Current.MainWindow = window; + Current.MainWindow.Title = Constant.Wox; + + // happlebao todo temp fix for instance code logic + // load plugin before change language, because plugin language also needs be changed + InternationalizationManager.Instance.Settings = _settings; + InternationalizationManager.Instance.ChangeLanguage(_settings.Language); + // main windows needs initialized before theme change because of blur settigns + ThemeManager.Instance.Settings = _settings; + ThemeManager.Instance.ChangeTheme(_settings.Theme); + + Http.Proxy = _settings.Proxy; + + RegisterExitEvents(); + + + _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 RegisterExitEvents() + { + AppDomain.CurrentDomain.ProcessExit += (s, e) => Dispose(); + Current.Exit += (s, e) => Dispose(); + Current.SessionEnding += (s, e) => Dispose(); + } + + /// + /// let exception throw as normal is better for Debug + /// + [Conditional("RELEASE")] + private void RegisterDispatcherUnhandledException() + { + DispatcherUnhandledException += ErrorReporting.DispatcherUnhandledException; + } + + + /// + /// let exception throw as normal is better for Debug + /// + [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; + } + } } \ No newline at end of file