show update log after upgraded

This commit is contained in:
Paddy Xu
2017-07-23 22:39:44 +03:00
parent 78fe8d2558
commit 2820b840e4
3 changed files with 54 additions and 30 deletions

View File

@@ -94,6 +94,8 @@ namespace QuickLook
if (!Settings.Default.Upgraded)
return;
Updater.CollectAndShowReleaseNotes();
Settings.Default.Upgrade();
Settings.Default.Upgraded = false;
Settings.Default.Save();

View File

@@ -38,15 +38,10 @@ namespace QuickLook.Helpers
{
try
{
var web = new WebClientEx(15 * 1000);
web.Headers.Add(HttpRequestHeader.UserAgent, "Wget/1.9.1");
var json = DownloadJson("https://api.github.com/repos/xupefei/QuickLook/releases/latest");
var response = web.DownloadDataStream("https://api.github.com/repos/xupefei/QuickLook/releases");
var json = JsonConvert.DeserializeObject<dynamic>(new StreamReader(response).ReadToEnd());
var nVersion = (string) json[0]["tag_name"];
//nVersion = "0.2.1";
var nVersion = (string) json["tag_name"];
//nVersion = "9.2.1";
if (new Version(nVersion) <= Assembly.GetExecutingAssembly().GetName().Version)
{
@@ -57,15 +52,11 @@ namespace QuickLook.Helpers
return;
}
string notes = CollectReleaseNotes(json);
var changeLogPath = Path.GetTempFileName() + ".md";
File.WriteAllText(changeLogPath, notes);
CollectAndShowReleaseNotes();
Application.Current.Dispatcher.Invoke(
() =>
{
ViewWindowManager.GetInstance().InvokeViewer(changeLogPath);
TrayIconManager.GetInstance().ShowNotification("",
string.Format(TranslationHelper.GetString("Update_Found"), nVersion),
timeout: 20000,
@@ -84,8 +75,14 @@ namespace QuickLook.Helpers
});
}
private static string CollectReleaseNotes(dynamic json)
public static void CollectAndShowReleaseNotes()
{
Task.Run(() =>
{
try
{
var json = DownloadJson("https://api.github.com/repos/xupefei/QuickLook/releases");
var notes = string.Empty;
foreach (var item in json)
@@ -94,7 +91,32 @@ namespace QuickLook.Helpers
notes += item["body"] + "\r\n\r\n";
}
return notes;
var changeLogPath = Path.GetTempFileName() + ".md";
File.WriteAllText(changeLogPath, notes);
Application.Current.Dispatcher.Invoke(() => ViewWindowManager.GetInstance()
.InvokeViewer(changeLogPath));
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
Application.Current.Dispatcher.Invoke(
() => TrayIconManager.GetInstance().ShowNotification("",
string.Format(TranslationHelper.GetString("Update_Error"), e.Message)));
}
});
}
private static dynamic DownloadJson(string url)
{
var web = new WebClientEx(15 * 1000);
web.Headers.Add(HttpRequestHeader.UserAgent, "Wget/1.9.1");
var response =
web.DownloadDataStream(url);
var json = JsonConvert.DeserializeObject<dynamic>(new StreamReader(response).ReadToEnd());
return json;
}
}
}

View File

@@ -30,13 +30,13 @@ namespace QuickLook
internal class ViewWindowManager : IDisposable
{
private static ViewWindowManager _instance;
private MainWindowNoTransparent _viewWindowNoTransparent;
private MainWindowTransparent _viewWindowTransparent;
private MainWindowTransparent _currentMainWindow;
private string _path = string.Empty;
private MainWindowNoTransparent _viewWindowNoTransparent;
private MainWindowTransparent _viewWindowTransparent;
internal ViewWindowManager()
{
_viewWindowTransparent = new MainWindowTransparent();
@@ -148,11 +148,11 @@ namespace QuickLook
if (e.FocusedFile == _path)
return;
Debug.WriteLine($"SwitchPreviewRemoteInvoke: {e.FocusedFile}");
if (string.IsNullOrEmpty(e.FocusedFile))
return;
Debug.WriteLine($"SwitchPreviewRemoteInvoke: {e.FocusedFile}");
_currentMainWindow?.Dispatcher.BeginInvoke(new Action(SwitchPreview), DispatcherPriority.ApplicationIdle);
}