Skip to content

Commit 291ee75

Browse files
committed
~ Finally compiles
1 parent 9389920 commit 291ee75

10 files changed

Lines changed: 82 additions & 20 deletions

File tree

Cork/CorkApp.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ struct CorkApp: App
297297
let convertedMinimalPackage: BrewPackage? = BrewPackage(using: packageToPreview)
298298

299299
PackagePreview(packageToPreview: convertedMinimalPackage)
300-
.navigationTitle(packageToPreview?.name ?? "")
300+
.navigationTitle(packageToPreview?.name(withPrecision: .precise) ?? "")
301301
.environment(appState)
302302
.environment(brewPackagesTracker)
303303
.environment(outdatedPackagesTracker)

Cork/Views/Installation/Reusables/Search Result Row.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ struct SearchResultRow: View, Sendable
1616
@Default(.showCompatibilityWarning) var showCompatibilityWarning: Bool
1717

1818
@Environment(BrewPackagesTracker.self) var brewPackagesTracker: BrewPackagesTracker
19+
@Environment(TopPackagesTracker.self) var topPackagesTracker: TopPackagesTracker
1920

2021
let searchedForPackage: MinimalHomebrewPackage
2122
let context: Self.Context
@@ -39,24 +40,27 @@ struct SearchResultRow: View, Sendable
3940
case .topPackages:
4041
Spacer()
4142

43+
// TODO: Reimplement download counts
44+
/*
4245
if let downloadCount = searchedForPackage.downloadCount
4346
{
4447
Text("add-package.top-packages.list-item-\(downloadCount)")
4548
.foregroundStyle(.secondary)
4649
.font(.caption)
4750
}
51+
*/
4852

4953
case .searchResults:
5054
if searchedForPackage.type == .formula
5155
{
52-
if brewPackagesTracker.successfullyLoadedFormulae.contains(where: { $0.getCompletePackageName() == searchedForPackage.getCompletePackageName() })
56+
if brewPackagesTracker.successfullyLoadedFormulae.contains(where: { $0.getCompletePackageName() == searchedForPackage.internalName })
5357
{
5458
PillTextWithLocalizableText(localizedText: "add-package.result.already-installed")
5559
}
5660
}
5761
else
5862
{
59-
if brewPackagesTracker.successfullyLoadedCasks.contains(where: { $0.getCompletePackageName() == searchedForPackage.getCompletePackageName() })
63+
if brewPackagesTracker.successfullyLoadedCasks.contains(where: { $0.getCompletePackageName() == searchedForPackage.internalName })
6064
{
6165
PillTextWithLocalizableText(localizedText: "add-package.result.already-installed")
6266
}
@@ -114,7 +118,7 @@ struct SearchResultRow: View, Sendable
114118
{
115119
if showDescriptionsInSearchResults
116120
{
117-
AppConstants.shared.logger.info("\(searchedForPackage.name, privacy: .auto) came into view")
121+
AppConstants.shared.logger.info("\(searchedForPackage.name(withPrecision: .precise), privacy: .auto) came into view")
118122

119123
if description == nil
120124
{
@@ -123,13 +127,15 @@ struct SearchResultRow: View, Sendable
123127
isLoadingDescription = false
124128
}
125129

126-
AppConstants.shared.logger.info("\(searchedForPackage.name, privacy: .auto) does not have its description loaded")
130+
AppConstants.shared.logger.info("\(searchedForPackage.name(withPrecision: .precise), privacy: .auto) does not have its description loaded")
127131

128132
do
129133
{
130134
guard let searchedForPackageConvertedForDetailLoading: BrewPackage = .init(using: searchedForPackage) else
131135
{
132136
AppConstants.shared.logger.error("Failed to convert minimal package to actual package")
137+
138+
return
133139
}
134140

135141
do

Cork/Views/Installation/Sub-Views/Initial/Top Packages Section.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ struct TopPackagesSection: View
4545
{
4646
ForEach(packages.prefix(15))
4747
{ topPackage in
48-
SearchResultRow(searchedForPackage: topPackage, context: .topPackages)
48+
49+
let convertedPackage: MinimalHomebrewPackage = .init(fromFullPackage: topPackage)
50+
51+
SearchResultRow(searchedForPackage: convertedPackage, context: .topPackages)
4952
}
5053
}
5154
} header: {

Cork/Views/Installation/Sub-Views/Presenting Search Results.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ struct PresentingSearchResultsView: View
128128
}
129129
openWindow(value: selectedPackage)
130130

131-
AppConstants.shared.logger.debug("Would preview package \(selectedPackage.name)")
131+
AppConstants.shared.logger.debug("Would preview package \(selectedPackage.name(withPrecision: .precise))")
132132
}
133133
.disabled(selectedPackage == nil)
134134
.labelStyle(.titleOnly)

Cork/Views/Taps/Tap Details/Sub-Views/Packages Included in Tap.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ struct PackagesIncludedInTapList: View
2424
{
2525
return packages.sorted
2626
{
27-
$0.name < $1.name
27+
$0.internalName < $1.internalName
2828
}
2929
}
3030
else
3131
{
32-
return packages.filter { $0.name.localizedCaseInsensitiveContains(searchString) }.sorted
32+
return packages.filter { $0.name(withPrecision: .precise).localizedCaseInsensitiveContains(searchString) }.sorted
3333
{
34-
$0.name < $1.name
34+
$0.internalName < $1.internalName
3535
}
3636
}
3737
}
@@ -58,13 +58,13 @@ struct PackagesIncludedInTapList: View
5858
{
5959
var packageContainedInFormulae: Bool {
6060
return brewPackagesTracker.successfullyLoadedFormulae.contains { installedPackage in
61-
installedPackage.name(withPrecision: .precise) == minimalPackage.name
61+
installedPackage.internalName == minimalPackage.internalName
6262
}
6363
}
6464

6565
var packageContainedInCasks: Bool {
6666
return brewPackagesTracker.successfullyLoadedCasks.contains { installedPackage in
67-
installedPackage.name(withPrecision: .precise) == minimalPackage.name
67+
installedPackage.internalName == minimalPackage.internalName
6868
}
6969
}
7070

Modules/Packages/PackagesModels/Logic/Installation & Removal/Install Package/Install Cask.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ extension InstallationProgressTracker
1717
) async throws(InstallationError.ImplementedError.CaskInstallError)
1818
{
1919
AppConstants.shared.logger.info("Package is Cask")
20-
AppConstants.shared.logger.debug("Installing package \(caskToInstall.name, privacy: .public)")
20+
AppConstants.shared.logger.debug("Installing package \(caskToInstall.name(withPrecision: .precise), privacy: .public)")
2121

22-
let (stream, process): (AsyncStream<TerminalOutput>, Process) = shell(AppConstants.shared.brewExecutablePath, ["install", caskToInstall.name])
22+
let (stream, process): (AsyncStream<TerminalOutput>, Process) = shell(AppConstants.shared.brewExecutablePath, ["install", caskToInstall.name(withPrecision: .precise)])
2323
installationProcess = process
2424

2525
var consolidatedUnimplementedOutput: [TerminalOutput] = .init()

Modules/Packages/PackagesModels/Logic/Installation & Removal/Install Package/Install Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extension InstallationProgressTracker
1818
cachedDownloadsTracker: CachedDownloadsTracker
1919
) async throws(InstallationError)
2020
{
21-
AppConstants.shared.logger.debug("Installing package \(packageToInstall.name), privacy: .auto), of type \(packageToInstall.type)")
21+
AppConstants.shared.logger.debug("Installing package \(packageToInstall.name(withPrecision: .precise)), privacy: .auto), of type \(packageToInstall.type)")
2222

2323
do
2424
{

Modules/Packages/PackagesModels/Models/Brew Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ public extension BrewPackage
398398
guard let minimalPackage = minimalPackage else { return nil }
399399

400400
self.init(
401-
rawName: minimalPackage.name,
401+
rawName: minimalPackage.name(withPrecision: .precise),
402402
type: minimalPackage.type,
403403
installedOn: minimalPackage.installDate,
404404
versions: [],

Modules/Packages/PackagesModels/Models/Intents/Minimal Homebrew Package.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Foundation
1010

1111
public struct MinimalHomebrewPackage: Identifiable, Hashable, AppEntity, Codable, PackageNameDisplayable
1212
{
13+
/// Initialize from an unparsed name
1314
public init(name: String, type: BrewPackage.PackageType, installDate: Date? = nil, installedIntentionally: Bool) {
1415
self.id = .init()
1516
self.internalName = .init(from: name)
@@ -18,6 +19,16 @@ public struct MinimalHomebrewPackage: Identifiable, Hashable, AppEntity, Codable
1819
self.installedIntentionally = installedIntentionally
1920
}
2021

22+
/// Initialize from a full package
23+
public init(fromFullPackage fullPackage: BrewPackage)
24+
{
25+
self.id = .init()
26+
self.internalName = fullPackage.internalName
27+
self.type = fullPackage.type
28+
self.installDate = fullPackage.installedOn
29+
self.installedIntentionally = fullPackage.installedIntentionally
30+
}
31+
2132
public var id: UUID
2233

2334
public var internalName: BrewPackageName
@@ -33,7 +44,7 @@ public struct MinimalHomebrewPackage: Identifiable, Hashable, AppEntity, Codable
3344
public var displayRepresentation: DisplayRepresentation
3445
{
3546
DisplayRepresentation(
36-
title: "\(name)",
47+
title: "\(name(withPrecision: .precise))",
3748
subtitle: "intents.type.minimal-homebrew-package.representation.subtitle"
3849
)
3950
}

Modules/Packages/PackagesModels/Protocols/Package Name Displayable.swift

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
// Created by David Bureš - P on 29.04.2026.
66
//
77

8+
import CorkShared
89
import Foundation
910
import SwiftUI
10-
import CorkShared
1111

1212
/// Adds support for parsing, storing and displaying a Brew package name in a friendly manner
1313
public protocol PackageNameDisplayable
@@ -28,8 +28,50 @@ public protocol PackageNameDisplayable
2828
}
2929

3030
/// The package's name parsed into chunks
31-
public struct BrewPackageName: Equatable, Hashable, Codable, Sendable
31+
public struct BrewPackageName: Equatable, Hashable, Codable, Comparable, Sendable
3232
{
33+
public static func < (lhs: BrewPackageName, rhs: BrewPackageName) -> Bool
34+
{
35+
// First, compare by packageIdentifier alphabetically
36+
if lhs.packageIdentifier != rhs.packageIdentifier
37+
{
38+
return lhs.packageIdentifier < rhs.packageIdentifier
39+
}
40+
41+
// If identifiers are equal, handle boundVersion comparison
42+
switch (lhs.boundVersion, rhs.boundVersion)
43+
{
44+
case (nil, nil): // Both have no bound version — equal
45+
return false
46+
47+
case (nil, _): // lhs has no version, rhs does — lhs comes first
48+
return true
49+
50+
case (_, nil): // rhs has no version, lhs does — rhs comes first
51+
return false
52+
53+
case (let lhsVersion?, let rhsVersion?): // Both have versions
54+
// Check if both are purely numeric
55+
let lhsIsNumeric = Double(lhsVersion) != nil
56+
let rhsIsNumeric = Double(rhsVersion) != nil
57+
58+
switch (lhsIsNumeric, rhsIsNumeric)
59+
{
60+
case (false, false): // Both alphanumeric — sort alphabetically
61+
return lhsVersion < rhsVersion
62+
63+
case (false, true): // lhs alphanumeric, rhs numeric — lhs comes first
64+
return true
65+
66+
case (true, false): // lhs numeric, rhs alphanumeric — rhs comes first
67+
return false
68+
69+
case (true, true): // Both numeric — sort numerically ascending
70+
return Int(lhsVersion)! < Int(rhsVersion)!
71+
}
72+
}
73+
}
74+
3375
public init(from unparsedName: String)
3476
{
3577
let packageNameWithoutTap: String =
@@ -134,7 +176,7 @@ public extension PackageNameDisplayable
134176
.foregroundColor(.green)
135177
.font(.subheadline)
136178
}
137-
179+
138180
if displayComponents.contains(.boundVersion)
139181
{
140182
if let boundVersion = self.internalName.boundVersion

0 commit comments

Comments
 (0)