Skip to content

Commit 8ad5f9b

Browse files
committed
Move stop ungrouping logic from calling functions to AlarmListManager.sendControls so it's applied everywhere automatically
1 parent c65485c commit 8ad5f9b

11 files changed

Lines changed: 200 additions & 38 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Furthermore it fixes some layout flaws of the official OpenShock Frontend like h
2222
You can also log in on multiple OpenShock instances at once. ShockAlarm will show all shockers from all instances seamlessly at a glance!
2323

2424
## Other information
25-
- I cannot guarentee that all features work with all possible configurations. I try to make them work with each other but sometimes I miss them. For example a random intensity won't work with the shock confirmation dialog. However a hard limit will.
25+
I cannot guarentee that all features work with all possible configurations. I try to make them work with each other but sometimes I miss them. For example a random intensity won't work with the shock confirmation dialog. However a hard limit will.
2626

2727
### Not supported in Web Version
2828
Everything with websockets is currently not supported due to authentication problems with websockets. This includes:
@@ -125,7 +125,7 @@ You can download a Portable version (zip file) from the [releases](https://githu
125125
- [x] Add global limit for self.
126126
- [x] Stop live playback when changing type
127127
- [x] Make sure text in popups is scrollable so it can be read completely
128-
- [ ] Implement login V2
128+
- [ ] Implement login V2 (how am I supposed to reliably extract sideKeys for turnstile on any OpenShock instance)
129129
- [ ] Implement Shares V2 (once officially declared done in backend and implementation in official frontend exists. Can't make sense of the api rn without explenation)
130130

131131
# Planned settings

lib/components/desktop_mobile_refresh_indicator.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'package:flutter/foundation.dart';
22
import 'package:flutter/material.dart';
3-
import 'package:flutter/services.dart';
43
import 'package:shock_alarm_app/services/alarm_list_manager.dart';
54

65
class DesktopMobileRefreshIndicator extends StatefulWidget {

lib/components/page_padding.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import 'package:flutter/foundation.dart';
21
import 'package:flutter/material.dart';
3-
import 'package:shock_alarm_app/screens/screen_selector.dart';
42

53
class PagePadding extends StatefulWidget {
64
final Widget child;

lib/components/predefined_spacing.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'package:flutter/widgets.dart';
22

33
class PredefinedSpacing extends StatelessWidget {
44
EdgeInsets? padding;
5-
PredefinedSpacing({this.padding = null});
5+
PredefinedSpacing({this.padding});
66
static EdgeInsets paddingExtraSmall() => EdgeInsets.all(5);
77
static EdgeInsets paddingSmall() => EdgeInsets.all(10);
88
static EdgeInsets paddingMedium() => EdgeInsets.all(15);

lib/screens/shockers/grouped/grouped_shockers.dart

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,6 @@ class _GroupedShockerScreenState extends State<GroupedShockerScreen> {
5353
for (Shocker s in AlarmListManager.getInstance().getSelectedShockers()) {
5454
controls.add(s.getLimitedControls(type, intensity, duration));
5555
}
56-
if (type == ControlType.stop) {
57-
// Temporary workaround until OpenShock fixed the issue with stop. So for now we send them individually
58-
for (Control c in controls) {
59-
AlarmListManager.getInstance().sendControls([c]);
60-
}
61-
return 0;
62-
}
6356
AlarmListManager.getInstance().sendControls(controls);
6457
return duration;
6558
}
@@ -73,13 +66,6 @@ class _GroupedShockerScreenState extends State<GroupedShockerScreen> {
7366
for (Shocker s in AlarmListManager.getInstance().getSelectedShockers()) {
7467
controls.add(s.getLimitedControls(type, intensity, 300));
7568
}
76-
if (type == ControlType.stop) {
77-
// Temporary workaround until OpenShock fixed the issue with stop. So for now we send them individually
78-
for (Control c in controls) {
79-
AlarmListManager.getInstance().sendControls([c]);
80-
}
81-
return;
82-
}
8369
AlarmListManager.getInstance().sendLiveControls(controls);
8470
}
8571

lib/screens/shockers/individual/shockers.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ class ShockerScreenState extends State<ShockerScreen> {
279279
List<Control> controls = [];
280280
int highestDuration = 0;
281281
for (Shocker s in shockers ?? AlarmListManager.getInstance().getSelectedShockers()) {
282+
if(s.paused) continue;
282283
Control c = s.getLimitedControls(type, AlarmListManager.getInstance().settings.useSeperateSliders && type == ControlType.vibrate ? s.controls.getRandomVibrateIntensity() : s.controls.getRandomIntensity(), s.controls.getRandomDuration());
283284
if (c.duration > highestDuration) {
284285
highestDuration = c.duration;

lib/screens/shockers/shocker_item.dart

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -464,13 +464,6 @@ class ShockerItemState extends State<ShockerItem>
464464

465465
void onSendLive(ControlType type, int intensity) {
466466
List<Control> controls = [widget.shocker.getLimitedControls(type, intensity, 300)];
467-
if (type == ControlType.stop) {
468-
// Temporary workaround until OpenShock fixed the issue with stop. So for now we send them individually
469-
for (Control c in controls) {
470-
widget.manager.sendControls([c]);
471-
}
472-
return;
473-
}
474467
widget.manager.sendLiveControls(controls);
475468
}
476469
}

lib/screens/tools/random_shocks/random_shocks.dart

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,6 @@ class _RandomShocksScreenState extends State<RandomShocksScreen> {
7878
for (Shocker s in AlarmListManager.getInstance().getSelectedShockers()) {
7979
controls.add(s.getLimitedControls(type, intensity, duration));
8080
}
81-
if (type == ControlType.stop) {
82-
// Temporary workaround until OpenShock fixed the issue with stop. So for now we send them individually
83-
for (Control c in controls) {
84-
AlarmListManager.getInstance().sendControls([c]);
85-
}
86-
return;
87-
}
8881
AlarmListManager.getInstance().sendControls(controls);
8982
}
9083

lib/services/alarm_list_manager.dart

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -792,19 +792,34 @@ class AlarmListManager {
792792
Future<String?> sendControls(List<Control> controls,
793793
{String? customName, bool useWs = true}) async {
794794
Map<int, List<Control>> controlsByToken = {};
795+
Map<int, List<Control>> stopControlsByToken = {};
795796
for (var control in controls) {
796-
controlsByToken.putIfAbsent(control.apiTokenId, () => []).add(control);
797+
// put stop controls into seperate list
798+
(control.type == ControlType.stop ? stopControlsByToken : controlsByToken).putIfAbsent(control.apiTokenId, () => []).add(control);
797799
}
798800
OpenShockClient client = OpenShockClient();
801+
bool stopControlFailed = false;
802+
// first do stop controls
799803
for (var token in getTokens()) {
800-
if (controlsByToken.containsKey(token.id)) {
801-
if (!await client.sendControls(token, controlsByToken[token.id]!, this,
804+
if (!stopControlsByToken.containsKey(token.id)) continue;
805+
for(Control stopControl in stopControlsByToken[token.id]!) {
806+
if (!await client.sendControls(token, [stopControl], this,
802807
customName: customName,
803808
useWs: !settings.useHttpShocking && useWs)) {
804-
return "Failed to send shock to at least 1 shocker, is your token still valid?";
809+
stopControlFailed = true; // make sure we also try to send the other stops
805810
}
806811
}
807812
}
813+
if(stopControlFailed) return "Failed to send stop to at least 1 shocker";
814+
// then the other ones
815+
for (var token in getTokens()) {
816+
if (!controlsByToken.containsKey(token.id)) continue;
817+
if (!await client.sendControls(token, controlsByToken[token.id]!, this,
818+
customName: customName,
819+
useWs: !settings.useHttpShocking && useWs)) {
820+
return "Failed to send shock to at least 1 shocker, is your token still valid?";
821+
}
822+
}
808823
return null;
809824
}
810825

0 commit comments

Comments
 (0)