mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-15 12:09:18 +08:00
245cffc4f7
1. remove unnecessary events from MainViewModel 2. remove usage of Obsolete api (show, hide etc) 3. fix space problem in #660 4. part of #486 5. fix up/down key bug introduced in 92b7ca6a1bafd254e39ee92812ff691906cd85c1 6. fix #678
150 lines
4.1 KiB
C#
150 lines
4.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using Squirrel;
|
|
using Wox.Core.Plugin;
|
|
using Wox.Core.Resource;
|
|
using Wox.Helper;
|
|
using Wox.Infrastructure.Hotkey;
|
|
using Wox.Plugin;
|
|
using Wox.ViewModel;
|
|
|
|
namespace Wox
|
|
{
|
|
public class PublicAPIInstance : IPublicAPI
|
|
{
|
|
private readonly SettingWindowViewModel _settingsVM;
|
|
private readonly MainViewModel _mainVM;
|
|
|
|
#region Constructor
|
|
|
|
public PublicAPIInstance(SettingWindowViewModel settingsVM, MainViewModel mainVM)
|
|
{
|
|
_settingsVM = settingsVM;
|
|
_mainVM = mainVM;
|
|
GlobalHotkey.Instance.hookedKeyboardCallback += KListener_hookedKeyboardCallback;
|
|
WebRequest.RegisterPrefix("data", new DataWebRequestFactory());
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Public API
|
|
|
|
public void ChangeQuery(string query, bool requery = false)
|
|
{
|
|
_mainVM.QueryText = query;
|
|
}
|
|
|
|
public void ChangeQueryText(string query, bool selectAll = false)
|
|
{
|
|
_mainVM.QueryText = query;
|
|
}
|
|
|
|
[Obsolete]
|
|
public void CloseApp()
|
|
{
|
|
Application.Current.MainWindow.Close();
|
|
}
|
|
|
|
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();
|
|
UpdateManager.RestartApp();
|
|
}
|
|
|
|
[Obsolete]
|
|
public void HideApp()
|
|
{
|
|
_mainVM.MainWindowVisibility = Visibility.Hidden;
|
|
}
|
|
|
|
[Obsolete]
|
|
public void ShowApp()
|
|
{
|
|
_mainVM.MainWindowVisibility = Visibility.Visible;
|
|
}
|
|
|
|
public void ShowMsg(string title, string subTitle = "", string iconPath = "")
|
|
{
|
|
Application.Current.Dispatcher.Invoke(() =>
|
|
{
|
|
var m = new Msg { Owner = Application.Current.MainWindow };
|
|
m.Show(title, subTitle, iconPath);
|
|
});
|
|
}
|
|
|
|
public void OpenSettingDialog()
|
|
{
|
|
Application.Current.Dispatcher.Invoke(() =>
|
|
{
|
|
SettingWindow sw = SingletonWindowOpener.Open<SettingWindow>(this, _settingsVM);
|
|
});
|
|
}
|
|
|
|
public void StartLoadingBar()
|
|
{
|
|
_mainVM.ProgressBarVisibility = Visibility.Visible;
|
|
}
|
|
|
|
public void StopLoadingBar()
|
|
{
|
|
_mainVM.ProgressBarVisibility = Visibility.Collapsed;
|
|
}
|
|
|
|
public void InstallPlugin(string path)
|
|
{
|
|
Application.Current.Dispatcher.Invoke(() => PluginManager.InstallPlugin(path));
|
|
}
|
|
|
|
public string GetTranslation(string key)
|
|
{
|
|
return InternationalizationManager.Instance.GetTranslation(key);
|
|
}
|
|
|
|
public List<PluginPair> GetAllPlugins()
|
|
{
|
|
return PluginManager.AllPlugins.ToList();
|
|
}
|
|
|
|
public event WoxGlobalKeyboardEventHandler GlobalKeyboardEvent;
|
|
|
|
[Obsolete("This will be removed in Wox 1.3")]
|
|
public void PushResults(Query query, PluginMetadata plugin, List<Result> results)
|
|
{
|
|
results.ForEach(o =>
|
|
{
|
|
o.PluginDirectory = plugin.PluginDirectory;
|
|
o.PluginID = plugin.ID;
|
|
o.OriginQuery = query;
|
|
});
|
|
Task.Run(() =>
|
|
{
|
|
_mainVM.UpdateResultView(results, plugin, query);
|
|
});
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Private Methods
|
|
|
|
private bool KListener_hookedKeyboardCallback(KeyEvent keyevent, int vkcode, SpecialKeyState state)
|
|
{
|
|
if (GlobalKeyboardEvent != null)
|
|
{
|
|
return GlobalKeyboardEvent((int)keyevent, vkcode, state);
|
|
}
|
|
return true;
|
|
}
|
|
#endregion
|
|
}
|
|
}
|