DEV Community

Cover image for What should 2.0.10 have been in PWin11 Tweaker?
ph2ncyn
ph2ncyn

Posted on

What should 2.0.10 have been in PWin11 Tweaker?

I'll just drop my Obsidian file where I wrote everything down, so you can take a look inside and see how the plan and writing process works.

Recommendations for Improving PWin11 Tweaker

Based on an analysis of the codebase, here are the main recommendations for adding functionality and improving the existing code:

What to Add

1. Settings Backup System

Add a module to create registry backups before applying changes:

// Recommended to add to InterfacePage.xaml.cs before ApplyButton_Click
private async Task CreateRegistryBackup()
{
    string backupPath = Path.Combine(Path.GetTempPath(), $"PWin11_Backup_{DateTime.Now:yyyyMMdd_HHmmss}.reg");
    string backupContent = "Windows Registry Editor Version 5.00\n" +
                          "[HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced]\n" +
                          "\"TaskbarAl\"=dword:00000001\n" +
                          // ... other keys
    await File.WriteAllTextAsync(backupPath, backupContent, Encoding.Unicode);
}
Enter fullscreen mode Exit fullscreen mode

2. System Requirements Validation

Add Windows 11 version compatibility check in page constructors PWin11-Tweaker:20-26 :

private void ValidateSystemRequirements()
{
    var version = Environment.OSVersion.Version;
    if (version.Major < 10 || (version.Major == 10 && version.Build < 22000))
    {
        throw new NotSupportedException("Windows 11 version 22H2 or higher is required");
    }
}
Enter fullscreen mode Exit fullscreen mode

3. Applied Changes Log

Create a class to log all changes with rollback capability:

public class ChangeLog
{
    public DateTime Timestamp { get; set; }
    public string Category { get; set; }
    public string Description { get; set; }
    public string RegistryPath { get; set; }
    public object OriginalValue { get; set; }
    public object NewValue { get; set; }
}
Enter fullscreen mode Exit fullscreen mode

What to Change/Fix

1. Improve Temporary File Handling

Current implementation doesn't delete .bat files after use PWin11-Tweaker:102-109 :

// Fix in ApplyButton_Click
string batContent = $"@echo off\n" +
                   $"reg import \"{tempRegPath}\" >nul 2>&1\n" +
                   $"if %ERRORLEVEL% NEQ 0 (exit /b %ERRORLEVEL%)\n" +
                   $"del \"{tempRegPath}\" >nul 2>&1\n" +
                   $"del \"{tempBatPath}\" >nul 2>&1\n" + // Add cleanup for bat file
                   $"taskkill /f /im explorer.exe >nul 2>&1\n" +
                   $"start explorer.exe\n" +
                   $"exit /b 0";
Enter fullscreen mode Exit fullscreen mode

2. Centralize Registry Management

Create a common class for registry operations instead of code duplication PWin11-Tweaker:51-59 :

public static class RegistryManager
{
    public static T? GetValue<T>(string keyPath, string valueName) where T : class
    {
        using var key = Registry.CurrentUser.OpenSubKey(keyPath);
        return key?.GetValue(valueName) as T;
    }

    public static void SetValue(string keyPath, string valueName, object value, RegistryValueKind kind)
    {
        Registry.SetValue(keyPath, valueName, value, kind);
    }
}
Enter fullscreen mode Exit fullscreen mode

3. Improve Error Handling

Add more detailed exception handling with logging PWin11-Tweaker:146-157 :

catch (UnauthorizedAccessException ex)
{
    await ShowErrorDialog("Access denied. Run the application as administrator.", ex);
}
catch (SecurityException ex)
{
    await ShowErrorDialog("Security error accessing the registry.", ex);
}
catch (Exception ex)
{
    await ShowErrorDialog($"Unknown error: {ex.Message}", ex);
}
Enter fullscreen mode Exit fullscreen mode

4. Optimize Explorer Restart

Add warning before restarting Explorer PWin11-Tweaker:106-108 :

private async Task<bool> ShowExplorerRestartWarning()
{
    var dialog = new ContentDialog
    {
        Title = resourceLoader.GetString("Warning"),
        Content = "All File Explorer windows will be closed. Save any unsaved data.",
        PrimaryButtonText = "Continue",
        CloseButtonText = "Cancel",
        XamlRoot = this.XamlRoot
    };
    var result = await dialog.ShowAsync();
    return result == ContentDialogResult.Primary;
}
Enter fullscreen mode Exit fullscreen mode

Architectural Improvements

1. Implement MVVM Pattern

Separate UI and logic by creating ViewModel for each page:

public class InterfaceViewModel : INotifyPropertyChanged
{
    private bool _taskbarTransparency;
    public bool TaskbarTransparency 
    { 
        get => _taskbarTransparency;
        set { _taskbarTransparency = value; OnPropertyChanged(); }
    }
    // ... other properties
}
Enter fullscreen mode Exit fullscreen mode

2. Add Unit Tests

Create a test project to verify critical functionality:

[Test]
public void TestRegistryValueRead()
{
    // Arrange
    var expectedValue = 1;

    // Act
    var actualValue = RegistryManager.GetValue<int>(@"Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "TaskbarAl");

    // Assert
    Assert.AreEqual(expectedValue, actualValue);
}
Enter fullscreen mode Exit fullscreen mode

User Interface Improvements

1. Add Progress Indicator for Long Operations

Enhance existing ProgressPanel PWin11-Tweaker:32-35 :

<StackPanel x:Name="ProgressPanel" Visibility="Collapsed" Spacing="5">
    <TextBlock x:Name="StatusText" Text="Executing..."/>
    <ProgressBar x:Name="ProgressBar" IsIndeterminate="False" Minimum="0" Maximum="100" Value="0"/>
    <TextBlock x:Name="ProgressDetailText" FontSize="12" Foreground="Gray" Text=""/>
</StackPanel>
Enter fullscreen mode Exit fullscreen mode

2. Add Dark Theme

Extend theme support in the interface:

<Page.RequestedTheme>
    <Binding Source="{x:Static Application.Current}" Path="RequestedTheme"/>
</Page.RequestedTheme>
Enter fullscreen mode Exit fullscreen mode

Notes

  • Recommendations are based on the current project architecture using WinUI 3 and .NET 9.0
  • All changes must maintain backward compatibility with existing settings
  • When adding new features, update localization files PWin11-Tweaker:541-600
  • It's important to test changes on different Windows 11 versions for compatibility

Wiki pages you might want to explore:

        public InterfacePage()
        {
            this.InitializeComponent();
            //Initialize our resources for localization
            resourceLoader = new ResourceLoader();
            LoadCurrentSettings();
        }
Enter fullscreen mode Exit fullscreen mode

File: PWin11 Tweaker's/Page/InterfacePage.xaml.cs (L102-109)

                string tempBatPath = Path.Combine(Path.GetTempPath(), "InterfaceTweaks.bat");
                string batContent = $"@echo off reg import \"{tempRegPath}\" >nul 2>&1" +
                                   "if %ERRORLEVEL% NEQ 0 (exit /b %ERRORLEVEL%)" +
                                   $"del \"{tempRegPath}\" >nul 2>&1" +
                                   "taskkill /f /im explorer.exe >nul 2>&1" +
                                   "start explorer.exe" +
                                   "exit /b 0";
                File.WriteAllText(tempBatPath, batContent);
Enter fullscreen mode Exit fullscreen mode

File: PWin11 Tweaker's/Page/InterfacePage.xaml.cs (L146-157)

            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"ApplyButton_Click: Error: {ex.Message}");
                var dialog = new ContentDialog
                {
                    Title = resourceLoader.GetString("Dialog_Error_Title"),
                    Content = $"{ex.Message}",
                    CloseButtonText = "OK",
                    XamlRoot = this.XamlRoot
                };
                await dialog.ShowAsync();
            }
Enter fullscreen mode Exit fullscreen mode

File: PWin11 Tweaker's/Page/SystemPage.xaml.cs (L51-59)

                using (var key = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\WSearch"))
                {
                    if (key != null)
                    {
                        int? startValue = key.GetValue("Start") as int?;
                        System.Diagnostics.Debug.WriteLine($"LoadCurrentSettings: WSearch Start = {startValue}");
                        DisableServicesCheckBox.IsChecked = startValue == 4; // 4 = disabled
                    }
                }
Enter fullscreen mode Exit fullscreen mode

File: PWin11 Tweaker's/Page/InterfacePage.xaml (L32-35)

        <StackPanel x:Name="ProgressPanel" Visibility="Collapsed" Spacing="5">
            <TextBlock x:Name="StatusText" Text="Executing..."/>
            <ProgressBar x:Name="ProgressBar" IsIndeterminate="False" Minimum="0" Maximum="100" Value="0"/>
        </StackPanel>
Enter fullscreen mode Exit fullscreen mode

File: PWin11 Tweaker's/Strings/en-US/Resources.resw (L541-600)

  </data>
  <data name="ExplorerButton_HomePage.Content" xml:space="preserve">
    <value>Settings Explorer</value>
  </data>
  <data name="AboutText_Settings.Text" xml:space="preserve">
    <value>PWin11 Tweaker is a lightweight, open-source utility that allows you to tweak various aspects of Windows 11 without delving into complex system settings or third-party software. With a focus on performance optimization, system cleanup, privacy protection, and interface customization, this tool simplifies the process of tailoring your OS to your specific needs. The intuitive navigation and responsive design make it accessible to everyone, while advanced options cater to tech enthusiasts.</value>
  </data>
  <data name="Small.Content" xml:space="preserve">
    <value>Small</value>
  </data>
  <data name="Large.Content" xml:space="preserve">
    <value>Large</value>
  </data>
  <data name="Medium.Content" xml:space="preserve">
    <value>Medium</value>
  </data>
  <data name="TaskbarSize.Text" xml:space="preserve">
    <value>Taskbar size</value>
  </data>
  <data name="TaskbarPosition.Text" xml:space="preserve">
    <value>Taskbar Position</value>
  </data>
  <data name="Top.Content" xml:space="preserve">
    <value>Top</value>
  </data>
  <data name="Bottom.Content" xml:space="preserve">
    <value>Bottom</value>
  </data>
  <data name="TempPageDeliveryOptCheckBox.Content" xml:space="preserve">
    <value>Delivery Optimization Cache</value>
  </data>
  <data name="TempPageSystemLogsCheckBox.Content" xml:space="preserve">
    <value>System Log Files</value>
  </data>
  <data name="TempPageOldWinFilesCheckBox.Content" xml:space="preserve">
    <value>Old Windows Installation Files</value>
  </data>
  <data name="TempPageAppCacheCheckBox.Content" xml:space="preserve">
    <value>Application Cache</value>
  </data>
  <data name="TweakClassicContextMenu.Text" xml:space="preserve">
    <value>Classic Context Menu</value>
  </data>
  <data name="TweakShowHiddenFiles.Text" xml:space="preserve">
    <value>Show Hidden Files</value>
  </data>
  <data name="TweakSmallCaptions.Text" xml:space="preserve">
    <value>Reduce Window Control Buttons</value>
  </data>
  <data name="TweakStartAllBack.Text" xml:space="preserve">
    <value>Install StartAllBack</value>
  </data>
  <data name="TweakTelemetry.Text" xml:space="preserve">
    <value>Disable Telemetry</value>
  </data>
  <data name="TweakAdvertisingId.Text" xml:space="preserve">
    <value>Disable Advertising ID</value>
  </data>
  <data name="TweakLocationTracking.Text" xml:space="preserve">
    <value>Disable Location Tracking</value>
Enter fullscreen mode Exit fullscreen mode

Automated Tweak Validation

The project already has an automated tweak checking system in SplashScreen.xaml.cs via the CheckTweaksStatus() method PWin11-Tweaker:167-364 .

Current Implementation

The system uses an array of TweakCheck objects with delegate check functions PWin11-Tweaker:172-201 :

var tweaks = new[]
{
    new TweakCheck(_resourceLoader.GetString("TweakClassicContextMenu"), new Func<bool>(() => CheckClassicContextMenu())),
    new TweakCheck(_resourceLoader.GetString("TweakShowHiddenFiles"), new Func<bool>(() => CheckShowHiddenFiles())),
    // ... other tweak checks
};
Enter fullscreen mode Exit fullscreen mode

Each tweak is checked through a separate method that reads registry values PWin11-Tweaker:366-386 :

private bool CheckClassicContextMenu()
{
    try
    {
        using var key = Registry.CurrentUser.OpenSubKey(@"Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32");
        if (key != null)
        {
            string? defaultValue = key.GetValue("") as string;
            return string.IsNullOrEmpty(defaultValue);
        }
        return false;
    }
    catch (Exception ex)
    {
        System.Diagnostics.Debug.WriteLine($"Error checking classic context menu: {ex.Message}");
        return false;
    }
}
Enter fullscreen mode Exit fullscreen mode

Improvement Recommendations

1. Create Base Class for Validations

public abstract class TweakValidator
{
    public abstract string Name { get; }
    public abstract bool Validate();
    public abstract RegistryKeyPath[] RegistryPaths { get; }
}

public class RegistryKeyPath
{
    public string Hive { get; set; }
    public string Path { get; set; }
    public string ValueName { get; set; }
    public object ExpectedValue { get; set; }
}
Enter fullscreen mode Exit fullscreen mode

2. Unify Service Checking

For services, use a unified check method PWin11-Tweaker:642-671 :

private bool CheckServiceStatus(string serviceName, int expectedStartValue)
{
    try
    {
        using var key = Registry.LocalMachine.OpenSubKey($@"SYSTEM\CurrentControlSet\Services\{serviceName}");
        int? start = key?.GetValue("Start") as int?;
        return start == expectedStartValue;
    }
    catch (Exception ex)
    {
        System.Diagnostics.Debug.WriteLine($"Error checking service {serviceName}: {ex.Message}");
        return false;
    }
}
Enter fullscreen mode Exit fullscreen mode

3. Add Value Validation

public static class RegistryValidator
{
    public static bool ValidateDwordValue(RegistryHive hive, string path, string valueName, int expectedValue)
    {
        using var key = hive == RegistryHive.CurrentUser 
            ? Registry.CurrentUser.OpenSubKey(path)
            : Registry.LocalMachine.OpenSubKey(path);

        return (int?)key?.GetValue(valueName) == expectedValue;
    }

    public static bool ValidateStringValue(RegistryHive hive, string path, string valueName, string expectedValue)
    {
        using var key = hive == RegistryHive.CurrentUser 
            ? Registry.CurrentUser.OpenSubKey(path)
            : Registry.LocalMachine.OpenSubKey(path);

        return key?.GetValue(valueName) as string == expectedValue;
    }
}
Enter fullscreen mode Exit fullscreen mode

4. Optimize Performance

Add result caching and parallel execution:

private async Task<Dictionary<string, bool>> CheckAllTweaksAsync()
{
    var validators = GetAllValidators();
    var tasks = validators.Select(async validator => 
    {
        var result = await Task.Run(() => validator.Validate());
        return new { validator.Name, Result = result };
    });

    var results = await Task.WhenAll(tasks);
    return results.ToDictionary(x => x.Name, x => x.Result);
}
Enter fullscreen mode Exit fullscreen mode

5. Improve Error Handling

public class TweakValidationResult
{
    public string TweakName { get; set; }
    public bool IsValid { get; set; }
    public string ErrorMessage { get; set; }
    public object ActualValue { get; set; }
    public object ExpectedValue { get; set; }
}
Enter fullscreen mode Exit fullscreen mode

Integration with Existing Code

The CheckTweaksStatus() method can be refactored to use the new architecture PWin11-Tweaker:206-343 :

private async Task CheckTweaksStatus()
{
    var validatorEngine = new TweakValidatorEngine();
    var results = await validatorEngine.ValidateAllTweaksAsync();

    foreach (var result in results)
    {
        UpdateProgressBar(result.TweakName);
        UpdateTweakStatus(result);
        await Task.Delay(100);
    }
}
Enter fullscreen mode Exit fullscreen mode

Notes

  • Current implementation is already well-structured and functional
  • Recommendations aim to increase reusability and performance
  • When refactoring, maintain compatibility with existing TweakStatus class
  • All checks should be asynchronous to improve user experience

Wiki pages you might want to explore:

        private async Task CheckTweaksStatus()
        {
            try
            {
                // Explicitly typed array using TweakCheck class
                var tweaks = new[]
                {
                    new TweakCheck(_resourceLoader.GetString("TweakClassicContextMenu"), new Func<bool>(() => CheckClassicContextMenu())),
                    new TweakCheck(_resourceLoader.GetString("TweakShowHiddenFiles"), new Func<bool>(() => CheckShowHiddenFiles())),
                    new TweakCheck(_resourceLoader.GetString("TweakSmallCaptions"), new Func<bool>(() => CheckSmallCaptions())),
                    new TweakCheck(_resourceLoader.GetString("TweakStartAllBack"), new Func<bool>(() => CheckStartAllBack())),
                    new TweakCheck(_resourceLoader.GetString("TweakTelemetry"), new Func<bool>(() => CheckTelemetry())),
                    new TweakCheck(_resourceLoader.GetString("TweakAdvertisingId"), new Func<bool>(() => CheckAdvertisingId())),
                    new TweakCheck(_resourceLoader.GetString("TweakLocationTracking"), new Func<bool>(() => CheckLocationTracking())),
                    new TweakCheck(_resourceLoader.GetString("TweakCortana"), new Func<bool>(() => CheckCortana())),
                    new TweakCheck(_resourceLoader.GetString("TweakBackgroundApps"), new Func<bool>(() => CheckBackgroundApps())),
                    new TweakCheck(_resourceLoader.GetString("TweakCloudContent"), new Func<bool>(() => CheckCloudContent())),
                    new TweakCheck(_resourceLoader.GetString("TweakFindMyDevice"), new Func<bool>(() => CheckFindMyDevice())),
                    new TweakCheck(_resourceLoader.GetString("TweakInsiderTelemetry"), new Func<bool>(() => CheckInsiderTelemetry())),
                    new TweakCheck(_resourceLoader.GetString("TweakEdgeDiagnostics"), new Func<bool>(() => CheckEdgeDiagnostics())),
                    new TweakCheck(_resourceLoader.GetString("TweakSuggestedContent"), new Func<bool>(() => CheckSuggestedContent())),
                    new TweakCheck(_resourceLoader.GetString("TweakHomeFolder"), new Func<bool>(() => CheckHomeFolderDisabled())),
                    new TweakCheck(_resourceLoader.GetString("TweakGalleryFolder"), new Func<bool>(() => CheckGalleryFolderDisabled())),
                    new TweakCheck(_resourceLoader.GetString("TweakTaskbarAlignment"), new Func<bool>(() => CheckTaskbarAlignmentLeft())),
                    new TweakCheck(_resourceLoader.GetString("TweakTaskbarTransparency"), new Func<bool>(() => CheckTaskbarTransparencyEnabled())),
                    new TweakCheck(_resourceLoader.GetString("TweakHideSearchButton"), new Func<bool>(() => CheckSearchButtonHidden())),
                    new TweakCheck(_resourceLoader.GetString("TweakVisualEffects"), new Func<bool>(() => CheckVisualEffects())),
                    new TweakCheck(_resourceLoader.GetString("TweakWindowsSearch"), new Func<bool>(() => CheckWindowsSearch())),
                    new TweakCheck(_resourceLoader.GetString("TweakSysMain"), new Func<bool>(() => CheckSysMain())),
                    new TweakCheck(_resourceLoader.GetString("TweakServices"), new Func<bool>(() => CheckServicesDisabled())),
                    new TweakCheck(_resourceLoader.GetString("TweakUAC"), new Func<bool>(() => CheckUACDisabled())),
                    new TweakCheck(_resourceLoader.GetString("TweakClipboardHistory"), new Func<bool>(() => CheckClipboardHistoryDisabled())),
                    new TweakCheck(_resourceLoader.GetString("TweakWindowsSpeedUp"), new Func<bool>(() => CheckWindowsSpeedUpApplied())),
                    new TweakCheck(_resourceLoader.GetString("TweakPowerPlan"), new Func<string?>(() => CheckCurrentPowerPlan()))
                };

                int totalTweaks = tweaks.Length;
                int completedTweaks = 0;

                foreach (var tweak in tweaks)
                {
                    if (this.Content is Grid rootGrid)
                    {
                        if (rootGrid.FindName("StatusText") is TextBlock statusText)
                        {
                            statusText.Text = tweak.Name;
                        }

                        if (rootGrid.FindName("ProgressBar") is ProgressBar progressBar)
                        {
                            completedTweaks++;
                            progressBar.Value = (double)completedTweaks / totalTweaks * 100;
                        }
                    }

                    if (tweak.CheckFunc is Func<bool> boolFunc)
                    {
                        bool result = boolFunc();
                        System.Diagnostics.Debug.WriteLine($"{tweak.Name} Result: {(result ? "Enabled" : "Disabled")}");

                        if (tweak.Name.Contains("classic context menu"))
                        {
                            TweakStatus.IsClassicContextMenuEnabled = result;
                        }
                        else if (tweak.Name.Contains("show hidden files"))
                        {
                            TweakStatus.IsShowHiddenFilesEnabled = result;
                        }
                        else if (tweak.Name.Contains("reduce window control buttons"))
                        {
                            TweakStatus.IsSmallCaptionsEnabled = result;
                        }
                        else if (tweak.Name.Contains("install StartAllBack"))
                        {
                            TweakStatus.IsStartAllBackInstalled = result;
                        }
                        else if (tweak.Name.Contains("telemetry"))
                        {
                            TweakStatus.IsTelemetryDisabled = result;
                        }
                        else if (tweak.Name.Contains("advertising ID"))
                        {
                            TweakStatus.IsAdvertisingIdDisabled = result;
                        }
                        else if (tweak.Name.Contains("location tracking"))
                        {
                            TweakStatus.IsLocationTrackingDisabled = result;
                        }
                        else if (tweak.Name.Contains("Cortana"))
                        {
                            TweakStatus.IsCortanaDisabled = result;
                        }
                        else if (tweak.Name.Contains("background apps"))
                        {
                            TweakStatus.IsBackgroundAppsDisabled = result;
                        }
                        else if (tweak.Name.Contains("cloud content"))
                        {
                            TweakStatus.IsCloudContentDisabled = result;
                        }
                        else if (tweak.Name.Contains("Find My Device"))
                        {
                            TweakStatus.IsFindMyDeviceDisabled = result;
                        }
                        else if (tweak.Name.Contains("Windows Insider telemetry"))
                        {
                            TweakStatus.IsInsiderTelemetryDisabled = result;
                        }
                        else if (tweak.Name.Contains("Microsoft Edge data collection"))
                        {
                            TweakStatus.IsEdgeDiagnosticsDisabled = result;
                        }
                        else if (tweak.Name.Contains("suggested content"))
                        {
                            TweakStatus.IsSuggestedContentDisabled = result;
                        }
                        else if (tweak.Name.Contains("Home folder"))
                        {
                            TweakStatus.IsHomeFolderDisabled = result;
                        }
                        else if (tweak.Name.Contains("Gallery folder"))
                        {
                            TweakStatus.IsGalleryFolderDisabled = result;
                        }
                        else if (tweak.Name.Contains("taskbar alignment"))
                        {
                            TweakStatus.IsTaskbarAlignmentLeft = result;
                        }
                        else if (tweak.Name.Contains("taskbar transparency"))
                        {
                            TweakStatus.IsTaskbarTransparencyEnabled = result;
                        }
                        else if (tweak.Name.Contains("hide search button"))
                        {
                            TweakStatus.IsSearchButtonHidden = result;
                        }
                        else if (tweak.Name.Contains("visual effects"))
                        {
                            TweakStatus.IsVisualEffectsDisabled = result;
                        }
                        else if (tweak.Name.Contains("Windows Search"))
                        {
                            TweakStatus.IsWindowsSearchDisabled = result;
                        }
                        else if (tweak.Name.Contains("SysMain"))
                        {
                            TweakStatus.IsSysMainDisabled = result;
                        }
                        else if (tweak.Name.Contains("services"))
                        {
                            TweakStatus.IsServicesDisabled = result;
                        }
                        else if (tweak.Name.Contains("UAC"))
                        {
                            TweakStatus.IsUACDisabled = result;
                        }
                        else if (tweak.Name.Contains("clipboard history"))
                        {
                            TweakStatus.IsClipboardHistoryDisabled = result;
                        }
                        else if (tweak.Name.Contains("Windows speed up"))
                        {
                            TweakStatus.IsWindowsSpeedUpApplied = result;
                        }
                    }
                    else if (tweak.CheckFunc is Func<string?> stringFunc)
                    {
                        string? result = stringFunc();
                        System.Diagnostics.Debug.WriteLine($"{tweak.Name} Result: {result ?? "Undefined"}");
                        if (tweak.Name.Contains("power plan"))
                        {
                            TweakStatus.CurrentPowerPlan = result;
                        }
                    }

                    await Task.Delay(200);
                }

                if (this.Content is Grid rootGridFinal)
                {
                    if (rootGridFinal.FindName("StatusText") is TextBlock finalStatusText)
                    {
                        finalStatusText.Text = "";
                    }

                    if (rootGridFinal.FindName("ProgressBar") is ProgressBar finalProgressBar)
                    {
                        finalProgressBar.Value = 100;
                    }
                }

                await Task.Delay(200);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"Error checking tweaks: {ex.Message}");
            }
        }
Enter fullscreen mode Exit fullscreen mode

File: PWin11 Tweaker's/Windowww/SplashScreen.xaml.cs (L366-386)

        private bool CheckClassicContextMenu()
        {
            try
            {
                using var key = Registry.CurrentUser.OpenSubKey(@"Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32");
                if (key != null)
                {
                    string? defaultValue = key.GetValue("") as string;
                    bool isClassicContextMenuEnabled = string.IsNullOrEmpty(defaultValue);
                    System.Diagnostics.Debug.WriteLine($"CheckClassicContextMenu: Key found, default value: '{defaultValue}', result: {isClassicContextMenuEnabled}");
                    return isClassicContextMenuEnabled;
                }
                System.Diagnostics.Debug.WriteLine("CheckClassicContextMenu: Key not found, result: false");
                return false;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"Error checking classic context menu: {ex.Message}");
                return false;
            }
        }
Enter fullscreen mode Exit fullscreen mode

File: PWin11 Tweaker's/Windowww/SplashScreen.xaml.cs (L642-671)

        private bool CheckWindowsSearch()
        {
            try
            {
                using var key = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\WSearch");
                int? start = key?.GetValue("Start") as int?;
                System.Diagnostics.Debug.WriteLine($"CheckWindowsSearch: Start value = {start}");
                return start == 4;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"CheckWindowsSearch: Error: {ex.Message}");
                return false;
            }
        }

        private bool CheckSysMain()
        {
            try
            {
                using var key = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\SysMain");
                int? start = key?.GetValue("Start") as int?;
                System.Diagnostics.Debug.WriteLine($"CheckSysMain: Start value = {start}");
                return start == 4;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"CheckSysMain: Error: {ex.Message}");
                return false;
            }
Enter fullscreen mode Exit fullscreen mode

Top comments (0)