Sync source edition with VCC Plus 3.7.0 build 63

This commit is contained in:
Brian Holman committed 2026-11-14 01:43:46 -07:00
1 parent c652a5276d
commit b2ecec4d87
86 files changed
+10519 -472

No files matched your search

+361 -37
View File
@@ -10,6 +10,7 @@ struct SoftwareLibraryView: View {
@State private var showAdvancedFilters = false
@State private var confirmingReturn = false
@State private var removingRelease: SoftwareLibraryRelease?
@State private var personalCoverDropTargeted = false
var body: some View {
VStack(spacing: 0) {
header
@@ -48,10 +49,10 @@ struct SoftwareLibraryView: View {
}
Divider()
HStack {
Text("Color Computer Archive software and VCC Plus-exclusive titles").font(.caption).foregroundStyle(.secondary)
Text("Color Computer Archive, creator submissions and your private software").font(.caption).foregroundStyle(.secondary)
Spacer()
if model.filtering { ProgressView().controlSize(.mini) }
Text(model.catalog.map { "\($0.titles.count.formatted()) titles · \($0.releaseCount.formatted()) editions" } ?? "")
Text(model.catalog.map { "Catalog: \($0.titles.count.formatted()) titles · \($0.releaseCount.formatted()) editions" } ?? "")
.font(.caption).foregroundStyle(.secondary)
}.padding(.horizontal, 16).padding(.vertical, 9)
}
@@ -65,6 +66,7 @@ struct SoftwareLibraryView: View {
if !model.isDiskCompanion { openWindow(id: "c-development") }
}
.modifier(SoftwareLibraryLaunchPresentation(model: model))
.modifier(SoftwareLibraryPersonalPresentation(model: model))
.environment(\.companionLibraryAccess, model.companionAccess)
.sheet(isPresented: $showManual) {
VStack(spacing: 0) {
@@ -82,7 +84,7 @@ struct SoftwareLibraryView: View {
} message: {
Text("This restarts the CoCo with the previous hardware and media assignments. It does not restore its previous program or memory. Unsaved media must be saved first.")
}
.onDisappear { Task { await model.state.flush() } }
.onDisappear { model.saveBrowseContext(); Task { await model.state.flush() } }
.alert("Remove from Library?", isPresented: Binding(get: { removingRelease != nil }, set: { if !$0 { removingRelease = nil } }), presenting: removingRelease) { release in
Button("Cancel", role: .cancel) { removingRelease = nil }
Button("Remove from Library") { Task { await model.removeInstallation(release.id) }; removingRelease = nil }
@@ -100,12 +102,13 @@ struct SoftwareLibraryView: View {
.accessibilityIdentifier("library-return-setup")
.disabled(model.launchBusy || model.installingReleaseID != nil)
}
libraryActions
HStack(spacing: 7) {
Image(systemName: "magnifyingglass").foregroundStyle(.secondary)
TextField("Search titles, authors, or keywords", text: $model.query.text)
TextField("Search titles, authors, or keywords", text: Binding(get: { model.query.text }, set: model.setSearchText))
.textFieldStyle(.plain).accessibilityLabel("Search software").accessibilityIdentifier("library-search")
if !model.query.text.isEmpty {
Button { model.query.text = "" } label: { Image(systemName: "xmark.circle.fill") }
Button { model.setSearchText("") } label: { Image(systemName: "xmark.circle.fill") }
.buttonStyle(.plain).help("Clear search").accessibilityLabel("Clear search")
}
}.padding(8).background(.quaternary.opacity(0.5), in: RoundedRectangle(cornerRadius: 8))
@@ -122,6 +125,7 @@ struct SoftwareLibraryView: View {
Text("My Library").font(.caption.weight(.semibold)).foregroundStyle(.secondary).padding(.top, 8)
scope("Favorites", icon: "heart", scope: .favorites, id: "favorites")
scope("Installed", icon: "internaldrive", scope: .installed, id: "installed")
scope("Personal Library", icon: "lock.rectangle.stack", scope: .personal, id: "personal")
}.padding(14)
Divider()
List {
@@ -156,6 +160,7 @@ struct SoftwareLibraryView: View {
}.buttonStyle(.plain).accessibilityIdentifier("library-scope-" + id)
}
private var heading: String {
if model.query.scope == .search { return "Search Results" }
if !model.query.softwareType.isEmpty { return SoftwareLibraryOwnedGame.categoryLabel(model.query.softwareType) }
if !model.query.category.isEmpty { return model.query.category.components(separatedBy: "/").last ?? "All Software" }
switch model.query.scope {
@@ -164,6 +169,8 @@ struct SoftwareLibraryView: View {
case .all: return "All Software"
case .favorites: return "Favorites"
case .installed: return "Installed"
case .personal: return "Personal Library"
case .search: return "Search Results"
}
}
private var browser: some View {
@@ -186,6 +193,14 @@ struct SoftwareLibraryView: View {
.help("Filter and sort").accessibilityLabel("Filter and sort").accessibilityIdentifier("library-filters")
.popover(isPresented: $showFilters, arrowEdge: .bottom) { ScrollView { filters.padding(18) }.frame(width: 370, height: showAdvancedFilters ? 460 : 340) }
}.padding(.horizontal, 16).padding(.top, 14)
if model.query.scope == .personal {
addPersonalSoftwareButton(id: "library-personal-add")
.padding(.horizontal, 16)
if model.isDiskCompanion {
Text("Add or edit personal software in VCC Plus. Your disk entries are available through the local connection.")
.font(.caption).foregroundStyle(.secondary).padding(.horizontal, 16)
}
}
if model.query.scope == .showcase {
Text("Software with cover art, labels and screenshots.")
.font(.callout).foregroundStyle(.secondary).padding(.horizontal, 16)
@@ -193,10 +208,8 @@ struct SoftwareLibraryView: View {
Text("A first selection to explore your CoCo. More guided picks will join the collection.")
.font(.callout).foregroundStyle(.secondary).padding(.horizontal, 16)
}
if !model.query.category.isEmpty || !model.query.softwareType.isEmpty {
Text(model.query.sort == .title
? "Curated titles appear first, alphabetically, followed by the alphabetical collection."
: "Curated titles appear first, alphabetically; the remaining titles use your selected sort.")
if let orderingCaption {
Text(orderingCaption)
.font(.caption).foregroundStyle(.secondary).padding(.horizontal, 16)
}
if !activeFilters.isEmpty {
@@ -206,9 +219,19 @@ struct SoftwareLibraryView: View {
Button("Clear filters") { model.clearFilters() }.controlSize(.small)
}.padding(.horizontal, 16)
}
if model.loading {
if let error = model.error, hasPersonalResults {
HStack(alignment: .top, spacing: 8) {
VStack(alignment: .leading, spacing: 3) {
Label("Catalog unavailable", systemImage: "exclamationmark.triangle")
Text(error).font(.caption).textSelection(.enabled)
Text("Your personal software is still available.").font(.caption)
}.foregroundStyle(.secondary).frame(maxWidth: .infinity, alignment: .leading)
Button("Retry") { Task { await model.load() } }.disabled(model.loading)
}.padding(.horizontal, 16).accessibilityIdentifier("library-catalog-unavailable-notice")
}
if model.loading && !hasPersonalResults {
Spacer(); ProgressView("Opening the library…").frame(maxWidth: .infinity); Spacer()
} else if let error = model.error {
} else if let error = model.error, !hasPersonalResults {
ContentUnavailableView { Label("Library unavailable", systemImage: "books.vertical") } description: { Text(error) } actions: {
Button("Try Again") { Task { await model.load() } }
}
@@ -224,19 +247,76 @@ struct SoftwareLibraryView: View {
model.selection = value
}
})) {
TableColumn("Title", value: \.name).width(min: 140, ideal: 240)
TableColumn("Title") { row in
HStack(spacing: 6) {
Text(row.name).lineLimit(2)
.accessibilityLabel(row.name + (row.isPersonal ? ", Personal Library" : ""))
.accessibilityIdentifier("library-table-title-" + row.id)
if row.isPersonal { personalBadge }
}
.accessibilityElement(children: .contain)
}.width(min: 140, ideal: 240)
TableColumn("Format", value: \.formats).width(min: 65, ideal: 95)
TableColumn("Size", value: \.size).width(55)
}.accessibilityLabel("Software titles")
.background(SoftwareLibraryScrollTracker(ids: model.rows.map(\.id), table: true,
restoreID: model.browseTopID, restoreOffset: model.browseOffset, changed: model.rememberBrowsePosition))
} else {
ScrollView {
LazyVGrid(columns: [GridItem(.adaptive(minimum: 155, maximum: 215), spacing: 18)], alignment: .leading, spacing: 22) {
ForEach(model.rows) { row in shelfCard(row) }
LazyVStack(alignment: .leading, spacing: 18) {
if hasPersonalAndCatalog {
shelfHeading("Personal Library", icon: "lock.fill")
shelfGrid(model.rows.filter(\.isPersonal))
shelfHeading("Catalog", icon: "books.vertical")
shelfGrid(model.rows.filter { !$0.isPersonal })
} else {
shelfGrid(model.rows)
}
}.padding(16)
}.background(Color.primary.opacity(0.018))
.background(SoftwareLibraryScrollTracker(ids: model.rows.map(\.id), table: false,
restoreID: model.browseTopID, restoreOffset: model.browseOffset, changed: model.rememberBrowsePosition))
}
}
}
private var hasPersonalResults: Bool { model.rows.contains(where: \.isPersonal) }
private var hasPersonalAndCatalog: Bool {
hasPersonalResults && model.rows.contains { !$0.isPersonal }
}
private var orderingCaption: String? {
let curatedFirst = !model.query.category.isEmpty || !model.query.softwareType.isEmpty
if hasPersonalAndCatalog {
if !curatedFirst {
return model.query.sort == .title
? "Personal titles appear first, alphabetically. Catalog titles follow alphabetically."
: "Personal titles appear first, alphabetically. Catalog titles follow using your selected sort."
}
return model.query.sort == .title
? "Personal titles appear first, alphabetically. Catalog titles follow, with curated titles first, then the alphabetical collection."
: "Personal titles appear first, alphabetically. Catalog titles follow, with curated titles first; the remaining titles use your selected sort."
}
guard model.rows.contains(where: { !$0.isPersonal }), curatedFirst else { return nil }
return model.query.sort == .title
? "Curated titles appear first, alphabetically, followed by the alphabetical collection."
: "Curated titles appear first, alphabetically; the remaining titles use your selected sort."
}
private func shelfHeading(_ title: String, icon: String) -> some View {
Label(title, systemImage: icon).font(.headline).foregroundStyle(.secondary)
.accessibilityAddTraits(.isHeader)
}
private func shelfGrid(_ rows: [LibraryBrowseRow]) -> some View {
LazyVGrid(columns: [GridItem(.adaptive(minimum: 155, maximum: 215), spacing: 18)], alignment: .leading, spacing: 22) {
ForEach(rows) { row in shelfCard(row) }
}
}
private var personalBadge: some View {
Label("Personal", systemImage: "lock.fill").font(.caption2).foregroundStyle(.secondary)
.labelStyle(.titleAndIcon)
.fixedSize()
.accessibilityElement(children: .ignore)
.accessibilityLabel("Personal")
.accessibilityIdentifier("library-personal-badge")
}
private var activeFilters: [String] {
var labels: [String] = []
if !model.query.softwareType.isEmpty { labels.append(SoftwareLibraryOwnedGame.categoryLabel(model.query.softwareType)) }
@@ -251,20 +331,33 @@ struct SoftwareLibraryView: View {
}
private var searchIsActive: Bool { !model.query.text.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty }
private var narrowed: Bool { searchIsActive || !activeFilters.isEmpty || !model.query.category.isEmpty }
private var personalLibraryIsEmpty: Bool {
#if !VCC_COMPANION_CLIENT
return !model.isDiskCompanion && model.query.scope == .personal && model.personalEntries.isEmpty
#else
return false
#endif
}
private var emptyState: some View {
ContentUnavailableView {
Label(!narrowed && model.query.scope == .installed ? "Your software will live here" : !narrowed && model.query.scope == .favorites ? "Keep your favorites close" : "No matching titles", systemImage: model.query.scope == .favorites ? "heart" : "books.vertical")
Label(personalLibraryIsEmpty ? "Add your first software" : !narrowed && model.query.scope == .installed ? "Your software will live here" : !narrowed && model.query.scope == .favorites ? "Keep your favorites close" : "No matching titles", systemImage: personalLibraryIsEmpty ? "lock.rectangle.stack" : model.query.scope == .favorites ? "heart" : "books.vertical")
} description: {
if model.catalog?.releaseCount == 0 { Text("This development build has an empty catalog. Build with a prepared Software Library catalog to browse software.").accessibilityIdentifier("library-catalog-empty") }
if personalLibraryIsEmpty { Text("Add a folder, ZIP, or CoCo media files to your private library on this Mac. Your originals stay untouched; nothing is uploaded or run.") }
else if model.query.scope != .personal && model.catalog?.releaseCount == 0 { Text("This development build has an empty catalog. Build with a prepared Software Library catalog to browse software.").accessibilityIdentifier("library-catalog-empty") }
else if narrowed { Text(searchIsActive ? "No titles match “\(model.query.text)” in this selection. Clear the search or adjust your filters." : "No titles match these filters. Try clearing them or choosing another category.") }
else if model.query.scope == .installed { Text("Choose a title and Install Only to keep a copy on your Mac. Your running CoCo session will stay as it is.") }
else if model.query.scope == .favorites { Text("Choose the heart beside a title to add it to your collection.") }
else { Text("Try a different search, category, or filter.") }
} actions: {
if searchIsActive {
Button("Clear Search") { model.query.text = "" }.accessibilityIdentifier("library-empty-clear-search")
if personalLibraryIsEmpty {
addPersonalSoftwareButton(id: "library-personal-add-first")
.buttonStyle(.borderedProminent)
} else {
if searchIsActive {
Button("Clear Search") { model.setSearchText("") }.accessibilityIdentifier("library-empty-clear-search")
}
Button("Browse All Titles") { model.query = LibraryBrowseQuery(scope: .all) }
}
Button("Browse All Titles") { model.query = LibraryBrowseQuery(scope: .all) }
}
}
private var filters: some View {
@@ -337,10 +430,13 @@ struct SoftwareLibraryView: View {
Text(row.name).font(.callout.weight(.medium)).lineLimit(2).frame(maxWidth: .infinity, alignment: .leading)
if model.state.isFavorite(row.id) { Image(systemName: "heart.fill").font(.caption).foregroundStyle(.pink) }
}
Text(row.formats).font(.caption).foregroundStyle(.secondary).lineLimit(1)
HStack {
Text(row.formats).font(.caption).foregroundStyle(.secondary).lineLimit(1)
if row.isPersonal { personalBadge }
}
}.padding(4).contentShape(Rectangle())
}.buttonStyle(.plain).accessibilityIdentifier("library-title-" + row.id)
.accessibilityLabel(row.name + ", " + row.formats).help(row.name)
.accessibilityLabel(row.name + (row.isPersonal ? ", Personal Library" : "") + ", " + row.formats).help(row.name)
}
@ViewBuilder private var detail: some View {
if let row = model.selectedRow, let release = model.selectedRelease {
@@ -358,11 +454,15 @@ struct SoftwareLibraryView: View {
.accessibilityIdentifier("library-favorite")
}
if let error = model.state.saveError { Label(error, systemImage: "exclamationmark.triangle").font(.callout).foregroundStyle(.orange) }
SoftwareLibraryArtworkView(
asset: release.assets.first(where: { SoftwareLibraryArtworkCache.canDisplay($0) }),
cacheDirectory: model.artworkDirectory,
softwareType: LibraryBrowseQuery.type(of: release, related: row.title.releases))
.frame(maxWidth: .infinity).frame(height: 200)
detailArtwork(release, title: row.title)
if release.isPersonal {
Label("Personal Library — Private on This Mac", systemImage: "lock.fill").font(.headline)
.accessibilityIdentifier("library-personal")
}
if release.isDirectSubmission {
Label("Creator-submitted software", systemImage: "person.crop.square").font(.headline)
if let author = release.metadata["author"].string { Text("By " + author).font(.callout) }
}
if let owned = release.ownedGame {
Label("VCC Plus-exclusive", systemImage: "sparkles").font(.headline)
.accessibilityIdentifier("library-exclusive")
@@ -408,11 +508,13 @@ struct SoftwareLibraryView: View {
}
}
assetLinks(release)
relatedReferences(release)
DisclosureGroup("Edition & source details") { metadata(release, title: row.title).padding(.top, 10) }
.font(.callout)
if release.ownedGame == nil {
if release.isArchive {
Link(destination: release.sourceURL.deletingLastPathComponent().appendingPathComponent("", isDirectory: true)) { Label("View on Color Computer Archive", systemImage: "arrow.up.right.square") }
}
if release.isDirectSubmission { Link("Visit Project", destination: URL(string: release.metadata["project_url"].string ?? "") ?? release.sourceURL) }
Text(model.isDiskCompanion
? "Insert Disk creates a separate writable copy for DriveWire. Choose its drive slot, then follow the loading instructions on your real CoCo."
: "Play previews the recommended setup before restarting. You can also use the Media menu to mount installed files yourself.")
@@ -423,6 +525,59 @@ struct SoftwareLibraryView: View {
ContentUnavailableView("Choose a title", systemImage: "book.closed", description: Text("Explore its editions, loading instructions, and manuals."))
}
}
private func artwork(_ release: SoftwareLibraryRelease, title: SoftwareLibraryTitle) -> some View {
SoftwareLibraryArtworkView(asset: release.assets.first(where: { SoftwareLibraryArtworkCache.canDisplay($0) }),
cacheDirectory: model.artworkDirectory, softwareType: LibraryBrowseQuery.type(of: release, related: title.releases))
.frame(maxWidth: .infinity).frame(height: 200)
}
@ViewBuilder private func detailArtwork(_ release: SoftwareLibraryRelease, title: SoftwareLibraryTitle) -> some View {
#if !VCC_COMPANION_CLIENT
if !model.isDiskCompanion, let entry = model.selectedPersonalEntry {
VStack(alignment: .leading, spacing: 8) {
artwork(release, title: title)
.overlay(RoundedRectangle(cornerRadius: 9).strokeBorder(personalCoverDropTargeted ? Color.accentColor : .clear, lineWidth: 3))
.contentShape(Rectangle())
.overlay {
PersonalCoverFileDropTarget(enabled: model.canEditPersonal && model.personalEditor == nil,
isTargeted: $personalCoverDropTargeted) { urls in
model.acceptPersonalCoverDrop(urls, for: entry)
}.frame(maxWidth: .infinity, maxHeight: .infinity).accessibilityHidden(true)
}
.accessibilityIdentifier("library-personal-cover")
HStack {
Menu {
Button("Choose Cover Image…", systemImage: "photo") { model.choosePersonalCover(for: entry) }
let imported = entry.files.filter { $0.kind == "cover" }
if !imported.isEmpty {
Menu("Use Imported Image") {
ForEach(imported) { file in
Button(URL(fileURLWithPath: file.path).lastPathComponent) {
model.selectPersonalCover(.imported(file.path), for: entry)
}
}
}
}
Button("Remove Cover", systemImage: "photo.badge.minus") {
model.selectPersonalCover(.categoryIcon, for: entry)
}.disabled(!release.assets.contains(where: { SoftwareLibraryArtworkCache.canDisplay($0) }))
} label: { Label("Cover Image", systemImage: "photo") }
.disabled(!model.canEditPersonal || model.personalEditor != nil)
.accessibilityIdentifier("library-personal-cover-menu")
if model.personalSaving { ProgressView().controlSize(.small) }
}
Text("Drop an image onto the cover, or choose one. It stays private on this Mac.")
.font(.caption).foregroundStyle(.secondary)
#if VCC_UI_TESTING
if ProcessInfo.processInfo.environment["VCC_COVER_DRAG_SOURCE"] != nil {
PersonalCoverFileDragFixture().frame(width: 120, height: 45)
}
#endif
}
} else { artwork(release, title: title) }
#else
artwork(release, title: title)
#endif
}
private func sourceCard(_ release: SoftwareLibraryRelease, owned: SoftwareLibraryOwnedGame) -> some View {
SecondaryCard {
Label("Learn from the source", systemImage: "curlybraces").font(.headline)
@@ -460,6 +615,8 @@ struct SoftwareLibraryView: View {
.font(.caption).foregroundStyle(.secondary)
}
Button("Cancel", role: .cancel) { model.cancelInstallation() }.accessibilityIdentifier("library-cancel-install")
} else if release.isPersonal && !model.isDiskCompanion {
personalActions(release)
} else if let installed = model.state.installedReleases[release.id] {
Label("Installed", systemImage: "checkmark.circle.fill").font(.headline).foregroundStyle(.green)
.accessibilityIdentifier("library-install-status")
@@ -467,8 +624,12 @@ struct SoftwareLibraryView: View {
Text("Your writable media is ready. The original files are kept separately.").font(.callout)
Button { NSWorkspace.shared.open(installed.workingDirectory) } label: { Label("Show Files in Finder", systemImage: "folder") }
.accessibilityIdentifier("library-reveal-install")
Button("Remove from Library…") { removingRelease = release }
.disabled(model.launchBusy || model.hasPendingLaunch || model.installingReleaseID != nil).accessibilityIdentifier("library-remove-install")
if release.isPersonal && model.isDiskCompanion {
Text("Manage this personal entry in VCC Plus.").font(.caption).foregroundStyle(.secondary)
} else {
Button("Remove from Library…") { removingRelease = release }
.disabled(model.launchBusy || model.hasPendingLaunch || model.installingReleaseID != nil).accessibilityIdentifier("library-remove-install")
}
} else {
if model.canLaunch { playButton(release, installed: false) }
Button { model.install(release) } label: { Label(model.installationErrors[release.id] == nil ? "Install Only" : "Try Again", systemImage: "arrow.down.circle") }
@@ -534,7 +695,7 @@ struct SoftwareLibraryView: View {
VStack(alignment: .leading, spacing: 6) {
Label("Controls", systemImage: "gamecontroller").font(.subheadline.weight(.medium))
ForEach(controls.keys.sorted(), id: \.self) { key in
Text(release.setup.controlDescription(key, source: release.ownedGame == nil ? "the Archive" : "the project")).font(.callout).textSelection(.enabled)
Text(release.setup.controlDescription(key, source: release.isPersonal ? "your setup" : release.isArchive ? "the Archive" : "the author")).font(.callout).textSelection(.enabled)
.accessibilityIdentifier("library-controls-" + key)
}
}
@@ -557,7 +718,7 @@ struct SoftwareLibraryView: View {
.accessibilityIdentifier("library-manual-" + manual.id)
} else {
Link(destination: manual.sourceURL) { Label(manual.name, systemImage: "arrow.up.right.square") }
.font(.callout).help(release.ownedGame == nil ? "Open this document on Color Computer Archive" : "Open this project document")
.font(.callout).help(release.isArchive ? "Open this document on Color Computer Archive" : "Open this project document")
}
}
}
@@ -578,18 +739,23 @@ struct SoftwareLibraryView: View {
}
if let publisher = release.publisher { LabeledContent("Publisher", value: publisher) }
if let year = release.year { LabeledContent("Year", value: String(year)) }
LabeledContent("Download", value: ByteCountFormatter.string(fromByteCount: release.byteSize, countStyle: .file))
LabeledContent(release.isPersonal ? "Retained files" : "Download", value: ByteCountFormatter.string(fromByteCount: release.byteSize, countStyle: .file))
if release.isDirectSubmission {
if let author = release.metadata["author"].string { LabeledContent("Author", value: author) }
if let license = release.metadata["license"].string { LabeledContent("License", value: license) }
if let version = release.metadata["software_version"].string { LabeledContent("Software version", value: version) }
}
if let owned = release.ownedGame {
LabeledContent("Author", value: owned.author)
LabeledContent("License", value: owned.license)
}
LabeledContent(release.ownedGame == nil ? "Archive modified" : "Project modified", value: release.modifiedAt ?? "Unknown")
if release.ownedGame == nil, release.modifiedAt != nil, release.modifiedTimezone == nil || release.modifiedTimezone == "unspecified" {
LabeledContent(release.isArchive ? "Archive modified" : "Modified", value: release.modifiedAt ?? "Unknown")
if release.isArchive, release.modifiedAt != nil, release.modifiedTimezone == nil || release.modifiedTimezone == "unspecified" {
Text("Archive date; time zone not specified.").font(.caption).foregroundStyle(.secondary)
}
LabeledContent("Loading evidence", value: release.ownedGame == nil ? release.setup.statusLabel : "Project-provided loading instructions")
LabeledContent("Loading evidence", value: release.isPersonal ? "User-provided private setup" : release.ownedGame == nil ? release.setup.statusLabel : "Project-provided loading instructions")
Text(release.setup.validationScope.map { "VCC Plus check: " + $0.replacingOccurrences(of: "-", with: " ") } ?? "Not individually tested in VCC Plus.")
if release.ownedGame == nil && title.releases.count > 1 && title.identityStatus == "suggested" { Text("Related editions are grouped from Archive names; their contents may differ.") }
if release.isArchive && title.releases.count > 1 && title.identityStatus == "suggested" { Text("Related editions are grouped from Archive names; their contents may differ.") }
if !release.videoModes.isEmpty { Text("Video: " + release.videoModes.joined(separator: ", ")) }
if let note = release.setup.curationNote { Text(note) }
if !release.assets.isEmpty {
@@ -597,7 +763,8 @@ struct SoftwareLibraryView: View {
Text("Artwork & manual sources").fontWeight(.medium)
ForEach(release.assets) { asset in
VStack(alignment: .leading, spacing: 3) {
Link(asset.name, destination: asset.sourceURL)
if asset.matchStatus == "personal" { Text(asset.name) }
else { Link(asset.name, destination: asset.sourceURL) }
Text(asset.credit).foregroundStyle(.secondary)
if asset.matchStatus == "candidate" { Text("Suggested match from Archive names; corrections are welcome.").font(.caption).foregroundStyle(.secondary) }
}
@@ -621,6 +788,65 @@ struct SoftwareLibraryView: View {
private func systemName(_ value: String) -> String {
switch value { case "coco3": return "Color Computer 3"; case "coco1-2", "coco1/2": return "Color Computer 1/2"; case "unknown": return "Not specified"; default: return value }
}
@ViewBuilder private func addPersonalSoftwareButton(id: String) -> some View {
#if !VCC_COMPANION_CLIENT
if !model.isDiskCompanion {
Button("Add Software…", systemImage: "folder.badge.plus") { model.choosePersonalSoftware() }
.disabled(!model.canEditPersonal || model.personalEditor != nil)
.help("Add software to your private Personal Library")
.accessibilityIdentifier(id)
}
#endif
}
@ViewBuilder private var libraryActions: some View {
#if !VCC_COMPANION_CLIENT
if !model.isDiskCompanion {
Menu {
Button("Add Personal Software…", systemImage: "folder.badge.plus") { model.choosePersonalSoftware() }
.disabled(!model.canEditPersonal)
Button("Submit Software…", systemImage: "paperplane") {
NSWorkspace.shared.open(URL(string: "https://vccplus.brianholman.com/software/submit/")!)
}
} label: { Image(systemName: "ellipsis.circle") }
.help("Library Actions").accessibilityLabel("Library Actions").accessibilityIdentifier("library-actions")
}
#endif
}
@ViewBuilder private func personalActions(_ release: SoftwareLibraryRelease) -> some View {
#if !VCC_COMPANION_CLIENT
if let entry = model.selectedPersonalEntry {
Label("Private copy", systemImage: "lock.fill").font(.headline)
if model.canLaunch, release.mediaType != "binary" { playButton(release, installed: true) }
Text(release.mediaType == "binary" ? "Open the working folder, then use File → Load Binary to load this program deliberately." : "Your writable media and retained originals are kept separately. Nothing is uploaded.").font(.caption).foregroundStyle(.secondary)
Button("Edit Details…", systemImage: "pencil") { model.editPersonal(entry) }.disabled(!model.canEditPersonal)
Button("Show Files in Finder", systemImage: "folder") { NSWorkspace.shared.open(model.personalDirectory(entry).appendingPathComponent("Working")) }
Button("Remove from Library…") { removingRelease = release }
.disabled(model.launchBusy || model.hasPendingLaunch)
}
#endif
}
@ViewBuilder private func relatedReferences(_ release: SoftwareLibraryRelease) -> some View {
#if !VCC_COMPANION_CLIENT
if !model.isDiskCompanion, !release.relatedArchiveReferences.isEmpty {
VStack(alignment: .leading, spacing: 8) {
Text("Guides & References").font(.headline)
ForEach(release.relatedArchiveReferences) { reference in
Button {
ArchiveLibraryNavigation.shared.open(documentID: reference.documentID, location: reference.page,
expectedSHA256: reference.sha256)
openWindow(id: "archive-library")
} label: {
VStack(alignment: .leading, spacing: 2) {
Label(reference.title, systemImage: "doc.text.magnifyingglass")
Text(reference.role + (reference.spoiler ? " · Contains spoilers" : "") + (reference.page.map { " · Page \($0)" } ?? ""))
.font(.caption).foregroundStyle(.secondary)
}
}.buttonStyle(.link).help("Open in Archive Library").accessibilityIdentifier("library-reference-" + reference.id)
}
}
}
#endif
}
private func profileName(_ value: String) -> String {
switch value { case "rom-cartridge": return "ROM Cartridge"; case "disk-basic": return "Disk BASIC"; case "hard-drive-basic", "hard-basic": return "Hard Drive BASIC"; case "coco-sdc": return "CoCo SDC"; case "nitros9": return "NitrOS-9"; default: return value.replacingOccurrences(of: "-", with: " ").capitalized }
}
@@ -642,3 +868,101 @@ private struct SoftwareLibraryLaunchPresentation: ViewModifier {
#endif
}
}
/// Observes the actual native clip view without taking over its delegate or
/// sending pointer events. Restoration runs once, after content is installed.
private struct SoftwareLibraryScrollTracker: NSViewRepresentable {
let ids: [String]
let table: Bool
let restoreID: String?
let restoreOffset: Double
let changed: (String?, Double) -> Void
func makeCoordinator() -> Coordinator { Coordinator() }
func makeNSView(context: Context) -> NSView { NSView() }
func updateNSView(_ view: NSView, context: Context) {
context.coordinator.ids = ids; context.coordinator.table = table; context.coordinator.changed = changed
context.coordinator.restoreID = restoreID; context.coordinator.restoreOffset = restoreOffset
context.coordinator.attach(view)
context.coordinator.refreshRestoration()
}
static func dismantleNSView(_ view: NSView, coordinator: Coordinator) { coordinator.clear() }
final class Coordinator {
var ids: [String] = [], table = false
var restoreID: String?, restoreOffset: Double = 0
var changed: ((String?, Double) -> Void)?
private var token: NSObjectProtocol?
private weak var scroll: NSScrollView?
private var restored = false, attaching = false
private var attachAttempts = 0, restoreAttempts = 0
func clear() { if let token { NotificationCenter.default.removeObserver(token) }; token = nil; scroll = nil; restored = false }
func attach(_ marker: NSView) {
guard scroll == nil, !attaching else { return }
attaching = true
DispatchQueue.main.async { [weak self, weak marker] in
guard let self else { return }; self.attaching = false
guard let marker, marker.window != nil else { return }
var ancestor: NSView? = marker.superview
let target = marker.convert(marker.bounds, to: nil)
for _ in 0..<6 {
guard let root = ancestor else { break }
func descendants(_ view: NSView) -> [NSScrollView] {
(view as? NSScrollView).map { [$0] } ?? view.subviews.flatMap(descendants)
}
if let match = descendants(root).first(where: { candidate in
let frame = candidate.convert(candidate.bounds, to: nil)
return target.width > 0 && target.height > 0 && frame.intersection(target).width > target.width * 0.8 &&
frame.intersection(target).height > target.height * 0.8 && (!self.table || candidate.documentView is NSTableView)
}) {
self.scroll = match; match.contentView.postsBoundsChangedNotifications = true
self.token = NotificationCenter.default.addObserver(forName: NSView.boundsDidChangeNotification,
object: match.contentView, queue: .main) { [weak self] _ in self?.record() }
DispatchQueue.main.async { [weak self] in self?.restore() }
return
}
ancestor = root.superview
}
if self.attachAttempts < 20 {
self.attachAttempts += 1
DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) { [weak self, weak marker] in
if let marker { self?.attach(marker) }
}
}
}
}
func refreshRestoration() {
guard !restored else { return }
DispatchQueue.main.async { [weak self] in self?.restore() }
}
private func restore() {
guard !restored, !ids.isEmpty, let scroll, let document = scroll.documentView else { return }
if document.bounds.height <= 0 || scroll.contentView.bounds.height <= 0 || ((document as? NSTableView).map { $0.numberOfRows < ids.count } ?? false) {
if restoreAttempts < 20 {
restoreAttempts += 1
DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) { [weak self] in self?.restore() }
}
return
}
restored = true
let range = max(0, document.bounds.height - scroll.contentView.bounds.height)
var y = CGFloat(max(0, min(restoreOffset, 1))) * range
if let table = document as? NSTableView, let id = restoreID, let index = ids.firstIndex(of: id), index < table.numberOfRows {
let row = table.rect(ofRow: index); y = row.minY + CGFloat(restoreOffset) * row.height
}
scroll.contentView.scroll(to: NSPoint(x: 0, y: min(max(0,y), range))); scroll.reflectScrolledClipView(scroll.contentView)
}
private func record() {
guard restored, let scroll, let document = scroll.documentView else { return }
let y = scroll.contentView.bounds.minY
if let table = document as? NSTableView {
let index = table.row(at: NSPoint(x: 1, y: y))
if ids.indices.contains(index) {
let row = table.rect(ofRow: index)
changed?(ids[index], Double((y - row.minY) / max(1,row.height))); return
}
}
let range = max(1, document.bounds.height - scroll.contentView.bounds.height)
changed?(nil, Double(y/range))
}
deinit { if let token { NotificationCenter.default.removeObserver(token) } }
}
}