Skip to content

Free, open-source Windows optimization tool for performance, privacy, and simplicity.

Refactor core logic and add community standards

itsfatduck1ba908488cce
diff --git a/.gitignore b/.gitignore
index 69218d8..75a5ed0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -681,4 +681,6 @@ $RECYCLE.BIN/
### VisualStudio Patch ###
# Additional files built by Visual Studio
-# End of https://www.toptal.com/developers/gitignore/api/csharp,rider,visualstudio,windows
\ No newline at end of file
+# End of https://www.toptal.com/developers/gitignore/api/csharp,rider,visualstudio,windows
+.gemini/
+gha-creds-*.json
diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md
new file mode 100644
index 0000000..bdfcabc
--- /dev/null
+++ b/CODE_OF_CONDUCT.md
@@ -0,0 +1,121 @@
+# Contributor Covenant Code of Conduct
+
+## Our Pledge
+
+We as members, contributors, and leaders pledge to make participation in our
+community a harassment-free experience for everyone, regardless of age, body
+size, visible or invisible disability, ethnicity, sex characteristics, gender
+identity and expression, level of experience, education, socio-economic status,
+nationality, personal appearance, race, religion, or sexual identity
+and orientation.
+
+We pledge to act and interact in ways that are welcoming, open, inclusive,
+and respectful.
+
+## Our Standards
+
+Examples of behavior that contributes to a positive environment for our
+community include:
+
+* Demonstrating empathy and kindness toward other people
+* Being respectful of differing opinions, viewpoints, and experiences
+* Giving and gracefully accepting constructive feedback
+* Accepting responsibility and apologizing to those affected by our mistakes,
+ and learning from the experience
+* Focusing on what is best not just for us as individuals, but for the
+ overall community
+
+Examples of unacceptable behavior include:
+
+* The use of sexualized language or imagery, and sexual attention or
+ advances of any kind
+* Trolling, insulting or derogatory comments, and personal or political attacks
+* Public or private harassment
+* Publishing others' private information, such as a physical or email
+ address, without their explicit permission
+* Other conduct which could reasonably be considered inappropriate in a
+ professional setting
+
+## Enforcement Responsibilities
+
+Community leaders are responsible for clarifying and enforcing our standards of
+acceptable behavior and will take appropriate and fair corrective action in
+response to any behavior that they deem inappropriate, threatening, offensive,
+or harmful.
+
+Community leaders have the right and responsibility to remove, edit, or reject
+comments, commits, code, wiki edits, issues, and other contributions that are
+not aligned to this Code of Conduct, and will communicate reasons for moderation
+decisions when appropriate.
+
+## Scope
+
+This Code of Conduct applies within all community spaces, and also applies when
+an individual is officially representing the community in public spaces.
+Examples of representing our community include using an official e-mail address,
+posting via an official social media account, or acting as an appointed
+representative at an online or offline event.
+
+## Enforcement
+
+Instances of abusive, harassing, or otherwise unacceptable behavior may be
+reported to the community leaders responsible for enforcement at [INSERT CONTACT METHOD].
+All complaints will be reviewed and investigated promptly and fairly.
+
+All community leaders are obligated to respect the privacy and security of the
+reporter of any incident.
+
+## Enforcement Guidelines
+
+Community leaders will follow these Community Impact Guidelines in determining
+the consequences for any action they deem in violation of this Code of Conduct:
+
+### 1. Correction
+
+**Community Impact**: Use of inappropriate language or other behavior deemed
+unprofessional or unwelcome in the community.
+
+**Consequence**: A private, written warning from community leaders, providing
+clarity around the nature of the violation and an explanation of why the
+behavior was inappropriate. A public apology may be requested.
+
+### 2. Warning
+
+**Community Impact**: A violation through a single incident or series
+of actions.
+
+**Consequence**: A warning with consequences for continued behavior. No
+interaction with the people involved, including unsolicited interaction with
+those enforcing the Code of Conduct, for a specified period of time. This
+includes avoiding interaction in community spaces as well as external channels
+like social media. Violating these terms may lead to a temporary or
+permanent ban.
+
+### 3. Temporary Ban
+
+**Community Impact**: A serious violation of community standards, including
+sustained inappropriate behavior.
+
+**Consequence**: A temporary ban from any sort of interaction or public
+communication with the community for a specified period of time. No public or
+private interaction with the people involved, including unsolicited interaction
+with those enforcing the Code of Conduct, is allowed during this period.
+Violating these terms may lead to a permanent ban.
+
+### 4. Permanent Ban
+
+**Community Impact**: Demonstrating a pattern of violation of community
+standards, including sustained inappropriate behavior, harassment of an
+individual, or aggression toward or disparagement of classes of individuals.
+
+**Consequence**: A permanent ban from any sort of public interaction within
+the community.
+
+## Attribution
+
+This Code of Conduct is adapted from the [Contributor Covenant][homepage],
+version 2.0, available at
+[https://www.contributor-covenant.org/version/2/0/code_of_conduct.html][v2.0].
+
+[homepage]: https://www.contributor-covenant.org
+[v2.0]: https://www.contributor-covenant.org/version/2/0/code_of_conduct.html
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000..c3b2b0d
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,244 @@
+# Contributing to optimizerDuck
+
+First off, thank you for considering contributing to optimizerDuck! We're thrilled you're here. This project is open to everyone, and we welcome any contributions, from fixing typos to implementing new features. Your help is essential for making optimizerDuck the best Windows optimization tool it can be.
+
+Our mission is to provide a free, open-source, and powerful tool that enhances system performance, privacy, and simplicity for everyone.
+
+## Code of Conduct
+
+This project and everyone participating in it is governed by the [optimizerDuck Code of Conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. Please report unacceptable behavior to the project maintainers via GitHub Issues or on our Discord server.
+
+## How Can I Contribute?
+
+### Reporting Bugs
+
+Bugs are tracked as [GitHub Issues](https://github.com/itsfatduck/optimizerDuck/issues). Before creating a bug report, please check the existing issues to see if someone has already reported it.
+
+When creating a bug report, please include as many details as possible. Fill out the required template, which will help us resolve issues faster.
+
+**Bug Report Template**:
+```markdown
+**Describe the bug**
+A clear and concise description of what the bug is.
+
+**To Reproduce**
+Steps to reproduce the behavior:
+1. Go to '...'
+2. Click on '....'
+3. Scroll down to '....'
+4. See error
+
+**Expected behavior**
+A clear and concise description of what you expected to happen.
+
+**Screenshots**
+If applicable, add screenshots to help explain your problem.
+
+**Environment**
+- OS: [e.g., Windows 11 Pro 23H2]
+- Version: [e.g., 1.3.0]
+
+**Logs**
+Please include any relevant logs. You can find the log file at `%APPDATA%\optimizerDuck\optimizerDuck.log`.
+```
+
+### Suggesting Features
+
+We love to hear your ideas for improving optimizerDuck! Feature suggestions are tracked as [GitHub Issues](https://github.com/itsfatduck/optimizerDuck/issues). Use the "Feature Request" template and provide a clear explanation of your suggestion.
+
+**Feature Request Template**:
+```markdown
+**Is your feature request related to a problem?**
+A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
+
+**Describe the solution you'd like**
+A clear and concise description of what you want to happen.
+
+**Describe alternatives you've considered**
+A clear and concise description of any alternative solutions or features you've considered.
+
+**Additional context**
+Add any other context or screenshots about the feature request here.
+```
+
+### Pull Requests
+
+Pull requests are the best way to propose changes to the codebase. We actively welcome your pull requests.
+
+1. Fork the repo and create your branch from `main`.
+2. If you've added code that should be tested, add tests.
+3. If you've changed APIs, update the documentation.
+4. Ensure the test suite passes.
+5. Make sure your code lints.
+6. Issue that pull request!
+
+## Development Setup
+
+Ready to contribute? Here’s how to set up optimizerDuck for local development.
+
+#### Prerequisites
+
+* [.NET 10.0 SDK](https://dotnet.microsoft.com/download/dotnet/10.0)
+* Git
+
+#### Setup Instructions
+
+```bash
+# 1. Clone the repository
+git clone https://github.com/itsfatduck/optimizerDuck.git
+
+# 2. Navigate to the project directory
+cd optimizerDuck
+
+# 3. Build the project to restore dependencies
+dotnet build
+
+# 4. Run the tests to ensure everything is working
+dotnet test
+
+# 5. Run the application
+dotnet run --project optimizerDuck
+```
+
+## Development Workflow
+
+#### Branch Naming
+
+To keep our branch structure organized, please follow this convention:
+
+* `feature/<description>` for new features (e.g., `feature/add-new-tweak`)
+* `fix/<description>` for bug fixes (e.g., `fix/resolve-crash-on-start`)
+* `docs/<description>` for documentation changes (e.g., `docs/update-readme`)
+* `refactor/<description>` for code refactoring (e.g., `refactor/optimize-registry-service`)
+* `chore/<description>` for build scripts, tooling, etc. (e.g., `chore/update-dependencies`)
+
+#### Commit Messages
+
+We follow the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) specification. This makes the commit history easier to read and helps with automating changelogs.
+
+A commit message should be structured as follows:
+
+```
+type(scope): subject
+
+body
+
+footer
+```
+
+**Types**: `feat`, `fix`, `docs`, `style`, `refactor`, `test`, `chore`
+
+**Examples**:
+
+```
+feat(Optimizers): add new tweak to disable Superfetch
+```
+
+```
+fix(UI): correct typo in the main menu prompt
+```
+
+```
+docs(CONTRIBUTING): add development setup instructions
+```
+
+## Coding Standards
+
+#### Style Guide
+
+* We follow the standard C# and .NET coding conventions.
+* Code formatting rules are defined in the `.editorconfig` file. Please ensure your editor respects these settings.
+* Use meaningful names for variables, methods, and classes.
+
+#### Best Practices
+
+* Write self-documenting code where possible.
+* Add XML comments (`///`) for public methods and complex logic.
+* Keep functions and methods small and focused on a single responsibility.
+* Aim for clarity and simplicity.
+
+## Testing
+
+#### Writing Tests
+
+* New features should be accompanied by unit tests.
+* Bug fixes should include a test case that reproduces the bug and verifies the fix.
+* Tests are located in the `optimizerDuck.Test` project.
+
+#### Running Tests
+
+You can run all tests from the root directory:
+
+```bash
+# Run all tests
+dotnet test
+
+# Run tests in watch mode
+dotnet watch test
+```
+
+## Documentation
+
+#### Code Documentation
+
+* Public APIs, classes, and methods should be documented using XML comments.
+* Explain complex algorithms or business logic with comments in the code.
+
+#### README Updates
+
+* If you add or change a feature, please update the `README.md` to reflect the changes.
+* Ensure any new tweaks are listed in the "What It Actually Does" section.
+
+## Pull Request Process
+
+1. **Before Submitting**
+ * Run `dotnet test` to ensure all tests pass locally.
+ * Ensure your code adheres to the coding standards.
+ * Update the `README.md` and any other relevant documentation.
+ * Self-review your changes to catch any obvious issues.
+
+2. **PR Description Template**
+ Please fill out the pull request template to help reviewers understand your contribution.
+
+ ```markdown
+ ## Description
+ A brief description of the changes in this pull request.
+
+ ## Type of Change
+ - [ ] Bug fix (non-breaking change which fixes an issue)
+ - [ ] New feature (non-breaking change which adds functionality)
+ - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
+ - [ ] Documentation update
+ - [ ] Refactor
+
+ ## Related Issues
+ Fixes #(issue number)
+
+ ## Testing
+ - [ ] All tests pass locally with my changes.
+ - [ ] I have added tests that prove my fix is effective or that my feature works.
+ - [ ] I have updated existing tests to accommodate my changes.
+
+ ## Checklist
+ - [ ] My code follows the style guidelines of this project.
+ - [ ] I have performed a self-review of my own code.
+ - [ ] I have commented on my code, particularly in hard-to-understand areas.
+ - [ ] I have made corresponding changes to the documentation.
+ - [ ] My changes generate no new warnings.
+ ```
+
+3. **Review Process**
+ * One or more maintainers will review your pull request.
+ * Please be responsive to feedback and questions.
+ * Once your PR is approved, it will be merged into the `main` branch.
+
+## Community
+
+#### Getting Help
+
+* **Discord:** Join our [Discord Server](https://discord.gg/tDUBDCYw9Q) to chat with the community and get help.
+* **GitHub Discussions:** Use [GitHub Discussions](https://github.com/itsfatduck/optimizerDuck/discussions) for questions, ideas, and to show off your results.
+
+## License
+
+By contributing to optimizerDuck, you agree that your contributions will be licensed under the [CC BY-NC-SA 4.0 License](./LICENSE).
diff --git a/optimizerDuck/Program.cs b/optimizerDuck/Program.cs
index 279142c..7463ae4 100644
--- a/optimizerDuck/Program.cs
+++ b/optimizerDuck/Program.cs
@@ -2,8 +2,8 @@
using optimizerDuck.Core;
using optimizerDuck.Core.Extensions;
using optimizerDuck.Core.Helpers;
-using optimizerDuck.Core.Managers;
using optimizerDuck.Core.Services;
+using optimizerDuck.src.UI;
using optimizerDuck.UI;
using optimizerDuck.UI.Components;
using optimizerDuck.UI.Logger;
@@ -37,7 +37,6 @@ namespace optimizerDuck;
internal class Program
{
private static readonly ILogger Log = Logger.CreateLogger<Program>();
- private OptimizationManager? _optimizer;
private SystemSnapshot _systemSnapshot = null!;
private async Task Init()
@@ -104,110 +103,17 @@ internal class Program
private async Task Start()
{
+ var menuHandler = new MenuHandler(_systemSnapshot);
+
while (true)
{
- SystemHelper.Title(
- $"{_systemSnapshot.Os.Name} {_systemSnapshot.Os.Edition} ({_systemSnapshot.Os.Architecture})");
- AnsiConsole.Clear();
- AnsiConsole.Write(Defaults.Logo);
-
- AnsiConsole.WriteLine();
-
- var start = Align.Center(
- new PromptPanel('E', "Start Optimization",
- $"""
- [bold]Customize your optimization process.[/]
- Browse the available options, pick the ones that suit you best,
- and apply them to improve your system.
+ MainMenu.Display(_systemSnapshot);
- [bold {Theme.Warning}]Some changes may require a restart.[/]
- [dim white]Certain options may also need an internet connection.[/]
- """,
- Theme.Primary,
- CustomBoxBorder.LeftBorder).Build()
- );
-
- var middlePanels = Align.Center(
- new Columns(
- new PromptPanel('D', "Join our Discord",
- $"""
- [bold]{Emoji.Known.SpeechBalloon} Get help, share ideas, and stay updated.[/]
- Connect with the community and the dev team directly.
- """,
- Theme.Info,
- CustomBoxBorder.UnderlineBorder).Build(),
- new PromptPanel('G', "GitHub",
- $"""
- [bold]{Emoji.Known.Laptop} Explore the source code and releases.[/]
- Contribute, report issues, or check for the latest updates.
- """,
- "white",
- CustomBoxBorder.UnderlineBorder).Build(),
- new PromptPanel('I', "System Information",
- $"""
- [bold]{Emoji.Known.Gear} View system information.[/]
- Review detailed system information and diagnostics.
- """,
- Theme.Accent,
- CustomBoxBorder.UnderlineBorder).Build()
- )
- { Expand = false }
- );
- AnsiConsole.Write(start);
- AnsiConsole.Write(middlePanels);
+ Console.CursorVisible = false;
+ var option = Console.ReadKey(true).KeyChar;
+ Console.CursorVisible = true;
- AnsiConsole.WriteLine();
-
- while (true)
- {
- Console.CursorVisible = false;
- var option = Console.ReadKey(true).KeyChar;
- Console.CursorVisible = true;
-
- if (option == 'e')
- {
- _optimizer ??= new OptimizationManager(_systemSnapshot);
- if (await _optimizer.Begin().ConfigureAwait(false))
- if (await OptimizationManager.RestorePoint().ConfigureAwait(false))
- await _optimizer.Run().ConfigureAwait(false);
-
- break;
- }
-
- if (option == 'd')
- {
- SystemHelper.OpenWebsite(Defaults.DiscordInvite);
- break;
- }
-
- if (option == 'g')
- {
- SystemHelper.OpenWebsite(Defaults.GitHubRepo);
- break;
- }
-
- if (option == 'i')
- {
- Log.LogInformation("Refreshing System Information...");
- _systemSnapshot = await SystemInfoService.RefreshAsync().ConfigureAwait(false);
-
- AnsiConsole.Clear();
- AnsiConsole.Write(Defaults.Logo);
-
- var detailedPanel = SystemInfoService.GetDetailedPanel(_systemSnapshot, Log);
- if (detailedPanel is not null)
- {
- AnsiConsole.Write(detailedPanel);
- AnsiConsole.Write(
- Align.Center(
- new Markup("[dim]Press any key to go back to the main menu.[/]"),
- VerticalAlignment.Middle)
- );
- Console.ReadKey();
- }
- break;
- }
- }
+ _systemSnapshot = await menuHandler.HandleInputAsync(option).ConfigureAwait(false);
}
}
diff --git a/optimizerDuck/optimizerDuck.csproj b/optimizerDuck/optimizerDuck.csproj
index 1bdfeec..aa3ecd6 100644
--- a/optimizerDuck/optimizerDuck.csproj
+++ b/optimizerDuck/optimizerDuck.csproj
@@ -18,17 +18,17 @@
</PropertyGroup>
<ItemGroup>
- <PackageReference Include="ConsoleInk.Net" Version="0.1.6"/>
- <PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="9.0.10"/>
- <PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.10"/>
- <PackageReference Include="Microsoft.PowerShell.SDK" Version="7.5.4"/>
- <PackageReference Include="Newtonsoft.Json" Version="13.0.4"/>
- <PackageReference Include="Serilog" Version="4.3.1-dev-02387"/>
- <PackageReference Include="Serilog.Extensions.Logging" Version="9.0.2"/>
- <PackageReference Include="Serilog.Sinks.File" Version="7.0.0"/>
- <PackageReference Include="Spectre.Console" Version="0.53.0"/>
- <PackageReference Include="System.Management" Version="9.0.10"/>
- <PackageReference Include="System.ServiceProcess.ServiceController" Version="9.0.10"/>
- <PackageReference Include="vertical-spectreconsolelogger" Version="0.10.1-dev.20241201.35"/>
+ <PackageReference Include="ConsoleInk.Net" Version="0.1.6" />
+ <PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="9.0.10" />
+ <PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.10" />
+ <PackageReference Include="Microsoft.PowerShell.SDK" Version="7.5.4" />
+ <PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
+ <PackageReference Include="Serilog" Version="4.3.1-dev-02387" />
+ <PackageReference Include="Serilog.Extensions.Logging" Version="9.0.2" />
+ <PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
+ <PackageReference Include="Spectre.Console" Version="0.53.0" />
+ <PackageReference Include="System.Management" Version="9.0.10" />
+ <PackageReference Include="System.ServiceProcess.ServiceController" Version="9.0.10" />
+ <PackageReference Include="vertical-spectreconsolelogger" Version="0.10.1-dev.20241201.35" />
</ItemGroup>
</Project>
diff --git a/optimizerDuck/src/Core/Defaults.cs b/optimizerDuck/src/Core/Defaults.cs
index b0b5cff..c4f3a95 100644
--- a/optimizerDuck/src/Core/Defaults.cs
+++ b/optimizerDuck/src/Core/Defaults.cs
@@ -55,7 +55,7 @@ public static class Defaults
// @formatter:on
HorizontalAlignment.Center
))
- { Border = CustomBoxBorder.UnderlineBorder, Padding = new Padding(0, 1, 0, 1) };
+ { Border = CustomBoxBorder.UnderlineBorder, Padding = new Padding(0, 1, 0, 1) };
public static readonly string ExePath = Environment.ProcessPath!;
public static readonly string ExeDir = Path.GetDirectoryName(ExePath)!;
@@ -74,7 +74,7 @@ public static class Defaults
["Microsoft.BingWeather"] = "Weather",
["Microsoft.BingNews"] = "Bing News",
["Microsoft.BingSearch"] = "Bing Search",
-
+
["Microsoft.GetHelp"] = "Get Help",
["Microsoft.GetStarted"] = "Get Started / Tips",
["Microsoft.Messaging"] = "Messaging",
@@ -117,6 +117,7 @@ public static class Defaults
["Microsoft.WindowsStore"] = "Microsoft Store",
["Microsoft.XboxIdentityProvider"] = "Xbox Identity Provider",
["Microsoft.WindowsTerminal"] = "Windows Terminal",
+ ["Microsoft.WindowsTerminalPreview"] = "Windows Terminal (Preview)",
["Clipchamp.Clipchamp"] = "Clipchamp (Video Editor)",
["Microsoft.WindowsNotepad"] = "Notepad",
["Microsoft.PowerAutomateDesktop"] = "Power Automate",
diff --git a/optimizerDuck/src/Core/Helpers/SystemHelper.cs b/optimizerDuck/src/Core/Helpers/SystemHelper.cs
index c4995e9..af723fa 100644
--- a/optimizerDuck/src/Core/Helpers/SystemHelper.cs
+++ b/optimizerDuck/src/Core/Helpers/SystemHelper.cs
@@ -85,7 +85,7 @@ public static class SystemHelper
public static void AddToExclusions(List<string> paths)
{
- using var tracker = ServiceTracker.Begin();
+ using var tracker = ServiceTracker.Begin(Log);
foreach (var path in paths)
{
var result = ShellService.PowerShell($"Add-MpPreference -ExclusionPath \"{path}\"");
diff --git a/optimizerDuck/src/Core/Helpers/SystemProtectionHelper.cs b/optimizerDuck/src/Core/Helpers/SystemProtectionHelper.cs
index a8ea069..10b5795 100644
--- a/optimizerDuck/src/Core/Helpers/SystemProtectionHelper.cs
+++ b/optimizerDuck/src/Core/Helpers/SystemProtectionHelper.cs
@@ -12,7 +12,7 @@ public static class SystemProtectionHelper
public static bool Enable()
{
- using var tracker = ServiceTracker.Begin();
+ using var tracker = ServiceTracker.Begin(Log);
Log.LogInformation("Enabling System Protection...");
var result = ShellService.PowerShell("Enable-ComputerRestore -Drive \"$env:SystemDrive\"");
@@ -35,7 +35,7 @@ public static class SystemProtectionHelper
public static void Create()
{
- using var tracker = ServiceTracker.Begin();
+ using var tracker = ServiceTracker.Begin(Log);
Log.LogInformation("Creating a restore point...");
var result =
diff --git a/optimizerDuck/src/Core/Managers/OptimizationManager.cs b/optimizerDuck/src/Core/Managers/OptimizationManager.cs
index 31003e7..9a87037 100644
--- a/optimizerDuck/src/Core/Managers/OptimizationManager.cs
+++ b/optimizerDuck/src/Core/Managers/OptimizationManager.cs
@@ -9,7 +9,6 @@ using optimizerDuck.UI.Components;
using optimizerDuck.UI.Logger;
using Spectre.Console;
using System.Diagnostics;
-using Spectre.Console.Rendering;
using ILogger = Microsoft.Extensions.Logging.ILogger;
namespace optimizerDuck.Core.Managers;
@@ -50,7 +49,7 @@ public class OptimizationManager(SystemSnapshot systemSnapshot)
foreach (var g in optimizationGroups)
promptTweakChoice.AddChoiceGroup(
new OptimizationTweakChoice(null, $"[bold underline]{g.Name}[/]", string.Empty,
- false), // hack to add group title ok vjp pro, and this cant be selected btw
+ false),
g.Tweaks
);
@@ -66,9 +65,9 @@ public class OptimizationManager(SystemSnapshot systemSnapshot)
_selectedTweaks = new Queue<OptimizationTweakChoice>(optimizationTweakChoices);
- if (_selectedTweaks.Any(t =>
- t.Instance?.GetType() ==
- typeof(BloatwareAndServices.RemoveBloatwareApps))) // if Bloatware selection is selected
+ var hasBloatwareSelection = _selectedTweaks.Any(t => t.Instance?.GetType() == typeof(BloatwareAndServices.RemoveBloatwareApps));
+
+ if (hasBloatwareSelection) // if Bloatware selection is selected
{
SystemHelper.Title("Select the bloatware you want to remove");
Log.LogDebug("Bloatware selection detected, prompting for bloatware apps...");
@@ -85,7 +84,7 @@ public class OptimizationManager(SystemSnapshot systemSnapshot)
We [{Theme.Warning}]couldn't[/] find any bloatware installed on your system.
There's nothing you need to remove, so you can [{Theme.Success}]safely continue[/].
""",
- new PromptOption("Continue", Theme.Success),
+ new PromptOption("Continue", Theme.Success, () => true),
new PromptOption("Back", Theme.Warning, () => false)
);
}
@@ -98,8 +97,7 @@ public class OptimizationManager(SystemSnapshot systemSnapshot)
.UseConverter(app =>
$"{(app.DisplayName.Contains("Safe Apps") || app.DisplayName.Contains("Caution Apps") ?
app.DisplayName :
- $"[bold]{app.DisplayName}[/] [dim]{app.Version} {app.InstallLocation}[/]")
- }")
+ $"[bold]{app.DisplayName}[/] [dim]{app.Version} {app.InstallLocation}[/]")}")
.PageSize(24);
if (appxClassification.SafeApps.Count > 0)
@@ -178,7 +176,8 @@ public class OptimizationManager(SystemSnapshot systemSnapshot)
Log.LogDebug("Selected tweaks ({TweakAmount}): {Tweaks}", _selectedTweaks.Count,
string.Join(", ", _selectedTweaks.Select(t => t.Name)));
- if (SelectedBloatware.Count != 0)
+ var hasBloatwareSelection = _selectedTweaks.Any(t => t.Instance?.GetType() == typeof(BloatwareAndServices.RemoveBloatwareApps));
+ if (hasBloatwareSelection) // if Bloatware selection is selected
Log.LogDebug("Selected bloatware apps ({BloatwareAmount}): {Bloatware}", SelectedBloatware.Count,
string.Join(", ", SelectedBloatware.Select(app => $"{app.DisplayName} ({app.Version})")));
@@ -193,7 +192,8 @@ public class OptimizationManager(SystemSnapshot systemSnapshot)
{
selectedTweak = selectedTweak with
{
- Name = selectedTweak.Name.Trim(), Description = selectedTweak.Description.Trim()
+ Name = selectedTweak.Name.Trim(),
+ Description = selectedTweak.Description.Trim()
};
SystemHelper.Title(selectedTweak.Name);
ctx.Status($"Applying [{Theme.Primary}]{selectedTweak.Name}[/]...");
diff --git a/optimizerDuck/src/Core/Optimizers/BloatwareAndServices.cs b/optimizerDuck/src/Core/Optimizers/BloatwareAndServices.cs
index 756f90a..0893e72 100644
--- a/optimizerDuck/src/Core/Optimizers/BloatwareAndServices.cs
+++ b/optimizerDuck/src/Core/Optimizers/BloatwareAndServices.cs
@@ -25,7 +25,7 @@ public class BloatwareAndServices : IOptimizationGroup
public Task Apply(SystemSnapshot s)
{
- using var tracker = ServiceTracker.Begin();
+ using var tracker = ServiceTracker.Begin(Log);
while (OptimizationManager.SelectedBloatware.TryDequeue(out var appxPackage))
{
@@ -75,7 +75,7 @@ public class BloatwareAndServices : IOptimizationGroup
public Task Apply(SystemSnapshot s)
{
- using var tracker = ServiceTracker.Begin();
+ using var tracker = ServiceTracker.Begin(Log);
RegistryService.Write(
// thank you again, WinUtil
new RegistryItem(@"HKLM\SOFTWARE\Policies\Microsoft\EdgeUpdate", "CreateDesktopShortcutDefault", 0),
@@ -111,7 +111,7 @@ public class BloatwareAndServices : IOptimizationGroup
public Task Apply(SystemSnapshot s)
{
- using var tracker = ServiceTracker.Begin();
+ using var tracker = ServiceTracker.Begin(Log);
ServiceProcessService.ChangeServiceStartupType(
new ServiceItem("AJRouter", ServiceStartupType.Disabled),
diff --git a/optimizerDuck/src/Core/Optimizers/Performance.cs b/optimizerDuck/src/Core/Optimizers/Performance.cs
index 2c6a638..e739ca4 100644
--- a/optimizerDuck/src/Core/Optimizers/Performance.cs
+++ b/optimizerDuck/src/Core/Optimizers/Performance.cs
@@ -97,6 +97,8 @@ public class Performance : IOptimizationGroup
public Task Apply(SystemSnapshot s)
{
+ using var tracker = ServiceTracker.Begin(Log);
+
if (s.Ram.TotalKB <= 0)
{
Log.LogInformation("Invalid RAM value: {RamTotalKB}. Skipping...", s.Ram.TotalKB);
@@ -124,7 +126,7 @@ public class Performance : IOptimizationGroup
public Task Apply(SystemSnapshot s)
{
- using var tracker = ServiceTracker.Begin();
+ using var tracker = ServiceTracker.Begin(Log);
RegistryService.Write(
new RegistryItem(@"HKCU\System\GameConfigStore", "GameBarEnabled", 0),
@@ -166,7 +168,7 @@ public class Performance : IOptimizationGroup
public Task Apply(SystemSnapshot s)
{
- using var tracker = ServiceTracker.Begin();
+ using var tracker = ServiceTracker.Begin(Log);
RegistryService.Write(
new RegistryItem(@"HKCU\Software\Microsoft\Windows\CurrentVersion\GameDVR", "AppCaptureEnabled", 0),
@@ -190,7 +192,7 @@ public class Performance : IOptimizationGroup
public Task Apply(SystemSnapshot s)
{
- using var tracker = ServiceTracker.Begin();
+ using var tracker = ServiceTracker.Begin(Log);
Log.LogInformation("Applying GPU tweaks for {GpuCount} GPUs...", s.Gpus.Count);
const string basePath =
diff --git a/optimizerDuck/src/Core/Optimizers/Power.cs b/optimizerDuck/src/Core/Optimizers/Power.cs
index 886b153..5b1ba92 100644
--- a/optimizerDuck/src/Core/Optimizers/Power.cs
+++ b/optimizerDuck/src/Core/Optimizers/Power.cs
@@ -51,7 +51,7 @@ public class Power : IOptimizationGroup
public Task Apply(SystemSnapshot s)
{
- using var tracker = ServiceTracker.Begin();
+ using var tracker = ServiceTracker.Begin(Log);
//https://discord.com/channels/1298592513816530994/1359513721738629140/1359524213047824517
//from FrameSync Labs
ShellService.PowerShell("""
@@ -81,7 +81,7 @@ public class Power : IOptimizationGroup
public async Task Apply(SystemSnapshot s)
{
- using var tracker = ServiceTracker.Begin();
+ using var tracker = ServiceTracker.Begin(Log);
var (success, powerPlanPath) =
await StreamHelper.TryDownloadAsync(Defaults.PowerPlanUrl, "optimizerDuck.pow");
if (success && !string.IsNullOrEmpty(powerPlanPath))
diff --git a/optimizerDuck/src/Core/Optimizers/SecurityAndPrivacy.cs b/optimizerDuck/src/Core/Optimizers/SecurityAndPrivacy.cs
index 8a2a464..237d540 100644
--- a/optimizerDuck/src/Core/Optimizers/SecurityAndPrivacy.cs
+++ b/optimizerDuck/src/Core/Optimizers/SecurityAndPrivacy.cs
@@ -23,7 +23,7 @@ public class SecurityAndPrivacy : IOptimizationGroup
public Task Apply(SystemSnapshot s)
{
- using var tracker = ServiceTracker.Begin();
+ using var tracker = ServiceTracker.Begin(Log);
RegistryService.Write(new RegistryItem(@"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System",
"EnableLUA", 0));
Log.LogInformation("Disabled UAC");
@@ -45,7 +45,7 @@ public class SecurityAndPrivacy : IOptimizationGroup
/// </summary>
public Task Apply(SystemSnapshot s)
{
- using var tracker = ServiceTracker.Begin();
+ using var tracker = ServiceTracker.Begin(Log);
// @formatter:off
RegistryService.Write(
new RegistryItem(@"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\DataCollection", "AllowTelemetry", 0),
@@ -134,7 +134,7 @@ public class SecurityAndPrivacy : IOptimizationGroup
return Task.CompletedTask;
}
}
-
+
public class DisableAutologger : IOptimizationTweak
{
public string Name { get; } = "Disable WMI AutoLogger";
@@ -146,7 +146,7 @@ public class SecurityAndPrivacy : IOptimizationGroup
public Task Apply(SystemSnapshot s)
{
- using var tracker = ServiceTracker.Begin();
+ using var tracker = ServiceTracker.Begin(Log);
RegistryService.Write(
new RegistryItem(@"HKLM\SYSTEM\CurrentControlSet\Control\WMI\Autologger\AppModel", "Start", 0),
new RegistryItem(@"HKLM\SYSTEM\CurrentControlSet\Control\WMI\Autologger\Cellcore", "Start", 0),
@@ -176,7 +176,7 @@ public class SecurityAndPrivacy : IOptimizationGroup
public Task Apply(SystemSnapshot s)
{
- using var tracker = ServiceTracker.Begin();
+ using var tracker = ServiceTracker.Begin(Log);
RegistryService.Write(
new RegistryItem(@"HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager", "ContentDeliveryAllowed", 0),
new RegistryItem(@"HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager", "OemPreInstalledAppsEnabled", 0),
@@ -193,7 +193,7 @@ public class SecurityAndPrivacy : IOptimizationGroup
return Task.CompletedTask;
}
}
-
+
public class DisableCortanaTweak : IOptimizationTweak
{
public string Name { get; } = "Disable Cortana & Search AI";
@@ -205,7 +205,7 @@ public class SecurityAndPrivacy : IOptimizationGroup
public Task Apply(SystemSnapshot s)
{
- using var tracker = ServiceTracker.Begin();
+ using var tracker = ServiceTracker.Begin(Log);
RegistryService.Write(
new RegistryItem(@"HKLM\SOFTWARE\Policies\Microsoft\Windows\Windows Search", "AllowCortana", 0),
@@ -234,7 +234,7 @@ public class SecurityAndPrivacy : IOptimizationGroup
public Task Apply(SystemSnapshot s)
{
- using var tracker = ServiceTracker.Begin();
+ using var tracker = ServiceTracker.Begin(Log);
RegistryService.Write(
new RegistryItem(@"HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsCopilot", "TurnOffWindowsCopilot", 1),
diff --git a/optimizerDuck/src/Core/Optimizers/UserExperience.cs b/optimizerDuck/src/Core/Optimizers/UserExperience.cs
index ea1a689..8764183 100644
--- a/optimizerDuck/src/Core/Optimizers/UserExperience.cs
+++ b/optimizerDuck/src/Core/Optimizers/UserExperience.cs
@@ -22,7 +22,7 @@ public class UserExperience : IOptimizationGroup
public Task Apply(SystemSnapshot s)
{
- using var tracker = ServiceTracker.Begin();
+ using var tracker = ServiceTracker.Begin(Log);
RegistryService.Write(
new RegistryItem(@"HKLM\SOFTWARE\Policies\Microsoft\Dsh", "AllowNewsAndInterests", 0),
new RegistryItem(@"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "TaskbarDa", 0),
@@ -54,7 +54,7 @@ public class UserExperience : IOptimizationGroup
public Task Apply(SystemSnapshot s)
{
- using var tracker = ServiceTracker.Begin();
+ using var tracker = ServiceTracker.Begin(Log);
RegistryService.Write(
new RegistryItem(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", "AppsUseLightTheme", 0),
new RegistryItem(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", "SystemUsesLightTheme", 0)
@@ -72,7 +72,7 @@ public class UserExperience : IOptimizationGroup
public Task Apply(SystemSnapshot s)
{
- using var tracker = ServiceTracker.Begin();
+ using var tracker = ServiceTracker.Begin(Log);
RegistryService.Write(
new RegistryItem(@"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "ShowSyncProviderNotifications", 0),
new RegistryItem(@"HKCU\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager", "SystemPaneSuggestionsEnabled", 0),
@@ -101,7 +101,7 @@ public class UserExperience : IOptimizationGroup
public Task Apply(SystemSnapshot s)
{
- using var tracker = ServiceTracker.Begin();
+ using var tracker = ServiceTracker.Begin(Log);
RegistryService.Write(
new RegistryItem(@"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\VisualEffects", "VisualFXSetting", 3),
new RegistryItem(@"HKCU\Control Panel\Desktop", "DragFullWindows", "0"),
@@ -125,7 +125,7 @@ public class UserExperience : IOptimizationGroup
public Task Apply(SystemSnapshot s)
{
- using var tracker = ServiceTracker.Begin();
+ using var tracker = ServiceTracker.Begin(Log);
RegistryService.Write(
new RegistryItem(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\PushNotifications",
@@ -151,7 +151,7 @@ public class UserExperience : IOptimizationGroup
public Task Apply(SystemSnapshot s)
{
- using var tracker = ServiceTracker.Begin();
+ using var tracker = ServiceTracker.Begin(Log);
RegistryService.Write(
new RegistryItem(@"HKCU\Control Panel\Mouse", "MouseSpeed", "0"),
@@ -175,7 +175,7 @@ public class UserExperience : IOptimizationGroup
public Task Apply(SystemSnapshot s)
{
- using var tracker = ServiceTracker.Begin();
+ using var tracker = ServiceTracker.Begin(Log);
RegistryService.Write(
new RegistryItem(@"HKEY_CURRENT_USER\Control Panel\Keyboard", "KeyboardDelay", "0"),
@@ -200,7 +200,7 @@ public class UserExperience : IOptimizationGroup
public async Task Apply(SystemSnapshot s)
{
- using var tracker = ServiceTracker.Begin();
+ using var tracker = ServiceTracker.Begin(Log);
var (success, zwtPath) = await StreamHelper.TryDownloadAsync(Defaults.ZwtDownloadUrl, "zwtimer.exe")
.ConfigureAwait(false);
diff --git a/optimizerDuck/src/Core/Services/SystemInfoService.cs b/optimizerDuck/src/Core/Services/SystemInfoService.cs
index 9c21d04..3a5c441 100644
--- a/optimizerDuck/src/Core/Services/SystemInfoService.cs
+++ b/optimizerDuck/src/Core/Services/SystemInfoService.cs
@@ -729,16 +729,16 @@ public static class SystemInfoService
{
try
{
- log.LogDebug("OS : {OsName} {OsEdition} {OsArchitecture} ({OsDeviceType})",
+ log.LogDebug("OS : {OsName} {OsEdition} [{OsArchitecture}] ({OsDeviceType})",
Snapshot.Os.Name, Snapshot.Os.Edition, Snapshot.Os.Architecture, Snapshot.Os.DeviceType);
LogGpuSummary(log);
- log.LogDebug("CPU: {CpuName} ({CpuVendor}) [{CpuCores} Cores/{CpuThreads} Threads]",
+ log.LogDebug("CPU: {CpuName} [{CpuVendor}] ({CpuCores} Cores/{CpuThreads} Threads)",
Snapshot.Cpu.Name, Snapshot.Cpu.Vendor, Snapshot.Cpu.Cores, Snapshot.Cpu.Threads);
- log.LogDebug("RAM: {RamTotalGb:F1} GB (Used: {RamUsedPercent:F1}%)",
- Snapshot.Ram.TotalGB, Snapshot.Ram.UsedPercent);
+ log.LogDebug("RAM: {RamTotalGb:F1} GB [{RamModules} Module(s)] (Used: {RamUsedGB:F1} GB)",
+ Snapshot.Ram.TotalGB, Snapshot.Ram.Modules.Count, Snapshot.Ram.UsedGB);
foreach (var volume in Snapshot.Disk.Volumes)
{
@@ -767,8 +767,8 @@ public static class SystemInfoService
if (gpuCount == 1)
{
var gpu = Snapshot.Gpus[0];
- var memoryInfo = gpu.MemoryMB.HasValue ? $" [{gpu.MemoryMB.Value / 1024.0:F0} GB]" : "";
- log.LogDebug("GPU: {GpuName} ({GpuVendor}){MemoryInfo}", gpu.Name, gpu.Vendor, memoryInfo);
+ var memoryInfo = gpu.MemoryMB.HasValue ? $" ({gpu.MemoryMB.Value / 1024.0:F0} GB)" : "";
+ log.LogDebug("GPU: {GpuName} [{GpuVendor}]{MemoryInfo}", gpu.Name, gpu.Vendor, memoryInfo);
return;
}
@@ -776,9 +776,9 @@ public static class SystemInfoService
if (Snapshot.PrimaryGpu != null)
{
var memoryInfoPrimary = Snapshot.PrimaryGpu.MemoryMB.HasValue
- ? $" [{Snapshot.PrimaryGpu.MemoryMB.Value / 1024.0:F0} GB]"
+ ? $" ({Snapshot.PrimaryGpu.MemoryMB.Value / 1024.0:F0} GB)"
: "";
- log.LogDebug("GPU (Primary): {PrimaryGpuName} ({PrimaryGpuVendor}){MemoryInfo}",
+ log.LogDebug("GPU (Primary): {PrimaryGpuName} [{PrimaryGpuVendor}]{MemoryInfo}",
Snapshot.PrimaryGpu.Name, Snapshot.PrimaryGpu.Vendor, memoryInfoPrimary);
for (var index = 0; index < Snapshot.Gpus.Count; index++)
diff --git a/optimizerDuck/src/UI/Logger/ServiceTracker.cs b/optimizerDuck/src/UI/Logger/ServiceTracker.cs
index ef70825..d4478f5 100644
--- a/optimizerDuck/src/UI/Logger/ServiceTracker.cs
+++ b/optimizerDuck/src/UI/Logger/ServiceTracker.cs
@@ -1,4 +1,5 @@
using Microsoft.Extensions.Logging;
+using System.Collections.Concurrent;
using System.Diagnostics;
namespace optimizerDuck.UI.Logger;
@@ -7,14 +8,14 @@ public class ServiceTracker : IDisposable
{
private static readonly AsyncLocal<ServiceTracker?> _current = new();
- private readonly Dictionary<string, (int Success, int Fail)> _serviceStats;
+ private readonly ConcurrentDictionary<string, (int Success, int Fail)> _serviceStats;
private readonly Stopwatch _stopwatch;
private ServiceTracker(ILogger logger)
{
Log = logger;
_stopwatch = Stopwatch.StartNew();
- _serviceStats = new Dictionary<string, (int Success, int Fail)>();
+ _serviceStats = new ConcurrentDictionary<string, (int Success, int Fail)>();
}
public static ServiceTracker? Current => _current.Value;
@@ -23,15 +24,23 @@ public class ServiceTracker : IDisposable
public void Dispose()
{
- _stopwatch.Stop();
- var time = FormatTime(_stopwatch.Elapsed);
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
- var stats = string.Join(" [dim]|[/] ", _serviceStats.Select(kvp =>
- $"{kvp.Key}: [{Theme.Success}]{kvp.Value.Success}[/][dim]/[/][{Theme.Error}]{kvp.Value.Fail}[/]"));
+ protected virtual void Dispose(bool disposing)
+ {
+ if (disposing)
+ {
+ _stopwatch.Stop();
+ var time = FormatTime(_stopwatch.Elapsed);
- Log.LogInformation($"[{Theme.Muted}]Time: {time}[/] [dim]|[/] {stats}");
+ var stats = string.Join(" [dim]|[/] ", _serviceStats.Select(kvp =>
+ $"{kvp.Key}: [{Theme.Success}]{kvp.Value.Success}[/][dim]/[/][{Theme.Error}]{kvp.Value.Fail}[/]"));
- _current.Value = null;
+ Log.LogInformation($"[{Theme.Muted}]Time: {time}[/] [dim]|[/] {stats}");
+ _current.Value = null;
+ }
}
@@ -43,24 +52,23 @@ public class ServiceTracker : IDisposable
return tracker;
}
- internal void Track(string serviceName, bool success)
+ public void Track(string serviceName, bool success)
{
- if (!_serviceStats.ContainsKey(serviceName)) _serviceStats[serviceName] = (0, 0);
+ if (!_serviceStats.TryGetValue(serviceName, out var current))
+ current = (0, 0);
- var current = _serviceStats[serviceName];
- _serviceStats[serviceName] = success
- ? (current.Success + 1, current.Fail)
- : (current.Success, current.Fail + 1);
+ _serviceStats.AddOrUpdate(
+ serviceName,
+ success ? (1, 0) : (0, 1),
+ (key, current) => success
+ ? (current.Success + 1, current.Fail)
+ : (current.Success, current.Fail + 1));
}
public static string FormatTime(TimeSpan time)
{
- return time.TotalSeconds >= 1
- ? $"{time.TotalSeconds:F1}s"
- : time.TotalMilliseconds >= 1
- ? $"{time.TotalMilliseconds:F0}ms"
- : time.Ticks > 0
- ? $"{time.Ticks} ticks"
- : "0";
+ if (time.TotalSeconds >= 1) return $"{time.TotalSeconds:F1}s";
+ if (time.TotalMilliseconds >= 1) return $"{time.TotalMilliseconds:F0}ms";
+ return time.Ticks > 0 ? $"{time.Ticks} ticks" : "0";
}
}
\ No newline at end of file
diff --git a/optimizerDuck/src/UI/MainMenu.cs b/optimizerDuck/src/UI/MainMenu.cs
new file mode 100644
index 0000000..43f45a4
--- /dev/null
+++ b/optimizerDuck/src/UI/MainMenu.cs
@@ -0,0 +1,66 @@
+using optimizerDuck.Core;
+using optimizerDuck.Core.Helpers;
+using optimizerDuck.Core.Services;
+using optimizerDuck.UI;
+using optimizerDuck.UI.Components;
+using Spectre.Console;
+
+namespace optimizerDuck.src.UI;
+
+internal static class MainMenu
+{
+ public static void Display(SystemSnapshot systemSnapshot)
+ {
+ SystemHelper.Title(
+ $"{systemSnapshot.Os.Name} {systemSnapshot.Os.Edition} ({systemSnapshot.Os.Architecture})");
+ AnsiConsole.Clear();
+ AnsiConsole.Write(Defaults.Logo);
+
+ AnsiConsole.WriteLine();
+
+ var start = Align.Center(
+ new PromptPanel('E', "Start Optimization",
+ $"""
+ [bold]Customize your optimization process.[/]
+ Browse the available options, pick the ones that suit you best,
+ and apply them to improve your system.
+
+ [bold {Theme.Warning}]Some changes may require a restart.[/]
+ [dim white]Certain options may also need an internet connection.[/]
+ """,
+ Theme.Primary,
+ CustomBoxBorder.LeftBorder).Build()
+ );
+
+ var middlePanels = Align.Center(
+ new Columns(
+ new PromptPanel('D', "Join our Discord",
+ $"""
+ [bold]{Emoji.Known.SpeechBalloon} Get help, share ideas, and stay updated.[/]
+ Connect with the community and the dev team directly.
+ """,
+ Theme.Info,
+ CustomBoxBorder.UnderlineBorder).Build(),
+ new PromptPanel('G', "GitHub",
+ $"""
+ [bold]{Emoji.Known.Laptop} Explore the source code and releases.[/]
+ Contribute, report issues, or check for the latest updates.
+ """,
+ "white",
+ CustomBoxBorder.UnderlineBorder).Build(),
+ new PromptPanel('I', "System Information",
+ $"""
+ [bold]{Emoji.Known.Gear} View system information.[/]
+ Review detailed system information and diagnostics.
+ """,
+ Theme.Accent,
+ CustomBoxBorder.UnderlineBorder).Build()
+ )
+ { Expand = false }
+ );
+ AnsiConsole.Write(start);
+ AnsiConsole.Write(middlePanels);
+
+ AnsiConsole.WriteLine();
+ }
+}
diff --git a/optimizerDuck/src/UI/MenuHandler.cs b/optimizerDuck/src/UI/MenuHandler.cs
new file mode 100644
index 0000000..0e10e26
--- /dev/null
+++ b/optimizerDuck/src/UI/MenuHandler.cs
@@ -0,0 +1,82 @@
+using Microsoft.Extensions.Logging;
+using optimizerDuck.Core;
+using optimizerDuck.Core.Helpers;
+using optimizerDuck.Core.Managers;
+using optimizerDuck.Core.Services;
+using optimizerDuck.UI.Logger;
+using Spectre.Console;
+
+namespace optimizerDuck.src.UI;
+
+internal class MenuHandler
+{
+ private readonly ILogger _log = Logger.CreateLogger<MenuHandler>();
+ private readonly Dictionary<char, Func<Task>> _menuActions;
+
+ private OptimizationManager? _optimizer;
+ private SystemSnapshot _systemSnapshot;
+
+ public MenuHandler(SystemSnapshot systemSnapshot)
+ {
+ _systemSnapshot = systemSnapshot;
+ _menuActions = new Dictionary<char, Func<Task>>
+ {
+ { 'e', HandleStartOptimizationAsync },
+ { 'd', HandleDiscordLinkAsync },
+ { 'g', HandleGitHubLinkAsync },
+ { 'i', HandleSystemInfoAsync }
+ };
+ }
+
+ public async Task<SystemSnapshot> HandleInputAsync(char option)
+ {
+ if (_menuActions.TryGetValue(option, out var action))
+ {
+ await action();
+ }
+
+ // If invalid key, do nothing and let the loop re-render the menu.
+ return _systemSnapshot;
+ }
+
+ private async Task HandleStartOptimizationAsync()
+ {
+ _optimizer ??= new OptimizationManager(_systemSnapshot);
+ if (await _optimizer.Begin().ConfigureAwait(false))
+ if (await OptimizationManager.RestorePoint().ConfigureAwait(false))
+ await _optimizer.Run().ConfigureAwait(false);
+ }
+
+ private Task HandleDiscordLinkAsync()
+ {
+ SystemHelper.OpenWebsite(Defaults.DiscordInvite);
+ return Task.CompletedTask;
+ }
+
+ private Task HandleGitHubLinkAsync()
+ {
+ SystemHelper.OpenWebsite(Defaults.GitHubRepo);
+ return Task.CompletedTask;
+ }
+
+ private async Task HandleSystemInfoAsync()
+ {
+ _log.LogInformation("Refreshing System Information...");
+ _systemSnapshot = await SystemInfoService.RefreshAsync().ConfigureAwait(false);
+
+ AnsiConsole.Clear();
+ AnsiConsole.Write(Defaults.Logo);
+
+ var detailedPanel = SystemInfoService.GetDetailedPanel(_systemSnapshot, _log);
+ if (detailedPanel is not null)
+ {
+ AnsiConsole.Write(detailedPanel);
+ AnsiConsole.Write(
+ Align.Center(
+ new Markup("[dim]Press any key to go back to the main menu.[/]"),
+ VerticalAlignment.Middle)
+ );
+ Console.ReadKey();
+ }
+ }
+}