Files
VirtualBuddy/VirtualUI/Source/Library/XcodeDebugSetup.swift
2026-11-20 16:12:23 -03:00

72 lines
2.8 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import AppKit
import SwiftUI
import Combine
import VirtualCore
@MainActor
public enum XcodeDebugSetup {
private static var observer: AnyCancellable?
private static var window: NSPanel?
public static func observeCachePreparation() {
observer = DebugSymbolCache.shared.$activities.map { !$0.isEmpty }.removeDuplicates().receive(on: RunLoop.main).sink { preparing in
if preparing {
let panel = NSPanel(contentRect: .init(x: 0, y: 0, width: 420, height: 150), styleMask: [.titled, .closable], backing: .buffered, defer: false)
panel.title = "Preparing Xcode Debugging Symbols"
panel.contentView = NSHostingView(rootView: DebugCacheProgress())
panel.center()
panel.orderFrontRegardless()
window = panel
} else {
window?.orderOut(nil)
window = nil
}
}
}
}
private struct DebugCacheProgress: View {
@ObservedObject private var cache = DebugSymbolCache.shared
var body: some View {
VStack(alignment: .leading, spacing: 12) {
ForEach(cache.activities) { activity in
Text("macOS " + activity.system).font(.headline)
ProgressView(value: activity.fraction) { Text(activity.detail) }
Button("Cancel") { cache.cancel(activity.id) }
}
}
.padding()
.frame(minWidth: 400)
}
}
struct DebugCacheSettings: View {
let showWhenEmpty: Bool
@ObservedObject private var cache = DebugSymbolCache.shared
var body: some View {
if showWhenEmpty || !cache.entries.isEmpty {
Section {
if cache.entries.isEmpty {
Text("No cached guest symbols").foregroundStyle(.secondary)
}
ForEach(cache.entries) { entry in
HStack {
VStack(alignment: .leading) {
Text("macOS " + entry.system)
Text(ByteCountFormatter.string(fromByteCount: entry.bytes, countStyle: .file)).foregroundStyle(.secondary)
}
Spacer()
Button("Delete") {
do { try cache.remove(entry) } catch { NSApp.presentError(error) }
}.disabled(cache.isInUse(entry))
}
}
} header: {
Text("Xcode Debugging Symbols", bundle: #bundle)
} footer: {
Text("Xcode uses these symbols to show function names from the VM’s system libraries in stack traces. If you delete them, VirtualBuddy rebuilds the cache the next time you debug that macOS build.", bundle: #bundle)
}
}
}
}