知了 Cicada · 任何会议和直播的实时字幕、同声传译、AI 会议纪要,Mac、Windows、Linux、Android 免费开源。Live subtitles, interpreting and meeting notes for any call or stream, on Mac, Windows, Linux and Android.
Swift androidlinuxlive-captionsmacosmeeting-notesmenubar-appsimultaneous-interpretationspeech-recognitionsubtitlesswiftswiftuitranslationwindows
test(ios): ctl.sh drives a connected iPhone (commands, log, screenshot), and state logs memory and heat
wqugurue6ba4c04a4e5
diff --git a/ios/Sources/Cicada/Debug.swift b/ios/Sources/Cicada/Debug.swiftindex d1ff260..ae82b18 100644--- a/ios/Sources/Cicada/Debug.swift+++ b/ios/Sources/Cicada/Debug.swift@@ -1,5 +1,6 @@import SwiftUIimport UIKit+import os/// The iOS side of the Mac's `AppModel.debugCommand`. `ios/scripts/ctl.sh <cmd>` writes the command/// into the container's Caches/debug-command and posts a Darwin notification, which wakes us here;@@ -390,6 +391,7 @@ extension AppModel {case "importState":debugLog("import busy=\(importer.busy) phase=\(importer.phase) progress=\(String(format: "%.2f", importer.progress)) queue=\(importer.queue.count) current=\(importer.current?.id ?? "-")")case "state":+ debugLog("memory \(DeviceLoad.line)")debugLog("room running=\(room.isRunning) lines=\(room.lines.count) draft=\(room.draft.count) level=\(room.level) status=\(room.status) speaker=\(room.speakerMode) paused=\(room.paused) pip=\(pip.isActive) session=\(room.sessionID ?? "-")")debugLog("state tab=\(tab.rawValue) selection=\(selection ?? "-") page=\(recordPage) sessions=\(store.sessions.count) query=\(query) notesLang=\(notesLanguageCode(selection ?? store.sessions.first?.id ?? "")) undo=\(speakerUndo?.text ?? "-")")default:@@ -440,3 +442,21 @@ struct DevWindow: ViewModifier {private extension Array where Element == String {var splitPair: (String, String) { (first ?? "", count > 1 ? self[1] : "") }}++/// What the phone has left while listening: how much the app takes, how much more it may take before+/// iOS ends it, and how warm it runs. Logged by `state` so a real-device pass can show whether a+/// second recognizer (the record's) fits.+enum DeviceLoad {+ static var footprintMB: Int {+ var info = task_vm_info_data_t()+ var count = mach_msg_type_number_t(MemoryLayout<task_vm_info_data_t>.size / MemoryLayout<integer_t>.size)+ let r = withUnsafeMutablePointer(to: &info) {+ $0.withMemoryRebound(to: integer_t.self, capacity: Int(count)) { task_info(mach_task_self_, task_flavor_t(TASK_VM_INFO), $0, &count) }+ }+ return r == KERN_SUCCESS ? Int(info.phys_footprint / 1_048_576) : -1+ }+ static var line: String {+ let thermal = ["nominal", "fair", "serious", "critical"][ProcessInfo.processInfo.thermalState.rawValue]+ return "footprint=\(footprintMB)MB available=\(os_proc_available_memory() / 1_048_576)MB thermal=\(thermal)"+ }+}diff --git a/ios/scripts/ctl.sh b/ios/scripts/ctl.shindex 0956516..088b246 100755--- a/ios/scripts/ctl.sh+++ b/ios/scripts/ctl.sh@@ -1,9 +1,34 @@#!/usr/bin/env bash-# Sends debug commands to the dev build in a simulator (ios/Sources/Cicada/Debug.swift), the iOS-# counterpart of tools/lsctl: ios/scripts/ctl.sh [-d "<device>"] <cmd> [<cmd>...]+# Sends debug commands to the dev build (ios/Sources/Cicada/Debug.swift), the iOS counterpart of+# tools/lsctl: ios/scripts/ctl.sh [-d "<device>"] <cmd> [<cmd>...]+# A simulator gets them through the container and a Darwin notification. A connected iPhone or iPad+# (its UDID, as `xcrun devicectl list devices` prints it) gets each one as a cicada-dev://debug URL,+# which devicectl opens without the confirmation simctl's openurl asks for.+# ios/scripts/ctl.sh -d <UDID> --log [<lines>] the device's debug log, last 40 lines by default+# ios/scripts/ctl.sh -d <UDID> --shot <file.png> a screenshot of the deviceset -euo pipefailDEVICE=bootedif [[ ${1:-} == -d ]]; then DEVICE=$2; shift 2; fi-DATA=$(xcrun simctl get_app_container "$DEVICE" com.indaloop.cicada.dev data)+APP=com.indaloop.cicada.dev++if xcrun devicectl list devices 2>/dev/null | grep -v simulated | grep -q -- "$DEVICE"; then+ case ${1:-} in+ --log)+ tmp=$(mktemp -d)+ xcrun devicectl device copy from --device "$DEVICE" --domain-type appDataContainer \+ --domain-identifier "$APP" --source Library/Caches/livesubs-dev-debug.log \+ --destination "$tmp/log" >/dev/null+ tail -n "${2:-40}" "$tmp/log"; rm -rf "$tmp"; exit ;;+ --shot)+ xcrun devicectl device capture screenshot --device "$DEVICE" --destination "$2" >/dev/null; exit ;;+ esac+ for cmd in "$@"; do+ url="cicada-dev://debug?cmd=$(python3 -c 'import sys, urllib.parse as u; print(u.quote(sys.argv[1], safe=""))' "$cmd")"+ xcrun devicectl device process launch --device "$DEVICE" --payload-url "$url" "$APP" >/dev/null+ done+ exit+fi++DATA=$(xcrun simctl get_app_container "$DEVICE" $APP data)printf '%s\n' "$@" >> "$DATA/Library/Caches/debug-command"xcrun simctl spawn "$DEVICE" notifyutil -p com.indaloop.cicada.debug