AppConfig.cs 15 KB

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