Skip to main content
The SettingsService manages application-wide settings including download paths, portal sessions, and user preferences. It uses persistent storage to maintain settings across app restarts.

Initialization

init

Initializes the settings service with persistent storage.
static Future<SettingsService> init(String databaseDirectory)
databaseDirectory
String
required
The directory path where settings database files will be stored.
return
Future<SettingsService>
A fully initialized settings service instance with loaded settings.
Example:
final settingsService = await SettingsService.init('/path/to/database');

Properties

downloadPathTemplate
PathTemplate
The template used to generate download paths for books. Supports variables like author name, title, series, etc.
authorsPathSeparator
String
The separator string used when multiple authors are included in file paths (e.g., ”, ” or ” & ”).
saveDirectory
String?
The base directory where books are saved. Can be null if not yet configured.
sessions
List<PortalSession>
A list of all portal sessions, one for each registered portal. Each session maintains portal-specific settings and authentication state.
storage
SettingsStorage
The underlying storage implementation used for persisting settings.

Methods

loadSettings

Loads all settings from persistent storage.
Future<void> loadSettings()
This method:
  1. Loads download path template
  2. Loads authors path separator
  3. Loads save directory
  4. Creates portal sessions for all registered portals with their saved settings
Example:
await settingsService.loadSettings();
print('Loaded ${settingsService.sessions.length} portal sessions');

sessionByCode

Retrieves a portal session by its portal code.
PortalSession sessionByCode(String code)
code
String
required
The unique code identifier of the portal.
return
PortalSession
The portal session for the specified portal.
Throws: StateError if no session exists for the given code. Example:
final flibustaSession = settingsService.sessionByCode('flibust');
if (flibustaSession.isAuthenticated) {
  print('User is logged in to Flibusta');
}

updateDownloadPathTemplate

Updates the download path template and persists it to storage.
void updateDownloadPathTemplate(PathTemplate template)
template
PathTemplate
required
The new path template to use for generating download paths.
Example:
final template = PathTemplate.parse('{author}/{series}/{title}');
settingsService.updateDownloadPathTemplate(template);

updateAuthorsPathSeparator

Updates the authors path separator and persists it to storage.
void updateAuthorsPathSeparator(String separator)
separator
String
required
The separator to use between multiple author names in file paths.
Example:
settingsService.updateAuthorsPathSeparator(' & ');
// Results in paths like: "Author1 & Author2/Book Title.epub"

updateSaveDirectory

Updates the base save directory and persists it to storage.
void updateSaveDirectory(String? path)
path
String?
required
The new base directory path, or null to unset.
Example:
settingsService.updateSaveDirectory('/home/user/Books');

Usage

Complete initialization example:
import 'package:re_ucm_lib/settings/settings_service.dart';
import 'package:re_ucm_lib/portals/portal_factory.dart';

Future<void> initializeApp() async {
  // Register portals first
  PortalFactory.registerAll([
    FlibustPortal(),
    LitresPortal(),
  ]);
  
  // Initialize settings
  final settings = await SettingsService.init('/path/to/database');
  
  // Configure download settings
  settings.updateSaveDirectory('/home/user/Books');
  settings.updateDownloadPathTemplate(
    PathTemplate.parse('{author}/{title}')
  );
  settings.updateAuthorsPathSeparator(', ');
  
  // Access portal sessions
  for (final session in settings.sessions) {
    print('Portal: ${session.portal.code}');
  }
}
Working with portal sessions:
// Get a specific portal session
final session = settingsService.sessionByCode('flibust');

// Update portal-specific settings
await session.updateSettings(newSettings);

// Check authentication status
if (!session.isAuthenticated) {
  await session.login(username, password);
}

Build docs developers (and LLMs) love