< Summary

Information
Class: SwitchBlade.Services.ThemeService
Assembly: SwitchBlade
File(s): D:\a\switchblade\switchblade\Services\ThemeService.cs
Tag: 203_23722840422
Line coverage
100%
Covered lines: 61
Uncovered lines: 0
Coverable lines: 61
Total lines: 110
Line coverage: 100%
Branch coverage
100%
Covered branches: 8
Total branches: 8
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_AvailableThemes()100%11100%
.ctor(...)100%22100%
InitializeThemes()100%11100%
CreateTheme(...)100%11100%
ApplyTheme(...)100%66100%
LoadCurrentTheme()100%11100%

File(s)

D:\a\switchblade\switchblade\Services\ThemeService.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Windows;
 5using System.Windows.Media;
 6using Color = System.Windows.Media.Color;
 7using ColorConverter = System.Windows.Media.ColorConverter;
 8
 9namespace SwitchBlade.Services
 10{
 11    public class ThemeInfo
 12    {
 13        public string Name { get; set; } = "";
 14        public ResourceDictionary Resources { get; set; } = new ResourceDictionary();
 15    }
 16
 17    public class ThemeService
 18    {
 19        private readonly ISettingsService _settingsService;
 20        private readonly IApplicationResourceHandler _resourceHandler;
 21        private ResourceDictionary? _currentThemeDictionary;
 14422        public List<ThemeInfo> AvailableThemes { get; private set; } = new List<ThemeInfo>();
 23
 4724        public ThemeService(ISettingsService settingsService, IApplicationResourceHandler? resourceHandler = null)
 4725        {
 4726            _settingsService = settingsService;
 4727            _resourceHandler = resourceHandler ?? new WpfApplicationResourceHandler();
 4728            InitializeThemes();
 4729        }
 30
 31        private void InitializeThemes()
 4732        {
 4733            AvailableThemes = new List<ThemeInfo>
 4734            {
 4735                // Sleek Dark (Default)
 4736                CreateTheme("Dark", "#1E1E1E", "#2D2D30", "#DDDDDD", "#3E3E42"),
 4737                // Cyberpunk (High Contrast Neon)
 4738                CreateTheme("Cyberpunk", "#09080D", "#13111A", "#00FF9F", "#FF003C"),
 4739                // Deep Ocean (Blue/Black)
 4740                CreateTheme("Deep Ocean", "#0F1724", "#172336", "#E6F1FF", "#1E2D45"),
 4741                // Moonlight (Cool Grey)
 4742                CreateTheme("Moonlight", "#22252A", "#2C3038", "#AABBC3", "#3C424D"),
 4743                // Dracula (Classic)
 4744                CreateTheme("Dracula", "#282a36", "#44475a", "#f8f8f2", "#7b88bd"),
 4745                // Light (Clean)
 4746                CreateTheme("Light", "#F5F5F5", "#FFFFFF", "#333333", "#E0E0E0"),
 4747                // Super Light (Pure White)
 4748                CreateTheme("Super Light", "#FFFFFF", "#FFFFFF", "#111111", "#F0F0F0"),
 4749            };
 4750        }
 51
 52        private static ThemeInfo CreateTheme(string name, string background, string controlBackground, string foreground
 32953        {
 32954            var dict = new ResourceDictionary();
 55
 56            // Background with 85% opacity for Glass effect
 32957            var bgCol = (Color)ColorConverter.ConvertFromString(background);
 32958            bgCol.A = 217; // ~85%
 32959            dict["WindowBackground"] = new SolidColorBrush(bgCol);
 60
 61            // Control background with 60% opacity
 32962            var ctrlCol = (Color)ColorConverter.ConvertFromString(controlBackground);
 32963            ctrlCol.A = 153; // ~60%
 32964            dict["ControlBackground"] = new SolidColorBrush(ctrlCol);
 65
 32966            dict["ForegroundBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString(foreground));
 67
 68            // Border with 60% opacity (Upgraded from 30% for secondary text contrast)
 32969            var borderCol = (Color)ColorConverter.ConvertFromString(border);
 32970            borderCol.A = 153; // ~60%
 32971            dict["BorderBrush"] = new SolidColorBrush(borderCol);
 72
 73            // Highlight: Use border color with more opacity for better hover contrast
 32974            var highlightCol = (Color)ColorConverter.ConvertFromString(border);
 32975            highlightCol.A = 150; // ~60% for better contrast
 32976            dict["HighlightBrush"] = new SolidColorBrush(highlightCol);
 77
 78            // Accent Brush (Blue-ish defaults, can be customized per theme)
 32979            dict["AccentBrush"] = new SolidColorBrush(Color.FromRgb(0, 120, 215));
 80
 32981            return new ThemeInfo { Name = name, Resources = dict };
 32982        }
 83
 84        public void ApplyTheme(string themeName)
 685        {
 2886            var theme = AvailableThemes.FirstOrDefault(t => t.Name == themeName) ?? AvailableThemes.First();
 87
 88            // Remove the previously applied theme dictionary
 689            if (_currentThemeDictionary != null)
 190            {
 191                _resourceHandler.RemoveMergedDictionary(_currentThemeDictionary);
 192            }
 93
 94            // apply new one
 695            _currentThemeDictionary = theme.Resources;
 696            _resourceHandler.AddMergedDictionary(_currentThemeDictionary);
 97
 698            if (_settingsService.Settings.CurrentTheme != themeName)
 499            {
 4100                _settingsService.Settings.CurrentTheme = themeName;
 4101                _settingsService.SaveSettings();
 4102            }
 6103        }
 104
 105        public void LoadCurrentTheme()
 1106        {
 1107            ApplyTheme(_settingsService.Settings.CurrentTheme);
 1108        }
 109    }
 110}