prepare for multiple apps

This commit is contained in:
Fabian Freund
2026-04-06 12:23:11 +02:00
parent bd1600e8dc
commit 5afc323f04
904 changed files with 29 additions and 29 deletions
@@ -0,0 +1,43 @@
/*
* 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:riverpod/experimental/persist.dart';
import 'package:riverpod_annotation/experimental/persist.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:weblibre/features/user/data/providers.dart';
part 'backup_directory.g.dart';
@Riverpod(keepAlive: true)
class BackupDirectoryUri extends _$BackupDirectoryUri {
// ignore: use_setters_to_change_properties
void set(Uri? value) => state = value;
@override
Uri? build() {
persist(
ref.watch(riverpodDatabaseStorageProvider),
key: 'BackupDirectoryUri',
encode: (state) => state?.toString() ?? '',
decode: (encoded) => encoded.isEmpty ? null : Uri.parse(encoded),
);
return stateOrNull;
}
}
@@ -0,0 +1,63 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'backup_directory.dart';
// **************************************************************************
// RiverpodGenerator
// **************************************************************************
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint, type=warning
@ProviderFor(BackupDirectoryUri)
final backupDirectoryUriProvider = BackupDirectoryUriProvider._();
final class BackupDirectoryUriProvider
extends $NotifierProvider<BackupDirectoryUri, Uri?> {
BackupDirectoryUriProvider._()
: super(
from: null,
argument: null,
retry: null,
name: r'backupDirectoryUriProvider',
isAutoDispose: false,
dependencies: null,
$allTransitiveDependencies: null,
);
@override
String debugGetCreateSourceHash() => _$backupDirectoryUriHash();
@$internal
@override
BackupDirectoryUri create() => BackupDirectoryUri();
/// {@macro riverpod.override_with_value}
Override overrideWithValue(Uri? value) {
return $ProviderOverride(
origin: this,
providerOverride: $SyncValueProvider<Uri?>(value),
);
}
}
String _$backupDirectoryUriHash() =>
r'4e5f4e7bde90b2a92c559afe8774ed5ee503277d';
abstract class _$BackupDirectoryUri extends $Notifier<Uri?> {
Uri? build();
@$mustCallSuper
@override
void runBuild() {
final ref = this.ref as $Ref<Uri?, Uri?>;
final element =
ref.element
as $ClassProviderElement<
AnyNotifier<Uri?, Uri?>,
Uri?,
Object?,
Object?
>;
element.handleCreate(ref, build);
}
}
@@ -0,0 +1,114 @@
/*
* 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/foundation.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:weblibre/features/user/domain/providers.dart';
import 'package:weblibre/features/user/domain/services/local_authentication.dart';
part 'profile_auth.g.dart';
String profileAccessAuthKey(String profileId) => 'profile_access::$profileId';
@Riverpod(keepAlive: true)
class ProfileAuthState extends _$ProfileAuthState {
bool _bootstrapped = false;
Future<void> bootstrapFromProfile() async {
if (_bootstrapped) return;
final profile = await ref.read(selectedProfileProvider.future);
if (!ref.mounted) return;
_bootstrapped = true;
if (!profile.authSettings.authenticationRequired) {
_unlock();
}
}
Future<bool> authenticate() async {
final profile = await ref.read(selectedProfileProvider.future);
if (!ref.mounted) return false;
if (!profile.authSettings.authenticationRequired) {
_unlock();
return true;
}
final result = await ref
.read(localAuthenticationServiceProvider.notifier)
.authenticate(
authKey: profileAccessAuthKey(profile.id),
localizedReason: 'Unlock profile',
settings: profile.authSettings,
useAuthCache: true,
);
if (!ref.mounted) return false;
state = result;
return result;
}
Future<void> revalidateAfterResume() async {
if (!state) return;
final profile = await ref.read(selectedProfileProvider.future);
if (!ref.mounted || !profile.authSettings.authenticationRequired) return;
final cached = ref
.read(localAuthenticationServiceProvider.notifier)
.isCached(profileAccessAuthKey(profile.id));
if (!cached && ref.mounted) {
_lock();
}
}
void _lock() {
state = false;
}
void _unlock() {
state = true;
}
@override
bool build() {
return false;
}
}
@Riverpod(keepAlive: true)
Raw<ProfileAuthNotifier> profileAuthNotifier(Ref ref) {
final notifier = ProfileAuthNotifier();
ref.listen<bool>(profileAuthStateProvider, (_, _) {
notifier.notify();
});
ref.onDispose(notifier.dispose);
return notifier;
}
class ProfileAuthNotifier extends ChangeNotifier {
void notify() => notifyListeners();
}
@@ -0,0 +1,110 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'profile_auth.dart';
// **************************************************************************
// RiverpodGenerator
// **************************************************************************
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint, type=warning
@ProviderFor(ProfileAuthState)
final profileAuthStateProvider = ProfileAuthStateProvider._();
final class ProfileAuthStateProvider
extends $NotifierProvider<ProfileAuthState, bool> {
ProfileAuthStateProvider._()
: super(
from: null,
argument: null,
retry: null,
name: r'profileAuthStateProvider',
isAutoDispose: false,
dependencies: null,
$allTransitiveDependencies: null,
);
@override
String debugGetCreateSourceHash() => _$profileAuthStateHash();
@$internal
@override
ProfileAuthState create() => ProfileAuthState();
/// {@macro riverpod.override_with_value}
Override overrideWithValue(bool value) {
return $ProviderOverride(
origin: this,
providerOverride: $SyncValueProvider<bool>(value),
);
}
}
String _$profileAuthStateHash() => r'9eb65fdb76baa0b088fc12a8063ea4ee63d54ac4';
abstract class _$ProfileAuthState extends $Notifier<bool> {
bool build();
@$mustCallSuper
@override
void runBuild() {
final ref = this.ref as $Ref<bool, bool>;
final element =
ref.element
as $ClassProviderElement<
AnyNotifier<bool, bool>,
bool,
Object?,
Object?
>;
element.handleCreate(ref, build);
}
}
@ProviderFor(profileAuthNotifier)
final profileAuthProvider = ProfileAuthNotifierProvider._();
final class ProfileAuthNotifierProvider
extends
$FunctionalProvider<
Raw<ProfileAuthNotifier>,
Raw<ProfileAuthNotifier>,
Raw<ProfileAuthNotifier>
>
with $Provider<Raw<ProfileAuthNotifier>> {
ProfileAuthNotifierProvider._()
: super(
from: null,
argument: null,
retry: null,
name: r'profileAuthProvider',
isAutoDispose: false,
dependencies: null,
$allTransitiveDependencies: null,
);
@override
String debugGetCreateSourceHash() => _$profileAuthNotifierHash();
@$internal
@override
$ProviderElement<Raw<ProfileAuthNotifier>> $createElement(
$ProviderPointer pointer,
) => $ProviderElement(pointer);
@override
Raw<ProfileAuthNotifier> create(Ref ref) {
return profileAuthNotifier(ref);
}
/// {@macro riverpod.override_with_value}
Override overrideWithValue(Raw<ProfileAuthNotifier> value) {
return $ProviderOverride(
origin: this,
providerOverride: $SyncValueProvider<Raw<ProfileAuthNotifier>>(value),
);
}
}
String _$profileAuthNotifierHash() =>
r'795f47b1494e4a9cdd74f5ff22d431b2bc59ffbd';