mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-14 19:49:15 +08:00
07310c7714
* fix typo * make function obsolete it is not used in the code * rewrite the function that converts chinese chars to pinyin 1. Only difference in this rewrite is instead of returning 2D array, return as a combined single string of all the possible pinyin combination. Since fuzzy search does character matching, this shouldn't be a problem. 2. Added a function that returns a custom language converter. In this case Pinyin converter. New converters can be added. * Use new language converter param + strip out ScoreForPinyin method * update * Change parameter name * fix failing tests * WIP * Remove todo There should be some distinction between score after precision filter and actual raw score derived from FuzzySearch. Although so far RawScore is used in testing, but it seems to describe the structure. Originally it was to avoid assigning score directly as it would be hard to reason about that output of FuzzySearch score is. * Add constructors, remove default to enforce required properties * remove setting rawscore in SearchPrecision * Change method name to reflect intention * Change parameter name + update comment * update * Remove params comment Co-authored-by: theClueless <14300910+theClueless@users.noreply.github.com>
172 lines
6.0 KiB
C#
172 lines
6.0 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.Threading.Tasks;
|
|
using System.Timers;
|
|
using System.Windows;
|
|
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 Wox
|
|
{
|
|
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(Wox.Properties.Settings.Default.GithubRepo);
|
|
private readonly Alphabet _alphabet = new Alphabet();
|
|
private StringMatcher _stringMatcher;
|
|
|
|
[STAThread]
|
|
public static void Main()
|
|
{
|
|
if (SingleInstance<App>.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.Instance = new StringMatcher(_alphabet);
|
|
_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()
|
|
{
|
|
if (_settings.StartWoxOnSystemStartup)
|
|
{
|
|
if (!SettingWindow.StartupSet())
|
|
{
|
|
SettingWindow.SetStartup();
|
|
}
|
|
}
|
|
}
|
|
|
|
//[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();
|
|
}
|
|
|
|
/// <summary>
|
|
/// let exception throw as normal is better for Debug
|
|
/// </summary>
|
|
[Conditional("RELEASE")]
|
|
private void RegisterDispatcherUnhandledException()
|
|
{
|
|
DispatcherUnhandledException += ErrorReporting.DispatcherUnhandledException;
|
|
}
|
|
|
|
|
|
/// <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 += (_, e) =>
|
|
{
|
|
Log.Exception("|App.RegisterAppDomainExceptions|First Chance Exception:", e.Exception);
|
|
};
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
} |