UpdateWindow.xaml.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using GeekDesk.Constant;
  2. using GeekDesk.Interface;
  3. using GeekDesk.Util;
  4. using GeekDesk.ViewModel;
  5. using Newtonsoft.Json.Linq;
  6. using System;
  7. using System.Configuration;
  8. using System.Diagnostics;
  9. using System.Windows;
  10. using System.Windows.Input;
  11. namespace GeekDesk.Control.Windows
  12. {
  13. /// <summary>
  14. /// UpdateWindow.xaml 的交互逻辑
  15. /// </summary>
  16. public partial class UpdateWindow : Window, IWindowCommon
  17. {
  18. private static AppConfig appConfig = MainWindow.appData.AppConfig;
  19. private static string githubUrl = "";
  20. private static string giteeUrl = "";
  21. private UpdateWindow(JObject jo)
  22. {
  23. try
  24. {
  25. WindowStartupLocation = WindowStartupLocation.CenterScreen;
  26. this.Topmost = true;
  27. InitializeComponent();
  28. DataHandle(jo);
  29. }
  30. catch (Exception)
  31. {
  32. }
  33. }
  34. /// <summary>
  35. /// 移动窗口
  36. /// </summary>
  37. /// <param name="sender"></param>
  38. /// <param name="e"></param>
  39. private void DragMove(object sender, System.Windows.Input.MouseButtonEventArgs e)
  40. {
  41. if (e.LeftButton == MouseButtonState.Pressed)
  42. {
  43. DragMove();
  44. }
  45. }
  46. private void DataHandle(JObject jo)
  47. {
  48. Title.Text = StringUtil.IsEmpty(jo["title"]) ? "" : jo["title"].ToString();
  49. SubTitle.Text = StringUtil.IsEmpty(jo["subTitle"]) ? "" : jo["subTitle"].ToString();
  50. MsgTitle.Text = StringUtil.IsEmpty(jo["msgTitle"]) ? "" : jo["msgTitle"].ToString();
  51. JArray ja = JArray.Parse(StringUtil.IsEmpty(jo["msg"]) ? "[]" : jo["msg"].ToString());
  52. githubUrl = StringUtil.IsEmpty(jo["githubUrl"]) ? ConfigurationManager.AppSettings["GitHubUrl"] : jo["githubUrl"].ToString();
  53. giteeUrl = StringUtil.IsEmpty(jo["giteeUrl"]) ? ConfigurationManager.AppSettings["GiteeUrl"] : jo["giteeUrl"].ToString();
  54. string msg = "";
  55. for (int i = 0; i < ja.Count; i++)
  56. {
  57. msg += "• " + ja[i].ToString() + "\n";
  58. }
  59. Msg.Text = msg;
  60. }
  61. private void Close_Click(object sender, RoutedEventArgs e)
  62. {
  63. this.Close();
  64. }
  65. private void Confirm_Click(object sender, RoutedEventArgs e)
  66. {
  67. string packageUrl;
  68. switch (appConfig.UpdateType)
  69. {
  70. case UpdateType.GitHub:
  71. packageUrl = githubUrl;
  72. break;
  73. default:
  74. packageUrl = giteeUrl;
  75. break;
  76. }
  77. Process.Start(packageUrl);
  78. this.Close();
  79. }
  80. private static System.Windows.Window window = null;
  81. public static void Show(JObject jo)
  82. {
  83. if (window == null || !window.Activate())
  84. {
  85. window = new UpdateWindow(jo);
  86. }
  87. window.Show();
  88. Keyboard.Focus(window);
  89. }
  90. public void OnKeyDown(object sender, KeyEventArgs e)
  91. {
  92. if (e.Key == Key.Escape)
  93. {
  94. this.DataContext = null;
  95. this.Close();
  96. }
  97. }
  98. }
  99. }