Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Let admins set the RMAB web login URL for browser view auto-login

Barnabasaf70425a5be7
diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb
index c68ed837..b915cc9b 100644
--- a/lib/l10n/app_en.arb
+++ b/lib/l10n/app_en.arb
@@ -594,6 +594,9 @@
"rmabConfigBaseUrlHint": "https://rmab.example.com",
"rmabConfigTokenLabel": "API token",
"rmabConfigTokenHint": "rmab_...",
+ "rmabConfigLegacyUrlLabel": "Web UI login URL (optional)",
+ "rmabConfigLegacyUrlHint": "https://rmab.example.com/?token=...",
+ "rmabConfigLegacyUrlHelp": "Paste your auto-login URL so 'Open in browser view' lands you signed in. Leave blank to use a regular login.",
"rmabConfigConnect": "Connect",
"rmabConfigDisconnect": "Disconnect",
"rmabConfigOpenWebView": "Open in browser view",
diff --git a/lib/l10n/app_localizations.dart b/lib/l10n/app_localizations.dart
index da9e6691..6a406a41 100644
--- a/lib/l10n/app_localizations.dart
+++ b/lib/l10n/app_localizations.dart
@@ -3214,6 +3214,24 @@ abstract class AppLocalizations {
/// **'rmab_...'**
String get rmabConfigTokenHint;
+ /// No description provided for @rmabConfigLegacyUrlLabel.
+ ///
+ /// In en, this message translates to:
+ /// **'Web UI login URL (optional)'**
+ String get rmabConfigLegacyUrlLabel;
+
+ /// No description provided for @rmabConfigLegacyUrlHint.
+ ///
+ /// In en, this message translates to:
+ /// **'https://rmab.example.com/?token=...'**
+ String get rmabConfigLegacyUrlHint;
+
+ /// No description provided for @rmabConfigLegacyUrlHelp.
+ ///
+ /// In en, this message translates to:
+ /// **'Paste your auto-login URL so \'Open in browser view\' lands you signed in. Leave blank to use a regular login.'**
+ String get rmabConfigLegacyUrlHelp;
+
/// No description provided for @rmabConfigConnect.
///
/// In en, this message translates to:
diff --git a/lib/l10n/app_localizations_de.dart b/lib/l10n/app_localizations_de.dart
index fd8e7801..1b3a3845 100644
--- a/lib/l10n/app_localizations_de.dart
+++ b/lib/l10n/app_localizations_de.dart
@@ -1758,6 +1758,16 @@ class AppLocalizationsDe extends AppLocalizations {
@override
String get rmabConfigTokenHint => 'rmab_...';
+ @override
+ String get rmabConfigLegacyUrlLabel => 'Web UI login URL (optional)';
+
+ @override
+ String get rmabConfigLegacyUrlHint => 'https://rmab.example.com/?token=...';
+
+ @override
+ String get rmabConfigLegacyUrlHelp =>
+ 'Paste your auto-login URL so \'Open in browser view\' lands you signed in. Leave blank to use a regular login.';
+
@override
String get rmabConfigConnect => 'Connect';
diff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dart
index b0626fae..757f60b4 100644
--- a/lib/l10n/app_localizations_en.dart
+++ b/lib/l10n/app_localizations_en.dart
@@ -1739,6 +1739,16 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get rmabConfigTokenHint => 'rmab_...';
+ @override
+ String get rmabConfigLegacyUrlLabel => 'Web UI login URL (optional)';
+
+ @override
+ String get rmabConfigLegacyUrlHint => 'https://rmab.example.com/?token=...';
+
+ @override
+ String get rmabConfigLegacyUrlHelp =>
+ 'Paste your auto-login URL so \'Open in browser view\' lands you signed in. Leave blank to use a regular login.';
+
@override
String get rmabConfigConnect => 'Connect';
diff --git a/lib/l10n/app_localizations_zh.dart b/lib/l10n/app_localizations_zh.dart
index 64336a91..0093f645 100644
--- a/lib/l10n/app_localizations_zh.dart
+++ b/lib/l10n/app_localizations_zh.dart
@@ -1676,6 +1676,16 @@ class AppLocalizationsZh extends AppLocalizations {
@override
String get rmabConfigTokenHint => 'rmab_...';
+ @override
+ String get rmabConfigLegacyUrlLabel => 'Web UI login URL (optional)';
+
+ @override
+ String get rmabConfigLegacyUrlHint => 'https://rmab.example.com/?token=...';
+
+ @override
+ String get rmabConfigLegacyUrlHelp =>
+ 'Paste your auto-login URL so \'Open in browser view\' lands you signed in. Leave blank to use a regular login.';
+
@override
String get rmabConfigConnect => 'Connect';
diff --git a/lib/widgets/rmab_config_sheet.dart b/lib/widgets/rmab_config_sheet.dart
index da5e89af..3983b740 100644
--- a/lib/widgets/rmab_config_sheet.dart
+++ b/lib/widgets/rmab_config_sheet.dart
@@ -70,8 +70,10 @@ class _RmabConfigSheet extends StatefulWidget {
class _RmabConfigSheetState extends State<_RmabConfigSheet> {
final _urlController = TextEditingController();
final _tokenController = TextEditingController();
+ final _legacyUrlController = TextEditingController();
final _urlFocus = FocusNode();
final _tokenFocus = FocusNode();
+ final _legacyUrlFocus = FocusNode();
bool _loadingPrefs = true;
bool _connecting = false;
@@ -111,6 +113,7 @@ class _RmabConfigSheetState extends State<_RmabConfigSheet> {
setState(() {
_urlController.text = prefilledBase;
_tokenController.text = token ?? '';
+ _legacyUrlController.text = legacy ?? '';
_legacyUrl = legacy;
_wasConfigured =
(base ?? '').isNotEmpty && (token ?? '').isNotEmpty;
@@ -122,8 +125,10 @@ class _RmabConfigSheetState extends State<_RmabConfigSheet> {
void dispose() {
_urlController.dispose();
_tokenController.dispose();
+ _legacyUrlController.dispose();
_urlFocus.dispose();
_tokenFocus.dispose();
+ _legacyUrlFocus.dispose();
super.dispose();
}
@@ -172,22 +177,43 @@ class _RmabConfigSheetState extends State<_RmabConfigSheet> {
await ScopedPrefs.setString(kRmabBaseUrlKey, cleanBase);
await ScopedPrefs.setString(kRmabApiTokenKey, token);
- // If no legacy URL exists, plant the bare base URL so "Open in browser
- // view" has something to load (the user will see RMAB's login page).
- // Don't overwrite an existing legacy URL — power users may rely on the
- // embedded `?token=` for one-tap SSO into the web UI.
- final existingLegacy = await ScopedPrefs.getString(kRmabLegacyUrlKey);
- if (existingLegacy == null || existingLegacy.isEmpty) {
- await ScopedPrefs.setString(kRmabLegacyUrlKey, cleanBase);
+ // Legacy URL handling depends on context:
+ // Admin: respect whatever they typed in the legacy URL field.
+ // Non-empty → save it. Empty → clear it. Gives admins explicit
+ // control over the auto-login URL used by "Open in browser view".
+ // Non-admin: legacy URL field isn't exposed. Keep any existing
+ // legacy URL (don't clobber a power-user setup); plant the base
+ // URL if none exists, so the WebView fallback has something to
+ // open (user will just see RMAB's login page).
+ if (widget.isAdminContext) {
+ final entered = _legacyUrlController.text.trim();
+ if (entered.isNotEmpty) {
+ await ScopedPrefs.setString(kRmabLegacyUrlKey, entered);
+ } else {
+ await ScopedPrefs.remove(kRmabLegacyUrlKey);
+ }
+ } else {
+ final existingLegacy =
+ await ScopedPrefs.getString(kRmabLegacyUrlKey);
+ if (existingLegacy == null || existingLegacy.isEmpty) {
+ await ScopedPrefs.setString(kRmabLegacyUrlKey, cleanBase);
+ }
}
if (!mounted) return;
debugPrint('[RMAB] connect ok (username=${me.username} role=${me.role})');
+ // Refresh the in-memory legacy URL so the "Open in browser view"
+ // button below uses the freshly-saved value without requiring a
+ // sheet reopen.
+ final refreshedLegacy =
+ await ScopedPrefs.getString(kRmabLegacyUrlKey);
+ if (!mounted) return;
setState(() {
_connecting = false;
_connectedAsName = me.username;
_wasConfigured = true;
_credsVersion++;
+ _legacyUrl = refreshedLegacy;
});
} on RmabException catch (e) {
if (!mounted) return;
@@ -479,8 +505,37 @@ class _SetupForm extends StatelessWidget {
onPressed: state._connecting ? null : state._toggleObscureToken,
),
),
- onSubmitted: (_) => state._connect(),
+ onSubmitted: (_) {
+ if (state.widget.isAdminContext) {
+ state._legacyUrlFocus.requestFocus();
+ } else {
+ state._connect();
+ }
+ },
),
+ // Admin-only: web UI login URL with embedded login token, so
+ // "Open in browser view" opens already signed in.
+ if (state.widget.isAdminContext) ...[
+ const SizedBox(height: 12),
+ TextField(
+ controller: state._legacyUrlController,
+ focusNode: state._legacyUrlFocus,
+ enabled: !state._connecting,
+ autocorrect: false,
+ keyboardType: TextInputType.url,
+ decoration: InputDecoration(
+ labelText: l.rmabConfigLegacyUrlLabel,
+ hintText: l.rmabConfigLegacyUrlHint,
+ border: const OutlineInputBorder(),
+ ),
+ onSubmitted: (_) => state._connect(),
+ ),
+ const SizedBox(height: 6),
+ Text(
+ l.rmabConfigLegacyUrlHelp,
+ style: tt.bodySmall?.copyWith(color: cs.onSurfaceVariant),
+ ),
+ ],
if (state._errorText != null) ...[
const SizedBox(height: 12),
Row(children: [