AppConfig.cs 23 KB

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