mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 02:06:36 +02:00
* [Analyzers][AdvancedPaste] Apply fix for SA1516 * [Analyzers][EnvironmentVariables] Apply fix for SA1516 * [Analyzers][RegistryPreview] Apply fix for SA1516 * [Analyzers][Peek] Apply fix for SA1516 * [Analyzers][PreviewPane] Apply fix for SA1516 * [Analyzers][FancyZones] Apply fix for SA1516 * [Analyzers][PT Run][Plugins] Apply fix for SA1516 * [Analyzers][PT Run] Apply fix for SA1516 * [Analyzers][PT Run][Wox] Apply fix for SA1516 * [Analyzers][Common] Apply fix for SA1516 * [Analyzers][ImageResizer] Apply fix for SA1516 * [Analyzers][ColorPicker] Apply fix for SA1516 * [Analyzers][MouseUtils] Apply fix for SA1516 * [Analyzers][DSC Schema Generator] Apply fix for SA1516 * [Analyzers][FileLocksmith] Apply fix for SA1516 * [Analyzers][Hosts] Apply fix for SA1516 * [Analyzers][MeasureTool] Apply fix for SA1516 * [Analyzers][MouseWithoutBorders] Apply fix for SA1516 * [Analyzers][TextExtractor] Apply fix for SA1516 * [Analyzers][Workspaces] Apply fix for SA1516 * [Analyzers][Awake] Apply fix for SA1516 * [Analyzers][PowerAccent] Apply fix for SA1516 * [Analyzers][RegistryPreview] Apply fix for SA1516 * [Analyzers][Settings] Apply fix for SA1516 * [Analyzers][MouseWithoutBorders] Apply fix for SA1616
136 lines
4.0 KiB
C#
136 lines
4.0 KiB
C#
// Copyright (c) Microsoft Corporation
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
|
|
using ManagedCommon;
|
|
using Microsoft.Toolkit.Uwp.Notifications;
|
|
using PowerLauncher.Helper;
|
|
using PowerLauncher.Plugin;
|
|
using PowerLauncher.ViewModel;
|
|
using Windows.UI.Notifications;
|
|
using Wox.Infrastructure;
|
|
using Wox.Infrastructure.Image;
|
|
using Wox.Plugin;
|
|
|
|
namespace Wox
|
|
{
|
|
public class PublicAPIInstance : IPublicAPI, IDisposable
|
|
{
|
|
private readonly SettingWindowViewModel _settingsVM;
|
|
private readonly MainViewModel _mainVM;
|
|
private readonly Alphabet _alphabet;
|
|
private readonly ThemeManager _themeManager;
|
|
private bool _disposed;
|
|
|
|
public event Common.UI.ThemeChangedHandler ThemeChanged;
|
|
|
|
public PublicAPIInstance(SettingWindowViewModel settingsVM, MainViewModel mainVM, Alphabet alphabet, ThemeManager themeManager)
|
|
{
|
|
_settingsVM = settingsVM ?? throw new ArgumentNullException(nameof(settingsVM));
|
|
_mainVM = mainVM ?? throw new ArgumentNullException(nameof(mainVM));
|
|
_alphabet = alphabet ?? throw new ArgumentNullException(nameof(alphabet));
|
|
_themeManager = themeManager ?? throw new ArgumentNullException(nameof(themeManager));
|
|
_themeManager.ThemeChanged += OnThemeChanged;
|
|
|
|
ToastNotificationManagerCompat.OnActivated += args =>
|
|
{
|
|
};
|
|
}
|
|
|
|
public void RemoveUserSelectedItem(Result result)
|
|
{
|
|
_mainVM.RemoveUserSelectedRecord(result);
|
|
_mainVM.ChangeQueryText(_mainVM.QueryText, true);
|
|
}
|
|
|
|
public void ChangeQuery(string query, bool requery = false)
|
|
{
|
|
Application.Current.Dispatcher.Invoke(() =>
|
|
{
|
|
_mainVM.ChangeQueryText(query, requery);
|
|
});
|
|
}
|
|
|
|
public void CheckForNewUpdate()
|
|
{
|
|
// _settingsVM.UpdateApp();
|
|
}
|
|
|
|
public void SaveAppAllSettings()
|
|
{
|
|
_mainVM.Save();
|
|
_settingsVM.Save();
|
|
PluginManager.Save();
|
|
ImageLoader.Save();
|
|
_alphabet.Save();
|
|
}
|
|
|
|
public void ReloadAllPluginData()
|
|
{
|
|
PluginManager.ReloadData();
|
|
}
|
|
|
|
public void ShowMsg(string title, string subTitle = "", string iconPath = "", bool useMainWindowAsOwner = true)
|
|
{
|
|
Application.Current.Dispatcher.Invoke(() =>
|
|
{
|
|
MessageBox.Show(subTitle, title);
|
|
});
|
|
}
|
|
|
|
public void ShowNotification(string text, string secondaryText = null)
|
|
{
|
|
var builder = new ToastContentBuilder().AddText(text);
|
|
|
|
if (!string.IsNullOrWhiteSpace(secondaryText))
|
|
{
|
|
builder.AddText(secondaryText);
|
|
}
|
|
|
|
Application.Current.Dispatcher.Invoke(() =>
|
|
{
|
|
var toast = new ToastNotification(builder.GetToastContent().GetXml());
|
|
ToastNotificationManagerCompat.CreateToastNotifier().Show(toast);
|
|
});
|
|
}
|
|
|
|
public List<PluginPair> GetAllPlugins()
|
|
{
|
|
return PluginManager.AllPlugins.ToList();
|
|
}
|
|
|
|
public Theme GetCurrentTheme()
|
|
{
|
|
return _themeManager.CurrentTheme;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
Dispose(disposing: true);
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
|
|
protected void OnThemeChanged(Theme oldTheme, Theme newTheme)
|
|
{
|
|
ThemeChanged?.Invoke(oldTheme, newTheme);
|
|
}
|
|
|
|
protected virtual void Dispose(bool disposing)
|
|
{
|
|
if (!_disposed)
|
|
{
|
|
if (disposing)
|
|
{
|
|
_themeManager.ThemeChanged -= OnThemeChanged;
|
|
_disposed = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|