fix(profiles): avoid placeholder profile on first launch

This commit is contained in:
edde746
2026-05-06 00:32:15 +02:00
parent 91c23786f2
commit da7aef4548
2 changed files with 8 additions and 23 deletions
-23
View File
@@ -1,7 +1,5 @@
import 'dart:convert';
import 'package:uuid/uuid.dart';
import '../models/plex/plex_home.dart';
import '../models/plex/plex_home_user.dart';
import '../profiles/profile.dart';
@@ -41,7 +39,6 @@ class ConnectionBootstrap {
final Future<Map<String, dynamic>> Function(String accountToken) _plexUserInfoFetcher;
static const String _keyProfileMigrationV1Done = 'profile_migration_v1_done';
static const String _ownerProfileIdPrefix = 'local-';
/// Run all idempotent boot-time migrations. Best-effort — errors are
/// logged but never thrown.
@@ -70,7 +67,6 @@ class ConnectionBootstrap {
return;
}
}
await _ensureOwnerProfile();
if (hadLegacyPlexToken) {
await storage.clearLegacyPlexToken();
}
@@ -271,25 +267,6 @@ class ConnectionBootstrap {
}
}
/// Make sure fresh non-Plex installs always have at least one local profile.
/// Migrated Plex accounts select a virtual Plex Home profile instead.
Future<void> _ensureOwnerProfile() async {
final existing = await profileRegistry.list();
if (existing.isNotEmpty) return;
if (storage.getActiveProfileId() != null) return;
final owner = Profile(
id: '$_ownerProfileIdPrefix${const Uuid().v4()}',
kind: ProfileKind.local,
displayName: 'Default',
sortOrder: 0,
createdAt: DateTime.now(),
);
await profileRegistry.upsert(owner);
await storage.setActiveProfileId(owner.id);
appLogger.i('Migration: created placeholder Default profile (no Plex account on first launch)');
}
Future<PlexAccountConnection?> _firstPlexAccount(PlexAccountConnection? preferred) async {
if (preferred != null) return preferred;
final connections = await connectionRegistry.list();
@@ -47,6 +47,14 @@ void main() {
});
group('ConnectionBootstrap.migrateLegacyPlexAccount', () {
test('run leaves fresh installs without a placeholder local profile', () async {
await bootstrap.run();
expect(await profileRegistry.list(), isEmpty);
expect(storage.getActiveProfileId(), isNull);
expect(storage.prefs.getBool('profile_migration_v1_done'), isTrue);
});
test('returns null when no legacy Plex token is stored', () async {
final result = await bootstrap.migrateLegacyPlexAccount();
expect(result, isNull);