Skip to content

Commit ee4b4a2

Browse files
authored
[leancode_debug_page] Vendor shake package, bump sensors_plus dependency (#325)
1 parent 32607ae commit ee4b4a2

File tree

7 files changed

+121
-46
lines changed

7 files changed

+121
-46
lines changed

packages/leancode_debug_page/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@
44

55
## 1.0.1
66

7-
- Fix screenshots in README.md
7+
- Fix screenshots in README.md
8+
9+
## 1.0.2
10+
11+
- Vendor shake package to avoid using obsolete version of sensors_plus

packages/leancode_debug_page/LICENSE

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,29 @@
198198
distributed under the License is distributed on an "AS IS" BASIS,
199199
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200200
See the License for the specific language governing permissions and
201-
limitations under the License.
201+
limitations under the License.
202+
203+
The file shake_detector.dart contains code from the shake package
204+
(https://pub.dev/packages/shake/license) and is governed by the original BSD-style license
205+
included below.
206+
207+
Copyright 2019 Deven Joshi
208+
209+
Redistribution and use in source and binary forms, with or without modification, are permitted
210+
provided that the following conditions are met:
211+
212+
1. Redistributions of source code must retain the above copyright notice, this list of conditions
213+
and the following disclaimer.
214+
215+
2. Redistributions in binary form must reproduce the above copyright notice, this list of
216+
conditions and the following disclaimer in the documentation and/or other materials provided with
217+
the distribution.
218+
219+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
220+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
221+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
222+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
223+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
224+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
225+
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
226+
WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

packages/leancode_debug_page/example/pubspec.lock

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ packages:
166166
path: ".."
167167
relative: true
168168
source: path
169-
version: "1.0.0"
169+
version: "1.0.1"
170170
lints:
171171
dependency: transitive
172172
description:
@@ -299,34 +299,18 @@ packages:
299299
dependency: transitive
300300
description:
301301
name: sensors_plus
302-
sha256: "362c8f4f001838b90dd5206b898bbad941bc0142479eab9a3415f0f79e622908"
302+
sha256: "6898cd4490ffc27fea4de5976585e92fae55355175d46c6c3b3d719d42f9e230"
303303
url: "https://pub.dev"
304304
source: hosted
305-
version: "1.4.1"
305+
version: "5.0.1"
306306
sensors_plus_platform_interface:
307307
dependency: transitive
308308
description:
309309
name: sensors_plus_platform_interface
310-
sha256: "95f0cc08791b8bf0c41c5fa99c84be2a7d5bf60a811ddc17e1438b1e68caf0d3"
310+
sha256: bc472d6cfd622acb4f020e726433ee31788b038056691ba433fec80e448a094f
311311
url: "https://pub.dev"
312312
source: hosted
313-
version: "1.1.3"
314-
sensors_plus_web:
315-
dependency: transitive
316-
description:
317-
name: sensors_plus_web
318-
sha256: fca8d7d9ab6233b2a059952666415508e252420be1ef54f092d07884da53ec5e
319-
url: "https://pub.dev"
320-
source: hosted
321-
version: "1.1.2"
322-
shake:
323-
dependency: transitive
324-
description:
325-
name: shake
326-
sha256: "107546951c6b8f5e4c2dca66dfb3aa27dd1a853b4e9a26c9aea224b167045023"
327-
url: "https://pub.dev"
328-
source: hosted
329-
version: "2.2.0"
313+
version: "1.2.0"
330314
share_plus:
331315
dependency: transitive
332316
description:
@@ -412,14 +396,6 @@ packages:
412396
url: "https://pub.dev"
413397
source: hosted
414398
version: "1.3.2"
415-
universal_io:
416-
dependency: transitive
417-
description:
418-
name: universal_io
419-
sha256: "1722b2dcc462b4b2f3ee7d188dad008b6eb4c40bbd03a3de451d82c78bba9aad"
420-
url: "https://pub.dev"
421-
source: hosted
422-
version: "2.2.2"
423399
url_launcher_linux:
424400
dependency: transitive
425401
description:

packages/leancode_debug_page/lib/src/core/debug_page_controller.dart

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@ import 'dart:async';
33
import 'package:flutter/foundation.dart';
44
import 'package:leancode_debug_page/src/core/logger_listener.dart';
55
import 'package:leancode_debug_page/src/core/logging_http_client.dart';
6+
import 'package:leancode_debug_page/src/core/shake_detector.dart';
67
import 'package:leancode_debug_page/src/models/filter.dart';
78
import 'package:leancode_debug_page/src/models/request_log_record.dart';
89
import 'package:logging/logging.dart';
910
import 'package:rxdart/rxdart.dart';
10-
import 'package:shake/shake.dart';
11-
import 'package:universal_io/io.dart';
12-
13-
bool get _isMobile => Platform.isAndroid || Platform.isIOS;
1411

1512
class DebugPageController {
1613
DebugPageController({
@@ -37,11 +34,7 @@ class DebugPageController {
3734
() => _updateLoggerLogsStream(loggerListener.logs),
3835
);
3936

40-
// Platform check is necessary due shake package dependency on an obsolete
41-
// version of sensors_plus. Without the check, an exception is thrown on
42-
// platforms where accelerometer is not available. Can be removed when
43-
// https://github.com/deven98/shake/pull/32 is merged.
44-
if (showOnShake && _isMobile) {
37+
if (showOnShake) {
4538
_shakeDetector = ShakeDetector.autoStart(
4639
shakeThresholdGravity: 4,
4740
onPhoneShake: () => visible.value = true,
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// This file mostly consists of code copied from https://pub.dev/packages/shake
2+
// The package must have been vendored in order to bump dependency on
3+
// sensors_plus and avoid exceptions caused by the old version of that package.
4+
// Shake dependency can be brought back once https://github.com/deven98/shake/pull/32
5+
// is merged
6+
7+
import 'dart:async';
8+
import 'dart:math';
9+
10+
import 'package:flutter/foundation.dart';
11+
import 'package:sensors_plus/sensors_plus.dart';
12+
13+
class ShakeDetector {
14+
/// This constructor automatically calls [startListening] and starts detection and callbacks.
15+
ShakeDetector.autoStart({
16+
required this.onPhoneShake,
17+
this.shakeThresholdGravity = 2.7,
18+
this.shakeSlopTimeMS = 500,
19+
this.shakeCountResetTime = 3000,
20+
this.minimumShakeCount = 1,
21+
}) {
22+
startListening();
23+
}
24+
25+
final VoidCallback onPhoneShake;
26+
27+
/// Shake detection threshold
28+
final double shakeThresholdGravity;
29+
30+
/// Minimum time between shake
31+
final int shakeSlopTimeMS;
32+
33+
/// Time before shake count resets
34+
final int shakeCountResetTime;
35+
36+
/// Number of shakes required before shake is triggered
37+
final int minimumShakeCount;
38+
39+
int mShakeTimestamp = DateTime.now().millisecondsSinceEpoch;
40+
int mShakeCount = 0;
41+
42+
StreamSubscription<AccelerometerEvent>? streamSubscription;
43+
44+
void startListening() {
45+
streamSubscription = accelerometerEventStream().listen(
46+
(event) {
47+
final gX = event.x / 9.80665;
48+
final gY = event.y / 9.80665;
49+
final gZ = event.z / 9.80665;
50+
51+
// gForce will be close to 1 when there is no movement.
52+
final gForce = sqrt(gX * gX + gY * gY + gZ * gZ);
53+
54+
if (gForce > shakeThresholdGravity) {
55+
final now = DateTime.now().millisecondsSinceEpoch;
56+
// ignore shake events too close to each other (500ms)
57+
if (mShakeTimestamp + shakeSlopTimeMS > now) {
58+
return;
59+
}
60+
61+
// reset the shake count after [shakeCountResetTime] seconds of no shakes
62+
if (mShakeTimestamp + shakeCountResetTime < now) {
63+
mShakeCount = 0;
64+
}
65+
66+
mShakeTimestamp = now;
67+
mShakeCount++;
68+
69+
if (mShakeCount >= minimumShakeCount) {
70+
onPhoneShake();
71+
}
72+
}
73+
},
74+
);
75+
}
76+
77+
void stopListening() {
78+
streamSubscription?.cancel();
79+
}
80+
}

packages/leancode_debug_page/lib/src/ui/debug_page_overlay.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ class DebugPageOverlay extends StatelessWidget {
3737
child: MaterialApp(
3838
theme: ThemeData(
3939
useMaterial3: true,
40-
colorScheme: ColorScheme.fromSeed(
41-
seedColor: Colors.deepPurple,
42-
),
40+
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
4341
),
4442
home: LogsInspector(
4543
controller: _controller,

packages/leancode_debug_page/pubspec.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: leancode_debug_page
2-
version: 1.0.1
2+
version: 1.0.2
33
homepage: https://github.com/leancodepl/flutter_corelibrary/tree/master/packages/leancode_debug_page
44
repository: https://github.com/leancodepl/flutter_corelibrary
55
description: >-
@@ -15,9 +15,8 @@ dependencies:
1515
http: ^1.1.0
1616
logging: ^1.2.0
1717
rxdart: ^0.27.7
18-
shake: ^2.2.0
18+
sensors_plus: ^5.0.1
1919
share_plus: ^9.0.0
20-
universal_io: ^2.2.2
2120

2221
dev_dependencies:
2322
custom_lint: ^0.6.4

0 commit comments

Comments
 (0)