Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions KAST.Core/Services/ThemeService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using KAST.Data.Models;

namespace KAST.Core.Services
{
public class ThemeService
{
private readonly ConfigService _configService;
private bool _isDarkMode = false;

public event Action<bool>? OnThemeChanged;

public ThemeService(ConfigService configService)
{
_configService = configService;
}

public bool IsDarkMode => _isDarkMode;

public async Task InitializeAsync()
{
var config = await _configService.GetConfigAsync();
await UpdateThemeFromSettings(config.ThemeMode);
}

public async Task SetThemeModeAsync(string themeMode)
{
var config = await _configService.GetConfigAsync();
config.ThemeMode = themeMode;
await _configService.UpdateConfigAsync(config);
await UpdateThemeFromSettings(themeMode);
}

public async Task ToggleDarkModeAsync()
{
var newMode = _isDarkMode ? "light" : "dark";
await SetThemeModeAsync(newMode);
}

private async Task UpdateThemeFromSettings(string? themeMode)
{
bool newDarkMode = themeMode switch
{
"dark" => true,
"light" => false,
"auto" => await GetSystemPreferenceAsync(),
_ => false
};

if (_isDarkMode != newDarkMode)
{
_isDarkMode = newDarkMode;
OnThemeChanged?.Invoke(_isDarkMode);
}
}

private async Task<bool> GetSystemPreferenceAsync()
{
// For now, default to light mode for "auto"
// In a real implementation, this could detect system preference
await Task.CompletedTask;
return false;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

236 changes: 236 additions & 0 deletions KAST.Data/Migrations/20250926081639_EnhanceSettingsModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace KAST.Data.Migrations
{
/// <inheritdoc />
public partial class EnhanceSettingsModel : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "ModProfiles");

migrationBuilder.DropTable(
name: "ProfileHistories");

migrationBuilder.DropTable(
name: "Mods");

migrationBuilder.DropTable(
name: "Profiles");

migrationBuilder.DropColumn(
name: "CreatedAt",
table: "Servers");

migrationBuilder.DropColumn(
name: "LastUpdated",
table: "Servers");

migrationBuilder.DropColumn(
name: "Version",
table: "Servers");

migrationBuilder.AddColumn<bool>(
name: "CheckForUpdates",
table: "Settings",
type: "INTEGER",
nullable: true);

migrationBuilder.AddColumn<bool>(
name: "DebugLogging",
table: "Settings",
type: "INTEGER",
nullable: true);

migrationBuilder.AddColumn<string>(
name: "Language",
table: "Settings",
type: "TEXT",
maxLength: 10,
nullable: true);

migrationBuilder.AddColumn<string>(
name: "ThemeMode",
table: "Settings",
type: "TEXT",
maxLength: 10,
nullable: true);
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "CheckForUpdates",
table: "Settings");

migrationBuilder.DropColumn(
name: "DebugLogging",
table: "Settings");

migrationBuilder.DropColumn(
name: "Language",
table: "Settings");

migrationBuilder.DropColumn(
name: "ThemeMode",
table: "Settings");

migrationBuilder.AddColumn<DateTime>(
name: "CreatedAt",
table: "Servers",
type: "TEXT",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));

migrationBuilder.AddColumn<DateTime>(
name: "LastUpdated",
table: "Servers",
type: "TEXT",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));

migrationBuilder.AddColumn<string>(
name: "Version",
table: "Servers",
type: "TEXT",
nullable: true);

migrationBuilder.CreateTable(
name: "Mods",
columns: table => new
{
Id = table.Column<Guid>(type: "TEXT", nullable: false),
Author = table.Column<string>(type: "TEXT", nullable: true),
CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: false),
IsEnabled = table.Column<bool>(type: "INTEGER", nullable: false),
IsLocal = table.Column<bool>(type: "INTEGER", nullable: false),
LastUpdated = table.Column<DateTime>(type: "TEXT", nullable: true),
Name = table.Column<string>(type: "TEXT", nullable: false),
Path = table.Column<string>(type: "TEXT", nullable: false),
SizeBytes = table.Column<long>(type: "INTEGER", nullable: false),
SteamId = table.Column<string>(type: "TEXT", nullable: true),
Version = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Mods", x => x.Id);
});

migrationBuilder.CreateTable(
name: "Profiles",
columns: table => new
{
Id = table.Column<Guid>(type: "TEXT", nullable: false),
ServerId = table.Column<Guid>(type: "TEXT", nullable: true),
CommandLineArgs = table.Column<string>(type: "TEXT", nullable: true),
CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: false),
Description = table.Column<string>(type: "TEXT", nullable: true),
IsActive = table.Column<bool>(type: "INTEGER", nullable: false),
LastModified = table.Column<DateTime>(type: "TEXT", nullable: false),
Name = table.Column<string>(type: "TEXT", maxLength: 255, nullable: false),
PerformanceConfig = table.Column<string>(type: "TEXT", nullable: true),
ServerConfig = table.Column<string>(type: "TEXT", nullable: true),
ServerProfile = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Profiles", x => x.Id);
table.ForeignKey(
name: "FK_Profiles_Servers_ServerId",
column: x => x.ServerId,
principalTable: "Servers",
principalColumn: "Id",
onDelete: ReferentialAction.SetNull);
});

migrationBuilder.CreateTable(
name: "ModProfiles",
columns: table => new
{
Id = table.Column<Guid>(type: "TEXT", nullable: false),
ModId = table.Column<Guid>(type: "TEXT", nullable: false),
ProfileId = table.Column<Guid>(type: "TEXT", nullable: false),
AddedAt = table.Column<DateTime>(type: "TEXT", nullable: false),
IsEnabled = table.Column<bool>(type: "INTEGER", nullable: false),
Order = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ModProfiles", x => x.Id);
table.ForeignKey(
name: "FK_ModProfiles_Mods_ModId",
column: x => x.ModId,
principalTable: "Mods",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_ModProfiles_Profiles_ProfileId",
column: x => x.ProfileId,
principalTable: "Profiles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});

migrationBuilder.CreateTable(
name: "ProfileHistories",
columns: table => new
{
Id = table.Column<Guid>(type: "TEXT", nullable: false),
ProfileId = table.Column<Guid>(type: "TEXT", nullable: false),
ChangeDescription = table.Column<string>(type: "TEXT", nullable: true),
ChangedBy = table.Column<string>(type: "TEXT", nullable: true),
CommandLineArgsSnapshot = table.Column<string>(type: "TEXT", nullable: true),
CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: false),
ModsSnapshot = table.Column<string>(type: "TEXT", nullable: true),
PerformanceConfigSnapshot = table.Column<string>(type: "TEXT", nullable: true),
ServerConfigSnapshot = table.Column<string>(type: "TEXT", nullable: true),
ServerProfileSnapshot = table.Column<string>(type: "TEXT", nullable: true),
Version = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ProfileHistories", x => x.Id);
table.ForeignKey(
name: "FK_ProfileHistories_Profiles_ProfileId",
column: x => x.ProfileId,
principalTable: "Profiles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});

migrationBuilder.CreateIndex(
name: "IX_ModProfiles_ModId_ProfileId",
table: "ModProfiles",
columns: new[] { "ModId", "ProfileId" },
unique: true);

migrationBuilder.CreateIndex(
name: "IX_ModProfiles_ProfileId",
table: "ModProfiles",
column: "ProfileId");

migrationBuilder.CreateIndex(
name: "IX_Mods_SteamId",
table: "Mods",
column: "SteamId",
unique: true);

migrationBuilder.CreateIndex(
name: "IX_ProfileHistories_ProfileId_Version",
table: "ProfileHistories",
columns: new[] { "ProfileId", "Version" },
unique: true);

migrationBuilder.CreateIndex(
name: "IX_Profiles_ServerId",
table: "Profiles",
column: "ServerId");
}
}
}
Loading
Loading