// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown // SPDX-License-Identifier: GPL-3.0-or-later import AudioToolbox import Foundation /// What the app and the extension agree on: the App Group and the AU's identity. enum Spike { static let group = "group.cc.tiredsysadmin.ios.sizzlespike" /// 'aumu' / 'sSpk' / 'Tsys' — must match AU/Info.plist. static let desc = AudioComponentDescription( componentType: kAudioUnitType_MusicDevice, componentSubType: fourCC("sSpk"), componentManufacturer: fourCC("Tsys"), componentFlags: 0, componentFlagsMask: 0) static func fourCC(_ s: String) -> FourCharCode { s.utf8.reduce(0) { ($0 << 8) | FourCharCode($1) } } /// Writes `.txt` into the App Group container and reports every file in it, /// so each side shows what the other one wrote. static func probeGroup(as who: String) -> String { guard let dir = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: group) else { return "App Group \(group): NOT AVAILABLE (entitlement missing or not honoured)" } let stamp = ISO8601DateFormatter().string(from: Date()) let wrote = (try? "\(who) was here at \(stamp)\n".write(to: dir.appendingPathComponent("\(who).txt"), atomically: true, encoding: .utf8)) != nil var out = "App Group OK, \(who) write \(wrote ? "OK" : "FAILED")" let files = (try? FileManager.default.contentsOfDirectory(atPath: dir.path).sorted()) ?? [] for f in files where f.hasSuffix(".txt") { let text = (try? String(contentsOf: dir.appendingPathComponent(f), encoding: .utf8)) ?? "?" out += "\n \(f): \(text.trimmingCharacters(in: .whitespacesAndNewlines))" } return out } }