2021-10-22 20:30:18 +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.
|
|
|
|
|
|
|
|
|
|
using System;
|
2021-10-26 02:39:48 +08:00
|
|
|
|
using System.Runtime.CompilerServices;
|
2021-10-22 20:30:18 +08:00
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
|
|
|
|
{
|
|
|
|
|
public class MouseUtilsViewModel : Observable
|
|
|
|
|
{
|
2021-10-26 02:39:48 +08:00
|
|
|
|
private ISettingsUtils SettingsUtils { get; set; }
|
|
|
|
|
|
2021-10-22 20:30:18 +08:00
|
|
|
|
private GeneralSettings GeneralSettingsConfig { get; set; }
|
|
|
|
|
|
2021-10-26 02:39:48 +08:00
|
|
|
|
private FindMyMouseSettings FindMyMouseSettingsConfig { get; set; }
|
|
|
|
|
|
|
|
|
|
public MouseUtilsViewModel(ISettingsUtils settingsUtils, ISettingsRepository<GeneralSettings> settingsRepository, ISettingsRepository<FindMyMouseSettings> findMyMouseSettingsRepository, Func<string, int> ipcMSGCallBackFunc)
|
2021-10-22 20:30:18 +08:00
|
|
|
|
{
|
2021-10-26 02:39:48 +08:00
|
|
|
|
SettingsUtils = settingsUtils;
|
|
|
|
|
|
2021-10-22 20:30:18 +08:00
|
|
|
|
// To obtain the general settings configurations of PowerToys Settings.
|
|
|
|
|
if (settingsRepository == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(settingsRepository));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GeneralSettingsConfig = settingsRepository.SettingsConfig;
|
|
|
|
|
|
|
|
|
|
_isFindMyMouseEnabled = GeneralSettingsConfig.Enabled.FindMyMouse;
|
|
|
|
|
|
2021-10-26 02:39:48 +08:00
|
|
|
|
// To obtain the find my mouse settings, if the file exists.
|
|
|
|
|
// If not, to create a file with the default settings and to return the default configurations.
|
|
|
|
|
if (findMyMouseSettingsRepository == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(findMyMouseSettingsRepository));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FindMyMouseSettingsConfig = findMyMouseSettingsRepository.SettingsConfig;
|
|
|
|
|
_findMyMouseDoNotActivateOnGameMode = FindMyMouseSettingsConfig.Properties.DoNotActivateOnGameMode.Value;
|
|
|
|
|
|
|
|
|
|
// set the callback functions value to handle outgoing IPC message.
|
2021-10-22 20:30:18 +08:00
|
|
|
|
SendConfigMSG = ipcMSGCallBackFunc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsFindMyMouseEnabled
|
|
|
|
|
{
|
|
|
|
|
get => _isFindMyMouseEnabled;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (_isFindMyMouseEnabled != value)
|
|
|
|
|
{
|
|
|
|
|
_isFindMyMouseEnabled = value;
|
|
|
|
|
|
|
|
|
|
GeneralSettingsConfig.Enabled.FindMyMouse = value;
|
|
|
|
|
OnPropertyChanged(nameof(IsFindMyMouseEnabled));
|
|
|
|
|
|
|
|
|
|
OutGoingGeneralSettings outgoing = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
|
|
|
|
SendConfigMSG(outgoing.ToString());
|
|
|
|
|
|
2021-10-26 02:39:48 +08:00
|
|
|
|
NotifyFindMyMousePropertyChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool FindMyMouseDoNotActivateOnGameMode
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _findMyMouseDoNotActivateOnGameMode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (_findMyMouseDoNotActivateOnGameMode != value)
|
|
|
|
|
{
|
|
|
|
|
_findMyMouseDoNotActivateOnGameMode = value;
|
|
|
|
|
FindMyMouseSettingsConfig.Properties.DoNotActivateOnGameMode.Value = value;
|
|
|
|
|
NotifyFindMyMousePropertyChanged();
|
2021-10-22 20:30:18 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-26 02:39:48 +08:00
|
|
|
|
public void NotifyFindMyMousePropertyChanged([CallerMemberName] string propertyName = null)
|
|
|
|
|
{
|
|
|
|
|
OnPropertyChanged(propertyName);
|
|
|
|
|
|
|
|
|
|
SndFindMyMouseSettings outsettings = new SndFindMyMouseSettings(FindMyMouseSettingsConfig);
|
|
|
|
|
SndModuleSettings<SndFindMyMouseSettings> ipcMessage = new SndModuleSettings<SndFindMyMouseSettings>(outsettings);
|
|
|
|
|
SendConfigMSG(ipcMessage.ToJsonString());
|
|
|
|
|
SettingsUtils.SaveSettings(FindMyMouseSettingsConfig.ToJsonString(), FindMyMouseSettings.ModuleName);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-22 20:30:18 +08:00
|
|
|
|
private Func<string, int> SendConfigMSG { get; }
|
|
|
|
|
|
|
|
|
|
private bool _isFindMyMouseEnabled;
|
2021-10-26 02:39:48 +08:00
|
|
|
|
private bool _findMyMouseDoNotActivateOnGameMode;
|
2021-10-22 20:30:18 +08:00
|
|
|
|
}
|
|
|
|
|
}
|