From 15677cef4a125276a78aa5fb6c5572e8aaf2bc11 Mon Sep 17 00:00:00 2001
From: Den Delimarsky <1389609+dend@users.noreply.github.com>
Date: Wed, 7 Apr 2021 17:05:45 -0700
Subject: [PATCH] Update settings
---
.../EspressoProperties.cs | 14 ++--
...osoft.PowerToys.Settings.UI.Library.csproj | 3 +
.../SndEspressoSettings.cs | 30 ++++++++
.../ViewModels/EspressoViewModel.cs | 73 +++++++++++++++++--
...oft.PowerToys.Settings.UI.UnitTests.csproj | 5 +-
.../Strings/en-us/Resources.resw | 6 ++
.../Views/EspressoPage.xaml | 24 ++++++
.../Views/EspressoPage.xaml.cs | 1 -
.../PowerToys.Settings.csproj | 3 +
9 files changed, 144 insertions(+), 15 deletions(-)
create mode 100644 src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/SndEspressoSettings.cs
diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/EspressoProperties.cs b/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/EspressoProperties.cs
index 7fe4995736..13a8305cc1 100644
--- a/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/EspressoProperties.cs
+++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/EspressoProperties.cs
@@ -10,23 +10,23 @@ namespace Microsoft.PowerToys.Settings.UI.Library
{
public EspressoProperties()
{
- IsEnabled = new BoolProperty();
KeepDisplayOn = new BoolProperty();
Mode = EspressoMode.INDEFINITE;
- TimeAllocation = new IntProperty();
+ Hours = new IntProperty();
+ Minutes = new IntProperty();
}
- [JsonPropertyName("espresso_is_enabled")]
- public BoolProperty IsEnabled { get; set; }
-
[JsonPropertyName("espresso_keep_display_on")]
public BoolProperty KeepDisplayOn { get; set; }
[JsonPropertyName("espresso_mode")]
public EspressoMode Mode { get; set; }
- [JsonPropertyName("espresso_time_allocation")]
- public IntProperty TimeAllocation { get; set; }
+ [JsonPropertyName("espresso_hours")]
+ public IntProperty Hours { get; set; }
+
+ [JsonPropertyName("espresso_minutes")]
+ public IntProperty Minutes { get; set; }
}
public enum EspressoMode
diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/Microsoft.PowerToys.Settings.UI.Library.csproj b/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/Microsoft.PowerToys.Settings.UI.Library.csproj
index 209e2647b9..da1f09145a 100644
--- a/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/Microsoft.PowerToys.Settings.UI.Library.csproj
+++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/Microsoft.PowerToys.Settings.UI.Library.csproj
@@ -20,6 +20,9 @@
x64
+ DEBUG;TRACE
+ full
+ true
diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/SndEspressoSettings.cs b/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/SndEspressoSettings.cs
new file mode 100644
index 0000000000..84bfe09014
--- /dev/null
+++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/SndEspressoSettings.cs
@@ -0,0 +1,30 @@
+// 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;
+using System.Collections.Generic;
+using System.Text;
+using System.Text.Json;
+
+namespace Microsoft.PowerToys.Settings.UI.Library
+{
+ public class SndEspressoSettings
+ {
+ public EspressoSettings Settings { get; set; }
+
+ public SndEspressoSettings()
+ {
+ }
+
+ public SndEspressoSettings(EspressoSettings settings)
+ {
+ Settings = settings;
+ }
+
+ public string ToJsonString()
+ {
+ return JsonSerializer.Serialize(this);
+ }
+ }
+}
diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/ViewModels/EspressoViewModel.cs b/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/ViewModels/EspressoViewModel.cs
index 4bde47862d..c13222097f 100644
--- a/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/ViewModels/EspressoViewModel.cs
+++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/ViewModels/EspressoViewModel.cs
@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using System;
+using System.Runtime.CompilerServices;
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
@@ -34,14 +35,14 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
Settings = moduleSettingsRepository.SettingsConfig;
+ _isEnabled = GeneralSettingsConfig.Enabled.Espresso;
_keepDisplayOn = Settings.Properties.KeepDisplayOn.Value;
_mode = Settings.Properties.Mode;
- _timeAllocation = Settings.Properties.TimeAllocation.Value;
+ _hours = Settings.Properties.Hours.Value;
+ _minutes = Settings.Properties.Minutes.Value;
// set the callback functions value to hangle outgoing IPC message.
SendConfigMSG = ipcMSGCallBackFunc;
-
- IsEnabled = GeneralSettingsConfig.Enabled.Espresso;
}
public bool IsEnabled
@@ -52,19 +53,79 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
if (_isEnabled != value)
{
_isEnabled = value;
- OnPropertyChanged(nameof(IsEnabled));
GeneralSettingsConfig.Enabled.Espresso = value;
- var outgoing = new OutGoingGeneralSettings(GeneralSettingsConfig);
+ var outgoing = new OutGoingGeneralSettings(GeneralSettingsConfig);
SendConfigMSG(outgoing.ToString());
+ NotifyPropertyChanged();
}
}
}
+ public bool KeepDisplayOn
+ {
+ get => _keepDisplayOn;
+ set
+ {
+ if (_keepDisplayOn != value)
+ {
+ _keepDisplayOn = value;
+ OnPropertyChanged(nameof(KeepDisplayOn));
+
+ Settings.Properties.KeepDisplayOn = new BoolProperty(value);
+ NotifyPropertyChanged();
+ }
+ }
+ }
+
+ public int Hours
+ {
+ get => _hours;
+ set
+ {
+ if (_hours != value)
+ {
+ _hours = value;
+ OnPropertyChanged(nameof(Hours));
+
+ Settings.Properties.Hours = new IntProperty(value);
+ NotifyPropertyChanged();
+ }
+ }
+ }
+
+ public int Minutes
+ {
+ get => _minutes;
+ set
+ {
+ if (_minutes != value)
+ {
+ _minutes = value;
+ OnPropertyChanged(nameof(Minutes));
+
+ Settings.Properties.Minutes = new IntProperty(value);
+ NotifyPropertyChanged();
+ }
+ }
+ }
+
+ public void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
+ {
+ OnPropertyChanged(propertyName);
+ if (SendConfigMSG != null)
+ {
+ SndEspressoSettings outsettings = new SndEspressoSettings(Settings);
+ SndModuleSettings ipcMessage = new SndModuleSettings(outsettings);
+ SendConfigMSG(ipcMessage.ToJsonString());
+ }
+ }
+
private bool _isEnabled;
+ private int _hours;
+ private int _minutes;
private bool _keepDisplayOn;
private EspressoMode _mode;
- private int _timeAllocation;
}
}
diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI.UnitTests/Microsoft.PowerToys.Settings.UI.UnitTests.csproj b/src/settings-ui/Microsoft.PowerToys.Settings.UI.UnitTests/Microsoft.PowerToys.Settings.UI.UnitTests.csproj
index a9b57204f2..3adf72b698 100644
--- a/src/settings-ui/Microsoft.PowerToys.Settings.UI.UnitTests/Microsoft.PowerToys.Settings.UI.UnitTests.csproj
+++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI.UnitTests/Microsoft.PowerToys.Settings.UI.UnitTests.csproj
@@ -1,4 +1,4 @@
-
+
netcoreapp3.1
@@ -9,6 +9,9 @@
..\..\..\x64\Debug\SettingsTests\
+ full
+ true
+ DEBUG;TRACE
diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw
index 6fec1d172c..b0381731b8 100644
--- a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw
+++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw
@@ -1182,4 +1182,10 @@ Win + Shift + O to toggle your video
Behavior
+
+ Hours
+
+
+ Minutes
+
\ No newline at end of file
diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Views/EspressoPage.xaml b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Views/EspressoPage.xaml
index a8ce161a7c..bd4df2fcfa 100644
--- a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Views/EspressoPage.xaml
+++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Views/EspressoPage.xaml
@@ -5,6 +5,7 @@
xmlns:local="using:Microsoft.PowerToys.Settings.UI.Views"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
xmlns:Custom="using:Microsoft.PowerToys.Settings.UI.Controls"
xmlns:Color="using:Microsoft.PowerToys.Settings.UI.Library.ViewModels" xmlns:Interactivity="using:Microsoft.Xaml.Interactivity" xmlns:Core="using:Microsoft.Xaml.Interactions.Core"
mc:Ignorable="d"
@@ -90,6 +91,29 @@
+
+
+
+
+
diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Views/EspressoPage.xaml.cs b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Views/EspressoPage.xaml.cs
index 36032d50b4..5a47c6165b 100644
--- a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Views/EspressoPage.xaml.cs
+++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Views/EspressoPage.xaml.cs
@@ -2,7 +2,6 @@
// 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.IO.Abstractions;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.ViewModels;
using Windows.UI.Xaml.Controls;
diff --git a/src/settings-ui/PowerToys.Settings/PowerToys.Settings.csproj b/src/settings-ui/PowerToys.Settings/PowerToys.Settings.csproj
index 92daaa3d46..1e2cec7e34 100644
--- a/src/settings-ui/PowerToys.Settings/PowerToys.Settings.csproj
+++ b/src/settings-ui/PowerToys.Settings/PowerToys.Settings.csproj
@@ -34,6 +34,9 @@
..\..\..\$(Platform)\$(Configuration)\Settings
false
+ full
+ true
+ DEBUG;TRACE