prepare for multiple apps
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:weblibre/core/filesystem.dart';
|
||||
import 'package:weblibre/domain/entities/profile.dart';
|
||||
import 'package:weblibre/features/user/domain/presentation/dialogs/switch_profile_dialog.dart';
|
||||
import 'package:weblibre/features/user/domain/repositories/profile.dart';
|
||||
import 'package:weblibre/utils/exit_app.dart';
|
||||
import 'package:weblibre/utils/ui_helper.dart' as ui_helper;
|
||||
|
||||
/// Handles the profile switching flow with confirmation dialog.
|
||||
///
|
||||
/// This function:
|
||||
/// - Checks if the profile is already active
|
||||
/// - Shows a confirmation dialog with browser restart warning
|
||||
/// - Switches to the selected profile and exits the app
|
||||
Future<void> handleSwitchProfile(
|
||||
BuildContext context,
|
||||
WidgetRef ref,
|
||||
Profile profile,
|
||||
) async {
|
||||
final isSelected = filesystem.selectedProfile == profile.uuidValue;
|
||||
|
||||
// Don't allow switching to the already active profile
|
||||
if (isSelected) {
|
||||
if (context.mounted) {
|
||||
ui_helper.showInfoMessage(context, 'This profile is already active');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!context.mounted) return;
|
||||
|
||||
final shouldSwitch = await showSwitchProfileDialog(
|
||||
context,
|
||||
profileName: profile.name,
|
||||
);
|
||||
|
||||
if (shouldSwitch == true) {
|
||||
await ref
|
||||
.read(profileRepositoryProvider.notifier)
|
||||
.switchProfile(profile.id);
|
||||
await exitApp(ref.container);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user