2020-04-18 06:25:08 +08:00
|
|
|
|
// Copyright (c) Microsoft Corporation
|
|
|
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
|
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
|
|
2020-08-18 04:10:56 +08:00
|
|
|
|
using System;
|
2020-04-18 06:25:08 +08:00
|
|
|
|
using System.Runtime.CompilerServices;
|
2020-08-18 04:10:56 +08:00
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Lib.Helpers;
|
2020-09-24 04:20:32 +08:00
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Lib.Interface;
|
2020-04-18 06:25:08 +08:00
|
|
|
|
|
2020-08-18 04:10:56 +08:00
|
|
|
|
namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
|
2020-04-18 06:25:08 +08:00
|
|
|
|
{
|
|
|
|
|
public class PowerPreviewViewModel : Observable
|
|
|
|
|
{
|
2020-09-24 04:20:32 +08:00
|
|
|
|
private const string ModuleName = PowerPreviewSettings.ModuleName;
|
2020-04-18 06:25:08 +08:00
|
|
|
|
|
|
|
|
|
private PowerPreviewSettings Settings { get; set; }
|
|
|
|
|
|
2020-08-18 04:10:56 +08:00
|
|
|
|
private Func<string, int> SendConfigMSG { get; }
|
|
|
|
|
|
2020-08-20 06:59:10 +08:00
|
|
|
|
private string _settingsConfigFileFolder = string.Empty;
|
2020-08-18 04:10:56 +08:00
|
|
|
|
|
2020-10-10 05:45:30 +08:00
|
|
|
|
private GeneralSettings GeneralSettingsConfig { get; set; }
|
|
|
|
|
|
|
|
|
|
public PowerPreviewViewModel(ISettingsRepository<PowerPreviewSettings> moduleSettingsRepository, ISettingsRepository<GeneralSettings> generalSettingsRepository, Func<string, int> ipcMSGCallBackFunc, string configFileSubfolder = "")
|
2020-04-18 06:25:08 +08:00
|
|
|
|
{
|
2020-08-18 04:10:56 +08:00
|
|
|
|
// Update Settings file folder:
|
2020-08-20 06:59:10 +08:00
|
|
|
|
_settingsConfigFileFolder = configFileSubfolder;
|
2020-09-24 04:20:32 +08:00
|
|
|
|
|
2020-10-10 05:45:30 +08:00
|
|
|
|
// To obtain the general Settings configurations of PowerToys
|
2020-10-20 04:32:05 +08:00
|
|
|
|
if (generalSettingsRepository == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(generalSettingsRepository));
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-10 05:45:30 +08:00
|
|
|
|
GeneralSettingsConfig = generalSettingsRepository.SettingsConfig;
|
|
|
|
|
|
2020-09-24 04:20:32 +08:00
|
|
|
|
// To obtain the PowerPreview settings if it exists.
|
|
|
|
|
// If the file does not exist, to create a new one and return the default settings configurations.
|
2020-10-20 04:32:05 +08:00
|
|
|
|
if (moduleSettingsRepository == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(moduleSettingsRepository));
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-24 04:20:32 +08:00
|
|
|
|
Settings = moduleSettingsRepository.SettingsConfig;
|
2020-04-18 06:25:08 +08:00
|
|
|
|
|
2020-08-18 04:10:56 +08:00
|
|
|
|
// set the callback functions value to hangle outgoing IPC message.
|
|
|
|
|
SendConfigMSG = ipcMSGCallBackFunc;
|
|
|
|
|
|
2020-08-20 06:59:10 +08:00
|
|
|
|
_svgRenderIsEnabled = Settings.Properties.EnableSvgPreview;
|
|
|
|
|
_svgThumbnailIsEnabled = Settings.Properties.EnableSvgThumbnail;
|
|
|
|
|
_mdRenderIsEnabled = Settings.Properties.EnableMdPreview;
|
2020-04-18 06:25:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-10 08:58:52 +08:00
|
|
|
|
private bool _svgRenderIsEnabled;
|
|
|
|
|
private bool _mdRenderIsEnabled;
|
|
|
|
|
private bool _svgThumbnailIsEnabled;
|
2020-04-18 06:25:08 +08:00
|
|
|
|
|
2020-05-03 18:17:06 +08:00
|
|
|
|
public bool SVGRenderIsEnabled
|
2020-04-18 06:25:08 +08:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _svgRenderIsEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != _svgRenderIsEnabled)
|
|
|
|
|
{
|
|
|
|
|
_svgRenderIsEnabled = value;
|
2020-07-24 02:01:49 +08:00
|
|
|
|
Settings.Properties.EnableSvgPreview = value;
|
2020-07-22 07:27:12 +08:00
|
|
|
|
RaisePropertyChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool SVGThumbnailIsEnabled
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _svgThumbnailIsEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != _svgThumbnailIsEnabled)
|
|
|
|
|
{
|
|
|
|
|
_svgThumbnailIsEnabled = value;
|
2020-07-24 02:01:49 +08:00
|
|
|
|
Settings.Properties.EnableSvgThumbnail = value;
|
2020-04-18 06:25:08 +08:00
|
|
|
|
RaisePropertyChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-03 18:17:06 +08:00
|
|
|
|
public bool MDRenderIsEnabled
|
2020-04-18 06:25:08 +08:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _mdRenderIsEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != _mdRenderIsEnabled)
|
|
|
|
|
{
|
|
|
|
|
_mdRenderIsEnabled = value;
|
2020-07-24 02:01:49 +08:00
|
|
|
|
Settings.Properties.EnableMdPreview = value;
|
2020-04-18 06:25:08 +08:00
|
|
|
|
RaisePropertyChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-18 04:10:56 +08:00
|
|
|
|
public string GetSettingsSubPath()
|
|
|
|
|
{
|
2020-08-20 06:59:10 +08:00
|
|
|
|
return _settingsConfigFileFolder + "\\" + ModuleName;
|
2020-08-18 04:10:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-10 05:45:30 +08:00
|
|
|
|
public bool IsElevated
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return GeneralSettingsConfig.IsElevated;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-18 06:25:08 +08:00
|
|
|
|
private void RaisePropertyChanged([CallerMemberName] string propertyName = null)
|
|
|
|
|
{
|
|
|
|
|
// Notify UI of property change
|
|
|
|
|
OnPropertyChanged(propertyName);
|
|
|
|
|
|
2020-08-18 04:10:56 +08:00
|
|
|
|
if (SendConfigMSG != null)
|
2020-04-18 06:25:08 +08:00
|
|
|
|
{
|
|
|
|
|
SndPowerPreviewSettings snd = new SndPowerPreviewSettings(Settings);
|
|
|
|
|
SndModuleSettings<SndPowerPreviewSettings> ipcMessage = new SndModuleSettings<SndPowerPreviewSettings>(snd);
|
2020-08-18 04:10:56 +08:00
|
|
|
|
SendConfigMSG(ipcMessage.ToJsonString());
|
2020-04-18 06:25:08 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|