mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-21 18:49:56 +01:00
Compare commits
3 Commits
async-cpp-
...
shawn/fixL
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
857f05b5af | ||
|
|
1c1704e982 | ||
|
|
b7063041c8 |
@@ -3,14 +3,17 @@
|
|||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
using ManagedCommon;
|
||||||
using Microsoft.PowerToys.Settings.UI.Library;
|
using Microsoft.PowerToys.Settings.UI.Library;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||||
|
|
||||||
namespace Settings.UI.Library
|
namespace Settings.UI.Library
|
||||||
{
|
{
|
||||||
public class LightSwitchSettings : BasePTModuleSettings, ISettingsConfig, ICloneable
|
public class LightSwitchSettings : BasePTModuleSettings, ISettingsConfig, ICloneable, IHotkeyConfig
|
||||||
{
|
{
|
||||||
public const string ModuleName = "LightSwitch";
|
public const string ModuleName = "LightSwitch";
|
||||||
|
|
||||||
@@ -24,6 +27,21 @@ namespace Settings.UI.Library
|
|||||||
[JsonPropertyName("properties")]
|
[JsonPropertyName("properties")]
|
||||||
public LightSwitchProperties Properties { get; set; }
|
public LightSwitchProperties Properties { get; set; }
|
||||||
|
|
||||||
|
public HotkeyAccessor[] GetAllHotkeyAccessors()
|
||||||
|
{
|
||||||
|
var hotkeyAccessors = new List<HotkeyAccessor>
|
||||||
|
{
|
||||||
|
new HotkeyAccessor(
|
||||||
|
() => Properties.ToggleThemeHotkey.Value,
|
||||||
|
value => Properties.ToggleThemeHotkey.Value = value ?? LightSwitchProperties.DefaultToggleThemeHotkey,
|
||||||
|
"LightSwitch_ThemeToggle_Shortcut"),
|
||||||
|
};
|
||||||
|
|
||||||
|
return hotkeyAccessors.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ModuleType GetModuleType() => ModuleType.LightSwitch;
|
||||||
|
|
||||||
public object Clone()
|
public object Clone()
|
||||||
{
|
{
|
||||||
return new LightSwitchSettings()
|
return new LightSwitchSettings()
|
||||||
@@ -41,6 +59,7 @@ namespace Settings.UI.Library
|
|||||||
SunsetOffset = new IntProperty((int)Properties.SunsetOffset.Value),
|
SunsetOffset = new IntProperty((int)Properties.SunsetOffset.Value),
|
||||||
Latitude = new StringProperty(Properties.Latitude.Value),
|
Latitude = new StringProperty(Properties.Latitude.Value),
|
||||||
Longitude = new StringProperty(Properties.Longitude.Value),
|
Longitude = new StringProperty(Properties.Longitude.Value),
|
||||||
|
ToggleThemeHotkey = new KeyboardKeysProperty(Properties.ToggleThemeHotkey.Value),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
|||||||
|
|
||||||
this.InitializeComponent();
|
this.InitializeComponent();
|
||||||
this.Loaded += LightSwitchPage_Loaded;
|
this.Loaded += LightSwitchPage_Loaded;
|
||||||
|
this.Loaded += (s, e) => ViewModel.OnPageLoaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LightSwitchPage_Loaded(object sender, RoutedEventArgs e)
|
private void LightSwitchPage_Loaded(object sender, RoutedEventArgs e)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -20,8 +21,10 @@ using Settings.UI.Library.Helpers;
|
|||||||
|
|
||||||
namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||||
{
|
{
|
||||||
public partial class LightSwitchViewModel : Observable
|
public partial class LightSwitchViewModel : PageViewModelBase
|
||||||
{
|
{
|
||||||
|
protected override string ModuleName => LightSwitchSettings.ModuleName;
|
||||||
|
|
||||||
private Func<string, int> SendConfigMSG { get; }
|
private Func<string, int> SendConfigMSG { get; }
|
||||||
|
|
||||||
public ObservableCollection<SearchLocation> SearchLocations { get; } = new();
|
public ObservableCollection<SearchLocation> SearchLocations { get; } = new();
|
||||||
@@ -35,14 +38,24 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
ForceDarkCommand = new RelayCommand(ForceDarkNow);
|
ForceDarkCommand = new RelayCommand(ForceDarkNow);
|
||||||
|
|
||||||
AvailableScheduleModes = new ObservableCollection<string>
|
AvailableScheduleModes = new ObservableCollection<string>
|
||||||
{
|
{
|
||||||
"FixedHours",
|
"FixedHours",
|
||||||
"SunsetToSunrise",
|
"SunsetToSunrise",
|
||||||
};
|
};
|
||||||
|
|
||||||
_toggleThemeHotkey = _moduleSettings.Properties.ToggleThemeHotkey.Value;
|
_toggleThemeHotkey = _moduleSettings.Properties.ToggleThemeHotkey.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override Dictionary<string, HotkeySettings[]> GetAllHotkeySettings()
|
||||||
|
{
|
||||||
|
var hotkeysDict = new Dictionary<string, HotkeySettings[]>
|
||||||
|
{
|
||||||
|
[ModuleName] = [ToggleThemeActivationShortcut],
|
||||||
|
};
|
||||||
|
|
||||||
|
return hotkeysDict;
|
||||||
|
}
|
||||||
|
|
||||||
private void ForceLightNow()
|
private void ForceLightNow()
|
||||||
{
|
{
|
||||||
Logger.LogInfo("Sending custom action: forceLight");
|
Logger.LogInfo("Sending custom action: forceLight");
|
||||||
@@ -395,22 +408,21 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
|
|
||||||
public HotkeySettings ToggleThemeActivationShortcut
|
public HotkeySettings ToggleThemeActivationShortcut
|
||||||
{
|
{
|
||||||
get => _toggleThemeHotkey;
|
get => ModuleSettings.Properties.ToggleThemeHotkey.Value;
|
||||||
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value != _toggleThemeHotkey)
|
if (value != ModuleSettings.Properties.ToggleThemeHotkey.Value)
|
||||||
{
|
{
|
||||||
if (value == null)
|
if (value == null)
|
||||||
{
|
{
|
||||||
_toggleThemeHotkey = LightSwitchProperties.DefaultToggleThemeHotkey;
|
ModuleSettings.Properties.ToggleThemeHotkey.Value = LightSwitchProperties.DefaultToggleThemeHotkey;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_toggleThemeHotkey = value;
|
ModuleSettings.Properties.ToggleThemeHotkey.Value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
_moduleSettings.Properties.ToggleThemeHotkey.Value = _toggleThemeHotkey;
|
|
||||||
NotifyPropertyChanged();
|
NotifyPropertyChanged();
|
||||||
|
|
||||||
SendConfigMSG(
|
SendConfigMSG(
|
||||||
@@ -418,7 +430,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
CultureInfo.InvariantCulture,
|
CultureInfo.InvariantCulture,
|
||||||
"{{ \"powertoys\": {{ \"{0}\": {1} }} }}",
|
"{{ \"powertoys\": {{ \"{0}\": {1} }} }}",
|
||||||
LightSwitchSettings.ModuleName,
|
LightSwitchSettings.ModuleName,
|
||||||
JsonSerializer.Serialize(_moduleSettings, (System.Text.Json.Serialization.Metadata.JsonTypeInfo<LightSwitchSettings>)SourceGenerationContextContext.Default.LightSwitchSettings)));
|
JsonSerializer.Serialize(_moduleSettings, SourceGenerationContextContext.Default.LightSwitchSettings)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user