From 2dbc404544fc88e027c3bb20a423cd27a42e131c Mon Sep 17 00:00:00 2001 From: qianlifeng Date: Sat, 13 Dec 2014 14:59:47 +0800 Subject: [PATCH 01/11] Update CI scripts --- Deploy/Nuget/wox.plugin.nuspec | Bin 6 -> 576 bytes appveyor.yml | 4 ++++ 2 files changed, 4 insertions(+) diff --git a/Deploy/Nuget/wox.plugin.nuspec b/Deploy/Nuget/wox.plugin.nuspec index 49cc8ef0e116cef009fe0bd72473a964bbd07f9b..2fceb983c8085dc8f43682ea29e749137a17d1a2 100644 GIT binary patch literal 576 zcmah{%TB{E5WM#*R#DF}2ysEKD+E0tRe(TMHNeqtd+M7Q99=A?KF9^wpo!Q;d zXx4nW9}H|UMD6UNxGt}XrI>Lq)wk?W%mDa+BpXTc2oltd_;ma7)r_6CoF$m~Nkh!1 zV$Ru_$^&ww-i0VOT3Vx9v>j(>E>9S(&_?_SM)X8J-Z9o`>c_fNZeYKAEE!<6aWxxc zBn)i*^sst>MU-NM0*u#=X695lE^<2*=6hQLoDU+QFKl3f%h&!;Mp zoLwG@x7uLLr%Amdf*91ID9b9nmy!HP)g#tpSEV$kbC!)U1&|CK(xONfD~oh Date: Sat, 13 Dec 2014 15:09:46 +0800 Subject: [PATCH 02/11] Update CI scripts --- Deploy/Nuget/pack.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Deploy/Nuget/pack.ps1 b/Deploy/Nuget/pack.ps1 index dcb264b78f..f1c75556a6 100644 --- a/Deploy/Nuget/pack.ps1 +++ b/Deploy/Nuget/pack.ps1 @@ -8,6 +8,6 @@ Write-Host "Setting .nuspec version tag to $versionStr" $content = (Get-Content $root\Deploy\NuGet\wox.plugin.nuspec) $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 From 259985d328e4299fa8acaad73f150e4af19b0769 Mon Sep 17 00:00:00 2001 From: qianlifeng Date: Sat, 13 Dec 2014 15:17:44 +0800 Subject: [PATCH 03/11] Update CI scripts :cry: --- Deploy/Nuget/wox.plugin.nuspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Deploy/Nuget/wox.plugin.nuspec b/Deploy/Nuget/wox.plugin.nuspec index 2fceb983c8..c55e4ded35 100644 --- a/Deploy/Nuget/wox.plugin.nuspec +++ b/Deploy/Nuget/wox.plugin.nuspec @@ -11,6 +11,6 @@ wox - + From 9867bd257f681975d48ae7c0c14e47d7a9bf29c8 Mon Sep 17 00:00:00 2001 From: qianlifeng Date: Sat, 13 Dec 2014 16:09:44 +0800 Subject: [PATCH 04/11] Update CI scripts :cry: --- appveyor.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 6e5d8fc3ab..631cc19940 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -20,8 +20,12 @@ deploy: provider: NuGet api_key: secure: yybUOFgBuGVpbmOVZxsurC8OpkClzt9dR+/54WpMWcq6b6oyMatciaelRPnXsjRn - artifact: /.*\.nupkg/ + artifact: nugetpackage + artifacts: path: Output\Release name: release-binary + + path: *.nupkg + name: nugetpackage From 4838813a3882d7731f7e40958307d3f5c6915a4d Mon Sep 17 00:00:00 2001 From: qianlifeng Date: Sat, 13 Dec 2014 16:17:54 +0800 Subject: [PATCH 05/11] update ci scripts. --- appveyor.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 631cc19940..08cc33e4d8 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -24,8 +24,8 @@ deploy: artifacts: - path: Output\Release - name: release-binary + - path: Output\Release + name: release-binary - path: *.nupkg - name: nugetpackage + - path: *.nupkg + name: nugetpackage From 51b37a49d5c67a26cdab9254b4f429235aa05a18 Mon Sep 17 00:00:00 2001 From: qianlifeng Date: Sat, 13 Dec 2014 16:30:00 +0800 Subject: [PATCH 06/11] update CI scripts --- appveyor.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 08cc33e4d8..a0bf407674 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -20,12 +20,9 @@ deploy: provider: NuGet api_key: secure: yybUOFgBuGVpbmOVZxsurC8OpkClzt9dR+/54WpMWcq6b6oyMatciaelRPnXsjRn - artifact: nugetpackage + artifact: *.nupkg artifacts: - - path: Output\Release - name: release-binary - - - path: *.nupkg - name: nugetpackage + path: Output\Release + name: release-binary From 85fd46e1c610b94ed9ed9abb70fd149a44eba603 Mon Sep 17 00:00:00 2001 From: qianlifeng Date: Sat, 13 Dec 2014 16:33:19 +0800 Subject: [PATCH 07/11] update ci scripts --- appveyor.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index a0bf407674..0c94c569c4 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -20,9 +20,11 @@ deploy: provider: NuGet api_key: secure: yybUOFgBuGVpbmOVZxsurC8OpkClzt9dR+/54WpMWcq6b6oyMatciaelRPnXsjRn - artifact: *.nupkg - + artifact: nugetpackage artifacts: - path: Output\Release - name: release-binary + - path: Output\Release + name: release-binary + + - path: '**\*.nupkg' + name: nugetpackage From df763c4dbdba968418d54114dbb76ee7c0a74f10 Mon Sep 17 00:00:00 2001 From: qianlifeng Date: Sat, 13 Dec 2014 16:47:17 +0800 Subject: [PATCH 08/11] update ci scripts --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 0c94c569c4..36de182df1 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -26,5 +26,5 @@ artifacts: - path: Output\Release name: release-binary - - path: '**\*.nupkg' + - path: '*.nupkg' name: nugetpackage From e303982ad8fb07f9556a0425f6cad0de637e2d17 Mon Sep 17 00:00:00 2001 From: qianlifeng Date: Sat, 13 Dec 2014 22:01:23 +0800 Subject: [PATCH 09/11] Deploy nuget only when commits on master branch. --- appveyor.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index 36de182df1..a9b1ca6113 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -21,6 +21,8 @@ deploy: api_key: secure: yybUOFgBuGVpbmOVZxsurC8OpkClzt9dR+/54WpMWcq6b6oyMatciaelRPnXsjRn artifact: nugetpackage + on: + branch: master artifacts: - path: Output\Release From ac3b86fb854a7d32c5334d9422482f30d53d7771 Mon Sep 17 00:00:00 2001 From: qianlifeng Date: Sun, 14 Dec 2014 22:24:05 +0800 Subject: [PATCH 10/11] Update wpm to use the new api --- Plugins/Wox.Plugin.PluginManagement/Main.cs | 34 +++++++++++---------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/Plugins/Wox.Plugin.PluginManagement/Main.cs b/Plugins/Wox.Plugin.PluginManagement/Main.cs index 432d6a7362..960a2c328c 100644 --- a/Plugins/Wox.Plugin.PluginManagement/Main.cs +++ b/Plugins/Wox.Plugin.PluginManagement/Main.cs @@ -10,30 +10,21 @@ using Newtonsoft.Json; namespace Wox.Plugin.PluginManagement { - public class WoxPlugin - { - public int apiVersion { get; set; } - public List result { get; set; } - } - public class WoxPluginResult { - public string actionkeyword; - public string download; - public string author; + public string plugin_file; public string description; - public string id; - public int star; + public int liked_count; public string name; public string version; - public string website; } public class Main : IPlugin { + private static string APIBASE = "https://api.getwox.com"; private static string PluginPath = AppDomain.CurrentDomain.BaseDirectory + "Plugins"; 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; public List Query(Query query) @@ -142,8 +133,18 @@ namespace Wox.Plugin.PluginManagement { StreamReader reader = new StreamReader(s, Encoding.UTF8); string json = reader.ReadToEnd(); - WoxPlugin o = JsonConvert.DeserializeObject(json); - foreach (WoxPluginResult r in o.result) + List searchedPlugins = null; + try + { + searchedPlugins = JsonConvert.DeserializeObject>(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; results.Add(new Result() @@ -169,7 +170,8 @@ namespace Wox.Plugin.PluginManagement { try { - Client.DownloadFile(r1.download, filePath); + string pluginUrl = APIBASE + "/media/" + r1.plugin_file; + Client.DownloadFile(pluginUrl, filePath); context.API.InstallPlugin(filePath); context.API.ReloadPlugins(); } From 128453fad1ff29b1960717351cbb077aaf6d0114 Mon Sep 17 00:00:00 2001 From: qianlifeng Date: Sun, 14 Dec 2014 23:16:29 +0800 Subject: [PATCH 11/11] Add upgrade check. --- Wox.Infrastructure/HttpRequest.cs | 26 +++++ .../UserSettings/UserSettingStorage.cs | 4 + Wox/MainWindow.xaml.cs | 12 +++ Wox/SettingWindow.xaml | 3 + Wox/SettingWindow.xaml.cs | 33 +++++-- Wox/Update/Release.cs | 16 ++++ Wox/Update/UpdateChecker.cs | 96 +++++++++++++++++++ Wox/Wox.csproj | 3 + 8 files changed, 186 insertions(+), 7 deletions(-) create mode 100644 Wox/Update/Release.cs create mode 100644 Wox/Update/UpdateChecker.cs diff --git a/Wox.Infrastructure/HttpRequest.cs b/Wox.Infrastructure/HttpRequest.cs index e082d07525..c5592e87df 100644 --- a/Wox.Infrastructure/HttpRequest.cs +++ b/Wox.Infrastructure/HttpRequest.cs @@ -9,6 +9,8 @@ using System.Security.Cryptography.X509Certificates; using System.Text; //From:http://blog.csdn.net/zhoufoxcn/article/details/6404236 +using Wox.Plugin; + namespace Wox.Infrastructure { 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)"; + 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) { if (string.IsNullOrEmpty(url)) diff --git a/Wox.Infrastructure/Storage/UserSettings/UserSettingStorage.cs b/Wox.Infrastructure/Storage/UserSettings/UserSettingStorage.cs index ec3b96813f..dbef1b084f 100644 --- a/Wox.Infrastructure/Storage/UserSettings/UserSettingStorage.cs +++ b/Wox.Infrastructure/Storage/UserSettings/UserSettingStorage.cs @@ -8,6 +8,9 @@ namespace Wox.Infrastructure.Storage.UserSettings { public class UserSettingStorage : BaseStorage { + [JsonProperty] + public bool DontPromptUpdateMsg { get; set; } + [JsonProperty] public string Hotkey { get; set; } @@ -145,6 +148,7 @@ namespace Wox.Infrastructure.Storage.UserSettings protected override UserSettingStorage LoadDefaultConfig() { + DontPromptUpdateMsg = false; Theme = "Dark"; ReplaceWinR = true; WebSearches = LoadDefaultWebSearches(); diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs index 3ed2fbbeb0..3a51724ddc 100644 --- a/Wox/MainWindow.xaml.cs +++ b/Wox/MainWindow.xaml.cs @@ -21,6 +21,7 @@ using Wox.Infrastructure.Storage; using Wox.Infrastructure.Storage.UserSettings; using Wox.Plugin; using Wox.PluginLoader; +using Wox.Update; using Application = System.Windows.Application; using Brushes = System.Windows.Media.Brushes; 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 //PublicAPI invoke in plugin init methods. E.g FolderPlugin ThreadPool.QueueUserWorkItem(o => Plugins.Init()); + + ThreadPool.QueueUserWorkItem(o => checkUpdate()); } void pnlResult_RightMouseClickEvent(Result result) @@ -195,6 +198,15 @@ namespace Wox 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) { UserSettingStorage.Instance.WindowLeft = Left; diff --git a/Wox/SettingWindow.xaml b/Wox/SettingWindow.xaml index b547e57896..21e8fc252c 100644 --- a/Wox/SettingWindow.xaml +++ b/Wox/SettingWindow.xaml @@ -28,6 +28,9 @@ Hide Wox when loses focus + + Don't show upgrade msg if new version available + diff --git a/Wox/SettingWindow.xaml.cs b/Wox/SettingWindow.xaml.cs index 5e76e7dc24..adefc2c006 100644 --- a/Wox/SettingWindow.xaml.cs +++ b/Wox/SettingWindow.xaml.cs @@ -38,8 +38,7 @@ namespace Wox private void Setting_Loaded(object sender, RoutedEventArgs ev) { - ctlHotkey.OnHotkeyChanged += ctlHotkey_OnHotkeyChanged; - ctlHotkey.SetHotkey(UserSettingStorage.Instance.Hotkey, false); + #region General cbHideWhenDeactive.Checked += (o, e) => { @@ -53,11 +52,25 @@ namespace Wox 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); cbHideWhenDeactive.IsChecked = UserSettingStorage.Instance.HideWhenDeactive; + cbDontPromptUpdateMsg.IsChecked = UserSettingStorage.Instance.DontPromptUpdateMsg; - #region Load Theme + #endregion + + #region Theme if (!string.IsNullOrEmpty(UserSettingStorage.Instance.QueryBoxFont) && Fonts.SystemFontFamilies.Count(o => o.FamilyNames.Values.Contains(UserSettingStorage.Instance.QueryBoxFont)) > 0) @@ -155,9 +168,17 @@ namespace Wox var wallpaperColor = WallpaperPathRetrieval.GetWallpaperColor(); PreviewPanel.Background = new SolidColorBrush(wallpaperColor); } + + //PreviewPanel + App.Window.SetTheme(UserSettingStorage.Instance.Theme); + #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 { @@ -200,9 +221,7 @@ namespace Wox #endregion - //PreviewPanel settingsLoaded = true; - App.Window.SetTheme(UserSettingStorage.Instance.Theme); } private void EnableProxy() diff --git a/Wox/Update/Release.cs b/Wox/Update/Release.cs new file mode 100644 index 0000000000..3664f5f2fa --- /dev/null +++ b/Wox/Update/Release.cs @@ -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; } + } +} diff --git a/Wox/Update/UpdateChecker.cs b/Wox/Update/UpdateChecker.cs new file mode 100644 index 0000000000..a66c6e50e1 --- /dev/null +++ b/Wox/Update/UpdateChecker.cs @@ -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/"; + + /// + /// If new release is available, then return the new release + /// otherwise, return null + /// + /// + 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(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; + } + + /// + /// if version1 > version2 return 1 + /// else -1 + /// + /// + /// + /// + 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 version1List = version1.Split('.').Select(int.Parse).ToList(); + List 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; + } + } +} diff --git a/Wox/Wox.csproj b/Wox/Wox.csproj index 0686453fea..c4f5faca5e 100644 --- a/Wox/Wox.csproj +++ b/Wox/Wox.csproj @@ -82,6 +82,7 @@ + @@ -103,6 +104,8 @@ + + MSBuild:Compile Designer