UpdateWindow.xaml.cs 3.5 KB

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