diff --git a/README.md b/README.md index 4297439..883fee9 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,14 @@ dotnet run --project SlipItIn.AppHost/SlipItIn.AppHost.csproj Der AppHost startet PostgreSQL (Container), wendet EF-Migrationen automatisch an und seedet Testdaten. Die MAUI-App verbindet sich standardmäßig mit `https://localhost:7274` (Android-Emulator: `http://10.0.2.2:5234`). +Für Windows-Entwicklung kann die Client-App ohne persistente lokale Speicherung gestartet werden: + +```powershell +dotnet run --project SlipItIn\SlipItIn.csproj -f net10.0-windows10.0.19041.0 -- --no-storage +``` + +In diesem Modus werden weder Token noch lokale Benutzer-, Spiel- oder Offline-Daten gelesen oder geschrieben. Die Sitzung bleibt nur im Arbeitsspeicher der laufenden App erhalten und geht beim Beenden verloren. + ## Konfiguration | Key | Zweck | diff --git a/SlipItIn/MauiProgram.cs b/SlipItIn/MauiProgram.cs index 433c753..f828e70 100644 --- a/SlipItIn/MauiProgram.cs +++ b/SlipItIn/MauiProgram.cs @@ -20,7 +20,14 @@ public static class MauiProgram }); builder.Services.AddSingleton(); +#if WINDOWS + var storageDisabled = Environment.GetCommandLineArgs().Any( + arg => string.Equals(arg, "--no-storage", StringComparison.OrdinalIgnoreCase)); + builder.Services.AddSingleton( + _ => new LocalStorageService(storageDisabled)); +#else builder.Services.AddSingleton(); +#endif builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); diff --git a/SlipItIn/Properties/launchSettings.json b/SlipItIn/Properties/launchSettings.json index 4f85793..80673f8 100644 --- a/SlipItIn/Properties/launchSettings.json +++ b/SlipItIn/Properties/launchSettings.json @@ -2,6 +2,7 @@ "profiles": { "Windows Machine": { "commandName": "Project", + "commandLineArgs": "--no-storage", "nativeDebugging": false } } diff --git a/SlipItIn/Services/LocalStorageService.cs b/SlipItIn/Services/LocalStorageService.cs index 5ea3f92..cf2fe37 100644 --- a/SlipItIn/Services/LocalStorageService.cs +++ b/SlipItIn/Services/LocalStorageService.cs @@ -14,34 +14,53 @@ public class LocalStorageService : ILocalStorageService private const string QueuedActionsKey = "queued_actions"; private static readonly JsonSerializerOptions JsonOptions = new(JsonSerializerDefaults.Web); + private readonly bool _storageDisabled; - public Task SaveAuthTokenAsync(string token) => SecureStorage.SetAsync(AuthTokenKey, token); + public LocalStorageService(bool storageDisabled = false) + { + _storageDisabled = storageDisabled; + } - public Task GetAuthTokenAsync() => SecureStorage.GetAsync(AuthTokenKey); + public Task SaveAuthTokenAsync(string token) => + _storageDisabled ? Task.CompletedTask : SecureStorage.SetAsync(AuthTokenKey, token); + + public Task GetAuthTokenAsync() => + _storageDisabled ? Task.FromResult(null) : SecureStorage.GetAsync(AuthTokenKey); public Task ClearAuthTokenAsync() { - SecureStorage.Remove(AuthTokenKey); + if (!_storageDisabled) + SecureStorage.Remove(AuthTokenKey); + return Task.CompletedTask; } public Task SaveAuthUserAsync(AuthResponseDto authResponse) { + if (_storageDisabled) + return Task.CompletedTask; + var json = JsonSerializer.Serialize(authResponse, JsonOptions); Preferences.Default.Set(AuthUserKey, json); return Task.CompletedTask; } - public Task GetAuthUserAsync() => ReadFromPreferencesAsync(AuthUserKey); + public Task GetAuthUserAsync() => + ReadFromPreferencesAsync(AuthUserKey); public Task ClearAuthUserAsync() { - Preferences.Default.Remove(AuthUserKey); + if (!_storageDisabled) + Preferences.Default.Remove(AuthUserKey); + return Task.CompletedTask; } public Task SaveGameStateAsync(GameStateDto state) { + if (_storageDisabled) + return Task.CompletedTask; + var json = JsonSerializer.Serialize(state, JsonOptions); Preferences.Default.Set(GameStateKey, json); return Task.CompletedTask; @@ -51,12 +70,17 @@ public class LocalStorageService : ILocalStorageService public Task ClearGameStateAsync() { - Preferences.Default.Remove(GameStateKey); + if (!_storageDisabled) + Preferences.Default.Remove(GameStateKey); + return Task.CompletedTask; } public Task SavePlayerHandAsync(PlayerHandDto hand) { + if (_storageDisabled) + return Task.CompletedTask; + var json = JsonSerializer.Serialize(hand, JsonOptions); Preferences.Default.Set(PlayerHandKey, json); return Task.CompletedTask; @@ -66,12 +90,17 @@ public class LocalStorageService : ILocalStorageService public Task ClearPlayerHandAsync() { - Preferences.Default.Remove(PlayerHandKey); + if (!_storageDisabled) + Preferences.Default.Remove(PlayerHandKey); + return Task.CompletedTask; } public Task SaveQueuedActionsAsync(IReadOnlyCollection actions) { + if (_storageDisabled) + return Task.CompletedTask; + var json = JsonSerializer.Serialize(actions, JsonOptions); Preferences.Default.Set(QueuedActionsKey, json); return Task.CompletedTask; @@ -85,12 +114,17 @@ public class LocalStorageService : ILocalStorageService public Task ClearQueuedActionsAsync() { - Preferences.Default.Remove(QueuedActionsKey); + if (!_storageDisabled) + Preferences.Default.Remove(QueuedActionsKey); + return Task.CompletedTask; } - private static Task ReadFromPreferencesAsync(string key) + private Task ReadFromPreferencesAsync(string key) { + if (_storageDisabled) + return Task.FromResult(default); + if (!Preferences.Default.ContainsKey(key)) return Task.FromResult(default);