mirror of
https://github.com/insidegui/VirtualBuddy.git
synced 2026-12-02 00:50:32 +08:00
* Redesign settings screen with more traditional tabs and layout * Add subtle rounded border around lists in settings, align first list item title with label
83 lines
3.2 KiB
Swift
83 lines
3.2 KiB
Swift
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 {
|
||
SettingsDivider()
|
||
|
||
SettingsRow("Debugging symbols:") {
|
||
SettingsItemList {
|
||
if cache.entries.isEmpty {
|
||
Text("No cached guest symbols")
|
||
.settingsListItemTitle()
|
||
} else {
|
||
ForEach(cache.entries) { entry in
|
||
HStack {
|
||
VStack(alignment: .leading) {
|
||
Text("macOS " + entry.system)
|
||
.settingsListItemTitle()
|
||
Text(entry.bytes.formatted(.byteCount(style: .file)))
|
||
.font(.callout)
|
||
.foregroundStyle(.secondary)
|
||
}
|
||
Spacer()
|
||
Button("Delete") {
|
||
do {
|
||
try cache.remove(entry)
|
||
} catch {
|
||
NSApp.presentError(error)
|
||
}
|
||
}
|
||
.disabled(cache.isInUse(entry))
|
||
}
|
||
}
|
||
}
|
||
}
|
||
SettingsCaption("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.")
|
||
}
|
||
}
|
||
}
|
||
}
|