From dcf6745a00a4db362cb54d7de9fd42169d295439 Mon Sep 17 00:00:00 2001 From: retransmit Date: Fri, 27 Nov 2026 18:32:31 +0530 Subject: [PATCH 1/8] feat(shortcuts): choose which services get launcher shortcuts --- .../launcher_shortcuts.dart | 86 +++++++++++ app/test/launcher_shortcuts_test.dart | 144 ++++++++++++++++++ 2 files changed, 230 insertions(+) create mode 100644 app/lib/src/launcher_shortcuts/launcher_shortcuts.dart create mode 100644 app/test/launcher_shortcuts_test.dart diff --git a/app/lib/src/launcher_shortcuts/launcher_shortcuts.dart b/app/lib/src/launcher_shortcuts/launcher_shortcuts.dart new file mode 100644 index 00000000..34b2a9a2 --- /dev/null +++ b/app/lib/src/launcher_shortcuts/launcher_shortcuts.dart @@ -0,0 +1,86 @@ +import 'dart:convert'; + +import 'package:core_models/core_models.dart'; +import 'package:core_profile/core_profile.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; + +import '../preferences.dart'; + +/// How many services get a launcher shortcut. Most launchers show about four +/// on a long-press, so a longer list would mostly go unseen. +const int maxLauncherShortcuts = 4; + +/// The `atrium://` link a shortcut opens: the instance's service screen, +/// picked by name, through the same path as any other Atrium link. +String shortcutLink(Instance instance) => Uri( + scheme: 'atrium', + host: instance.kind.name.toLowerCase(), + queryParameters: {'instance': instance.name}, + ).toString(); + +/// The instances that get a shortcut, in sidebar order. +/// +/// [chosenIds] is null until the user edits the list, and then the first +/// [maxLauncherShortcuts] services stand in, so shortcuts work with no setup. +/// Once chosen, an empty list means none, and IDs of deleted instances drop +/// out. +List shortcutInstances( + List instances, + List? chosenIds, +) { + final Iterable picked = chosenIds == null + ? instances + : instances.where((Instance i) => chosenIds.contains(i.id)); + return picked.take(maxLauncherShortcuts).toList(growable: false); +} + +/// The services a profile's user ticked for launcher shortcuts, or null when +/// they never edited the list. Kept per profile in the settings box. +class LauncherShortcutChoiceController extends Notifier?> { + LauncherShortcutChoiceController(this.profileId); + + final String profileId; + + String get _key => 'launcherShortcuts.$profileId'; + + @override + List? build() { + final String? raw = ref.read(settingsBoxProvider).get(_key); + if (raw == null) { + return null; + } + try { + final Object? decoded = jsonDecode(raw); + if (decoded is List) { + return decoded.whereType().toList(growable: false); + } + } on FormatException { + // Falls through to the default below. + } + return null; + } + + Future setChosen(List ids) async { + final List next = List.unmodifiable(ids); + await ref.read(settingsBoxProvider).put(_key, jsonEncode(next)); + state = next; + } +} + +final launcherShortcutChoiceProvider = NotifierProvider.family< + LauncherShortcutChoiceController, List?, String>( + LauncherShortcutChoiceController.new, +); + +/// The active profile's services that get a launcher shortcut. +final Provider> launcherShortcutInstancesProvider = + Provider>((Ref ref) { + final Profile? profile = ref.watch(activeProfileProvider); + if (profile == null) { + return const []; + } + return shortcutInstances( + profile.instances, + ref.watch(launcherShortcutChoiceProvider(profile.id)), + ); +}); diff --git a/app/test/launcher_shortcuts_test.dart b/app/test/launcher_shortcuts_test.dart new file mode 100644 index 00000000..e2851738 --- /dev/null +++ b/app/test/launcher_shortcuts_test.dart @@ -0,0 +1,144 @@ +import 'dart:io'; + +import 'package:atrium/src/launcher_shortcuts/launcher_shortcuts.dart'; +import 'package:atrium/src/preferences.dart'; +import 'package:atrium/src/share_intake/atrium_link.dart'; +import 'package:core_models/core_models.dart'; +import 'package:core_profile/core_profile.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:flutter_riverpod/misc.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:hive_ce/hive.dart'; + +Instance _i(String id, {String? name, ServiceKind kind = ServiceKind.sonarr}) => + Instance( + id: id, + name: name ?? id, + kind: kind, + localUrl: 'http://localhost', + externalUrl: '', + urlMode: UrlMode.auto, + auth: const InstanceAuth.apiKey(apiKey: 'k'), + ); + +List _ids(List list) => + list.map((Instance i) => i.id).toList(); + +void main() { + final List six = [ + for (final String id in ['a', 'b', 'c', 'd', 'e', 'f']) _i(id), + ]; + + group('shortcutInstances', () { + test('defaults to the first four in sidebar order', () { + expect(_ids(shortcutInstances(six, null)), ['a', 'b', 'c', 'd']); + }); + + test('keeps a stored choice in sidebar order', () { + expect(_ids(shortcutInstances(six, ['e', 'b'])), ['b', 'e']); + }); + + test('drops chosen ids that no longer exist', () { + expect(_ids(shortcutInstances(six, ['b', 'gone'])), ['b']); + }); + + test('caps a stored choice at four', () { + expect( + shortcutInstances(six, ['a', 'b', 'c', 'd', 'e']), + hasLength(maxLauncherShortcuts), + ); + expect(maxLauncherShortcuts, 4); + }); + + test('an empty choice means none', () { + expect(shortcutInstances(six, []), isEmpty); + }); + }); + + group('shortcutLink', () { + test('links round-trip every service kind', () { + for (final ServiceKind kind in ServiceKind.values) { + final Instance instance = _i('x', name: 'My ${kind.name}', kind: kind); + final Object parsed = parseAtriumLink(shortcutLink(instance)); + expect(parsed, isA(), reason: kind.name); + final AtriumLink link = parsed as AtriumLink; + expect(link.service, kind); + expect(link.item, LinkItem.none); + expect(link.instanceName, instance.name); + } + }); + + test('links keep awkward names', () { + for (final String name in ['Sonarr 4K', 'A&B=C#1', 'Séries']) { + final AtriumLink link = + parseAtriumLink(shortcutLink(_i('x', name: name))) as AtriumLink; + expect(link.instanceName, name); + } + }); + }); + + group('stored choice', () { + late Directory tempDir; + late Box box; + + setUp(() async { + tempDir = Directory.systemTemp.createTempSync('atrium_shortcuts'); + Hive.init(tempDir.path); + box = await Hive.openBox('settings'); + }); + + tearDown(() async { + await box.close(); + await Hive.deleteBoxFromDisk('settings'); + tempDir.deleteSync(recursive: true); + }); + + ProviderContainer relaunch() { + final ProviderContainer container = ProviderContainer( + overrides: [settingsBoxProvider.overrideWithValue(box)], + ); + addTearDown(container.dispose); + return container; + } + + test('choice persists per profile', () async { + await relaunch() + .read(launcherShortcutChoiceProvider('p1').notifier) + .setChosen(['x']); + + final ProviderContainer again = relaunch(); + expect(again.read(launcherShortcutChoiceProvider('p1')), ['x']); + expect(again.read(launcherShortcutChoiceProvider('p2')), isNull); + }); + + test('garbage in the box reads as the default', () async { + await box.put('launcherShortcuts.p1', 'not json'); + expect(relaunch().read(launcherShortcutChoiceProvider('p1')), isNull); + }); + + test('the active profile picks its own instances', () async { + await box.put('launcherShortcuts.p1', '["c"]'); + final ProviderContainer container = ProviderContainer( + overrides: [ + settingsBoxProvider.overrideWithValue(box), + activeProfileProvider.overrideWithValue( + Profile(id: 'p1', name: 'Home', instances: six), + ), + ], + ); + addTearDown(container.dispose); + expect(_ids(container.read(launcherShortcutInstancesProvider)), ['c']); + }); + + test('no profile means no shortcuts', () { + final ProviderContainer container = ProviderContainer( + overrides: [ + settingsBoxProvider.overrideWithValue(box), + activeProfileProvider.overrideWithValue(null), + ], + ); + addTearDown(container.dispose); + expect(container.read(launcherShortcutInstancesProvider), isEmpty); + }); + }); +} From c3d80bf75341cb70a51119c5bd50507b59d68a78 Mon Sep 17 00:00:00 2001 From: retransmit Date: Fri, 27 Nov 2026 18:35:53 +0530 Subject: [PATCH 2/8] feat(shortcuts): keep launcher shortcuts in step with the active profile --- app/lib/app.dart | 5 + .../launcher_shortcuts_publisher.dart | 69 +++++++ .../launcher_shortcuts_publisher_test.dart | 173 ++++++++++++++++++ 3 files changed, 247 insertions(+) create mode 100644 app/lib/src/launcher_shortcuts/launcher_shortcuts_publisher.dart create mode 100644 app/test/launcher_shortcuts_publisher_test.dart diff --git a/app/lib/app.dart b/app/lib/app.dart index d634651c..4e05d077 100644 --- a/app/lib/app.dart +++ b/app/lib/app.dart @@ -10,6 +10,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; import 'src/custom_theme_providers.dart'; +import 'src/launcher_shortcuts/launcher_shortcuts_publisher.dart'; import 'src/preferences.dart'; import 'src/router.dart'; import 'src/share_intake/torrent_share_listener.dart'; @@ -57,6 +58,10 @@ class AtriumApp extends ConsumerWidget { // profile changes after this widget is built. syncGlobalHeaders(ref.read(activeProfileProvider)); + // Keeps the long-press shortcuts on Atrium's launcher icon in step with + // the active profile's services. + ref.watch(launcherShortcutsSyncProvider); + final ThemeSource themeSource = ref.watch(preferencesProvider.select((Preferences p) => p.themeSource)); final (ColorScheme customLight, ColorScheme customDark) = diff --git a/app/lib/src/launcher_shortcuts/launcher_shortcuts_publisher.dart b/app/lib/src/launcher_shortcuts/launcher_shortcuts_publisher.dart new file mode 100644 index 00000000..bc2fd4c1 --- /dev/null +++ b/app/lib/src/launcher_shortcuts/launcher_shortcuts_publisher.dart @@ -0,0 +1,69 @@ +import 'package:collection/collection.dart'; +import 'package:core_models/core_models.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; + +import 'launcher_shortcuts.dart'; + +/// Hands the launcher shortcut list to Android, which shows it on a +/// long-press of Atrium's icon and in launcher search. +class LauncherShortcutsPublisher { + LauncherShortcutsPublisher([ + this._channel = const MethodChannel('app.atrium/launcher'), + ]); + + final MethodChannel _channel; + + /// What Android was last given. Android limits how often an app may change + /// its shortcuts, so an unchanged list is not sent again. + List>? _sent; + + Future publish(List instances) async { + if (defaultTargetPlatform != TargetPlatform.android) { + return; + } + final List> shortcuts = >[ + for (final Instance i in instances) + { + 'id': i.id, + 'name': i.name, + 'link': shortcutLink(i), + 'icon': 'assets/service_icons/${i.kind.name}.png', + }, + ]; + if (const DeepCollectionEquality().equals(shortcuts, _sent)) { + return; + } + _sent = shortcuts; + try { + await _channel.invokeMethod( + 'setShortcuts', + {'shortcuts': shortcuts}, + ); + } on MissingPluginException { + _sent = null; + } on PlatformException { + // Not sent, so the next change, or the next launch, tries again. + _sent = null; + } + } +} + +final Provider launcherShortcutsPublisherProvider = + Provider( + (Ref ref) => LauncherShortcutsPublisher(), +); + +/// Publishes the active profile's shortcut list now and again whenever it +/// changes: a profile switch, a service added, renamed, reordered or deleted, +/// or a new choice in Settings. Watched once at the app root. +final Provider launcherShortcutsSyncProvider = Provider((Ref ref) { + final LauncherShortcutsPublisher publisher = + ref.watch(launcherShortcutsPublisherProvider); + ref.listen>( + launcherShortcutInstancesProvider, + (_, List next) => publisher.publish(next), + fireImmediately: true, + ); +}); diff --git a/app/test/launcher_shortcuts_publisher_test.dart b/app/test/launcher_shortcuts_publisher_test.dart new file mode 100644 index 00000000..0bd3a763 --- /dev/null +++ b/app/test/launcher_shortcuts_publisher_test.dart @@ -0,0 +1,173 @@ +import 'dart:io'; + +import 'package:atrium/src/launcher_shortcuts/launcher_shortcuts.dart'; +import 'package:atrium/src/launcher_shortcuts/launcher_shortcuts_publisher.dart'; +import 'package:atrium/src/preferences.dart'; +import 'package:core_models/core_models.dart'; +import 'package:core_profile/core_profile.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:flutter_riverpod/legacy.dart'; +import 'package:flutter_riverpod/misc.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:hive_ce/hive.dart'; + +const MethodChannel _channel = MethodChannel('app.atrium/launcher'); + +Instance _i(String id, {String? name, ServiceKind kind = ServiceKind.sonarr}) => + Instance( + id: id, + name: name ?? id, + kind: kind, + localUrl: 'http://localhost', + externalUrl: '', + urlMode: UrlMode.auto, + auth: const InstanceAuth.apiKey(apiKey: 'k'), + ); + +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + late List calls; + + void mockChannel() { + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger + .setMockMethodCallHandler(_channel, (MethodCall call) async { + calls.add(call); + return true; + }); + } + + List shortcutsOf(MethodCall call) => + (call.arguments as Map)['shortcuts']! as List; + + setUp(() { + calls = []; + mockChannel(); + }); + + tearDown(() { + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger + .setMockMethodCallHandler(_channel, null); + }); + + test('sends id, name, link and icon in order', () async { + final Instance sonarr = _i('s1', name: 'Sonarr 4K'); + final Instance adguard = + _i('a1', name: 'DNS', kind: ServiceKind.adguardHome); + await LauncherShortcutsPublisher().publish([sonarr, adguard]); + + expect(calls.single.method, 'setShortcuts'); + expect(shortcutsOf(calls.single), [ + { + 'id': 's1', + 'name': 'Sonarr 4K', + 'link': shortcutLink(sonarr), + 'icon': 'assets/service_icons/sonarr.png', + }, + { + 'id': 'a1', + 'name': 'DNS', + 'link': shortcutLink(adguard), + 'icon': 'assets/service_icons/adguardHome.png', + }, + ]); + }); + + test('does not resend an unchanged list', () async { + final LauncherShortcutsPublisher publisher = LauncherShortcutsPublisher(); + await publisher.publish([_i('a')]); + await publisher.publish([_i('a')]); + expect(calls, hasLength(1)); + }); + + test('a rename is sent again', () async { + final LauncherShortcutsPublisher publisher = LauncherShortcutsPublisher(); + await publisher.publish([_i('a', name: 'Old')]); + await publisher.publish([_i('a', name: 'New')]); + expect(calls, hasLength(2)); + }); + + test('an empty list clears', () async { + final LauncherShortcutsPublisher publisher = LauncherShortcutsPublisher(); + await publisher.publish([_i('a')]); + await publisher.publish(const []); + expect(calls, hasLength(2)); + expect(shortcutsOf(calls.last), isEmpty); + }); + + test('no handler does not throw', () async { + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger + .setMockMethodCallHandler(_channel, null); + await LauncherShortcutsPublisher().publish([_i('a')]); + }); + + test('a failed send is tried again next time', () async { + int attempts = 0; + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger + .setMockMethodCallHandler(_channel, (MethodCall call) async { + attempts++; + if (attempts == 1) { + throw PlatformException(code: 'busy'); + } + return true; + }); + final LauncherShortcutsPublisher publisher = LauncherShortcutsPublisher(); + await publisher.publish([_i('a')]); + await publisher.publish([_i('a')]); + expect(attempts, 2); + }); + + group('kept in step with the active profile', () { + late Directory tempDir; + late Box box; + + setUp(() async { + tempDir = Directory.systemTemp.createTempSync('atrium_shortcut_sync'); + Hive.init(tempDir.path); + box = await Hive.openBox('settings'); + }); + + tearDown(() async { + await box.close(); + await Hive.deleteBoxFromDisk('settings'); + tempDir.deleteSync(recursive: true); + }); + + test("switching profile publishes that profile's list", () async { + final Profile p1 = Profile( + id: 'p1', + name: 'Home', + instances: [_i('a1'), _i('a2')], + ); + final Profile p2 = Profile( + id: 'p2', + name: 'Work', + instances: [for (int n = 1; n <= 5; n++) _i('b$n')], + ); + await box.put('launcherShortcuts.p1', '["a1"]'); + final StateProvider active = StateProvider((_) => p1); + final ProviderContainer container = ProviderContainer( + overrides: [ + settingsBoxProvider.overrideWithValue(box), + activeProfileProvider.overrideWith((Ref ref) => ref.watch(active)), + ], + ); + addTearDown(container.dispose); + + container.listen(launcherShortcutsSyncProvider, (_, __) {}); + await pumpEventQueue(); + expect( + shortcutsOf(calls.last).map((Object? s) => (s! as Map)['id']), + ['a1'], + ); + + container.read(active.notifier).state = p2; + await pumpEventQueue(); + expect( + shortcutsOf(calls.last).map((Object? s) => (s! as Map)['id']), + ['b1', 'b2', 'b3', 'b4'], + ); + }); + }); +} From c60e79c3c92d411ec2ee2e429f3d717b5314a992 Mon Sep 17 00:00:00 2001 From: retransmit Date: Fri, 27 Nov 2026 18:44:19 +0530 Subject: [PATCH 3/8] feat(android): publish launcher shortcuts --- .../main/kotlin/app/atrium/MainActivity.kt | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/app/android/app/src/main/kotlin/app/atrium/MainActivity.kt b/app/android/app/src/main/kotlin/app/atrium/MainActivity.kt index 0ac6907a..f148eccc 100644 --- a/app/android/app/src/main/kotlin/app/atrium/MainActivity.kt +++ b/app/android/app/src/main/kotlin/app/atrium/MainActivity.kt @@ -1,9 +1,19 @@ package app.atrium import android.content.Intent +import android.content.pm.ShortcutInfo +import android.content.pm.ShortcutManager +import android.graphics.Bitmap +import android.graphics.BitmapFactory +import android.graphics.Canvas +import android.graphics.Color +import android.graphics.Paint +import android.graphics.Rect +import android.graphics.drawable.Icon import android.net.Uri import android.os.Build import android.provider.OpenableColumns +import io.flutter.FlutterInjector import io.flutter.embedding.android.FlutterFragmentActivity import io.flutter.embedding.engine.FlutterEngine import io.flutter.plugin.common.MethodChannel @@ -79,12 +89,77 @@ class MainActivity : FlutterFragmentActivity() { } else { result.error("INVALID_ARGUMENT", "URL is required", null) } + } else if (call.method == "setShortcuts") { + val shortcuts = call.argument>>("shortcuts") + if (shortcuts == null) { + result.error("INVALID_ARGUMENT", "shortcuts is required", null) + } else { + result.success(runCatching { setShortcuts(shortcuts) }.getOrDefault(false)) + } } else { result.notImplemented() } } } + /// Replaces Atrium's launcher shortcuts (long-press on the icon, and + /// launcher search) with [shortcuts]. Each opens an atrium:// link, so a + /// tap takes the same path as any other Atrium link. An empty list clears + /// them. False below Android 7.1, which has no launcher shortcuts. + private fun setShortcuts(shortcuts: List>): Boolean { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) return false + val manager = getSystemService(ShortcutManager::class.java) ?: return false + val infos = shortcuts.mapIndexedNotNull { index, entry -> + val id = entry["id"] ?: return@mapIndexedNotNull null + val name = entry["name"] ?: return@mapIndexedNotNull null + val link = entry["link"] ?: return@mapIndexedNotNull null + val intent = Intent(Intent.ACTION_VIEW, Uri.parse(link)) + .setClass(this, MainActivity::class.java) + ShortcutInfo.Builder(this, id) + .setShortLabel(name) + .setLongLabel("Open $name") + .setRank(index) + .setIntent(intent) + .setIcon(shortcutIcon(entry["icon"])) + .build() + } + manager.dynamicShortcuts = infos + return true + } + + /// The service's bundled icon, or Atrium's own when the service has none + /// or it cannot be read. + private fun shortcutIcon(assetPath: String?): Icon { + val bitmap = assetPath?.let { path -> + runCatching { + val key = FlutterInjector.instance().flutterLoader().getLookupKeyForAsset(path) + assets.open(key).use { BitmapFactory.decodeStream(it) } + }.getOrNull() + } ?: return Icon.createWithResource(this, R.mipmap.ic_launcher) + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { + return Icon.createWithBitmap(bitmap) + } + return Icon.createWithAdaptiveBitmap(adaptiveBitmap(bitmap)) + } + + /// Centres [logo] on a white square sized for an adaptive icon. The + /// launcher masks the outer edge into its own shape, so the logo sits + /// inside the square that fits the smallest (circular) mask. + private fun adaptiveBitmap(logo: Bitmap): Bitmap { + val size = 432 + val inner = size * 46 / 108 + val out = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888) + val canvas = Canvas(out) + canvas.drawColor(Color.WHITE) + val scale = minOf(inner.toFloat() / logo.width, inner.toFloat() / logo.height) + val w = (logo.width * scale).toInt() + val h = (logo.height * scale).toInt() + val left = (size - w) / 2 + val top = (size - h) / 2 + canvas.drawBitmap(logo, null, Rect(left, top, left + w, top + h), Paint(Paint.FILTER_BITMAP_FLAG)) + return out + } + // Reached when Atrium is already running (launchMode is singleTop), so // Dart is live and the payload can be pushed straight across. override fun onNewIntent(intent: Intent) { From c69ce7791819f9623830dc6791c45efd81100893 Mon Sep 17 00:00:00 2001 From: retransmit Date: Fri, 27 Nov 2026 18:49:01 +0530 Subject: [PATCH 4/8] feat(settings): pick which services get launcher shortcuts --- .../screens/launcher_shortcuts_screen.dart | 81 ++++++++++ app/lib/src/screens/settings_screen.dart | 10 ++ app/test/launcher_shortcuts_screen_test.dart | 140 ++++++++++++++++++ 3 files changed, 231 insertions(+) create mode 100644 app/lib/src/screens/launcher_shortcuts_screen.dart create mode 100644 app/test/launcher_shortcuts_screen_test.dart diff --git a/app/lib/src/screens/launcher_shortcuts_screen.dart b/app/lib/src/screens/launcher_shortcuts_screen.dart new file mode 100644 index 00000000..16fe4d87 --- /dev/null +++ b/app/lib/src/screens/launcher_shortcuts_screen.dart @@ -0,0 +1,81 @@ +import 'package:core_models/core_models.dart'; +import 'package:core_profile/core_profile.dart'; +import 'package:core_ui/core_ui.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; + +import '../launcher_shortcuts/launcher_shortcuts.dart'; +import '../service_icon.dart'; + +/// Picks which of the active profile's services appear when Atrium's +/// launcher icon is long-pressed. Until something is changed here, the first +/// four in sidebar order are used. +class LauncherShortcutsScreen extends ConsumerWidget { + const LauncherShortcutsScreen({super.key}); + + @override + Widget build(BuildContext context, WidgetRef ref) { + final Profile? profile = ref.watch(activeProfileProvider); + final List instances = profile?.instances ?? const []; + final Set ticked = ref + .watch(launcherShortcutInstancesProvider) + .map((Instance i) => i.id) + .toSet(); + final bool full = ticked.length >= maxLauncherShortcuts; + final ThemeData theme = Theme.of(context); + + void toggle(Instance instance, bool on) { + final Set next = {...ticked}; + if (on) { + next.add(instance.id); + } else { + next.remove(instance.id); + } + ref.read(launcherShortcutChoiceProvider(profile!.id).notifier).setChosen( + [ + for (final Instance i in instances) + if (next.contains(i.id)) i.id, + ], + ); + } + + return Scaffold( + appBar: AppBar(title: const Text('Launcher shortcuts')), + body: instances.isEmpty + ? Center( + child: Text( + 'No services configured.', + style: theme.textTheme.bodyMedium?.copyWith( + color: theme.colorScheme.onSurfaceVariant, + ), + ), + ) + : ListView( + children: [ + Padding( + padding: const EdgeInsets.symmetric( + horizontal: Insets.lg, + vertical: Insets.md, + ), + child: Text( + "Long-press Atrium's icon to open these. Up to four.", + style: theme.textTheme.bodyMedium?.copyWith( + color: theme.colorScheme.onSurfaceVariant, + ), + ), + ), + for (final Instance instance in instances) + CheckboxListTile( + secondary: ServiceIcon(kind: instance.kind, size: 32), + title: Text(instance.name), + subtitle: Text(instance.kind.displayName), + value: ticked.contains(instance.id), + onChanged: !ticked.contains(instance.id) && full + ? null + : (bool? on) => toggle(instance, on ?? false), + ), + ], + ), + ); + } +} diff --git a/app/lib/src/screens/settings_screen.dart b/app/lib/src/screens/settings_screen.dart index a46dfcaa..4e870410 100644 --- a/app/lib/src/screens/settings_screen.dart +++ b/app/lib/src/screens/settings_screen.dart @@ -18,6 +18,7 @@ import '../update_check/app_version.dart'; import '../update_check/update_check_tile.dart'; import 'changelog_screen.dart'; import 'custom_headers_screen.dart'; +import 'launcher_shortcuts_screen.dart'; import 'reorder_sidebar_screen.dart'; import 'wake_on_lan_screen.dart'; @@ -184,6 +185,15 @@ class SettingsScreen extends ConsumerWidget { onTap: () => pushScreen(context, const ReorderSidebarScreen()), ), + ListTile( + leading: const Icon(Icons.app_shortcut_rounded), + title: const Text('Launcher shortcuts'), + subtitle: const Text( + "Services shown when you long-press Atrium's icon.", + ), + onTap: () => + pushScreen(context, const LauncherShortcutsScreen()), + ), const Divider(), const _SectionHeader('About'), const ListTile( diff --git a/app/test/launcher_shortcuts_screen_test.dart b/app/test/launcher_shortcuts_screen_test.dart new file mode 100644 index 00000000..14a35155 --- /dev/null +++ b/app/test/launcher_shortcuts_screen_test.dart @@ -0,0 +1,140 @@ +import 'package:atrium/src/launcher_shortcuts/launcher_shortcuts.dart'; +import 'package:atrium/src/preferences.dart'; +import 'package:atrium/src/screens/launcher_shortcuts_screen.dart'; +import 'package:atrium/src/screens/settings_screen.dart'; +import 'package:atrium/src/update_check/update_check_state.dart'; +import 'package:atrium/src/update_check/update_checker.dart'; +import 'package:core_models/core_models.dart'; +import 'package:core_profile/core_profile.dart'; +import 'package:core_ui/core_ui.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:flutter_riverpod/misc.dart'; +import 'package:flutter_test/flutter_test.dart'; + +Instance _i(String id) => Instance( + id: id, + name: 'Service $id', + kind: ServiceKind.sonarr, + localUrl: 'http://localhost', + externalUrl: '', + urlMode: UrlMode.auto, + auth: const InstanceAuth.apiKey(apiKey: 'k'), + ); + +final Profile _profile = Profile( + id: 'p1', + name: 'Home', + instances: [for (final String id in ['a', 'b', 'c', 'd', 'e']) _i(id)], +); + +/// Keeps the choice in memory instead of the settings box. +class _MemoryChoice extends LauncherShortcutChoiceController { + _MemoryChoice(super.profileId); + + @override + List? build() => null; + + @override + Future setChosen(List ids) async { + state = List.unmodifiable(ids); + } +} + +class _FakePreferencesController extends PreferencesController { + @override + Preferences build() => const Preferences(); +} + +class _IdleUpdateChecker extends UpdateChecker { + @override + UpdateCheckState build() => const UpdateCheckState(); + @override + Future check() async {} +} + +Future _pump(WidgetTester tester, Widget home) async { + tester.view.physicalSize = const Size(800, 1600); + tester.view.devicePixelRatio = 1.0; + addTearDown(tester.view.resetPhysicalSize); + addTearDown(tester.view.resetDevicePixelRatio); + await tester.pumpWidget( + ProviderScope( + overrides: [ + activeProfileProvider.overrideWithValue(_profile), + launcherShortcutChoiceProvider('p1') + .overrideWith(() => _MemoryChoice('p1')), + preferencesProvider.overrideWith(_FakePreferencesController.new), + updateCheckProvider.overrideWith(_IdleUpdateChecker.new), + ], + child: MaterialApp(theme: AtriumTheme.light(null), home: home), + ), + ); + await tester.pump(); +} + +CheckboxListTile _row(WidgetTester tester, String id) => tester.widget( + find.ancestor( + of: find.text('Service $id'), + matching: find.byType(CheckboxListTile), + ), + ); + +List? _stored(WidgetTester tester) => ProviderScope.containerOf( + tester.element(find.byType(LauncherShortcutsScreen)), + ).read(launcherShortcutChoiceProvider('p1')); + +void main() { + testWidgets('ticks the first four by default', (WidgetTester tester) async { + await _pump(tester, const LauncherShortcutsScreen()); + + expect(find.text("Long-press Atrium's icon to open these. Up to four."), + findsOneWidget); + for (final String id in ['a', 'b', 'c', 'd']) { + expect(_row(tester, id).value, isTrue, reason: id); + } + expect(_row(tester, 'e').value, isFalse); + expect(_row(tester, 'e').onChanged, isNull); + }); + + testWidgets('unticking frees a slot', (WidgetTester tester) async { + await _pump(tester, const LauncherShortcutsScreen()); + + await tester.tap(find.text('Service b')); + await tester.pump(); + + expect(_stored(tester), ['a', 'c', 'd']); + expect(_row(tester, 'b').value, isFalse); + expect(_row(tester, 'e').onChanged, isNotNull); + }); + + testWidgets('ticking stores the choice', (WidgetTester tester) async { + await _pump(tester, const LauncherShortcutsScreen()); + + await tester.tap(find.text('Service b')); + await tester.pump(); + await tester.tap(find.text('Service e')); + await tester.pump(); + + expect(_stored(tester), ['a', 'c', 'd', 'e']); + expect(_row(tester, 'b').onChanged, isNull); + }); + + testWidgets('settings opens the screen', (WidgetTester tester) async { + await _pump(tester, const SettingsScreen()); + + final Finder tile = find.text('Launcher shortcuts'); + await tester.scrollUntilVisible( + tile, + 300, + scrollable: find.byType(Scrollable).first, + ); + expect(find.text("Services shown when you long-press Atrium's icon."), + findsOneWidget); + await tester.tap(tile); + await tester.pump(); + await tester.pump(const Duration(milliseconds: 500)); + + expect(find.byType(LauncherShortcutsScreen), findsOneWidget); + }); +} From 9d87c7f19e98f473692515dad68a4cf055802eb1 Mon Sep 17 00:00:00 2001 From: retransmit Date: Fri, 27 Nov 2026 18:57:15 +0530 Subject: [PATCH 5/8] fix(shortcuts): wait for profiles to load before publishing shortcuts --- .../launcher_shortcuts_publisher.dart | 30 +++++++-- .../launcher_shortcuts_publisher_test.dart | 66 +++++++++++++++++++ 2 files changed, 90 insertions(+), 6 deletions(-) diff --git a/app/lib/src/launcher_shortcuts/launcher_shortcuts_publisher.dart b/app/lib/src/launcher_shortcuts/launcher_shortcuts_publisher.dart index bc2fd4c1..e3b290ca 100644 --- a/app/lib/src/launcher_shortcuts/launcher_shortcuts_publisher.dart +++ b/app/lib/src/launcher_shortcuts/launcher_shortcuts_publisher.dart @@ -1,5 +1,6 @@ import 'package:collection/collection.dart'; import 'package:core_models/core_models.dart'; +import 'package:core_profile/core_profile.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; @@ -55,15 +56,32 @@ final Provider launcherShortcutsPublisherProvider = (Ref ref) => LauncherShortcutsPublisher(), ); -/// Publishes the active profile's shortcut list now and again whenever it -/// changes: a profile switch, a service added, renamed, reordered or deleted, -/// or a new choice in Settings. Watched once at the app root. +/// The shortcut list to publish, or null while the profiles are still +/// loading (at launch, while secure storage is read) or failed to load. +/// Publishing then would clear the shortcuts until the profiles arrive, or +/// for good if they never do. +final Provider?> _publishableShortcutsProvider = + Provider?>((Ref ref) { + if (!ref.watch(profileListProvider).hasValue) { + return null; + } + return ref.watch(launcherShortcutInstancesProvider); +}); + +/// Publishes the active profile's shortcut list once the profiles have +/// loaded, and again whenever it changes: a profile switch, a service added, +/// renamed, reordered or deleted, or a new choice in Settings. Watched once +/// at the app root. final Provider launcherShortcutsSyncProvider = Provider((Ref ref) { final LauncherShortcutsPublisher publisher = ref.watch(launcherShortcutsPublisherProvider); - ref.listen>( - launcherShortcutInstancesProvider, - (_, List next) => publisher.publish(next), + ref.listen?>( + _publishableShortcutsProvider, + (_, List? next) { + if (next != null) { + publisher.publish(next); + } + }, fireImmediately: true, ); }); diff --git a/app/test/launcher_shortcuts_publisher_test.dart b/app/test/launcher_shortcuts_publisher_test.dart index 0bd3a763..d07b7ff3 100644 --- a/app/test/launcher_shortcuts_publisher_test.dart +++ b/app/test/launcher_shortcuts_publisher_test.dart @@ -1,3 +1,4 @@ +import 'dart:async'; import 'dart:io'; import 'package:atrium/src/launcher_shortcuts/launcher_shortcuts.dart'; @@ -12,6 +13,28 @@ import 'package:flutter_riverpod/misc.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:hive_ce/hive.dart'; +/// Profiles that arrive when [_profiles] completes, as they do at launch +/// once secure storage has been read. +class _SlowProfiles extends ProfileListController { + _SlowProfiles(this._profiles); + final Future> _profiles; + + @override + Future> build() => _profiles; +} + +class _FixedActiveId extends ActiveProfileIdController { + @override + String? build() => 'p1'; +} + +class _NoChoice extends LauncherShortcutChoiceController { + _NoChoice(super.profileId); + + @override + List? build() => null; +} + const MethodChannel _channel = MethodChannel('app.atrium/launcher'); Instance _i(String id, {String? name, ServiceKind kind = ServiceKind.sonarr}) => @@ -118,6 +141,46 @@ void main() { expect(attempts, 2); }); + test('nothing is sent until profiles have loaded', () async { + final Completer> loading = Completer>(); + final ProviderContainer container = ProviderContainer( + overrides: [ + profileListProvider.overrideWith(() => _SlowProfiles(loading.future)), + activeProfileIdProvider.overrideWith(_FixedActiveId.new), + launcherShortcutChoiceProvider('p1') + .overrideWith(() => _NoChoice('p1')), + ], + ); + addTearDown(container.dispose); + + container.listen(launcherShortcutsSyncProvider, (_, __) {}); + await pumpEventQueue(); + expect(calls, isEmpty); + + loading.complete([ + Profile(id: 'p1', name: 'Home', instances: [_i('a')]), + ]); + await pumpEventQueue(); + expect(calls, hasLength(1)); + expect(shortcutsOf(calls.single), hasLength(1)); + }); + + test('a failed profile load leaves the shortcuts alone', () async { + final ProviderContainer container = ProviderContainer( + overrides: [ + profileListProvider.overrideWith( + () => _SlowProfiles(Future>.error(StateError('no'))), + ), + activeProfileIdProvider.overrideWith(_FixedActiveId.new), + ], + ); + addTearDown(container.dispose); + + container.listen(launcherShortcutsSyncProvider, (_, __) {}); + await pumpEventQueue(); + expect(calls, isEmpty); + }); + group('kept in step with the active profile', () { late Directory tempDir; late Box box; @@ -150,6 +213,9 @@ void main() { final ProviderContainer container = ProviderContainer( overrides: [ settingsBoxProvider.overrideWithValue(box), + profileListProvider.overrideWith( + () => _SlowProfiles(Future>.value([p1, p2])), + ), activeProfileProvider.overrideWith((Ref ref) => ref.watch(active)), ], ); From d048170ec161e03b32f2b4774ff4c35571c2c1c3 Mon Sep 17 00:00:00 2001 From: retransmit Date: Fri, 27 Nov 2026 21:14:11 +0530 Subject: [PATCH 6/8] fix(android): publish launcher shortcuts off the main thread Icons are decoded and the list handed to Android on one background thread, so a slow update no longer holds up the UI and updates stay in order. A service with an empty name is skipped instead of failing the whole list, and Android's own answer is returned, so a refused update reads as not applied. --- .../main/kotlin/app/atrium/MainActivity.kt | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/app/android/app/src/main/kotlin/app/atrium/MainActivity.kt b/app/android/app/src/main/kotlin/app/atrium/MainActivity.kt index f148eccc..f9adf01f 100644 --- a/app/android/app/src/main/kotlin/app/atrium/MainActivity.kt +++ b/app/android/app/src/main/kotlin/app/atrium/MainActivity.kt @@ -12,11 +12,15 @@ import android.graphics.Rect import android.graphics.drawable.Icon import android.net.Uri import android.os.Build +import android.os.Handler +import android.os.Looper import android.provider.OpenableColumns import io.flutter.FlutterInjector import io.flutter.embedding.android.FlutterFragmentActivity import io.flutter.embedding.engine.FlutterEngine import io.flutter.plugin.common.MethodChannel +import java.util.concurrent.ExecutorService +import java.util.concurrent.Executors // FlutterFragmentActivity (not FlutterActivity) is required by local_auth so // the BiometricPrompt can attach to a FragmentActivity host. @@ -34,6 +38,11 @@ class MainActivity : FlutterFragmentActivity() { private var shareChannel: MethodChannel? = null + // Publishing shortcuts decodes icons and can take Android a while, so it + // runs off the main thread. One thread keeps updates in the order sent. + private val shortcutExecutor: ExecutorService = Executors.newSingleThreadExecutor() + private val mainHandler = Handler(Looper.getMainLooper()) + // The intent Atrium was launched with, held until Dart asks for it. Dart // is not running yet when a cold start arrives, so it cannot be pushed. private var pendingShareIntent: Intent? = null @@ -94,7 +103,10 @@ class MainActivity : FlutterFragmentActivity() { if (shortcuts == null) { result.error("INVALID_ARGUMENT", "shortcuts is required", null) } else { - result.success(runCatching { setShortcuts(shortcuts) }.getOrDefault(false)) + shortcutExecutor.execute { + val applied = runCatching { setShortcuts(shortcuts) }.getOrDefault(false) + mainHandler.post { result.success(applied) } + } } } else { result.notImplemented() @@ -105,13 +117,15 @@ class MainActivity : FlutterFragmentActivity() { /// Replaces Atrium's launcher shortcuts (long-press on the icon, and /// launcher search) with [shortcuts]. Each opens an atrium:// link, so a /// tap takes the same path as any other Atrium link. An empty list clears - /// them. False below Android 7.1, which has no launcher shortcuts. + /// them. False below Android 7.1, which has no launcher shortcuts, and + /// when Android refuses the update (it rate limits apps in the background). private fun setShortcuts(shortcuts: List>): Boolean { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) return false val manager = getSystemService(ShortcutManager::class.java) ?: return false val infos = shortcuts.mapIndexedNotNull { index, entry -> val id = entry["id"] ?: return@mapIndexedNotNull null - val name = entry["name"] ?: return@mapIndexedNotNull null + // Android rejects an empty label, which would fail the whole list. + val name = entry["name"]?.takeIf { it.isNotEmpty() } ?: return@mapIndexedNotNull null val link = entry["link"] ?: return@mapIndexedNotNull null val intent = Intent(Intent.ACTION_VIEW, Uri.parse(link)) .setClass(this, MainActivity::class.java) @@ -123,8 +137,7 @@ class MainActivity : FlutterFragmentActivity() { .setIcon(shortcutIcon(entry["icon"])) .build() } - manager.dynamicShortcuts = infos - return true + return manager.setDynamicShortcuts(infos) } /// The service's bundled icon, or Atrium's own when the service has none @@ -160,6 +173,11 @@ class MainActivity : FlutterFragmentActivity() { return out } + override fun onDestroy() { + shortcutExecutor.shutdown() + super.onDestroy() + } + // Reached when Atrium is already running (launchMode is singleTop), so // Dart is live and the payload can be pushed straight across. override fun onNewIntent(intent: Intent) { From f2fda33ee266df07a4fdcb96e187f89077ac66ca Mon Sep 17 00:00:00 2001 From: retransmit Date: Fri, 27 Nov 2026 21:14:11 +0530 Subject: [PATCH 7/8] fix(shortcuts): retry refused updates and keep quick ticks A list Android refused is sent again next time instead of being taken as applied. A tick shows at once, so a second tap made while the first is still saving builds on it, and a failed save puts the old choice back. --- .../launcher_shortcuts.dart | 13 +++++++- .../launcher_shortcuts_publisher.dart | 8 ++++- .../launcher_shortcuts_publisher_test.dart | 15 +++++++++ app/test/launcher_shortcuts_test.dart | 33 +++++++++++++++++++ 4 files changed, 67 insertions(+), 2 deletions(-) diff --git a/app/lib/src/launcher_shortcuts/launcher_shortcuts.dart b/app/lib/src/launcher_shortcuts/launcher_shortcuts.dart index 34b2a9a2..9beeaeb7 100644 --- a/app/lib/src/launcher_shortcuts/launcher_shortcuts.dart +++ b/app/lib/src/launcher_shortcuts/launcher_shortcuts.dart @@ -60,10 +60,21 @@ class LauncherShortcutChoiceController extends Notifier?> { return null; } + /// Shows [ids] at once, so a second tap made while this one is still + /// saving starts from it, then saves. A failed save puts the earlier + /// choice back, unless a later one has replaced it. Future setChosen(List ids) async { + final List? previous = state; final List next = List.unmodifiable(ids); - await ref.read(settingsBoxProvider).put(_key, jsonEncode(next)); state = next; + try { + await ref.read(settingsBoxProvider).put(_key, jsonEncode(next)); + } catch (_) { + if (identical(state, next)) { + state = previous; + } + rethrow; + } } } diff --git a/app/lib/src/launcher_shortcuts/launcher_shortcuts_publisher.dart b/app/lib/src/launcher_shortcuts/launcher_shortcuts_publisher.dart index e3b290ca..fdb440a6 100644 --- a/app/lib/src/launcher_shortcuts/launcher_shortcuts_publisher.dart +++ b/app/lib/src/launcher_shortcuts/launcher_shortcuts_publisher.dart @@ -38,10 +38,16 @@ class LauncherShortcutsPublisher { } _sent = shortcuts; try { - await _channel.invokeMethod( + final bool? applied = await _channel.invokeMethod( 'setShortcuts', {'shortcuts': shortcuts}, ); + // Android can refuse (rate limited while in the background) or fail. + // Forget the list so the same one is tried again, unless a newer + // publish has already replaced it. + if (applied != true && identical(_sent, shortcuts)) { + _sent = null; + } } on MissingPluginException { _sent = null; } on PlatformException { diff --git a/app/test/launcher_shortcuts_publisher_test.dart b/app/test/launcher_shortcuts_publisher_test.dart index d07b7ff3..0e743622 100644 --- a/app/test/launcher_shortcuts_publisher_test.dart +++ b/app/test/launcher_shortcuts_publisher_test.dart @@ -141,6 +141,21 @@ void main() { expect(attempts, 2); }); + test('a refused update is tried again next time', () async { + int attempts = 0; + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger + .setMockMethodCallHandler(_channel, (MethodCall call) async { + attempts++; + // Android said no (rate limited, or the update threw). + return attempts > 1; + }); + final LauncherShortcutsPublisher publisher = LauncherShortcutsPublisher(); + await publisher.publish([_i('a')]); + await publisher.publish([_i('a')]); + await publisher.publish([_i('a')]); + expect(attempts, 2); + }); + test('nothing is sent until profiles have loaded', () async { final Completer> loading = Completer>(); final ProviderContainer container = ProviderContainer( diff --git a/app/test/launcher_shortcuts_test.dart b/app/test/launcher_shortcuts_test.dart index e2851738..0e85a2eb 100644 --- a/app/test/launcher_shortcuts_test.dart +++ b/app/test/launcher_shortcuts_test.dart @@ -116,6 +116,39 @@ void main() { expect(relaunch().read(launcherShortcutChoiceProvider('p1')), isNull); }); + test('a new choice shows before the save finishes', () async { + final ProviderContainer container = relaunch(); + final LauncherShortcutChoiceController choice = + container.read(launcherShortcutChoiceProvider('p1').notifier); + + final Future first = choice.setChosen(['a', 'b']); + // A second tap, made while the first save is still running, starts + // from the first tap's choice. + expect(container.read(launcherShortcutChoiceProvider('p1')), + ['a', 'b']); + final Future second = choice.setChosen(['b']); + await Future.wait(>[first, second]); + + expect(relaunch().read(launcherShortcutChoiceProvider('p1')), ['b']); + }); + + test('a failed save puts the old choice back', () async { + await box.put('launcherShortcuts.p1', '["a"]'); + final ProviderContainer container = relaunch(); + expect(container.read(launcherShortcutChoiceProvider('p1')), ['a']); + await box.close(); + + await expectLater( + container + .read(launcherShortcutChoiceProvider('p1').notifier) + .setChosen(['b']), + throwsA(anything), + ); + expect(container.read(launcherShortcutChoiceProvider('p1')), ['a']); + + box = await Hive.openBox('settings'); + }); + test('the active profile picks its own instances', () async { await box.put('launcherShortcuts.p1', '["c"]'); final ProviderContainer container = ProviderContainer( From 49972ffb039fac92c930e6a6c4d61e137e200ed2 Mon Sep 17 00:00:00 2001 From: retransmit Date: Fri, 27 Nov 2026 23:40:28 +0530 Subject: [PATCH 8/8] fix(android): share one shortcut thread across the process A recreated activity now publishes on the same thread as the one it replaced, so an older shortcut list can never land after a newer one. The thread is no longer shut down with the activity. --- .../src/main/kotlin/app/atrium/MainActivity.kt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/android/app/src/main/kotlin/app/atrium/MainActivity.kt b/app/android/app/src/main/kotlin/app/atrium/MainActivity.kt index f9adf01f..de6e088f 100644 --- a/app/android/app/src/main/kotlin/app/atrium/MainActivity.kt +++ b/app/android/app/src/main/kotlin/app/atrium/MainActivity.kt @@ -25,6 +25,14 @@ import java.util.concurrent.Executors // FlutterFragmentActivity (not FlutterActivity) is required by local_auth so // the BiometricPrompt can attach to a FragmentActivity host. class MainActivity : FlutterFragmentActivity() { + companion object { + // Publishing shortcuts decodes icons and can take Android a while, so + // it runs off the main thread. One thread for the whole process keeps + // updates in the order sent, even across a recreated activity, so an + // older list can never land after a newer one. + private val shortcutExecutor: ExecutorService by lazy { Executors.newSingleThreadExecutor() } + } + private val CHANNEL = "app.atrium/launcher" private val SHARE_CHANNEL = "app.atrium/share" @@ -38,9 +46,6 @@ class MainActivity : FlutterFragmentActivity() { private var shareChannel: MethodChannel? = null - // Publishing shortcuts decodes icons and can take Android a while, so it - // runs off the main thread. One thread keeps updates in the order sent. - private val shortcutExecutor: ExecutorService = Executors.newSingleThreadExecutor() private val mainHandler = Handler(Looper.getMainLooper()) // The intent Atrium was launched with, held until Dart asks for it. Dart @@ -173,11 +178,6 @@ class MainActivity : FlutterFragmentActivity() { return out } - override fun onDestroy() { - shortcutExecutor.shutdown() - super.onDestroy() - } - // Reached when Atrium is already running (launchMode is singleTop), so // Dart is live and the payload can be pushed straight across. override fun onNewIntent(intent: Intent) {