Skip to content

Commit 542a747

Browse files
committed
fix: Complete Pocket WAL integration with proper file storage
- Fix WAL storage to use disk storage instead of sdcard - Add initializeWals() public method to reload WALs after saving - Force reload WALs in phone sync service after adding Pocket recordings - Add DeviceType.pocket case to device image switch - WALs now appear correctly in Sync page after download
1 parent a9c2dd8 commit 542a747

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

app/lib/pages/pocket/pocket_device_page.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,14 @@ class _PocketDevicePageState extends State<PocketDevicePage> {
179179
device: widget.device,
180180
);
181181

182-
// Add WALs to the service
182+
// Save WALs to file
183183
await PocketWalService.addWalsToService(wals);
184184

185+
// Force reload WALs in the phone sync service
186+
final walService = ServiceManager.instance().wal;
187+
await walService.getSyncs().phone.initializeWals();
188+
debugPrint('Reloaded WALs in phone sync service');
189+
185190
if (!mounted) return;
186191

187192
// Step 3: Trigger sync

app/lib/services/pocket_wal_service.dart

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ class PocketWalService {
2727
final directory = await getApplicationDocumentsDirectory();
2828
final cleanDeviceId = device.id.replaceAll(RegExp(r'[^a-zA-Z0-9]'), "").toLowerCase();
2929
final mp3Filename = 'pocket_${cleanDeviceId}_$timerStart.mp3';
30-
final filePath = '${directory.path}/$mp3Filename';
30+
final fullPath = '${directory.path}/$mp3Filename';
3131

32-
final file = File(filePath);
32+
final file = File(fullPath);
3333
await file.writeAsBytes(mp3Data);
3434

35-
debugPrint('Saved Pocket MP3: $filePath');
35+
debugPrint('Saved Pocket MP3: $fullPath');
3636

3737
// Create WAL object
3838
// Note: We use opus codec as a placeholder since the backend will handle MP3
@@ -44,8 +44,8 @@ class PocketWalService {
4444
sampleRate: 16000, // Standard sample rate
4545
channel: 1, // Mono
4646
status: WalStatus.miss, // Mark as missing/ready to sync
47-
storage: WalStorage.sdcard, // Mark as external source (like SD card)
48-
filePath: filePath,
47+
storage: WalStorage.disk, // Store as phone storage (not SD card)
48+
filePath: mp3Filename, // Store only filename, not full path
4949
device: device.id,
5050
deviceModel: 'Pocket',
5151
storageOffset: 0,
@@ -85,26 +85,32 @@ class PocketWalService {
8585

8686
/// Add WAL files to the WAL service for syncing
8787
static Future<void> addWalsToService(List<Wal> wals) async {
88+
debugPrint('addWalsToService: Adding ${wals.length} WALs');
89+
8890
// Load existing WALs
8991
final existingWals = await WalFileManager.loadWals();
92+
debugPrint('addWalsToService: Loaded ${existingWals.length} existing WALs');
9093

9194
// Add new WALs (avoid duplicates by checking timerStart and device)
9295
final updatedWals = List<Wal>.from(existingWals);
96+
int addedCount = 0;
9397
for (final wal in wals) {
9498
final isDuplicate = existingWals.any(
9599
(existing) => existing.device == wal.device && existing.timerStart == wal.timerStart,
96100
);
97101
if (!isDuplicate) {
98102
updatedWals.add(wal);
99-
debugPrint('Added Pocket WAL to service: ${wal.id}');
103+
addedCount++;
104+
debugPrint('Added Pocket WAL: device=${wal.device}, timerStart=${wal.timerStart}, filePath=${wal.filePath}');
100105
} else {
101-
debugPrint('Skipped duplicate Pocket WAL: ${wal.id}');
106+
debugPrint('Skipped duplicate Pocket WAL: device=${wal.device}, timerStart=${wal.timerStart}');
102107
}
103108
}
104109

105110
// Save updated WALs
111+
debugPrint('addWalsToService: Saving ${updatedWals.length} total WALs (added $addedCount new)');
106112
await WalFileManager.saveWals(updatedWals);
107-
debugPrint('Saved ${wals.length} Pocket WALs to service');
113+
debugPrint('addWalsToService: Successfully saved WALs');
108114
}
109115

110116
/// Parse timestamp from Pocket recording format (YYYYMMDDHHMMSS)

app/lib/services/wals.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,12 +676,17 @@ class LocalWalSync implements IWalSync {
676676
});
677677
}
678678

679-
Future<void> _initializeWals() async {
679+
Future<void> initializeWals() async {
680680
await WalFileManager.init();
681681
_wals = await WalFileManager.loadWals();
682682
debugPrint("wal service start: ${_wals.length}");
683683
listener.onWalUpdated();
684684
}
685+
686+
// Keep old private method for backward compatibility
687+
Future<void> _initializeWals() async {
688+
await initializeWals();
689+
}
685690

686691
@override
687692
Future stop() async {

0 commit comments

Comments
 (0)