2016-02-23 05:43:37 +08:00
|
|
|
|
using System;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net;
|
2016-05-06 04:15:13 +08:00
|
|
|
|
using System.Threading.Tasks;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
using System.Windows;
|
2016-05-08 05:44:38 +08:00
|
|
|
|
using Squirrel;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
using Wox.Core.Plugin;
|
|
|
|
|
using Wox.Core.Resource;
|
|
|
|
|
using Wox.Helper;
|
2017-03-02 07:47:50 +08:00
|
|
|
|
using Wox.Infrastructure;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
using Wox.Infrastructure.Hotkey;
|
2017-03-02 07:47:50 +08:00
|
|
|
|
using Wox.Infrastructure.Image;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
using Wox.Plugin;
|
|
|
|
|
using Wox.ViewModel;
|
|
|
|
|
|
|
|
|
|
namespace Wox
|
|
|
|
|
{
|
|
|
|
|
public class PublicAPIInstance : IPublicAPI
|
|
|
|
|
{
|
2016-05-25 08:00:10 +08:00
|
|
|
|
private readonly SettingWindowViewModel _settingsVM;
|
|
|
|
|
private readonly MainViewModel _mainVM;
|
2016-05-10 06:35:20 +08:00
|
|
|
|
|
2016-02-18 19:30:36 +08:00
|
|
|
|
#region Constructor
|
|
|
|
|
|
2016-05-25 08:00:10 +08:00
|
|
|
|
public PublicAPIInstance(SettingWindowViewModel settingsVM, MainViewModel mainVM)
|
2016-02-18 19:30:36 +08:00
|
|
|
|
{
|
2016-05-25 08:00:10 +08:00
|
|
|
|
_settingsVM = settingsVM;
|
|
|
|
|
_mainVM = mainVM;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
GlobalHotkey.Instance.hookedKeyboardCallback += KListener_hookedKeyboardCallback;
|
|
|
|
|
WebRequest.RegisterPrefix("data", new DataWebRequestFactory());
|
2016-03-28 10:09:57 +08:00
|
|
|
|
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Public API
|
|
|
|
|
|
|
|
|
|
public void ChangeQuery(string query, bool requery = false)
|
|
|
|
|
{
|
2016-07-21 06:37:06 +08:00
|
|
|
|
_mainVM.ChangeQueryText(query);
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ChangeQueryText(string query, bool selectAll = false)
|
|
|
|
|
{
|
2016-07-21 06:37:06 +08:00
|
|
|
|
_mainVM.ChangeQueryText(query);
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-25 08:00:10 +08:00
|
|
|
|
[Obsolete]
|
2016-02-18 19:30:36 +08:00
|
|
|
|
public void CloseApp()
|
|
|
|
|
{
|
2016-05-10 05:45:20 +08:00
|
|
|
|
Application.Current.MainWindow.Close();
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RestarApp()
|
|
|
|
|
{
|
2016-05-25 08:00:10 +08:00
|
|
|
|
_mainVM.MainWindowVisibility = Visibility.Hidden;
|
2017-03-02 07:47:50 +08:00
|
|
|
|
|
2016-05-10 05:45:20 +08:00
|
|
|
|
// we must manually save
|
2016-05-09 00:47:28 +08:00
|
|
|
|
// UpdateManager.RestartApp() will call Environment.Exit(0)
|
|
|
|
|
// which will cause ungraceful exit
|
2017-03-02 07:47:50 +08:00
|
|
|
|
_mainVM.Save();
|
|
|
|
|
_settingsVM.Save();
|
|
|
|
|
PluginManager.Save();
|
|
|
|
|
ImageLoader.Save();
|
|
|
|
|
Alphabet.Save();
|
|
|
|
|
|
2016-05-08 05:44:38 +08:00
|
|
|
|
UpdateManager.RestartApp();
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-25 08:00:10 +08:00
|
|
|
|
[Obsolete]
|
2016-02-18 19:30:36 +08:00
|
|
|
|
public void HideApp()
|
|
|
|
|
{
|
2016-05-25 08:00:10 +08:00
|
|
|
|
_mainVM.MainWindowVisibility = Visibility.Hidden;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-25 08:00:10 +08:00
|
|
|
|
[Obsolete]
|
2016-02-18 19:30:36 +08:00
|
|
|
|
public void ShowApp()
|
|
|
|
|
{
|
2016-05-25 08:00:10 +08:00
|
|
|
|
_mainVM.MainWindowVisibility = Visibility.Visible;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-25 09:22:24 +08:00
|
|
|
|
public void ShowMsg(string title, string subTitle = "", string iconPath = "")
|
2016-02-18 19:30:36 +08:00
|
|
|
|
{
|
|
|
|
|
Application.Current.Dispatcher.Invoke(() =>
|
|
|
|
|
{
|
|
|
|
|
var m = new Msg { Owner = Application.Current.MainWindow };
|
|
|
|
|
m.Show(title, subTitle, iconPath);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-23 02:16:39 +08:00
|
|
|
|
public void OpenSettingDialog()
|
2016-02-18 19:30:36 +08:00
|
|
|
|
{
|
|
|
|
|
Application.Current.Dispatcher.Invoke(() =>
|
|
|
|
|
{
|
2016-05-25 08:00:10 +08:00
|
|
|
|
SettingWindow sw = SingletonWindowOpener.Open<SettingWindow>(this, _settingsVM);
|
2016-02-18 19:30:36 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void StartLoadingBar()
|
|
|
|
|
{
|
2016-05-25 08:00:10 +08:00
|
|
|
|
_mainVM.ProgressBarVisibility = Visibility.Visible;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void StopLoadingBar()
|
|
|
|
|
{
|
2016-05-25 08:00:10 +08:00
|
|
|
|
_mainVM.ProgressBarVisibility = Visibility.Collapsed;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
2016-03-28 08:09:40 +08:00
|
|
|
|
[Obsolete("This will be removed in Wox 1.3")]
|
2016-02-18 19:30:36 +08:00
|
|
|
|
public void PushResults(Query query, PluginMetadata plugin, List<Result> results)
|
|
|
|
|
{
|
|
|
|
|
results.ForEach(o =>
|
|
|
|
|
{
|
|
|
|
|
o.PluginDirectory = plugin.PluginDirectory;
|
|
|
|
|
o.PluginID = plugin.ID;
|
|
|
|
|
o.OriginQuery = query;
|
|
|
|
|
});
|
2016-05-06 04:15:13 +08:00
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
2016-05-25 08:00:10 +08:00
|
|
|
|
_mainVM.UpdateResultView(results, plugin, query);
|
2016-05-06 04:15:13 +08:00
|
|
|
|
});
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
}
|
|
|
|
|
}
|