37 lines
1.3 KiB
Dart
37 lines
1.3 KiB
Dart
|
|
import 'controllers/reader_settings_controller.dart'
|
||
|
|
show ReaderSettingsController;
|
||
|
|
import 'pages/mews_urls.dart';
|
||
|
|
|
||
|
|
/// Applies the change an action address encodes, e.g. mews:do/set-theme.
|
||
|
|
/// Returns whether anything changed, so the navigator can skip a rerender that
|
||
|
|
/// would show the same page.
|
||
|
|
///
|
||
|
|
/// An unknown verb or a missing argument does nothing and reports nothing: the
|
||
|
|
/// only links carrying these addresses are the ones the client builds, so a
|
||
|
|
/// miss is a bug rather than something to explain to the reader.
|
||
|
|
class InternalActions {
|
||
|
|
InternalActions({required ReaderSettingsController settings})
|
||
|
|
: _settings = settings;
|
||
|
|
|
||
|
|
final ReaderSettingsController _settings;
|
||
|
|
|
||
|
|
Future<bool> apply(String url) async {
|
||
|
|
final verb = MewsUrls.verbOf(url);
|
||
|
|
if (verb == null) return false;
|
||
|
|
final args = Uri.parse(url).queryParameters;
|
||
|
|
return switch (verb) {
|
||
|
|
'set-font' => _settings.setFont(args['value'] ?? ''),
|
||
|
|
'set-size' => _setSize(args['step']),
|
||
|
|
'set-theme' => _settings.setThemeMode(args['value'] ?? ''),
|
||
|
|
'set-colors' => _settings.setVariant(args['value'] ?? ''),
|
||
|
|
_ => false,
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
Future<bool> _setSize(String? step) => switch (step) {
|
||
|
|
'up' => _settings.increaseSize(),
|
||
|
|
'down' => _settings.decreaseSize(),
|
||
|
|
_ => Future.value(false),
|
||
|
|
};
|
||
|
|
}
|