AppConfig.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. 
  2. using GeekDesk.Constant;
  3. using GeekDesk.Util;
  4. using System;
  5. using System.Collections.ObjectModel;
  6. using System.ComponentModel;
  7. using System.Windows;
  8. using System.Windows.Input;
  9. using System.Windows.Media.Imaging;
  10. /// <summary>
  11. /// 程序设置
  12. /// </summary>
  13. namespace GeekDesk.ViewModel
  14. {
  15. [Serializable]
  16. public class AppConfig : INotifyPropertyChanged
  17. {
  18. private SortType menuSortType = SortType.CUSTOM; //菜单排序类型
  19. private SortType iconSortType = SortType.CUSTOM; //图表排序类型
  20. private double windowWidth = (double)CommonEnum.WINDOW_WIDTH; //窗口宽度
  21. private double windowHeight = (double)CommonEnum.WINDOW_HEIGHT; //窗口高度
  22. private double menuCardWidth = (double)CommonEnum.MENU_CARD_WIDHT;//菜单栏宽度
  23. private int selectedMenuIndex = 0; //上次选中菜单索引
  24. private bool followMouse = true; //面板跟随鼠标 默认是
  25. private Visibility configIconVisible = Visibility.Visible; // 设置按钮是否显示
  26. private AppHideType appHideType = AppHideType.START_EXE; //面板关闭方式 (默认启动程序后)
  27. private bool startedShowPanel = true; //启动时是否显示主面板 默认显示
  28. [field: NonSerialized]
  29. private BitmapImage bitmapImage; //位图
  30. private byte[] imageByteArr; //背景图片 byte数组
  31. private string bacImgName = "系统默认";
  32. private int cardOpacity = 10; //默认0.1的不透明度 此处显示数值 * 100
  33. private int bgOpacity = 100; // 背景图片不透明度 此处显示数值 * 100
  34. private int pannelOpacity = 100; //主面板不透明度 此处显示数值 * 100
  35. private int pannelCornerRadius = 4; //面板圆角 默认4
  36. [field: NonSerialized]
  37. private ObservableCollection<IconInfo> selectedMenuIcons;
  38. private string hotkeyStr = "Ctrl + Q"; //默认启动面板快捷键
  39. private HotkeyModifiers hotkeyModifiers = HotkeyModifiers.MOD_CONTROL; //默认启动面板快捷键
  40. private Key hotkey = Key.Q; //默认启动面板快捷键
  41. private string toDoHotkeyStr; //待办任务快捷键
  42. private HotkeyModifiers toDoHotkeyModifiers; //待办任务快捷键
  43. private Key toDoHotkey; //待办任务快捷键
  44. private string customIconUrl; //自定义图标url
  45. private string customIconJsonUrl; //自定义图标json信息url
  46. private bool blurEffect = false; //毛玻璃效果 默认否
  47. private double blurValue;
  48. private UpdateType updateType = UpdateType.Gitee; //更新源 默认gitee源
  49. private bool selfStartUp = true; //开机自启动设置
  50. private bool selfStartUped = false; //是否已设置
  51. private bool pmModel = false; //性能模式
  52. private string textColor = "#000000"; //字体颜色
  53. private double imgPanelWidth = (double)CommonEnum.IMAGE_PANEL_WIDTH;
  54. private double imgPanelHeight = (double)CommonEnum.IMAGE_PANEL_HEIGHT;
  55. #region GetSet
  56. public double ImgPanelWidth
  57. {
  58. get
  59. {
  60. if (imgPanelWidth == 0d) return (double)CommonEnum.IMAGE_PANEL_WIDTH;
  61. return imgPanelWidth;
  62. }
  63. set
  64. {
  65. imgPanelWidth = value;
  66. OnPropertyChanged("ImgPanelWidth");
  67. }
  68. }
  69. public double ImgPanelHeight
  70. {
  71. get
  72. {
  73. if (imgPanelHeight == 0d) return (double)CommonEnum.IMAGE_PANEL_HEIGHT;
  74. return imgPanelHeight;
  75. }
  76. set
  77. {
  78. imgPanelHeight = value;
  79. OnPropertyChanged("ImgPanelHeight");
  80. }
  81. }
  82. public string TextColor
  83. {
  84. get
  85. {
  86. if (textColor == null) return "#000000";
  87. return textColor;
  88. }
  89. set
  90. {
  91. textColor = value;
  92. OnPropertyChanged("TextColor");
  93. }
  94. }
  95. public bool PMModel
  96. {
  97. get
  98. {
  99. return pmModel;
  100. }
  101. set
  102. {
  103. pmModel = value;
  104. OnPropertyChanged("PMModel");
  105. }
  106. }
  107. public bool SelfStartUped
  108. {
  109. get
  110. {
  111. return selfStartUped;
  112. }
  113. set
  114. {
  115. selfStartUped = value;
  116. OnPropertyChanged("SelfStartUped");
  117. }
  118. }
  119. public bool SelfStartUp
  120. {
  121. get
  122. {
  123. return selfStartUp;
  124. }
  125. set
  126. {
  127. selfStartUp = value;
  128. selfStartUped = true;
  129. OnPropertyChanged("SelfStartUp");
  130. }
  131. }
  132. public Key ToDoHotkey
  133. {
  134. get
  135. {
  136. return toDoHotkey;
  137. }
  138. set
  139. {
  140. toDoHotkey = value;
  141. OnPropertyChanged("ToDoHotkey");
  142. }
  143. }
  144. public HotkeyModifiers ToDoHotkeyModifiers
  145. {
  146. get
  147. {
  148. return toDoHotkeyModifiers;
  149. }
  150. set
  151. {
  152. toDoHotkeyModifiers = value;
  153. OnPropertyChanged("ToDoHotkeyModifiers");
  154. }
  155. }
  156. public string ToDoHotkeyStr
  157. {
  158. get
  159. {
  160. return toDoHotkeyStr;
  161. }
  162. set
  163. {
  164. toDoHotkeyStr = value;
  165. OnPropertyChanged("ToDoHotkeyStr");
  166. }
  167. }
  168. public UpdateType UpdateType
  169. {
  170. get
  171. {
  172. return updateType;
  173. }
  174. set
  175. {
  176. updateType = value;
  177. OnPropertyChanged("UpdateType");
  178. }
  179. }
  180. public double BlurValue
  181. {
  182. get
  183. {
  184. return blurValue;
  185. }
  186. set
  187. {
  188. blurValue = value;
  189. OnPropertyChanged("BlurValue");
  190. }
  191. }
  192. public bool BlurEffect
  193. {
  194. get
  195. {
  196. return blurEffect;
  197. }
  198. set
  199. {
  200. blurEffect = value;
  201. if (blurEffect)
  202. {
  203. BlurValue = 100;
  204. } else
  205. {
  206. BlurValue = 0;
  207. }
  208. OnPropertyChanged("BlurEffect");
  209. }
  210. }
  211. public string CustomIconUrl
  212. {
  213. get
  214. {
  215. return customIconUrl;
  216. }
  217. set
  218. {
  219. customIconUrl = value;
  220. OnPropertyChanged("CustomIconUrl");
  221. }
  222. }
  223. public string CustomIconJsonUrl
  224. {
  225. get
  226. {
  227. return customIconJsonUrl;
  228. }
  229. set
  230. {
  231. customIconJsonUrl = value;
  232. OnPropertyChanged("CustomIconJsonUrl");
  233. }
  234. }
  235. public Key Hotkey
  236. {
  237. get
  238. {
  239. return hotkey;
  240. }
  241. set
  242. {
  243. hotkey = value;
  244. OnPropertyChanged("Hotkey");
  245. }
  246. }
  247. public string HotkeyStr
  248. {
  249. get
  250. {
  251. return hotkeyStr;
  252. }
  253. set
  254. {
  255. hotkeyStr = value;
  256. OnPropertyChanged("HotkeyStr");
  257. }
  258. }
  259. public HotkeyModifiers HotkeyModifiers
  260. {
  261. get
  262. {
  263. return hotkeyModifiers;
  264. }
  265. set
  266. {
  267. hotkeyModifiers = value;
  268. OnPropertyChanged("HotkeyModifiers");
  269. }
  270. }
  271. public ObservableCollection<IconInfo> SelectedMenuIcons
  272. {
  273. get
  274. {
  275. return selectedMenuIcons;
  276. }
  277. set
  278. {
  279. selectedMenuIcons = value;
  280. OnPropertyChanged("SelectedMenuIcons");
  281. }
  282. }
  283. public int PannelCornerRadius
  284. {
  285. get
  286. {
  287. return pannelCornerRadius;
  288. }
  289. set
  290. {
  291. pannelCornerRadius = value;
  292. OnPropertyChanged("pannelCornerRadius");
  293. }
  294. }
  295. public int PannelOpacity
  296. {
  297. get
  298. {
  299. return pannelOpacity;
  300. }
  301. set
  302. {
  303. pannelOpacity = value;
  304. OnPropertyChanged("PannelOpacity");
  305. }
  306. }
  307. public int BgOpacity
  308. {
  309. get
  310. {
  311. return bgOpacity;
  312. }
  313. set
  314. {
  315. bgOpacity = value;
  316. OnPropertyChanged("BgOpacity");
  317. }
  318. }
  319. public int CardOpacity
  320. {
  321. get
  322. {
  323. return cardOpacity;
  324. }
  325. set
  326. {
  327. cardOpacity = value;
  328. OnPropertyChanged("CardOpacity");
  329. }
  330. }
  331. public string BacImgName
  332. {
  333. get
  334. {
  335. return bacImgName;
  336. }
  337. set
  338. {
  339. bacImgName = value;
  340. OnPropertyChanged("BacImgName");
  341. }
  342. }
  343. public byte[] ImageByteArr
  344. {
  345. get
  346. {
  347. return imageByteArr;
  348. }
  349. set
  350. {
  351. imageByteArr = value;
  352. OnPropertyChanged("ImageByteArr");
  353. }
  354. }
  355. public BitmapImage BitmapImage
  356. {
  357. get
  358. {
  359. if (imageByteArr == null || imageByteArr.Length == 0)
  360. {
  361. bacImgName = "系统默认";
  362. //Image image = ImageUtil.ByteArrayToImage(Convert.FromBase64String(Constants.DEFAULT_BAC_IMAGE_BASE64));
  363. return ImageUtil.ByteArrToImage(Convert.FromBase64String(Constants.DEFAULT_BAC_IMAGE_BASE64));
  364. } else
  365. {
  366. return ImageUtil.ByteArrToImage(ImageByteArr);
  367. }
  368. }
  369. set
  370. {
  371. bitmapImage = value;
  372. imageByteArr = ImageUtil.BitmapImageToByte(bitmapImage);
  373. OnPropertyChanged("BitmapImage");
  374. }
  375. }
  376. public bool StartedShowPanel
  377. {
  378. get
  379. {
  380. return startedShowPanel;
  381. }
  382. set
  383. {
  384. startedShowPanel = value;
  385. OnPropertyChanged("StartedShowPanel");
  386. }
  387. }
  388. public AppHideType AppHideType
  389. {
  390. get
  391. {
  392. return appHideType;
  393. }
  394. set
  395. {
  396. appHideType = value;
  397. OnPropertyChanged("AppHideType");
  398. }
  399. }
  400. public Visibility ConfigIconVisible
  401. {
  402. get
  403. {
  404. return configIconVisible;
  405. }
  406. set
  407. {
  408. configIconVisible = value;
  409. OnPropertyChanged("ConfigIconVisible");
  410. }
  411. }
  412. public bool FollowMouse
  413. {
  414. get
  415. {
  416. return followMouse;
  417. }
  418. set
  419. {
  420. followMouse = value;
  421. OnPropertyChanged("FollowMouse");
  422. }
  423. }
  424. public int SelectedMenuIndex
  425. {
  426. get
  427. {
  428. return selectedMenuIndex;
  429. }
  430. set
  431. {
  432. selectedMenuIndex = value;
  433. OnPropertyChanged("SelectedMenuIndex");
  434. }
  435. }
  436. public SortType MenuSortType
  437. {
  438. get
  439. {
  440. return menuSortType;
  441. }
  442. set
  443. {
  444. menuSortType = value;
  445. OnPropertyChanged("MenuSortType");
  446. }
  447. }
  448. public SortType IconSortType
  449. {
  450. get
  451. {
  452. return iconSortType;
  453. }
  454. set
  455. {
  456. iconSortType = value;
  457. OnPropertyChanged("IconSortType");
  458. }
  459. }
  460. public double WindowWidth
  461. {
  462. get
  463. {
  464. return windowWidth;
  465. }
  466. set
  467. {
  468. windowWidth = value;
  469. OnPropertyChanged("WindowWidth");
  470. }
  471. }
  472. public double WindowHeight
  473. {
  474. get
  475. {
  476. return windowHeight;
  477. }
  478. set
  479. {
  480. windowHeight = value;
  481. OnPropertyChanged("WindowHeight");
  482. }
  483. }
  484. public double MenuCardWidth
  485. {
  486. get
  487. {
  488. return menuCardWidth;
  489. }
  490. set
  491. {
  492. menuCardWidth = value;
  493. OnPropertyChanged("MenuCardWidth");
  494. }
  495. }
  496. [field: NonSerializedAttribute()]
  497. public event PropertyChangedEventHandler PropertyChanged;
  498. private void OnPropertyChanged(string propertyName)
  499. {
  500. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  501. CommonCode.SaveAppData(MainWindow.appData);
  502. }
  503. #endregion
  504. }
  505. }