AppConfig.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911
  1. 
  2. using GeekDesk.Constant;
  3. using GeekDesk.Util;
  4. using GeekDesk.ViewModel.Temp;
  5. using Newtonsoft.Json;
  6. using System;
  7. using System.Collections.ObjectModel;
  8. using System.ComponentModel;
  9. using System.Windows;
  10. using System.Windows.Input;
  11. using System.Windows.Media.Imaging;
  12. using static GeekDesk.Util.GlobalHotKey;
  13. /// <summary>
  14. /// 程序设置
  15. /// </summary>
  16. namespace GeekDesk.ViewModel
  17. {
  18. [Serializable]
  19. public class AppConfig : INotifyPropertyChanged
  20. {
  21. private SortType menuSortType = SortType.CUSTOM; //菜单排序类型
  22. private SortType iconSortType = SortType.CUSTOM; //图表排序类型
  23. private double windowWidth = (double)CommonEnum.WINDOW_WIDTH; //窗口宽度
  24. private double windowHeight = (double)CommonEnum.WINDOW_HEIGHT; //窗口高度
  25. private double menuCardWidth = (double)CommonEnum.MENU_CARD_WIDHT;//菜单栏宽度
  26. private int selectedMenuIndex = 0; //上次选中菜单索引
  27. private bool followMouse = true; //面板跟随鼠标 默认是
  28. private Visibility configIconVisible = Visibility.Visible; // 设置按钮是否显示
  29. private Visibility titleLogoVisible = Visibility.Visible; // 标题logo是否显示
  30. private AppHideType appHideType = AppHideType.START_EXE; //面板关闭方式 (默认启动程序后)
  31. private bool startedShowPanel = true; //启动时是否显示主面板 默认显示
  32. [field: NonSerialized]
  33. private BitmapImage bitmapImage; //位图
  34. private byte[] imageByteArr; //背景图片 byte数组
  35. private string bacImgName = "系统默认";
  36. private int cardOpacity = 10; //默认0.1的不透明度 此处显示数值 * 100
  37. private int bgOpacity = 100; // 背景图片不透明度 此处显示数值 * 100
  38. private int pannelOpacity = 100; //主面板不透明度 此处显示数值 * 100
  39. private int pannelCornerRadius = 4; //面板圆角 默认4
  40. [field: NonSerialized]
  41. private ObservableCollection<IconInfo> selectedMenuIcons;
  42. private string hotkeyStr = "Ctrl + Q"; //默认启动面板快捷键
  43. private HotkeyModifiers hotkeyModifiers = HotkeyModifiers.MOD_CONTROL; //默认启动面板快捷键
  44. private Key hotkey = Key.Q; //默认启动面板快捷键
  45. private string toDoHotkeyStr = "Ctrl + Shift + Q"; //待办任务快捷键
  46. private HotkeyModifiers toDoHotkeyModifiers; //待办任务快捷键
  47. private Key toDoHotkey = Key.Q; //待办任务快捷键
  48. private string colorPickerHotkeyStr = ""; //拾色器快捷键
  49. private HotkeyModifiers colorPickerHotkeyModifiers; //拾色器快捷键
  50. private Key colorPickerHotkey; //拾色器快捷键
  51. private string customIconUrl; //自定义图标url
  52. private string customIconJsonUrl; //自定义图标json信息url
  53. private bool blurEffect = false; //毛玻璃效果 默认否
  54. private double blurValue;
  55. private UpdateType updateType = UpdateType.Gitee; //更新源 默认gitee源
  56. private bool selfStartUp = true; //开机自启动设置
  57. private bool selfStartUped = false; //是否已设置
  58. private bool pmModel = false; //性能模式
  59. private string textColor = "#000000"; //字体颜色
  60. private double imgPanelWidth = (double)CommonEnum.IMAGE_PANEL_WIDTH;
  61. private double imgPanelHeight = (double)CommonEnum.IMAGE_PANEL_HEIGHT;
  62. private bool marginHide = false; //贴边隐藏
  63. private bool appAnimation = false; //主窗口动画效果
  64. private int imageWidth = (int)CommonEnum.IMAGE_WIDTH; //图片宽度
  65. private int imageHeight = (int)CommonEnum.IMAGE_HEIGHT; //图片高度
  66. private bool mouseMiddleShow = false; //鼠标中键呼出 默认不启用
  67. private bool showBarIcon = true; //显示托盘图标 默认显示
  68. private bool doubleOpen = false; //双击打开项目 默认关闭
  69. private bool hoverMenu = false; //悬停切换菜单 默认关闭
  70. private BGStyle bgStyle = BGStyle.ImgBac; //背景风格
  71. private GradientBGParam gradientBGParam = null; //渐变背景参数
  72. private bool? enableAppHotKey = true; //可能为null 开启热键
  73. private bool? enableTodoHotKey = true; //可能为null 开启待办热键
  74. private bool enableColorPickerHotKey; //新增 默认为false 不需要考虑null值
  75. private SearchType searchType;
  76. #region GetSet
  77. public SearchType SearchType
  78. {
  79. get
  80. {
  81. return searchType;
  82. }
  83. set
  84. {
  85. searchType = value;
  86. OnPropertyChanged("SearchType");
  87. }
  88. }
  89. public bool EnableColorPickerHotKey
  90. {
  91. get
  92. {
  93. return enableColorPickerHotKey;
  94. }
  95. set
  96. {
  97. enableColorPickerHotKey = value;
  98. OnPropertyChanged("EnableColorPickerHotKey");
  99. }
  100. }
  101. public bool? EnableAppHotKey
  102. {
  103. get
  104. {
  105. if (enableAppHotKey == null) enableAppHotKey = true;
  106. return enableAppHotKey;
  107. }
  108. set
  109. {
  110. enableAppHotKey = value;
  111. OnPropertyChanged("EnableAppHotKey");
  112. }
  113. }
  114. public bool? EnableTodoHotKey
  115. {
  116. get
  117. {
  118. if (enableTodoHotKey == null) enableTodoHotKey = true;
  119. return enableTodoHotKey;
  120. }
  121. set
  122. {
  123. enableTodoHotKey = value;
  124. OnPropertyChanged("EnableTodoHotKey");
  125. }
  126. }
  127. public Visibility TitleLogoVisible
  128. {
  129. get
  130. {
  131. return titleLogoVisible;
  132. }
  133. set
  134. {
  135. titleLogoVisible = value;
  136. OnPropertyChanged("TitleLogoVisible");
  137. }
  138. }
  139. public GradientBGParam GradientBGParam
  140. {
  141. get
  142. {
  143. if (gradientBGParam == null)
  144. {
  145. gradientBGParam = GradientBGParamList.GradientBGParams[0];
  146. }
  147. return gradientBGParam;
  148. }
  149. set
  150. {
  151. gradientBGParam = value;
  152. OnPropertyChanged("GradientBGParam");
  153. }
  154. }
  155. public BGStyle BGStyle
  156. {
  157. get
  158. {
  159. if (bgStyle == 0)
  160. {
  161. bgStyle = (BGStyle)1;
  162. }
  163. return bgStyle;
  164. }
  165. set
  166. {
  167. bgStyle = value;
  168. OnPropertyChanged("BGStyle");
  169. }
  170. }
  171. public bool HoverMenu
  172. {
  173. get
  174. {
  175. return hoverMenu;
  176. }
  177. set
  178. {
  179. hoverMenu = value;
  180. OnPropertyChanged("HoverMenu");
  181. }
  182. }
  183. public bool DoubleOpen
  184. {
  185. get
  186. {
  187. return doubleOpen;
  188. }
  189. set
  190. {
  191. doubleOpen = value;
  192. OnPropertyChanged("DoubleOpen");
  193. }
  194. }
  195. public bool ShowBarIcon
  196. {
  197. get
  198. {
  199. return showBarIcon;
  200. }
  201. set
  202. {
  203. showBarIcon = value;
  204. OnPropertyChanged("ShowBarIcon");
  205. }
  206. }
  207. public bool MouseMiddleShow
  208. {
  209. get
  210. {
  211. return mouseMiddleShow;
  212. }
  213. set
  214. {
  215. mouseMiddleShow = value;
  216. OnPropertyChanged("MouseMiddleShow");
  217. }
  218. }
  219. public int ImageWidth
  220. {
  221. get
  222. {
  223. // 为了兼容旧版 暂时使用默认
  224. if (imageWidth == 0)
  225. {
  226. return (int)CommonEnum.IMAGE_WIDTH;
  227. }
  228. else
  229. {
  230. return imageWidth;
  231. }
  232. }
  233. set
  234. {
  235. imageWidth = value;
  236. //同时设置高度
  237. ImageHeight = value;
  238. //计算 容器宽度因子
  239. double i = ((double)imageWidth - (double)CommonEnum.IMAGE_WIDTH) / 5d;
  240. double s = 2.44;
  241. i *= 2d;
  242. while (i > 1)
  243. {
  244. i /= 10d;
  245. }
  246. if (i > 0d)
  247. {
  248. s -= i;
  249. }
  250. if (s < 2.2)
  251. {
  252. s = 2.2;
  253. }
  254. //设置容器宽度
  255. ImgPanelWidth = (int)(ImageWidth * s);
  256. OnPropertyChanged("ImageWidth");
  257. }
  258. }
  259. public int ImageHeight
  260. {
  261. get
  262. {
  263. //都使用宽度来确定大小
  264. // 为了兼容旧版 暂时使用默认
  265. if (imageHeight == 0)
  266. {
  267. return (int)CommonEnum.IMAGE_HEIGHT;
  268. }
  269. else
  270. {
  271. return imageHeight;
  272. }
  273. }
  274. set
  275. {
  276. imageHeight = value;
  277. //计算容器高度因子
  278. double i = ((double)imageHeight - (double)CommonEnum.IMAGE_HEIGHT) / 5d;
  279. while (i > 1)
  280. {
  281. i /= 10d;
  282. }
  283. double s = 2.00;
  284. if (i > 0d)
  285. {
  286. s -= i;
  287. }
  288. if (s < 1.5) s = 1.5;
  289. //设置容器高度
  290. ImgPanelHeight = ImageHeight * s;
  291. OnPropertyChanged("ImageHeight");
  292. }
  293. }
  294. public bool AppAnimation
  295. {
  296. get
  297. {
  298. return appAnimation;
  299. }
  300. set
  301. {
  302. appAnimation = value;
  303. OnPropertyChanged("AppAnimation");
  304. }
  305. }
  306. public bool MarginHide
  307. {
  308. get
  309. {
  310. return marginHide;
  311. }
  312. set
  313. {
  314. marginHide = value;
  315. OnPropertyChanged("MarginHide");
  316. }
  317. }
  318. public double ImgPanelWidth
  319. {
  320. get
  321. {
  322. if (imgPanelWidth == 0d) return (double)CommonEnum.IMAGE_PANEL_WIDTH;
  323. return imgPanelWidth;
  324. }
  325. set
  326. {
  327. imgPanelWidth = value;
  328. OnPropertyChanged("ImgPanelWidth");
  329. }
  330. }
  331. public double ImgPanelHeight
  332. {
  333. get
  334. {
  335. if (imgPanelHeight == 0d) return (double)CommonEnum.IMAGE_PANEL_HEIGHT;
  336. return imgPanelHeight;
  337. }
  338. set
  339. {
  340. imgPanelHeight = value;
  341. OnPropertyChanged("ImgPanelHeight");
  342. }
  343. }
  344. public string TextColor
  345. {
  346. get
  347. {
  348. if (textColor == null) return "#000000";
  349. return textColor;
  350. }
  351. set
  352. {
  353. textColor = value;
  354. OnPropertyChanged("TextColor");
  355. }
  356. }
  357. public bool PMModel
  358. {
  359. get
  360. {
  361. return pmModel;
  362. }
  363. set
  364. {
  365. pmModel = value;
  366. OnPropertyChanged("PMModel");
  367. }
  368. }
  369. public bool SelfStartUped
  370. {
  371. get
  372. {
  373. return selfStartUped;
  374. }
  375. set
  376. {
  377. selfStartUped = value;
  378. OnPropertyChanged("SelfStartUped");
  379. }
  380. }
  381. public bool SelfStartUp
  382. {
  383. get
  384. {
  385. return selfStartUp;
  386. }
  387. set
  388. {
  389. selfStartUp = value;
  390. selfStartUped = true;
  391. OnPropertyChanged("SelfStartUp");
  392. }
  393. }
  394. public Key ColorPickerHotkey
  395. {
  396. get
  397. {
  398. return colorPickerHotkey;
  399. }
  400. set
  401. {
  402. colorPickerHotkey = value;
  403. OnPropertyChanged("ColorPickerHotkey");
  404. }
  405. }
  406. public HotkeyModifiers ColorPickerHotkeyModifiers
  407. {
  408. get
  409. {
  410. return colorPickerHotkeyModifiers;
  411. }
  412. set
  413. {
  414. colorPickerHotkeyModifiers = value;
  415. OnPropertyChanged("ColorPickerHotkeyModifiers");
  416. }
  417. }
  418. public string ColorPickerHotkeyStr
  419. {
  420. get
  421. {
  422. return colorPickerHotkeyStr;
  423. }
  424. set
  425. {
  426. colorPickerHotkeyStr = value;
  427. OnPropertyChanged("ColorPickerHotkeyStr");
  428. }
  429. }
  430. public Key ToDoHotkey
  431. {
  432. get
  433. {
  434. //兼容老版本
  435. if (toDoHotkey == Key.None)
  436. {
  437. toDoHotkey = Key.E;
  438. }
  439. return toDoHotkey;
  440. }
  441. set
  442. {
  443. toDoHotkey = value;
  444. OnPropertyChanged("ToDoHotkey");
  445. }
  446. }
  447. public HotkeyModifiers ToDoHotkeyModifiers
  448. {
  449. get
  450. {
  451. if (toDoHotkeyModifiers == 0)
  452. {
  453. toDoHotkeyModifiers = HotkeyModifiers.MOD_CONTROL | HotkeyModifiers.MOD_SHIFT;
  454. }
  455. return toDoHotkeyModifiers;
  456. }
  457. set
  458. {
  459. toDoHotkeyModifiers = value;
  460. OnPropertyChanged("ToDoHotkeyModifiers");
  461. }
  462. }
  463. public string ToDoHotkeyStr
  464. {
  465. get
  466. {
  467. //兼容老版本
  468. if (toDoHotkeyStr == null)
  469. {
  470. toDoHotkeyStr = "Ctrl + Shift + Q";
  471. }
  472. return toDoHotkeyStr;
  473. }
  474. set
  475. {
  476. toDoHotkeyStr = value;
  477. OnPropertyChanged("ToDoHotkeyStr");
  478. }
  479. }
  480. public UpdateType UpdateType
  481. {
  482. get
  483. {
  484. return updateType;
  485. }
  486. set
  487. {
  488. updateType = value;
  489. OnPropertyChanged("UpdateType");
  490. }
  491. }
  492. public double BlurValue
  493. {
  494. get
  495. {
  496. return blurValue;
  497. }
  498. set
  499. {
  500. blurValue = value;
  501. OnPropertyChanged("BlurValue");
  502. }
  503. }
  504. public bool BlurEffect
  505. {
  506. get
  507. {
  508. return blurEffect;
  509. }
  510. set
  511. {
  512. blurEffect = value;
  513. if (blurEffect)
  514. {
  515. BlurValue = 100;
  516. }
  517. else
  518. {
  519. BlurValue = 0;
  520. }
  521. OnPropertyChanged("BlurEffect");
  522. }
  523. }
  524. public string CustomIconUrl
  525. {
  526. get
  527. {
  528. return customIconUrl;
  529. }
  530. set
  531. {
  532. customIconUrl = value;
  533. OnPropertyChanged("CustomIconUrl");
  534. }
  535. }
  536. public string CustomIconJsonUrl
  537. {
  538. get
  539. {
  540. return customIconJsonUrl;
  541. }
  542. set
  543. {
  544. customIconJsonUrl = value;
  545. OnPropertyChanged("CustomIconJsonUrl");
  546. }
  547. }
  548. public Key Hotkey
  549. {
  550. get
  551. {
  552. return hotkey;
  553. }
  554. set
  555. {
  556. hotkey = value;
  557. OnPropertyChanged("Hotkey");
  558. }
  559. }
  560. public string HotkeyStr
  561. {
  562. get
  563. {
  564. return hotkeyStr;
  565. }
  566. set
  567. {
  568. hotkeyStr = value;
  569. OnPropertyChanged("HotkeyStr");
  570. }
  571. }
  572. public HotkeyModifiers HotkeyModifiers
  573. {
  574. get
  575. {
  576. if (hotkeyModifiers == 0)
  577. {
  578. hotkeyModifiers = HotkeyModifiers.MOD_CONTROL;
  579. }
  580. return hotkeyModifiers;
  581. }
  582. set
  583. {
  584. hotkeyModifiers = value;
  585. OnPropertyChanged("HotkeyModifiers");
  586. }
  587. }
  588. public ObservableCollection<IconInfo> SelectedMenuIcons
  589. {
  590. get
  591. {
  592. return selectedMenuIcons;
  593. }
  594. set
  595. {
  596. selectedMenuIcons = value;
  597. OnPropertyChanged("SelectedMenuIcons");
  598. }
  599. }
  600. public int PannelCornerRadius
  601. {
  602. get
  603. {
  604. return pannelCornerRadius;
  605. }
  606. set
  607. {
  608. pannelCornerRadius = value;
  609. OnPropertyChanged("pannelCornerRadius");
  610. }
  611. }
  612. public int PannelOpacity
  613. {
  614. get
  615. {
  616. return pannelOpacity;
  617. }
  618. set
  619. {
  620. pannelOpacity = value;
  621. OnPropertyChanged("PannelOpacity");
  622. }
  623. }
  624. public int BgOpacity
  625. {
  626. get
  627. {
  628. return bgOpacity;
  629. }
  630. set
  631. {
  632. bgOpacity = value;
  633. OnPropertyChanged("BgOpacity");
  634. }
  635. }
  636. public int CardOpacity
  637. {
  638. get
  639. {
  640. return cardOpacity;
  641. }
  642. set
  643. {
  644. cardOpacity = value;
  645. OnPropertyChanged("CardOpacity");
  646. }
  647. }
  648. public string BacImgName
  649. {
  650. get
  651. {
  652. return bacImgName;
  653. }
  654. set
  655. {
  656. bacImgName = value;
  657. OnPropertyChanged("BacImgName");
  658. }
  659. }
  660. public byte[] ImageByteArr
  661. {
  662. get
  663. {
  664. return imageByteArr;
  665. }
  666. set
  667. {
  668. imageByteArr = value;
  669. OnPropertyChanged("ImageByteArr");
  670. }
  671. }
  672. public BitmapImage BitmapImage
  673. {
  674. get
  675. {
  676. if (imageByteArr == null || imageByteArr.Length == 0)
  677. {
  678. bacImgName = "系统默认";
  679. //Image image = ImageUtil.ByteArrayToImage(Convert.FromBase64String(Constants.DEFAULT_BAC_IMAGE_BASE64));
  680. return ImageUtil.ByteArrToImage(Convert.FromBase64String(Constants.DEFAULT_BAC_IMAGE_BASE64));
  681. }
  682. else
  683. {
  684. return ImageUtil.ByteArrToImage(ImageByteArr);
  685. }
  686. }
  687. set
  688. {
  689. bitmapImage = value;
  690. imageByteArr = ImageUtil.BitmapImageToByte(bitmapImage);
  691. OnPropertyChanged("BitmapImage");
  692. }
  693. }
  694. public bool StartedShowPanel
  695. {
  696. get
  697. {
  698. return startedShowPanel;
  699. }
  700. set
  701. {
  702. startedShowPanel = value;
  703. OnPropertyChanged("StartedShowPanel");
  704. }
  705. }
  706. public AppHideType AppHideType
  707. {
  708. get
  709. {
  710. return appHideType;
  711. }
  712. set
  713. {
  714. appHideType = value;
  715. OnPropertyChanged("AppHideType");
  716. }
  717. }
  718. public Visibility ConfigIconVisible
  719. {
  720. get
  721. {
  722. return configIconVisible;
  723. }
  724. set
  725. {
  726. configIconVisible = value;
  727. OnPropertyChanged("ConfigIconVisible");
  728. }
  729. }
  730. public bool FollowMouse
  731. {
  732. get
  733. {
  734. return followMouse;
  735. }
  736. set
  737. {
  738. followMouse = value;
  739. OnPropertyChanged("FollowMouse");
  740. }
  741. }
  742. public int SelectedMenuIndex
  743. {
  744. get
  745. {
  746. return selectedMenuIndex;
  747. }
  748. set
  749. {
  750. selectedMenuIndex = value;
  751. OnPropertyChanged("SelectedMenuIndex");
  752. }
  753. }
  754. public SortType MenuSortType
  755. {
  756. get
  757. {
  758. return menuSortType;
  759. }
  760. set
  761. {
  762. menuSortType = value;
  763. OnPropertyChanged("MenuSortType");
  764. }
  765. }
  766. public SortType IconSortType
  767. {
  768. get
  769. {
  770. return iconSortType;
  771. }
  772. set
  773. {
  774. iconSortType = value;
  775. OnPropertyChanged("IconSortType");
  776. }
  777. }
  778. public double WindowWidth
  779. {
  780. get
  781. {
  782. return windowWidth;
  783. }
  784. set
  785. {
  786. windowWidth = value;
  787. OnPropertyChanged("WindowWidth");
  788. }
  789. }
  790. public double WindowHeight
  791. {
  792. get
  793. {
  794. return windowHeight;
  795. }
  796. set
  797. {
  798. windowHeight = value;
  799. OnPropertyChanged("WindowHeight");
  800. }
  801. }
  802. public double MenuCardWidth
  803. {
  804. get
  805. {
  806. return menuCardWidth;
  807. }
  808. set
  809. {
  810. menuCardWidth = value;
  811. OnPropertyChanged("MenuCardWidth");
  812. }
  813. }
  814. [field: NonSerializedAttribute()]
  815. public event PropertyChangedEventHandler PropertyChanged;
  816. private void OnPropertyChanged(string propertyName)
  817. {
  818. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  819. CommonCode.SaveAppData(MainWindow.appData);
  820. }
  821. #endregion
  822. public override String ToString()
  823. {
  824. return JsonConvert.SerializeObject(this);
  825. }
  826. }
  827. }