feat: add a hub for the client's own pages and gate mews:do action links
This commit is contained in:
parent
df705d831f
commit
b311b9f7dd
21 changed files with 966 additions and 404 deletions
36
app/lib/application/internal_actions.dart
Normal file
36
app/lib/application/internal_actions.dart
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
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),
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue