Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

iOS compatibility - hide unsupported features, fix keyboard, add notifications

Nathan Poulsonf27340f958dd
diff --git a/ios/Runner/AppDelegate.swift b/ios/Runner/AppDelegate.swift
index c5bb46fd..9e350acf 100644
--- a/ios/Runner/AppDelegate.swift
+++ b/ios/Runner/AppDelegate.swift
@@ -33,6 +33,23 @@ import AVFoundation
result(FlutterMethodNotImplemented)
}
}
+
+ let storageChannel = FlutterMethodChannel(name: "com.absorb.storage",
+ binaryMessenger: controller.binaryMessenger)
+ storageChannel.setMethodCallHandler { (call, result) in
+ switch call.method {
+ case "getDeviceStorage":
+ if let attrs = try? FileManager.default.attributesOfFileSystem(forPath: NSHomeDirectory()),
+ let total = (attrs[.systemSize] as? NSNumber)?.int64Value,
+ let free = (attrs[.systemFreeSize] as? NSNumber)?.int64Value {
+ result(["totalBytes": total, "availableBytes": free])
+ } else {
+ result(nil)
+ }
+ default:
+ result(FlutterMethodNotImplemented)
+ }
+ }
}
private func getAudioOutputDevices() -> [[String: Any]] {
diff --git a/lib/main.dart b/lib/main.dart
index 6f06ed6a..c2ef0162 100644
--- a/lib/main.dart
+++ b/lib/main.dart
@@ -454,11 +454,13 @@ class _AuthGateState extends State<AuthGate> {
debugPrint('[Init] Permission request failed: $e');
}
- // Initialize Chromecast
- try {
- await ChromecastService().init();
- } catch (e) {
- debugPrint('[Init] Chromecast init failed: $e');
+ // Initialize Chromecast (Android only)
+ if (Platform.isAndroid) {
+ try {
+ await ChromecastService().init();
+ } catch (e) {
+ debugPrint('[Init] Chromecast init failed: $e');
+ }
}
// Initialize download tracker and progress sync
@@ -467,10 +469,12 @@ class _AuthGateState extends State<AuthGate> {
await ProgressSyncService().init();
await EqualizerService().init();
await SleepTimerService().loadAutoSleepSettings();
- // Pre-populate Android Auto browse tree in background.
- Future.microtask(() => AndroidAutoService().refresh());
- // Initialize homescreen widget
- await HomeWidgetService().init();
+ if (Platform.isAndroid) {
+ // Pre-populate Android Auto browse tree in background.
+ Future.microtask(() => AndroidAutoService().refresh());
+ // Initialize homescreen widget
+ await HomeWidgetService().init();
+ }
} catch (e) {
debugPrint('[Init] Service init failed: $e');
}
diff --git a/lib/screens/login_screen.dart b/lib/screens/login_screen.dart
index f97c5df1..2bd8ab48 100644
--- a/lib/screens/login_screen.dart
+++ b/lib/screens/login_screen.dart
@@ -244,9 +244,12 @@ class _LoginScreenState extends State<LoginScreen>
setState(() {
_loginError = auth.errorMessage ?? 'Login failed';
});
- } else if (Navigator.of(context).canPop()) {
- // If pushed as a route (e.g. Add Account), pop back
- Navigator.of(context).pop();
+ } else {
+ FocusManager.instance.primaryFocus?.unfocus();
+ if (Navigator.of(context).canPop()) {
+ // If pushed as a route (e.g. Add Account), pop back
+ Navigator.of(context).pop();
+ }
}
}
}
@@ -275,6 +278,7 @@ class _LoginScreenState extends State<LoginScreen>
final result = await oidc.handleCallback(callbackUri);
if (result != null && mounted) {
+ FocusManager.instance.primaryFocus?.unfocus();
final auth = context.read<AuthProvider>();
final success = await auth.loginWithOidc(
serverUrl: fullUrl,
@@ -887,12 +891,15 @@ class _LoginScreenState extends State<LoginScreen>
void Function(String)? onFieldSubmitted,
String? Function(String?)? validator,
}) {
+ final isUrl = keyboardType == TextInputType.url;
return TextFormField(
controller: controller,
focusNode: focusNode,
keyboardType: keyboardType,
textInputAction: textInputAction,
obscureText: obscureText,
+ autocorrect: !isUrl,
+ enableSuggestions: !isUrl,
onFieldSubmitted: onFieldSubmitted,
validator: validator,
style: TextStyle(color: cs.onSurface),
diff --git a/lib/screens/settings_screen.dart b/lib/screens/settings_screen.dart
index 1e908ac9..3cba8903 100644
--- a/lib/screens/settings_screen.dart
+++ b/lib/screens/settings_screen.dart
@@ -1613,6 +1613,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
}
},
),
+ if (Platform.isAndroid) ...[
const Divider(height: 1, indent: 16, endIndent: 16),
ListTile(
leading: const Icon(Icons.battery_saver_outlined),
@@ -1621,24 +1622,23 @@ class _SettingsScreenState extends State<SettingsScreen> {
style: tt.bodySmall?.copyWith(color: cs.onSurfaceVariant)),
trailing: Icon(Icons.chevron_right_rounded, color: cs.onSurfaceVariant),
onTap: () async {
- if (Platform.isAndroid) {
- final status = await Permission.ignoreBatteryOptimizations.status;
- if (status.isGranted) {
- if (mounted) {
- ScaffoldMessenger.of(context).showSnackBar(SnackBar(
- duration: const Duration(seconds: 2),
- content: const Text('Battery already unrestricted'),
- behavior: SnackBarBehavior.floating,
- shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
- ));
- }
- } else {
- final result = await Permission.ignoreBatteryOptimizations.request();
- if (result.isPermanentlyDenied && mounted) await openAppSettings();
+ final status = await Permission.ignoreBatteryOptimizations.status;
+ if (status.isGranted) {
+ if (mounted) {
+ ScaffoldMessenger.of(context).showSnackBar(SnackBar(
+ duration: const Duration(seconds: 2),
+ content: const Text('Battery already unrestricted'),
+ behavior: SnackBarBehavior.floating,
+ shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
+ ));
}
+ } else {
+ final result = await Permission.ignoreBatteryOptimizations.request();
+ if (result.isPermanentlyDenied && mounted) await openAppSettings();
}
},
),
+ ],
],
),
const SizedBox(height: 16),
diff --git a/lib/services/audio_player_service.dart b/lib/services/audio_player_service.dart
index 82e2f138..2ab1417c 100644
--- a/lib/services/audio_player_service.dart
+++ b/lib/services/audio_player_service.dart
@@ -314,7 +314,10 @@ class PlayerSettings {
static Future<List<String>> getCardButtonOrder() async {
final stored = await ScopedPrefs.getStringList('card_button_order');
- if (stored.isEmpty) return List.from(defaultButtonOrder);
+ if (stored.isEmpty) {
+ final knownIds = allCardButtons.map((b) => b.id).toSet();
+ return defaultButtonOrder.where((id) => knownIds.contains(id)).toList();
+ }
// Append any new buttons that were added since the user last saved their order
final knownIds = allCardButtons.map((b) => b.id).toSet();
final result = stored.where((id) => knownIds.contains(id)).toList();
diff --git a/lib/services/download_notification_service.dart b/lib/services/download_notification_service.dart
index 9b3fca01..ba825a48 100644
--- a/lib/services/download_notification_service.dart
+++ b/lib/services/download_notification_service.dart
@@ -40,9 +40,9 @@ class DownloadNotificationService {
const androidSettings = AndroidInitializationSettings('drawable/ic_notification');
const iosSettings = DarwinInitializationSettings(
- requestAlertPermission: false,
+ requestAlertPermission: true,
requestBadgePermission: false,
- requestSoundPermission: false,
+ requestSoundPermission: true,
);
const settings = InitializationSettings(android: androidSettings, iOS: iosSettings);
await _plugin.initialize(settings);
@@ -313,7 +313,10 @@ class DownloadNotificationService {
_progressNotifId(slot),
'Downloading: $title',
subtitle,
- NotificationDetails(android: androidDetails),
+ NotificationDetails(
+ android: androidDetails,
+ iOS: const DarwinNotificationDetails(),
+ ),
);
}
@@ -342,7 +345,10 @@ class DownloadNotificationService {
alertId,
title,
body,
- const NotificationDetails(android: androidDetails),
+ const NotificationDetails(
+ android: androidDetails,
+ iOS: DarwinNotificationDetails(),
+ ),
);
}
}
diff --git a/lib/widgets/card_button_config.dart b/lib/widgets/card_button_config.dart
index 19422d75..897a1fa6 100644
--- a/lib/widgets/card_button_config.dart
+++ b/lib/widgets/card_button_config.dart
@@ -1,3 +1,4 @@
+import 'dart:io';
import 'package:flutter/material.dart';
class CardButtonDef {
@@ -7,7 +8,10 @@ class CardButtonDef {
const CardButtonDef(this.id, this.label, this.icon);
}
-const allCardButtons = [
+/// Button IDs that are hidden on iOS (features not yet supported).
+final Set<String> _iosHiddenButtons = Platform.isIOS ? const {'cast', 'equalizer'} : const {};
+
+const _allCardButtons = [
CardButtonDef('chapters', 'Chapters', Icons.list_rounded),
CardButtonDef('speed', 'Speed', Icons.speed_rounded),
CardButtonDef('sleep', 'Sleep Timer', Icons.bedtime_outlined),
@@ -21,6 +25,10 @@ const allCardButtons = [
CardButtonDef('notes', 'Notes', Icons.note_rounded),
];
+/// Card buttons filtered for the current platform.
+final List<CardButtonDef> allCardButtons =
+ _allCardButtons.where((b) => !_iosHiddenButtons.contains(b.id)).toList();
+
/// Look up a button definition by ID.
CardButtonDef? buttonDefById(String id) {
for (final b in allCardButtons) {
diff --git a/lib/widgets/card_buttons.dart b/lib/widgets/card_buttons.dart
index 137fb036..92ac81e8 100644
--- a/lib/widgets/card_buttons.dart
+++ b/lib/widgets/card_buttons.dart
@@ -1,3 +1,4 @@
+import 'dart:io';
import 'package:flutter/material.dart';
import '../services/audio_player_service.dart';
import '../services/bookmark_service.dart';
@@ -711,6 +712,7 @@ class _MoreMenuSheetState extends State<MoreMenuSheet> {
alignment: Alignment.center,
children: [
Container(width: 40, height: 4, decoration: BoxDecoration(color: cs.onSurface.withValues(alpha: 0.24), borderRadius: BorderRadius.circular(2))),
+ if (!Platform.isIOS)
Align(
alignment: Alignment.centerLeft,
child: GestureDetector(