Skip to content

Commit

Permalink
add app shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
Codel1417 committed May 23, 2024
1 parent a74ee95 commit be7f9f5
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/Backend/action_registry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'Bluetooth/bluetooth_manager.dart';
import 'Bluetooth/bluetooth_manager_plus.dart';
import 'Definitions/Action/base_action.dart';
import 'Definitions/Device/device_definition.dart';
import 'appShortcuts.dart';

part 'action_registry.g.dart';

Expand Down Expand Up @@ -224,5 +225,6 @@ class FavoriteActions extends _$FavoriteActions {
SentryHive.box<FavoriteAction>(favoriteActionsBox)
..clear()
..addAll(state);
updateShortcuts(ref);
}
}
41 changes: 41 additions & 0 deletions lib/Backend/appShortcuts.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';

Check notice on line 1 in lib/Backend/appShortcuts.dart

View workflow job for this annotation

GitHub Actions / Linter

The file name 'appShortcuts.dart' isn't a lower_case_with_underscores identifier. For more details, see https://dart.dev/tools/diagnostic-messages#file_names

Check warning on line 1 in lib/Backend/appShortcuts.dart

View workflow job for this annotation

GitHub Actions / Linter

Invalid format. For more details, see https://dart.dev/guides/language/effective-dart/style#formatting
import 'package:quick_actions/quick_actions.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:tail_app/Backend/Bluetooth/bluetooth_manager.dart';
import 'package:tail_app/Backend/Definitions/Action/base_action.dart';
import 'package:tail_app/Backend/action_registry.dart';
import 'package:tail_app/Backend/move_lists.dart';
import 'package:tail_app/Backend/sensors.dart';

import 'Definitions/Device/device_definition.dart';

part 'appShortcuts.g.dart';

const QuickActions quickActions = QuickActions();

@Riverpod(keepAlive: true)
Future<void> appShortcuts(AppShortcutsRef ref) async {
quickActions.initialize((shortcutType) {
BaseAction? action = ref.read(getActionFromUUIDProvider(shortcutType));
if (action != null) {
Iterable<BaseStatefulDevice> knownDevices =
ref.read(knownDevicesProvider).values.where((element) => action.deviceCategory.contains(element.baseDeviceDefinition.deviceType)).where((element) => element.deviceConnectionState.value == ConnectivityState.connected).where((element) => element.deviceState.value == DeviceState.standby);
for (BaseStatefulDevice device in knownDevices) {
runAction(action, device);
}
}
});
updateShortcuts(ref);
}

Future<void> updateShortcuts(Ref ref) async {
Iterable<BaseAction> allActions = ref.read(favoriteActionsProvider).map(
(e) => ref.read(getActionFromUUIDProvider(e.actionUUID)) as BaseAction,
);

quickActions.setShortcutItems(allActions
.map(
(e) => ShortcutItem(type: e.uuid, localizedTitle: e.name),
)
.toList());
}
3 changes: 2 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import 'package:sentry_hive/sentry_hive.dart';
import 'package:sentry_logging/sentry_logging.dart';
import 'package:tail_app/Backend/Definitions/Device/device_definition.dart';
import 'package:tail_app/Backend/action_registry.dart';
import 'package:tail_app/Backend/appShortcuts.dart';
import 'package:tail_app/Frontend/Widgets/bt_app_state_controller.dart';

import 'Backend/Definitions/Action/base_action.dart';
Expand Down Expand Up @@ -293,7 +294,7 @@ class _EagerInitialization extends ConsumerWidget {
//ref.watch(triggerListProvider);
//ref.watch(moveListsProvider);
//ref.watch(favoriteActionsProvider);

ref.watch(appShortcutsProvider);
return child;
}
}
32 changes: 32 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,38 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.2.3"
quick_actions:
dependency: "direct main"
description:
name: quick_actions
sha256: b17da113df7a7005977f64adfa58ccc49c829d3ccc6e8e770079a8c7fbf2da9e
url: "https://pub.dev"
source: hosted
version: "1.0.7"
quick_actions_android:
dependency: transitive
description:
name: quick_actions_android
sha256: b95ef1e4b2d60316d5819006ace12dc5d7289e5c5f7ffe4b131764fa1b6c1c44
url: "https://pub.dev"
source: hosted
version: "1.0.12"
quick_actions_ios:
dependency: transitive
description:
name: quick_actions_ios
sha256: "65f519b689926161eaf483001c8b6cadb3d45eea9e4ede7a143a13c2472af0e2"
url: "https://pub.dev"
source: hosted
version: "1.1.0"
quick_actions_platform_interface:
dependency: transitive
description:
name: quick_actions_platform_interface
sha256: "81a1e40c519bb3cacfec38b3008b13cef665a75bd270da94f40091b57f0f9236"
url: "https://pub.dev"
source: hosted
version: "1.0.6"
riverpod:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ dependencies:
git:
url: https://github.com/undreeyyy/flutter_plugin_install_referrer
ref: fd87e9b8f0d5ed909e929388244456f72b9b63c7
quick_actions: ^1.0.7 # puts favorites on the home screen

# Riverpod
flutter_riverpod: ^2.5.1
Expand Down

0 comments on commit be7f9f5

Please sign in to comment.