Skip to content

Commit

Permalink
add check if walk mode is supported
Browse files Browse the repository at this point in the history
  • Loading branch information
Codel1417 committed Jan 25, 2025
1 parent 56fb652 commit bb7e920
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 74 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.0
1.1.1
23 changes: 23 additions & 0 deletions lib/Backend/sensors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ abstract class TriggerDefinition extends ChangeNotifier implements Comparable<Tr

TriggerDefinition(this.ref);

// add check here if a trigger is supported on a given device/platform
Future<bool> isSupported() {
return Future.value(true);
}

Future<void> sendCommands(String name, Ref ref) async {
if (ref.read(getAvailableGearProvider).isEmpty) {
return;
Expand Down Expand Up @@ -363,6 +368,13 @@ class WalkingTriggerDefinition extends TriggerDefinition {
];
}

@override
Future<bool> isSupported() async {
bool isStepCountSupported = await Pedometer.isStepCountSupported == true;
bool isStepDetectionSupported = await Pedometer.isStepDetectionSupported == true;
return isStepDetectionSupported && isStepCountSupported;
}

@override
Future<void> onDisable() async {
pedestrianStatusStream?.cancel();
Expand Down Expand Up @@ -407,6 +419,11 @@ class CoverTriggerDefinition extends TriggerDefinition {
super.actionTypes = [TriggerActionDef(name: "Near", translated: triggerCoverNear(), uuid: "bf3d0ce0-15c0-46db-95ce-e2cd6a5ecd0f"), TriggerActionDef(name: "Far", translated: triggerCoverFar(), uuid: "d121e4a8-a12d-4f0a-8348-89c62eb72a7a")];
}

@override
Future<bool> isSupported() {
return Future.value(true);
}

@override
Future<void> onDisable() async {
proximityStream?.cancel();
Expand All @@ -418,6 +435,7 @@ class CoverTriggerDefinition extends TriggerDefinition {
if (proximityStream != null) {
return;
}

proximityStream = ProximitySensor.events.listen((int event) {
sensorsLogger.fine("CoverEvent:: $event");
if (event >= 1) {
Expand Down Expand Up @@ -637,6 +655,11 @@ class VolumeButtonTriggerDefinition extends TriggerDefinition {
super.actionTypes = [TriggerActionDef(name: "Volume Up", translated: triggerVolumeButtonVolumeUp(), uuid: "834a9bef-9ae2-4623-81fa-bbead69eb28e"), TriggerActionDef(name: "Volume Down", translated: triggerVolumeButtonVolumeDown(), uuid: "2972aa14-33de-4d4f-ac67-4f572306b5c4")];
}

@override
Future<bool> isSupported() {
return Future.value(Platform.isAndroid);
}

@override
Future<void> onDisable() async {
subscription?.cancel();
Expand Down
54 changes: 32 additions & 22 deletions lib/Frontend/pages/triggers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,22 @@ class _TriggersState extends ConsumerState<Triggers> {
builder: (BuildContext context, Widget? child) {
return Semantics(
label: 'A switch to toggle the trigger ${trigger.triggerDefinition?.name}',
child: Switch(
value: trigger.enabled,
onChanged: (bool value) async {
setState(
() {
trigger.storedEnable = !trigger.enabled;
ref.read(triggerListProvider.notifier).store();
plausible.event(name: "Enable Trigger", props: {"Trigger Type": ref.watch(triggerDefinitionListProvider).where((element) => element.uuid == trigger.triggerDefUUID).first.toString()});
},
);
},
child: FutureBuilder(
future: trigger.triggerDefinition!.isSupported(),
builder: (context, snapshot) => Switch(
value: trigger.enabled,
onChanged: snapshot.data == true
? (bool value) async {
setState(
() {
trigger.storedEnable = !trigger.enabled;
ref.read(triggerListProvider.notifier).store();
plausible.event(name: "Enable Trigger", props: {"Trigger Type": ref.watch(triggerDefinitionListProvider).where((element) => element.uuid == trigger.triggerDefUUID).first.toString()});
},
);
}
: null,
),
),
);
},
Expand Down Expand Up @@ -240,17 +245,22 @@ class _TriggerEditState extends ConsumerState<TriggerEdit> {
builder: (BuildContext context, Widget? child) {
return Semantics(
label: 'A switch to toggle the trigger ${triggerDefinition?.name}',
child: Switch(
value: trigger!.enabled,
onChanged: (bool value) {
setState(
() {
trigger!.storedEnable = !trigger!.enabled;
ref.read(triggerListProvider.notifier).store();
plausible.event(name: "Enable Trigger", props: {"Trigger Type": ref.watch(triggerDefinitionListProvider).where((element) => element.uuid == trigger!.triggerDefUUID).first.toString()});
},
);
},
child: FutureBuilder(
future: trigger!.triggerDefinition!.isSupported(),
builder: (context, snapshot) => Switch(
value: trigger!.enabled,
onChanged: snapshot.data == true
? (bool value) {
setState(
() {
trigger!.storedEnable = !trigger!.enabled;
ref.read(triggerListProvider.notifier).store();
plausible.event(name: "Enable Trigger", props: {"Trigger Type": ref.watch(triggerDefinitionListProvider).where((element) => element.uuid == trigger!.triggerDefUUID).first.toString()});
},
);
}
: null,
),
),
);
},
Expand Down
Loading

0 comments on commit bb7e920

Please sign in to comment.