mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-24 04:00:02 +01:00
<!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request This pull request introduces a new module called "Light Switch" which allows users to automatically switch between light and dark mode on a timer.  <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [x] Closes: #1331 - [x] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [x] **Tests:** Added/updated and all pass - [x] **Localization:** All end-user-facing strings can be localized - [x] **Dev docs:** Added/updated - [x] **New binaries:** Added on the required places - [x] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [x] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [x] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: [#5867](https://github.com/MicrosoftDocs/windows-dev-docs-pr/pull/5867) <!-- Provide a more detailed description of the PR, other things fixed, or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments ### Known bugs: - Default settings not saving correctly when switching modes - Issue: Sometimes when you switch from one mode to another, they are supposed to update with new defaults but sometimes this fails for the second variable. Potentially has to do with accessing the settings file while another chunk of code is still updating. - Sometimes the system looks "glitched" when switching themes ### To do: - [x] OOBE page and assets - [x] Logic to disable the chart when no location has been selected - [x] Localization ### How to and what to test Grab the latest installer from the pipeline below for your architecture and install PowerToys from there. - Toggle theme shortcutSystem only, Apps only, Both system and apps selected - Does changing the values on the settings page update the settings file? %LOCALAPPDATA%/Microsoft/PowerToys/LightSwitch/settings.json - Manual mode: System only, Apps only, Both system and apps selected - Sunrise modes: Are the times accurate? - If you manage to let this run through sunset/rise does the theme change? - Set your theme to change within the next minute using manual mode and set your device to sleepOpen your device and login once the time you set has passed. --> Do your settings resync once the next minute ticks after logging back into your device? - Disable the service and ensure the tasks actually ends. - While the module is disabled: - Make sure the shortcut no longer works - Make sure the last time you set doesn't trigger a theme change - Bonus: Toggle GPO Configuration and make sure you are unable to enable the module --------- Co-authored-by: Niels Laute <niels.laute@live.nl> Co-authored-by: Gordon Lam (SH) <yeelam@microsoft.com>
164 lines
5.7 KiB
C#
164 lines
5.7 KiB
C#
// 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.Runtime.CompilerServices;
|
|
|
|
[assembly: InternalsVisibleTo("UITestBase")]
|
|
[assembly: InternalsVisibleTo("Session")]
|
|
|
|
namespace Microsoft.PowerToys.UITest
|
|
{
|
|
/// <summary>
|
|
/// This file manages the configuration of modules for UI tests.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// How to add a new module:
|
|
/// 1. Define the new module in the PowerToysModule enum.
|
|
/// 2. Add the exe window name to the ModuleWindowName dictionary in the ModuleConfigData constructor.
|
|
/// 3. Add the exe path to the ModulePath dictionary in the ModuleConfigData constructor.
|
|
/// </remarks>
|
|
|
|
/// <summary>
|
|
/// Represents the modules in PowerToys.
|
|
/// </summary>
|
|
public enum PowerToysModule
|
|
{
|
|
PowerToysSettings,
|
|
FancyZone,
|
|
Hosts,
|
|
Runner,
|
|
Workspaces,
|
|
PowerRename,
|
|
CommandPalette,
|
|
ScreenRuler,
|
|
LightSwitch,
|
|
}
|
|
|
|
/// <summary>
|
|
/// Represents the window size for the UI test.
|
|
/// </summary>
|
|
public enum WindowSize
|
|
{
|
|
/// <summary>
|
|
/// Unspecified window size, won't make any size change
|
|
/// </summary>
|
|
UnSpecified,
|
|
|
|
/// <summary>
|
|
/// Small window size, 640 * 480
|
|
/// </summary>
|
|
Small,
|
|
|
|
/// <summary>
|
|
/// Small window size, 480 * 640
|
|
/// </summary>
|
|
Small_Vertical,
|
|
|
|
/// <summary>
|
|
/// Medium window size, 1024 * 768
|
|
/// </summary>
|
|
Medium,
|
|
|
|
/// <summary>
|
|
/// Medium window size, 768 * 1024
|
|
/// </summary>
|
|
Medium_Vertical,
|
|
|
|
/// <summary>
|
|
/// Large window size, 1920 * 1080
|
|
/// </summary>
|
|
Large,
|
|
|
|
/// <summary>
|
|
/// Large window size, 1080 * 1920
|
|
/// </summary>
|
|
Large_Vertical,
|
|
}
|
|
|
|
internal class ModuleConfigData
|
|
{
|
|
private Dictionary<PowerToysModule, ModuleInfo> ModuleInfo { get; }
|
|
|
|
// Singleton instance of ModuleConfigData.
|
|
private static readonly Lazy<ModuleConfigData> SingletonInstance = new Lazy<ModuleConfigData>(() => new ModuleConfigData());
|
|
|
|
public static ModuleConfigData Instance => SingletonInstance.Value;
|
|
|
|
public const string WindowsApplicationDriverUrl = "http://127.0.0.1:4723";
|
|
|
|
private bool UseInstallerForTest { get; }
|
|
|
|
private ModuleConfigData()
|
|
{
|
|
// Check if we should use installer paths from environment variable
|
|
UseInstallerForTest = EnvironmentConfig.UseInstallerForTest;
|
|
|
|
// Module information including executable name, window name, and optional subdirectory
|
|
ModuleInfo = new Dictionary<PowerToysModule, ModuleInfo>
|
|
{
|
|
[PowerToysModule.PowerToysSettings] = new ModuleInfo("PowerToys.Settings.exe", "PowerToys Settings", "WinUI3Apps"),
|
|
[PowerToysModule.FancyZone] = new ModuleInfo("PowerToys.FancyZonesEditor.exe", "FancyZones Layout"),
|
|
[PowerToysModule.Hosts] = new ModuleInfo("PowerToys.Hosts.exe", "Hosts File Editor", "WinUI3Apps"),
|
|
[PowerToysModule.Runner] = new ModuleInfo("PowerToys.exe", "PowerToys"),
|
|
[PowerToysModule.Workspaces] = new ModuleInfo("PowerToys.WorkspacesEditor.exe", "Workspaces Editor"),
|
|
[PowerToysModule.PowerRename] = new ModuleInfo("PowerToys.PowerRename.exe", "PowerRename", "WinUI3Apps"),
|
|
[PowerToysModule.CommandPalette] = new ModuleInfo("Microsoft.CmdPal.UI.exe", "PowerToys Command Palette", "WinUI3Apps\\CmdPal"),
|
|
[PowerToysModule.ScreenRuler] = new ModuleInfo("PowerToys.MeasureToolUI.exe", "PowerToys.ScreenRuler", "WinUI3Apps"),
|
|
[PowerToysModule.LightSwitch] = new ModuleInfo("PowerToys.LightSwitch.exe", "PowerToys.LightSwitch", "LightSwitchService"),
|
|
};
|
|
}
|
|
|
|
private string GetPowerToysInstallPath()
|
|
{
|
|
// Try common installation paths
|
|
string[] possiblePaths =
|
|
{
|
|
@"C:\Program Files\PowerToys",
|
|
@"C:\Program Files (x86)\PowerToys",
|
|
Environment.ExpandEnvironmentVariables(@"%LocalAppData%\PowerToys"),
|
|
Environment.ExpandEnvironmentVariables(@"%ProgramFiles%\PowerToys"),
|
|
};
|
|
|
|
foreach (string path in possiblePaths)
|
|
{
|
|
if (Directory.Exists(path) && File.Exists(Path.Combine(path, "PowerToys.exe")))
|
|
{
|
|
return path;
|
|
}
|
|
}
|
|
|
|
// Fallback to Program Files if not found
|
|
return @"C:\Program Files\PowerToys";
|
|
}
|
|
|
|
public string GetModulePath(PowerToysModule scope)
|
|
{
|
|
var moduleInfo = ModuleInfo[scope];
|
|
|
|
if (UseInstallerForTest)
|
|
{
|
|
string powerToysInstallPath = GetPowerToysInstallPath();
|
|
string installedPath = moduleInfo.GetInstalledPath(powerToysInstallPath);
|
|
|
|
if (File.Exists(installedPath))
|
|
{
|
|
return installedPath;
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine($"Warning: Installed module not found at {installedPath}, using development path");
|
|
}
|
|
}
|
|
|
|
return moduleInfo.GetDevelopmentPath();
|
|
}
|
|
|
|
public string GetWindowsApplicationDriverUrl() => WindowsApplicationDriverUrl;
|
|
|
|
public string GetModuleWindowName(PowerToysModule scope) => ModuleInfo[scope].WindowName;
|
|
}
|
|
}
|