Files
GeekDesk/ViewModel/AppConfig.cs

727 lines
18 KiB
C#
Raw Normal View History

2021-04-13 15:26:19 +08:00

2021-04-12 13:46:05 +08:00
using GeekDesk.Constant;
2021-05-20 17:33:49 +08:00
using GeekDesk.Util;
2021-04-13 15:26:19 +08:00
using System;
2021-05-28 18:01:19 +08:00
using System.Collections.ObjectModel;
2021-04-13 15:26:19 +08:00
using System.ComponentModel;
2021-05-19 17:31:28 +08:00
using System.Windows;
2021-05-31 21:54:10 +08:00
using System.Windows.Input;
2021-05-20 21:59:32 +08:00
using System.Windows.Media.Imaging;
using static GeekDesk.Util.GlobalHotKey;
2021-04-12 13:46:05 +08:00
2021-05-19 17:31:28 +08:00
/// <summary>
/// 程序设置
/// </summary>
2021-04-12 13:46:05 +08:00
namespace GeekDesk.ViewModel
{
2021-04-13 15:26:19 +08:00
2021-04-12 13:46:05 +08:00
[Serializable]
2021-05-14 16:48:26 +08:00
public class AppConfig : INotifyPropertyChanged
2021-04-12 13:46:05 +08:00
{
2021-05-19 17:31:28 +08:00
private SortType menuSortType = SortType.CUSTOM; //菜单排序类型
private SortType iconSortType = SortType.CUSTOM; //图表排序类型
private double windowWidth = (double)CommonEnum.WINDOW_WIDTH; //窗口宽度
private double windowHeight = (double)CommonEnum.WINDOW_HEIGHT; //窗口高度
private double menuCardWidth = (double)CommonEnum.MENU_CARD_WIDHT;//菜单栏宽度
2021-05-12 10:00:12 +08:00
private int selectedMenuIndex = 0; //上次选中菜单索引
2021-05-19 17:31:28 +08:00
private bool followMouse = true; //面板跟随鼠标 默认是
private Visibility configIconVisible = Visibility.Visible; // 设置按钮是否显示
private AppHideType appHideType = AppHideType.START_EXE; //面板关闭方式 (默认启动程序后)
2021-05-20 17:33:49 +08:00
private bool startedShowPanel = true; //启动时是否显示主面板 默认显示
2021-05-20 21:59:32 +08:00
[field: NonSerialized]
private BitmapImage bitmapImage; //位图
private byte[] imageByteArr; //背景图片 byte数组
2021-05-21 17:19:46 +08:00
private string bacImgName = "系统默认";
2021-05-28 18:01:19 +08:00
private int cardOpacity = 10; //默认0.1的不透明度 此处显示数值 * 100
private int bgOpacity = 100; // 背景图片不透明度 此处显示数值 * 100
private int pannelOpacity = 100; //主面板不透明度 此处显示数值 * 100
private int pannelCornerRadius = 4; //面板圆角 默认4
[field: NonSerialized]
private ObservableCollection<IconInfo> selectedMenuIcons;
2021-07-12 17:28:57 +08:00
private string hotkeyStr = "Ctrl + Q"; //默认启动面板快捷键
private HotkeyModifiers hotkeyModifiers = HotkeyModifiers.MOD_CONTROL; //默认启动面板快捷键
private Key hotkey = Key.Q; //默认启动面板快捷键
private string toDoHotkeyStr = "Ctrl + Shift + Q"; //待办任务快捷键
private HotkeyModifiers toDoHotkeyModifiers; //待办任务快捷键
private Key toDoHotkey = Key.E; //待办任务快捷键
2021-07-12 17:28:57 +08:00
private string customIconUrl; //自定义图标url
private string customIconJsonUrl; //自定义图标json信息url
2021-05-20 21:59:32 +08:00
2021-07-13 17:29:33 +08:00
private bool blurEffect = false; //毛玻璃效果 默认否
private double blurValue;
private UpdateType updateType = UpdateType.Gitee; //更新源 默认gitee源
2021-07-21 11:15:51 +08:00
private bool selfStartUp = true; //开机自启动设置
private bool selfStartUped = false; //是否已设置
private bool pmModel = false; //性能模式
private string textColor = "#000000"; //字体颜色
private double imgPanelWidth = (double)CommonEnum.IMAGE_PANEL_WIDTH;
private double imgPanelHeight = (double)CommonEnum.IMAGE_PANEL_HEIGHT;
private bool marginHide = false; //贴边隐藏
private bool appAnimation = false; //主窗口动画效果
private int imageWidth = (int)CommonEnum.IMAGE_WIDTH; //图片宽度
private int imageHeight = (int)CommonEnum.IMAGE_HEIGHT; //图片高度
private bool mouseMiddleShow = false; //鼠标中键呼出 默认不启用
2021-12-13 10:53:55 +08:00
private bool showBarIcon = true; //显示托盘图标 默认显示
2021-12-21 16:52:31 +08:00
private bool doubleOpen = false; //双击打开项目 默认关闭
2021-05-28 18:01:19 +08:00
#region GetSet
2021-12-21 16:52:31 +08:00
public bool DoubleOpen
{
get
{
return doubleOpen;
}
set
{
doubleOpen = value;
OnPropertyChanged("DoubleOpen");
}
}
2021-12-13 10:53:55 +08:00
public bool ShowBarIcon
{
get
{
return showBarIcon;
}
set
{
showBarIcon = value;
OnPropertyChanged("ShowBarIcon");
}
}
public bool MouseMiddleShow
{
get
{
return mouseMiddleShow;
}
set
{
mouseMiddleShow = value;
OnPropertyChanged("MouseMiddleShow");
}
}
public int ImageWidth
{
get
{
// 为了兼容旧版 暂时使用默认
if (imageWidth == 0)
{
return (int)CommonEnum.IMAGE_WIDTH;
} else
{
return imageWidth;
}
}
set
{
imageWidth = value;
//同时设置高度
ImageHeight = value;
//计算 容器宽度因子
double i = ((double)imageWidth - (double)CommonEnum.IMAGE_WIDTH) / 5d;
double s = 2.44;
i *= 2d;
while (i > 1)
{
i /= 10d;
}
if (i > 0d)
{
s -= i;
}
if (s < 2.2)
{
s = 2.2;
}
//设置容器宽度
ImgPanelWidth = (int)(ImageWidth * s);
OnPropertyChanged("ImageWidth");
}
}
public int ImageHeight
{
get
{
//都使用宽度来确定大小
// 为了兼容旧版 暂时使用默认
if (imageHeight == 0)
{
return (int)CommonEnum.IMAGE_HEIGHT;
}
else
{
return imageHeight;
}
}
set
{
imageHeight = value;
//计算容器高度因子
double i = ((double)imageHeight - (double)CommonEnum.IMAGE_HEIGHT) / 5d;
while (i > 1)
{
i /= 10d;
}
double s = 2.00;
if (i > 0d)
{
s -= i;
}
if (s < 1.5) s = 1.5;
//设置容器高度
ImgPanelHeight = ImageHeight * s;
OnPropertyChanged("ImageHeight");
}
}
2021-07-13 17:29:33 +08:00
public bool AppAnimation
{
get
{
return appAnimation;
}
set
{
appAnimation = value;
OnPropertyChanged("AppAnimation");
}
}
public bool MarginHide
{
get
{
return marginHide;
}
set
{
marginHide = value;
OnPropertyChanged("MarginHide");
}
}
public double ImgPanelWidth
{
get
{
if (imgPanelWidth == 0d) return (double)CommonEnum.IMAGE_PANEL_WIDTH;
return imgPanelWidth;
}
set
{
imgPanelWidth = value;
OnPropertyChanged("ImgPanelWidth");
}
}
public double ImgPanelHeight
{
get
{
if (imgPanelHeight == 0d) return (double)CommonEnum.IMAGE_PANEL_HEIGHT;
return imgPanelHeight;
}
set
{
imgPanelHeight = value;
OnPropertyChanged("ImgPanelHeight");
}
}
public string TextColor
{
get
{
if (textColor == null) return "#000000";
return textColor;
}
set
{
textColor = value;
OnPropertyChanged("TextColor");
}
}
public bool PMModel
{
get
{
return pmModel;
}
set
{
pmModel = value;
OnPropertyChanged("PMModel");
}
}
2021-07-21 11:15:51 +08:00
public bool SelfStartUped
{
get
{
return selfStartUped;
}
set
{
selfStartUped = value;
OnPropertyChanged("SelfStartUped");
}
}
public bool SelfStartUp
{
get
{
return selfStartUp;
}
set
{
selfStartUp = value;
selfStartUped = true;
OnPropertyChanged("SelfStartUp");
}
}
public Key ToDoHotkey
{
get
{
//兼容老版本
if (toDoHotkey == Key.None)
{
toDoHotkey = Key.Q;
}
return toDoHotkey;
}
set
{
toDoHotkey = value;
OnPropertyChanged("ToDoHotkey");
}
}
public HotkeyModifiers ToDoHotkeyModifiers
{
get
{
if (toDoHotkeyModifiers == 0)
{
toDoHotkeyModifiers = HotkeyModifiers.MOD_CONTROL | HotkeyModifiers.MOD_SHIFT;
}
return toDoHotkeyModifiers;
}
set
{
toDoHotkeyModifiers = value;
OnPropertyChanged("ToDoHotkeyModifiers");
}
}
public string ToDoHotkeyStr
{
get
{
//兼容老版本
if (toDoHotkeyStr == null)
{
toDoHotkeyStr = "Ctrl + Shift + Q";
}
return toDoHotkeyStr;
}
set
{
toDoHotkeyStr = value;
OnPropertyChanged("ToDoHotkeyStr");
}
}
public UpdateType UpdateType
{
get
{
return updateType;
}
set
{
updateType = value;
OnPropertyChanged("UpdateType");
}
}
2021-07-13 17:29:33 +08:00
public double BlurValue
{
get
{
return blurValue;
}
set
{
blurValue = value;
OnPropertyChanged("BlurValue");
}
}
public bool BlurEffect
{
get
{
return blurEffect;
}
set
{
blurEffect = value;
if (blurEffect)
{
BlurValue = 100;
} else
{
BlurValue = 0;
}
OnPropertyChanged("BlurEffect");
}
}
2021-07-12 17:28:57 +08:00
public string CustomIconUrl
{
get
{
return customIconUrl;
}
set
{
customIconUrl = value;
OnPropertyChanged("CustomIconUrl");
}
}
public string CustomIconJsonUrl
{
get
{
return customIconJsonUrl;
}
set
{
customIconJsonUrl = value;
OnPropertyChanged("CustomIconJsonUrl");
}
}
2021-05-31 21:54:10 +08:00
public Key Hotkey
{
get
{
return hotkey;
}
set
{
hotkey = value;
OnPropertyChanged("Hotkey");
}
}
public string HotkeyStr
{
get
{
return hotkeyStr;
}
set
{
hotkeyStr = value;
OnPropertyChanged("HotkeyStr");
}
}
public HotkeyModifiers HotkeyModifiers
{
get
{
if (hotkeyModifiers == 0)
{
hotkeyModifiers = HotkeyModifiers.MOD_CONTROL;
}
2021-05-31 21:54:10 +08:00
return hotkeyModifiers;
}
set
{
hotkeyModifiers = value;
OnPropertyChanged("HotkeyModifiers");
}
}
2021-05-28 18:01:19 +08:00
public ObservableCollection<IconInfo> SelectedMenuIcons
{
get
{
return selectedMenuIcons;
}
set
{
selectedMenuIcons = value;
OnPropertyChanged("SelectedMenuIcons");
}
}
2021-04-12 13:46:05 +08:00
2021-05-28 18:01:19 +08:00
public int PannelCornerRadius
{
get
{
return pannelCornerRadius;
}
set
{
pannelCornerRadius = value;
OnPropertyChanged("pannelCornerRadius");
}
}
2021-04-13 15:26:19 +08:00
2021-05-28 18:01:19 +08:00
public int PannelOpacity
{
get
{
return pannelOpacity;
}
set
{
pannelOpacity = value;
OnPropertyChanged("PannelOpacity");
}
}
public int BgOpacity
{
get
{
return bgOpacity;
}
set
{
bgOpacity = value;
OnPropertyChanged("BgOpacity");
}
}
public int CardOpacity
{
get
{
return cardOpacity;
}
set
{
cardOpacity = value;
OnPropertyChanged("CardOpacity");
}
}
2021-05-19 17:31:28 +08:00
2021-05-21 17:19:46 +08:00
public string BacImgName
2021-05-20 21:59:32 +08:00
{
get
{
2021-05-21 17:19:46 +08:00
return bacImgName;
2021-05-20 21:59:32 +08:00
}
set
{
2021-05-21 17:19:46 +08:00
bacImgName = value;
OnPropertyChanged("BacImgName");
2021-05-20 21:59:32 +08:00
}
}
2021-05-21 17:19:46 +08:00
public byte[] ImageByteArr
2021-05-20 21:59:32 +08:00
{
get
{
2021-05-21 17:19:46 +08:00
return imageByteArr;
2021-05-20 21:59:32 +08:00
}
set
{
2021-05-21 17:19:46 +08:00
imageByteArr = value;
OnPropertyChanged("ImageByteArr");
2021-05-20 21:59:32 +08:00
}
}
2021-05-21 17:19:46 +08:00
2021-05-20 21:59:32 +08:00
public BitmapImage BitmapImage
{
get
{
2021-05-21 17:19:46 +08:00
if (imageByteArr == null || imageByteArr.Length == 0)
{
2021-05-28 18:01:19 +08:00
bacImgName = "系统默认";
2021-07-07 17:28:29 +08:00
//Image image = ImageUtil.ByteArrayToImage(Convert.FromBase64String(Constants.DEFAULT_BAC_IMAGE_BASE64));
2021-05-21 17:19:46 +08:00
return ImageUtil.ByteArrToImage(Convert.FromBase64String(Constants.DEFAULT_BAC_IMAGE_BASE64));
} else
{
return ImageUtil.ByteArrToImage(ImageByteArr);
}
2021-05-20 21:59:32 +08:00
}
set
{
bitmapImage = value;
2021-05-21 17:19:46 +08:00
imageByteArr = ImageUtil.BitmapImageToByte(bitmapImage);
2021-05-20 21:59:32 +08:00
OnPropertyChanged("BitmapImage");
}
}
2021-05-20 17:33:49 +08:00
public bool StartedShowPanel
2021-05-19 17:31:28 +08:00
{
get
{
return startedShowPanel;
}
set
{
startedShowPanel = value;
OnPropertyChanged("StartedShowPanel");
}
}
public AppHideType AppHideType
{
get
{
return appHideType;
}
set
{
appHideType = value;
OnPropertyChanged("AppHideType");
}
}
public Visibility ConfigIconVisible
{
get
{
return configIconVisible;
}
set
{
configIconVisible = value;
OnPropertyChanged("ConfigIconVisible");
}
}
public bool FollowMouse
{
get
{
return followMouse;
}
set
{
followMouse = value;
OnPropertyChanged("FollowMouse");
}
}
2021-05-12 10:00:12 +08:00
public int SelectedMenuIndex
{
get
{
return selectedMenuIndex;
}
set
{
selectedMenuIndex = value;
OnPropertyChanged("SelectedMenuIndex");
}
}
2021-05-19 17:31:28 +08:00
public SortType MenuSortType
2021-04-13 15:26:19 +08:00
{
2021-04-12 13:46:05 +08:00
get
{
return menuSortType;
}
set
{
menuSortType = value;
2021-04-13 15:26:19 +08:00
OnPropertyChanged("MenuSortType");
2021-04-12 13:46:05 +08:00
}
}
2021-05-19 17:31:28 +08:00
public SortType IconSortType
2021-04-12 13:46:05 +08:00
{
get
{
return iconSortType;
}
set
{
iconSortType = value;
2021-04-13 15:26:19 +08:00
OnPropertyChanged("IconSortType");
2021-04-12 13:46:05 +08:00
}
}
public double WindowWidth
{
get
{
return windowWidth;
}
set
{
windowWidth = value;
2021-04-13 15:26:19 +08:00
OnPropertyChanged("WindowWidth");
2021-04-12 13:46:05 +08:00
}
}
public double WindowHeight
{
get
{
return windowHeight;
}
set
{
windowHeight = value;
2021-04-13 15:26:19 +08:00
OnPropertyChanged("WindowHeight");
2021-04-12 13:46:05 +08:00
}
}
public double MenuCardWidth
{
get
{
return menuCardWidth;
}
set
{
menuCardWidth = value;
2021-04-13 15:26:19 +08:00
OnPropertyChanged("MenuCardWidth");
2021-04-12 13:46:05 +08:00
}
}
2021-04-13 15:26:19 +08:00
[field: NonSerializedAttribute()]
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
2021-05-20 17:33:49 +08:00
CommonCode.SaveAppData(MainWindow.appData);
2021-04-13 15:26:19 +08:00
}
2021-04-12 13:46:05 +08:00
#endregion
}
}