From f3c7bbbcbf9cd54366cd6c99332e86d59817179f Mon Sep 17 00:00:00 2001 From: Jonas Bark Date: Sun, 19 Oct 2025 09:48:51 +0200 Subject: [PATCH] Revert "Use file storage instead of SharedPreferences for challenge codes" This reverts commit a744242c70c8b1c9dc152ea57b8d9e8652d252b9. --- lib/bluetooth/devices/elite/elite_sterzo.dart | 26 +++++++++---------- pubspec.yaml | 1 - 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/lib/bluetooth/devices/elite/elite_sterzo.dart b/lib/bluetooth/devices/elite/elite_sterzo.dart index 7fc91d9..c335be9 100644 --- a/lib/bluetooth/devices/elite/elite_sterzo.dart +++ b/lib/bluetooth/devices/elite/elite_sterzo.dart @@ -1,11 +1,10 @@ import 'dart:convert'; -import 'dart:io'; import 'dart:typed_data'; import 'package:dartx/dartx.dart'; import 'package:flutter/foundation.dart'; import 'package:http/http.dart' as http; -import 'package:path_provider/path_provider.dart'; +import 'package:shared_preferences/shared_preferences.dart'; import 'package:swift_control/bluetooth/devices/base_device.dart'; import 'package:swift_control/utils/keymap/buttons.dart'; import 'package:universal_ble/universal_ble.dart'; @@ -193,9 +192,12 @@ class EliteSterzo extends BaseDevice { static Future _loadCachedChallengeCodes() async { try { - final file = await _getCacheFile(); - if (await file.exists()) { - return await file.readAsBytes(); + final prefs = await SharedPreferences.getInstance(); + final cached = prefs.getString(SterzoConstants.CACHE_KEY); + + if (cached != null) { + // Decode from base64 + return base64Decode(cached); } } catch (e) { if (kDebugMode) { @@ -207,8 +209,9 @@ class EliteSterzo extends BaseDevice { static Future _cacheChallengeCodes(Uint8List data) async { try { - final file = await _getCacheFile(); - await file.writeAsBytes(data); + final prefs = await SharedPreferences.getInstance(); + // Encode to base64 for storage + await prefs.setString(SterzoConstants.CACHE_KEY, base64Encode(data)); } catch (e) { if (kDebugMode) { print('Failed to cache challenge codes: $e'); @@ -216,11 +219,6 @@ class EliteSterzo extends BaseDevice { } } - static Future _getCacheFile() async { - final directory = await getApplicationDocumentsDirectory(); - return File('${directory.path}/${SterzoConstants.CACHE_FILENAME}'); - } - void _handleSteeringMeasurement(Uint8List bytes) { if (bytes.length >= 4) { // Steering angle is a 32-bit float (little-endian) @@ -288,6 +286,6 @@ class SterzoConstants { static const String CHALLENGE_CODES_URL = 'https://github.com/zacharyedwardbull/pycycling/raw/refs/heads/master/pycycling/data/sterzo-challenge-codes.dat'; - // Filename for cached challenge codes - static const String CACHE_FILENAME = 'sterzo_challenge_codes.dat'; + // Cache key for SharedPreferences + static const String CACHE_KEY = 'elite_sterzo_challenge_codes'; } diff --git a/pubspec.yaml b/pubspec.yaml index bbb5c58..983012f 100755 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -32,7 +32,6 @@ dependencies: keypress_simulator: path: keypress_simulator/packages/keypress_simulator shared_preferences: ^2.5.3 - path_provider: ^2.1.5 flex_color_scheme: ^8.3.0 accessibility: path: accessibility