2020-04-07 10:19:14 -07: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-09-23 13:20:32 -07:00
|
|
|
|
using System;
|
2020-03-24 19:55:02 -07:00
|
|
|
|
using System.Text.Json;
|
2020-04-16 11:45:27 -07:00
|
|
|
|
using System.Text.Json.Serialization;
|
2024-10-17 05:14:57 -04:00
|
|
|
|
|
2023-03-21 10:27:29 +01:00
|
|
|
|
using ManagedCommon;
|
2020-10-22 09:45:48 -07:00
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
|
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
2024-04-02 01:09:47 +02:00
|
|
|
|
using Settings.UI.Library.Attributes;
|
2020-03-24 19:55:02 -07:00
|
|
|
|
|
2020-10-22 09:45:48 -07:00
|
|
|
|
namespace Microsoft.PowerToys.Settings.UI.Library
|
2020-03-24 19:55:02 -07:00
|
|
|
|
{
|
2025-11-05 10:42:24 +01:00
|
|
|
|
public enum DashboardSortOrder
|
|
|
|
|
|
{
|
|
|
|
|
|
Alphabetical,
|
|
|
|
|
|
ByStatus,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-23 13:20:32 -07:00
|
|
|
|
public class GeneralSettings : ISettingsConfig
|
2020-03-24 19:55:02 -07:00
|
|
|
|
{
|
2020-04-07 10:19:14 -07:00
|
|
|
|
// Gets or sets a value indicating whether run powertoys on start-up.
|
2020-04-16 11:45:27 -07:00
|
|
|
|
[JsonPropertyName("startup")]
|
|
|
|
|
|
public bool Startup { get; set; }
|
2020-04-07 10:19:14 -07:00
|
|
|
|
|
2025-05-26 05:03:35 -04:00
|
|
|
|
// Gets or sets a value indicating whether the powertoys system tray icon should be hidden.
|
|
|
|
|
|
[JsonPropertyName("show_tray_icon")]
|
|
|
|
|
|
public bool ShowSysTrayIcon { get; set; }
|
|
|
|
|
|
|
2020-04-07 10:19:14 -07:00
|
|
|
|
// Gets or sets a value indicating whether the powertoy elevated.
|
2024-04-02 01:09:47 +02:00
|
|
|
|
[CmdConfigureIgnoreAttribute]
|
2020-04-16 11:45:27 -07:00
|
|
|
|
[JsonPropertyName("is_elevated")]
|
|
|
|
|
|
public bool IsElevated { get; set; }
|
2020-04-07 10:19:14 -07:00
|
|
|
|
|
|
|
|
|
|
// Gets or sets a value indicating whether powertoys should run elevated.
|
2020-04-16 11:45:27 -07:00
|
|
|
|
[JsonPropertyName("run_elevated")]
|
2024-04-02 01:09:47 +02:00
|
|
|
|
[CmdConfigureIgnoreAttribute]
|
2020-04-16 11:45:27 -07:00
|
|
|
|
public bool RunElevated { get; set; }
|
2020-04-07 10:19:14 -07:00
|
|
|
|
|
|
|
|
|
|
// Gets or sets a value indicating whether is admin.
|
2020-04-16 11:45:27 -07:00
|
|
|
|
[JsonPropertyName("is_admin")]
|
2024-04-02 01:09:47 +02:00
|
|
|
|
[CmdConfigureIgnoreAttribute]
|
2020-04-16 11:45:27 -07:00
|
|
|
|
public bool IsAdmin { get; set; }
|
2020-04-07 10:19:14 -07:00
|
|
|
|
|
2024-01-03 20:22:54 +03:00
|
|
|
|
// Gets or sets a value indicating whether is warnings of elevated apps enabled.
|
|
|
|
|
|
[JsonPropertyName("enable_warnings_elevated_apps")]
|
|
|
|
|
|
public bool EnableWarningsElevatedApps { get; set; }
|
|
|
|
|
|
|
2020-04-07 10:19:14 -07:00
|
|
|
|
// Gets or sets theme Name.
|
2020-04-16 11:45:27 -07:00
|
|
|
|
[JsonPropertyName("theme")]
|
|
|
|
|
|
public string Theme { get; set; }
|
2020-04-07 10:19:14 -07:00
|
|
|
|
|
|
|
|
|
|
// Gets or sets system theme name.
|
2020-04-16 11:45:27 -07:00
|
|
|
|
[JsonPropertyName("system_theme")]
|
2024-04-02 01:09:47 +02:00
|
|
|
|
[CmdConfigureIgnore]
|
2020-04-16 11:45:27 -07:00
|
|
|
|
public string SystemTheme { get; set; }
|
2020-04-07 10:19:14 -07:00
|
|
|
|
|
|
|
|
|
|
// Gets or sets powertoys version number.
|
2020-04-16 11:45:27 -07:00
|
|
|
|
[JsonPropertyName("powertoys_version")]
|
2024-04-02 01:09:47 +02:00
|
|
|
|
[CmdConfigureIgnore]
|
2020-04-16 11:45:27 -07:00
|
|
|
|
public string PowertoysVersion { get; set; }
|
|
|
|
|
|
|
2020-05-03 03:17:06 -07:00
|
|
|
|
[JsonPropertyName("action_name")]
|
2024-04-02 01:09:47 +02:00
|
|
|
|
[CmdConfigureIgnore]
|
2020-05-03 03:17:06 -07:00
|
|
|
|
public string CustomActionName { get; set; }
|
|
|
|
|
|
|
2020-04-16 11:45:27 -07:00
|
|
|
|
[JsonPropertyName("enabled")]
|
2024-04-02 01:09:47 +02:00
|
|
|
|
[CmdConfigureIgnore]
|
2020-04-16 11:45:27 -07:00
|
|
|
|
public EnabledModules Enabled { get; set; }
|
2020-03-24 19:55:02 -07:00
|
|
|
|
|
2024-01-19 16:18:05 +01:00
|
|
|
|
[JsonPropertyName("show_new_updates_toast_notification")]
|
|
|
|
|
|
public bool ShowNewUpdatesToastNotification { get; set; }
|
|
|
|
|
|
|
2020-05-03 03:17:06 -07:00
|
|
|
|
[JsonPropertyName("download_updates_automatically")]
|
|
|
|
|
|
public bool AutoDownloadUpdates { get; set; }
|
|
|
|
|
|
|
2024-01-18 16:18:17 +01:00
|
|
|
|
[JsonPropertyName("show_whats_new_after_updates")]
|
|
|
|
|
|
public bool ShowWhatsNewAfterUpdates { get; set; }
|
|
|
|
|
|
|
2023-02-14 18:38:53 -08:00
|
|
|
|
[JsonPropertyName("enable_experimentation")]
|
|
|
|
|
|
public bool EnableExperimentation { get; set; }
|
|
|
|
|
|
|
2025-11-05 10:42:24 +01:00
|
|
|
|
[JsonPropertyName("dashboard_sort_order")]
|
|
|
|
|
|
public DashboardSortOrder DashboardSortOrder { get; set; }
|
|
|
|
|
|
|
2025-09-29 08:53:07 +08:00
|
|
|
|
[JsonPropertyName("ignored_conflict_properties")]
|
|
|
|
|
|
public ShortcutConflictProperties IgnoredConflictProperties { get; set; }
|
|
|
|
|
|
|
2020-03-30 05:38:03 -07:00
|
|
|
|
public GeneralSettings()
|
|
|
|
|
|
{
|
2020-08-19 15:59:10 -07:00
|
|
|
|
Startup = false;
|
2025-05-26 05:03:35 -04:00
|
|
|
|
ShowSysTrayIcon = true;
|
2020-08-19 15:59:10 -07:00
|
|
|
|
IsAdmin = false;
|
2024-01-03 20:22:54 +03:00
|
|
|
|
EnableWarningsElevatedApps = true;
|
2020-08-19 15:59:10 -07:00
|
|
|
|
IsElevated = false;
|
2024-01-19 16:18:05 +01:00
|
|
|
|
ShowNewUpdatesToastNotification = true;
|
2020-08-19 15:59:10 -07:00
|
|
|
|
AutoDownloadUpdates = false;
|
2023-02-14 18:38:53 -08:00
|
|
|
|
EnableExperimentation = true;
|
2025-11-05 10:42:24 +01:00
|
|
|
|
DashboardSortOrder = DashboardSortOrder.Alphabetical;
|
2020-08-19 15:59:10 -07:00
|
|
|
|
Theme = "system";
|
|
|
|
|
|
SystemTheme = "light";
|
2020-05-05 16:01:55 -07:00
|
|
|
|
try
|
|
|
|
|
|
{
|
2020-08-19 15:59:10 -07:00
|
|
|
|
PowertoysVersion = DefaultPowertoysVersion();
|
2020-05-05 16:01:55 -07:00
|
|
|
|
}
|
2020-10-21 12:32:53 -07:00
|
|
|
|
catch (Exception e)
|
2020-05-05 16:01:55 -07:00
|
|
|
|
{
|
2020-10-21 12:32:53 -07:00
|
|
|
|
Logger.LogError("Exception encountered when getting PowerToys version", e);
|
2020-08-19 15:59:10 -07:00
|
|
|
|
PowertoysVersion = "v0.0.0";
|
2020-05-05 16:01:55 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-19 15:59:10 -07:00
|
|
|
|
Enabled = new EnabledModules();
|
|
|
|
|
|
CustomActionName = string.Empty;
|
2025-09-29 08:53:07 +08:00
|
|
|
|
IgnoredConflictProperties = new ShortcutConflictProperties();
|
2020-03-30 05:38:03 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-07 10:19:14 -07:00
|
|
|
|
// converts the current to a json string.
|
2020-04-02 06:08:56 -07:00
|
|
|
|
public string ToJsonString()
|
2020-03-24 19:55:02 -07:00
|
|
|
|
{
|
2025-12-02 16:31:02 +08:00
|
|
|
|
return JsonSerializer.Serialize(this, SettingsSerializationContext.Default.GeneralSettings);
|
2020-03-24 19:55:02 -07:00
|
|
|
|
}
|
2020-05-05 16:01:55 -07:00
|
|
|
|
|
2020-10-09 17:58:52 -07:00
|
|
|
|
private static string DefaultPowertoysVersion()
|
2020-05-05 16:01:55 -07:00
|
|
|
|
{
|
2024-08-08 15:26:43 +01:00
|
|
|
|
return global::PowerToys.Interop.CommonManaged.GetProductVersion();
|
2020-05-05 16:01:55 -07:00
|
|
|
|
}
|
2020-09-23 13:20:32 -07:00
|
|
|
|
|
|
|
|
|
|
// This function is to implement the ISettingsConfig interface.
|
|
|
|
|
|
// This interface helps in getting the settings configurations.
|
|
|
|
|
|
public string GetModuleName()
|
|
|
|
|
|
{
|
|
|
|
|
|
// The SettingsUtils functions access general settings when the module name is an empty string.
|
|
|
|
|
|
return string.Empty;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool UpgradeSettingsConfiguration()
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2020-10-08 16:34:19 -07:00
|
|
|
|
if (Helper.CompareVersions(PowertoysVersion, Helper.GetProductVersion()) != 0)
|
2020-09-23 13:20:32 -07:00
|
|
|
|
{
|
|
|
|
|
|
// Update settings
|
|
|
|
|
|
PowertoysVersion = Helper.GetProductVersion();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (FormatException)
|
|
|
|
|
|
{
|
|
|
|
|
|
// If there is an issue with the version number format, don't migrate settings.
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-29 08:53:07 +08:00
|
|
|
|
// Ensure IgnoredConflictProperties is initialized (for backward compatibility)
|
|
|
|
|
|
if (IgnoredConflictProperties == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
IgnoredConflictProperties = new ShortcutConflictProperties();
|
|
|
|
|
|
return true; // Indicate that settings were upgraded
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-23 13:20:32 -07:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2023-01-31 00:00:11 +01:00
|
|
|
|
|
|
|
|
|
|
public void AddEnabledModuleChangeNotification(Action callBack)
|
|
|
|
|
|
{
|
|
|
|
|
|
Enabled.AddEnabledModuleChangeNotification(callBack);
|
|
|
|
|
|
}
|
2020-03-24 19:55:02 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|