Skip to content

Commit e30d817

Browse files
committed
fix(mac): add robust diagnostic logging for Perl adapter to debug execution flow
1 parent 66e835a commit e30d817

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

Mac/CarpeCast-Swift/MediaManager.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,20 @@ class MediaManager: ObservableObject {
9191

9292
let data = pipe.fileHandleForReading.readDataToEndOfFile()
9393
if let output = String(data: data, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines) {
94+
try? "Perl output: \(output)".write(toFile: "/tmp/perl_output.log", atomically: true, encoding: .utf8)
9495
if output == "nil" || output.isEmpty {
9596
completion(nil)
96-
} else {
97+
} else if output.components(separatedBy: "|||").count >= 6 {
9798
completion(output)
99+
} else {
100+
// Probably a perl error
101+
completion(nil)
98102
}
99103
} else {
100104
completion(nil)
101105
}
102106
} catch {
103-
print("Failed to run mac_nowplaying: \(error)")
107+
try? "Process error: \(error)".write(toFile: "/tmp/perl_output.log", atomically: true, encoding: .utf8)
104108
completion(nil)
105109
}
106110
}

Mac/CarpeCast-Swift/NowPlayingHelper.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,22 @@ public func run_helper() {
1717

1818
let MRMediaRemoteGetNowPlayingInfo = unsafeBitCast(pointer, to: MRMediaRemoteGetNowPlayingInfoFunction.self)
1919

20+
try? "Perl injected and MRMediaRemoteGetNowPlayingInfo loaded".write(toFile: "/tmp/perl_debug.log", atomically: true, encoding: .utf8)
21+
2022
let group = DispatchGroup()
2123
group.enter()
2224

2325
MRMediaRemoteGetNowPlayingInfo(DispatchQueue.main) { infoOpt in
2426
defer { group.leave() }
2527

2628
guard let info = infoOpt else {
29+
try? "infoOpt is nil".write(toFile: "/tmp/perl_debug.log", atomically: true, encoding: .utf8)
2730
print("nil")
2831
return
2932
}
3033

34+
try? "infoOpt received: \(info.keys)".write(toFile: "/tmp/perl_debug.log", atomically: true, encoding: .utf8)
35+
3136
let title = (info["kMRMediaRemoteNowPlayingInfoTitle"] as? String) ?? ""
3237
let artist = (info["kMRMediaRemoteNowPlayingInfoArtist"] as? String) ?? ""
3338
let album = (info["kMRMediaRemoteNowPlayingInfoAlbum"] as? String) ?? ""

0 commit comments

Comments
 (0)