This commit is contained in:
qianlifeng 2014-12-15 18:29:42 +08:00
commit cecd4aa36a
12 changed files with 215 additions and 25 deletions

View File

@ -8,6 +8,6 @@ Write-Host "Setting .nuspec version tag to $versionStr"
$content = (Get-Content $root\Deploy\NuGet\wox.plugin.nuspec) $content = (Get-Content $root\Deploy\NuGet\wox.plugin.nuspec)
$content = $content -replace '\$version\$',$versionStr $content = $content -replace '\$version\$',$versionStr
$content | Out-File $root\wox.plugin.nuspec $content | Out-File $root\deploy\nuget\wox.plugin.nuspec
& $root\.nuget\NuGet.exe pack $root\deploy\nuget\wox.plugin.nuspec & $root\.nuget\NuGet.exe pack $root\deploy\nuget\wox.plugin.nuspec

Binary file not shown.

View File

@ -10,30 +10,21 @@ using Newtonsoft.Json;
namespace Wox.Plugin.PluginManagement namespace Wox.Plugin.PluginManagement
{ {
public class WoxPlugin
{
public int apiVersion { get; set; }
public List<WoxPluginResult> result { get; set; }
}
public class WoxPluginResult public class WoxPluginResult
{ {
public string actionkeyword; public string plugin_file;
public string download;
public string author;
public string description; public string description;
public string id; public int liked_count;
public int star;
public string name; public string name;
public string version; public string version;
public string website;
} }
public class Main : IPlugin public class Main : IPlugin
{ {
private static string APIBASE = "https://api.getwox.com";
private static string PluginPath = AppDomain.CurrentDomain.BaseDirectory + "Plugins"; private static string PluginPath = AppDomain.CurrentDomain.BaseDirectory + "Plugins";
private static string PluginConfigName = "plugin.json"; private static string PluginConfigName = "plugin.json";
private static string pluginSearchUrl = "http://www.getwox.com/api/plugin/search/"; private static string pluginSearchUrl = APIBASE +"/plugin/search/";
private PluginInitContext context; private PluginInitContext context;
public List<Result> Query(Query query) public List<Result> Query(Query query)
@ -142,8 +133,18 @@ namespace Wox.Plugin.PluginManagement
{ {
StreamReader reader = new StreamReader(s, Encoding.UTF8); StreamReader reader = new StreamReader(s, Encoding.UTF8);
string json = reader.ReadToEnd(); string json = reader.ReadToEnd();
WoxPlugin o = JsonConvert.DeserializeObject<WoxPlugin>(json); List<WoxPluginResult> searchedPlugins = null;
foreach (WoxPluginResult r in o.result) try
{
searchedPlugins = JsonConvert.DeserializeObject<List<WoxPluginResult>>(json);
}
catch
{
context.API.ShowMsg("Coundn't parse api search results", "Please update your Wox!",string.Empty);
return results;
}
foreach (WoxPluginResult r in searchedPlugins)
{ {
WoxPluginResult r1 = r; WoxPluginResult r1 = r;
results.Add(new Result() results.Add(new Result()
@ -169,7 +170,8 @@ namespace Wox.Plugin.PluginManagement
{ {
try try
{ {
Client.DownloadFile(r1.download, filePath); string pluginUrl = APIBASE + "/media/" + r1.plugin_file;
Client.DownloadFile(pluginUrl, filePath);
context.API.InstallPlugin(filePath); context.API.InstallPlugin(filePath);
context.API.ReloadPlugins(); context.API.ReloadPlugins();
} }

View File

@ -9,6 +9,8 @@ using System.Security.Cryptography.X509Certificates;
using System.Text; using System.Text;
//From:http://blog.csdn.net/zhoufoxcn/article/details/6404236 //From:http://blog.csdn.net/zhoufoxcn/article/details/6404236
using Wox.Plugin;
namespace Wox.Infrastructure namespace Wox.Infrastructure
{ {
public class HttpRequest public class HttpRequest
@ -16,6 +18,30 @@ namespace Wox.Infrastructure
private static readonly string DefaultUserAgent = "Wox/" + Assembly.GetEntryAssembly().GetName().Version.ToString() + " (+https://github.com/qianlifeng/Wox)"; private static readonly string DefaultUserAgent = "Wox/" + Assembly.GetEntryAssembly().GetName().Version.ToString() + " (+https://github.com/qianlifeng/Wox)";
public static HttpWebResponse CreateGetHttpResponse(string url, IHttpProxy proxy)
{
if (string.IsNullOrEmpty(url))
{
throw new ArgumentNullException("url");
}
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
if (proxy != null && proxy.Enabled && !string.IsNullOrEmpty(proxy.Server))
{
if (string.IsNullOrEmpty(proxy.UserName) || string.IsNullOrEmpty(proxy.Password))
{
request.Proxy = new WebProxy(proxy.Server, proxy.Port);
}
else
{
request.Proxy = new WebProxy(proxy.Server, proxy.Port);
request.Proxy.Credentials = new NetworkCredential(proxy.UserName, proxy.Password);
}
}
request.Method = "GET";
request.UserAgent = DefaultUserAgent;
return request.GetResponse() as HttpWebResponse;
}
public static HttpWebResponse CreateGetHttpResponse(string url, int? timeout, string userAgent, CookieCollection cookies) public static HttpWebResponse CreateGetHttpResponse(string url, int? timeout, string userAgent, CookieCollection cookies)
{ {
if (string.IsNullOrEmpty(url)) if (string.IsNullOrEmpty(url))

View File

@ -8,6 +8,9 @@ namespace Wox.Infrastructure.Storage.UserSettings
{ {
public class UserSettingStorage : BaseStorage<UserSettingStorage> public class UserSettingStorage : BaseStorage<UserSettingStorage>
{ {
[JsonProperty]
public bool DontPromptUpdateMsg { get; set; }
[JsonProperty] [JsonProperty]
public string Hotkey { get; set; } public string Hotkey { get; set; }
@ -145,6 +148,7 @@ namespace Wox.Infrastructure.Storage.UserSettings
protected override UserSettingStorage LoadDefaultConfig() protected override UserSettingStorage LoadDefaultConfig()
{ {
DontPromptUpdateMsg = false;
Theme = "Dark"; Theme = "Dark";
ReplaceWinR = true; ReplaceWinR = true;
WebSearches = LoadDefaultWebSearches(); WebSearches = LoadDefaultWebSearches();

View File

@ -21,6 +21,7 @@ using Wox.Infrastructure.Storage;
using Wox.Infrastructure.Storage.UserSettings; using Wox.Infrastructure.Storage.UserSettings;
using Wox.Plugin; using Wox.Plugin;
using Wox.PluginLoader; using Wox.PluginLoader;
using Wox.Update;
using Application = System.Windows.Application; using Application = System.Windows.Application;
using Brushes = System.Windows.Media.Brushes; using Brushes = System.Windows.Media.Brushes;
using Color = System.Windows.Media.Color; using Color = System.Windows.Media.Color;
@ -188,6 +189,8 @@ namespace Wox
//since MainWIndow implement IPublicAPI, so we need to finish ctor MainWindow object before //since MainWIndow implement IPublicAPI, so we need to finish ctor MainWindow object before
//PublicAPI invoke in plugin init methods. E.g FolderPlugin //PublicAPI invoke in plugin init methods. E.g FolderPlugin
ThreadPool.QueueUserWorkItem(o => Plugins.Init()); ThreadPool.QueueUserWorkItem(o => Plugins.Init());
ThreadPool.QueueUserWorkItem(o => checkUpdate());
} }
void pnlResult_RightMouseClickEvent(Result result) void pnlResult_RightMouseClickEvent(Result result)
@ -195,6 +198,15 @@ namespace Wox
ShowContextMenu(result); ShowContextMenu(result);
} }
void checkUpdate()
{
Release release = new UpdateChecker().CheckUpgrade();
if (release != null && !UserSettingStorage.Instance.DontPromptUpdateMsg)
{
ShowMsg(string.Format("New version {0} available!",release.version),string.Empty,string.Empty);
}
}
void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{ {
UserSettingStorage.Instance.WindowLeft = Left; UserSettingStorage.Instance.WindowLeft = Left;

View File

@ -28,6 +28,9 @@
<CheckBox x:Name="cbHideWhenDeactive" Margin="10"> <CheckBox x:Name="cbHideWhenDeactive" Margin="10">
Hide Wox when loses focus Hide Wox when loses focus
</CheckBox> </CheckBox>
<CheckBox x:Name="cbDontPromptUpdateMsg" Margin="10">
Don't show upgrade msg if new version available
</CheckBox>
</StackPanel> </StackPanel>
</TabItem> </TabItem>
<TabItem Header="Plugin"> <TabItem Header="Plugin">

View File

@ -38,8 +38,7 @@ namespace Wox
private void Setting_Loaded(object sender, RoutedEventArgs ev) private void Setting_Loaded(object sender, RoutedEventArgs ev)
{ {
ctlHotkey.OnHotkeyChanged += ctlHotkey_OnHotkeyChanged; #region General
ctlHotkey.SetHotkey(UserSettingStorage.Instance.Hotkey, false);
cbHideWhenDeactive.Checked += (o, e) => cbHideWhenDeactive.Checked += (o, e) =>
{ {
@ -53,11 +52,25 @@ namespace Wox
UserSettingStorage.Instance.Save(); UserSettingStorage.Instance.Save();
}; };
lvCustomHotkey.ItemsSource = UserSettingStorage.Instance.CustomPluginHotkeys; cbDontPromptUpdateMsg.Checked += (o, e) =>
{
UserSettingStorage.Instance.DontPromptUpdateMsg = true;
UserSettingStorage.Instance.Save();
};
cbDontPromptUpdateMsg.Unchecked += (o, e) =>
{
UserSettingStorage.Instance.DontPromptUpdateMsg = false;
UserSettingStorage.Instance.Save();
};
cbStartWithWindows.IsChecked = File.Exists(woxLinkPath); cbStartWithWindows.IsChecked = File.Exists(woxLinkPath);
cbHideWhenDeactive.IsChecked = UserSettingStorage.Instance.HideWhenDeactive; cbHideWhenDeactive.IsChecked = UserSettingStorage.Instance.HideWhenDeactive;
cbDontPromptUpdateMsg.IsChecked = UserSettingStorage.Instance.DontPromptUpdateMsg;
#region Load Theme #endregion
#region Theme
if (!string.IsNullOrEmpty(UserSettingStorage.Instance.QueryBoxFont) && if (!string.IsNullOrEmpty(UserSettingStorage.Instance.QueryBoxFont) &&
Fonts.SystemFontFamilies.Count(o => o.FamilyNames.Values.Contains(UserSettingStorage.Instance.QueryBoxFont)) > 0) Fonts.SystemFontFamilies.Count(o => o.FamilyNames.Values.Contains(UserSettingStorage.Instance.QueryBoxFont)) > 0)
@ -155,9 +168,17 @@ namespace Wox
var wallpaperColor = WallpaperPathRetrieval.GetWallpaperColor(); var wallpaperColor = WallpaperPathRetrieval.GetWallpaperColor();
PreviewPanel.Background = new SolidColorBrush(wallpaperColor); PreviewPanel.Background = new SolidColorBrush(wallpaperColor);
} }
//PreviewPanel
App.Window.SetTheme(UserSettingStorage.Instance.Theme);
#endregion #endregion
#region Load Plugin #region Plugin
ctlHotkey.OnHotkeyChanged += ctlHotkey_OnHotkeyChanged;
ctlHotkey.SetHotkey(UserSettingStorage.Instance.Hotkey, false);
lvCustomHotkey.ItemsSource = UserSettingStorage.Instance.CustomPluginHotkeys;
var plugins = new CompositeCollection var plugins = new CompositeCollection
{ {
@ -200,9 +221,7 @@ namespace Wox
#endregion #endregion
//PreviewPanel
settingsLoaded = true; settingsLoaded = true;
App.Window.SetTheme(UserSettingStorage.Instance.Theme);
} }
private void EnableProxy() private void EnableProxy()

16
Wox/Update/Release.cs Normal file
View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Wox.Update
{
public class Release
{
public string version { get; set; }
public string download_link { get; set; }
public string download_link1 { get; set; }
public string download_link2 { get; set; }
public string description { get; set; }
}
}

View File

@ -0,0 +1,96 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using Newtonsoft.Json;
using Wox.Helper;
using Wox.Infrastructure;
namespace Wox.Update
{
public class UpdateChecker
{
private string updateURL = "https://api.getwox.com/release/latest/";
/// <summary>
/// If new release is available, then return the new release
/// otherwise, return null
/// </summary>
/// <returns></returns>
public Release CheckUpgrade()
{
Release release = null;
HttpWebResponse response = HttpRequest.CreateGetHttpResponse(updateURL, HttpProxy.Instance);
Stream s = response.GetResponseStream();
if (s != null)
{
StreamReader reader = new StreamReader(s, Encoding.UTF8);
string json = reader.ReadToEnd();
try
{
release = JsonConvert.DeserializeObject<Release>(json);
}
catch
{
return null;
}
}
if (!IsNewerThanCurrent(release))
{
return null;
}
return release;
}
private bool IsNewerThanCurrent(Release release)
{
if (release == null) return false;
string currentVersion = ConfigurationManager.AppSettings["version"];
return CompareVersion(release.version, currentVersion) > 0;
}
/// <summary>
/// if version1 > version2 return 1
/// else -1
/// </summary>
/// <param name="version1"></param>
/// <param name="version2"></param>
/// <returns></returns>
private int CompareVersion(string version1, string version2)
{
if (version1 == version2) return 0;
if (string.IsNullOrEmpty(version1) || string.IsNullOrEmpty(version2)) return 0;
//semantic version, e.g. 1.1.0
List<int> version1List = version1.Split('.').Select(int.Parse).ToList();
List<int> version2List = version2.Split('.').Select(int.Parse).ToList();
if (version1List[0] > version2List[0])
{
return 1;
}
else if (version1List[0] == version2List[0])
{
if (version1List[1] > version2List[1])
{
return 1;
}
else if (version1List[1] == version2List[1])
{
if (version1List[2] > version2List[2])
{
return 1;
}
}
}
return -1;
}
}
}

View File

@ -82,6 +82,7 @@
<Reference Include="PresentationUI, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" /> <Reference Include="PresentationUI, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="ReachFramework" /> <Reference Include="ReachFramework" />
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Deployment" /> <Reference Include="System.Deployment" />
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
@ -103,6 +104,8 @@
<Reference Include="WPFToolkit, Version=3.5.40128.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" /> <Reference Include="WPFToolkit, Version=3.5.40128.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Update\Release.cs" />
<Compile Include="Update\UpdateChecker.cs" />
<Page Include="App.xaml"> <Page Include="App.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>

View File

@ -20,4 +20,13 @@ deploy:
provider: NuGet provider: NuGet
api_key: api_key:
secure: yybUOFgBuGVpbmOVZxsurC8OpkClzt9dR+/54WpMWcq6b6oyMatciaelRPnXsjRn secure: yybUOFgBuGVpbmOVZxsurC8OpkClzt9dR+/54WpMWcq6b6oyMatciaelRPnXsjRn
artifact: /.*\.nupkg/ artifact: nugetpackage
on:
branch: master
artifacts:
- path: Output\Release
name: release-binary
- path: '*.nupkg'
name: nugetpackage