feat: PYRAMID_PROFILE_DIR-Override fuer Desktop-Testprofile (app_dirs.dart)

DB, auth_log und Media-Cache laufen jetzt ueber appSupportDir(); nur auf
Desktop und nur wenn PYRAMID_PROFILE_DIR gesetzt ist, landet alles in einem
eigenen Profilverzeichnis - fuer Autopilot-Testlogins parallel zur echten
Session. Ohne Variable exakt das bisherige Verhalten. secure_storage/
shared_preferences bewusst nicht umgeleitet (Begruendung im Dateikopf).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Bernd Steckmeister
2026-07-06 18:55:30 +02:00
parent fdc16afa70
commit dba4b64df8
5 changed files with 46 additions and 6 deletions
+2 -2
View File
@@ -5,11 +5,11 @@ import 'dart:math';
import 'package:flutter/foundation.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:path/path.dart' as p;
import 'package:path_provider/path_provider.dart';
import 'package:sqflite/sqflite.dart' as sqflite_native;
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
import 'package:sqlcipher_flutter_libs/sqlcipher_flutter_libs.dart';
import 'package:sqlite3/open.dart';
import 'package:pyramid/core/app_dirs.dart';
import 'package:pyramid/core/auth_log.dart';
/// Läuft im DB-Isolate der FFI-Factory (muss deshalb top-level sein):
@@ -56,7 +56,7 @@ class AppDatabase {
!kIsWeb && (Platform.isAndroid || Platform.isWindows || Platform.isLinux);
static Future<String> _dbPath() async {
final appDir = await getApplicationSupportDirectory();
final appDir = await appSupportDir();
return p.join(appDir.path, 'pyramid.sqlite');
}
+31
View File
@@ -0,0 +1,31 @@
import 'dart:io';
import 'package:path_provider/path_provider.dart';
/// Basisverzeichnis für alle lokalen App-Daten (pyramid.sqlite, auth_log.txt,
/// Media-Cache).
///
/// Normalfall: das Application-Support-Verzeichnis der Plattform exakt wie
/// bisher, es ändert sich NICHTS.
///
/// Nur auf dem Desktop kann die Umgebungsvariable `PYRAMID_PROFILE_DIR` ein
/// abweichendes Verzeichnis erzwingen. Zweck: Testläufe mit den
/// Autopilot-Testkonten in einem eigenen Profil, parallel zur echten
/// Session desselben Windows-Nutzers (die echte Session sieht die Variable
/// nie und bleibt unberührt). Bewusst NICHT umgeleitet werden
/// shared_preferences und flutter_secure_storage deren Plugins lösen ihre
/// Pfade selbst auf; ein Testprofil teilt sich also den DB-Schlüssel
/// (`db_cipher_key`) und die UI-Prefs mit dem Hauptprofil. Für Tests ist das
/// unkritisch (der Schlüssel wird nur GELESEN, nie überschrieben), echte
/// Zweitkonten bräuchten mehr.
Future<Directory> appSupportDir() async {
final override = Platform.isWindows || Platform.isLinux || Platform.isMacOS
? Platform.environment['PYRAMID_PROFILE_DIR']
: null;
if (override != null && override.trim().isNotEmpty) {
final dir = Directory(override.trim());
await dir.create(recursive: true);
return dir;
}
return getApplicationSupportDirectory();
}
+2 -2
View File
@@ -2,7 +2,7 @@ import 'dart:async';
import 'dart:io';
import 'package:path/path.dart' as p;
import 'package:path_provider/path_provider.dart';
import 'package:pyramid/core/app_dirs.dart';
/// Schreibt Login-/Logout-relevante Ereignisse in eine Datei, die einen
/// App-Neustart übersteht. Zweck: den Uta-Random-Logout-Bug nachvollziehen
@@ -15,7 +15,7 @@ class AuthLog {
static Future<File> _ensureFile() async {
final existing = _file;
if (existing != null) return existing;
final dir = await getApplicationSupportDirectory();
final dir = await appSupportDir();
final file = File(p.join(dir.path, 'auth_log.txt'));
return _file = file;
}
+2 -2
View File
@@ -4,7 +4,7 @@ import 'dart:io';
import 'dart:typed_data';
import 'package:crypto/crypto.dart';
import 'package:path_provider/path_provider.dart';
import 'package:pyramid/core/app_dirs.dart';
/// Shared, bounded LRU cache for media bytes (chat images, document previews,
/// avatars). Eviction is driven by a total byte budget plus a hard entry cap,
@@ -89,7 +89,7 @@ class MediaCache {
}
Future<Directory> _initDiskDir() async {
final support = await getApplicationSupportDirectory();
final support = await appSupportDir();
final dir = Directory(
'${support.path}${Platform.pathSeparator}media_cache');
await dir.create(recursive: true);