From 112829b5534d253c30c5ca896fc9a3abe0cfaf9c Mon Sep 17 00:00:00 2001 From: Duong Thai Date: Thu, 23 Nov 2023 22:53:15 +0700 Subject: [PATCH] rebase main --- Xcodes.xcodeproj/project.pbxproj | 4 + Xcodes/Frontend/InfoPane/CompilersView.swift | 82 ++++++++++++++++++++ Xcodes/Frontend/InfoPane/InfoPane.swift | 29 +------ 3 files changed, 87 insertions(+), 28 deletions(-) create mode 100644 Xcodes/Frontend/InfoPane/CompilersView.swift diff --git a/Xcodes.xcodeproj/project.pbxproj b/Xcodes.xcodeproj/project.pbxproj index eeaa3d4..b108061 100644 --- a/Xcodes.xcodeproj/project.pbxproj +++ b/Xcodes.xcodeproj/project.pbxproj @@ -16,6 +16,7 @@ B0403CF02AD92D7B00137C09 /* ReleaseNotesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0403CEF2AD92D7B00137C09 /* ReleaseNotesView.swift */; }; B0403CF22AD934B600137C09 /* CompatibilityView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0403CF12AD934B600137C09 /* CompatibilityView.swift */; }; B0403CF42AD9381D00137C09 /* SDKsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0403CF32AD9381D00137C09 /* SDKsView.swift */; }; + B0403CF62AD9849E00137C09 /* CompilersView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0403CF52AD9849E00137C09 /* CompilersView.swift */; }; B0C6AD042AD6E65700E64698 /* ReleaseDateView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C6AD032AD6E65700E64698 /* ReleaseDateView.swift */; }; B0C6AD0B2AD9178E00E64698 /* IdenticalBuildView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C6AD0A2AD9178E00E64698 /* IdenticalBuildView.swift */; }; B0C6AD0D2AD91D7900E64698 /* IconView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C6AD0C2AD91D7900E64698 /* IconView.swift */; }; @@ -201,6 +202,7 @@ B0403CEF2AD92D7B00137C09 /* ReleaseNotesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReleaseNotesView.swift; sourceTree = ""; }; B0403CF12AD934B600137C09 /* CompatibilityView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompatibilityView.swift; sourceTree = ""; }; B0403CF32AD9381D00137C09 /* SDKsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SDKsView.swift; sourceTree = ""; }; + B0403CF52AD9849E00137C09 /* CompilersView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompilersView.swift; sourceTree = ""; }; B0C6AD032AD6E65700E64698 /* ReleaseDateView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReleaseDateView.swift; sourceTree = ""; }; B0C6AD0A2AD9178E00E64698 /* IdenticalBuildView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IdenticalBuildView.swift; sourceTree = ""; }; B0C6AD0C2AD91D7900E64698 /* IconView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IconView.swift; sourceTree = ""; }; @@ -629,6 +631,7 @@ children = ( B0403CEF2AD92D7B00137C09 /* ReleaseNotesView.swift */, B0403CF32AD9381D00137C09 /* SDKsView.swift */, + B0403CF52AD9849E00137C09 /* CompilersView.swift */, B0403CF12AD934B600137C09 /* CompatibilityView.swift */, CAFBDC67259A308B003DCC5A /* InfoPane.swift */, E8E98A9525D863D700EC89A0 /* InstallationStepDetailView.swift */, @@ -921,6 +924,7 @@ CAE424B4259A764700B8B246 /* AppState+Install.swift in Sources */, CAE42487259A68A300B8B246 /* XcodeListCategory.swift in Sources */, CAA858C425A2BE4E00ACF8C0 /* Downloader.swift in Sources */, + B0403CF62AD9849E00137C09 /* CompilersView.swift in Sources */, E8977EA325C11E1500835F80 /* PreferencesView.swift in Sources */, CA9FF87B2595293E00E47BAF /* DataSource.swift in Sources */, CABFA9C92592EEEA00380FEE /* URLRequest+Apple.swift in Sources */, diff --git a/Xcodes/Frontend/InfoPane/CompilersView.swift b/Xcodes/Frontend/InfoPane/CompilersView.swift new file mode 100644 index 0000000..68d2f52 --- /dev/null +++ b/Xcodes/Frontend/InfoPane/CompilersView.swift @@ -0,0 +1,82 @@ +// +// CompilersView.swift +// Xcodes +// +// Created by Duong Thai on 13/10/2023. +// Copyright © 2023 Robots and Pencils. All rights reserved. +// + +import SwiftUI +import struct XCModel.Compilers + +struct CompilersView: View { + let compilers: Compilers? + + var body: some View { + if let compilers = compilers { + VStack(alignment: .leading) { + Text("Compilers").font(.headline) + Text(Self.content(from: compilers)).font(.subheadline) + } + } else { + EmptyView() + } + } + + static func content(from compilers: Compilers) -> String { + [ ("Swift", compilers.swift), + ("Clang", compilers.clang), + ("LLVM", compilers.llvm), + ("LLVM GCC", compilers.llvm_gcc), + ("GCC", compilers.gcc) + ].compactMap { // remove nil compiler + guard $0.1 != nil, // has version array + !$0.1!.isEmpty // has at least 1 version + else { return nil } + + let numbers = $0.1!.compactMap { $0.number } // remove nil number + guard !numbers.isEmpty // has at least 1 number + else { return nil } + + // description for each type of compilers + return "\($0.0): \(numbers.joined(separator: ", "))" + }.joined(separator: "\n") + } +} + +struct CompilersView_Preview: PreviewProvider { + static var previews: some View { + WrapperView() + } +} + +private struct WrapperView: View { + @State var isNil = false + var compilers: Compilers? { + isNil + ? nil + : Compilers( + gcc: .init(number: "4"), + llvm_gcc: .init(number: "213"), + llvm: .init(number: "2.3"), + clang: .init(number: "7.3"), + swift: .init(number: "5.3.2")) + } + + var body: some View { + VStack { + HStack { + CompilersView(compilers: compilers) + .border(.red) + } + Spacer() + Toggle(isOn: $isNil) { + Text("Is Nil?") + } + } + .animation(.default) + .frame(width: 200, height: 100) + .padding() + } +} + diff --git a/Xcodes/Frontend/InfoPane/InfoPane.swift b/Xcodes/Frontend/InfoPane/InfoPane.swift index f617165..5cf6eb2 100644 --- a/Xcodes/Frontend/InfoPane/InfoPane.swift +++ b/Xcodes/Frontend/InfoPane/InfoPane.swift @@ -59,7 +59,7 @@ struct InfoPane: View { IdenticalBuildsView(builds: xcode.identicalBuilds) CompatibilityView(requiredMacOSVersion: xcode.requiredMacOSVersion) SDKsView(sdks: xcode.sdks) - compilers(for: xcode) + CompilersView(compilers: xcode.compilers) } Spacer() @@ -73,33 +73,6 @@ struct InfoPane: View { } } - @ViewBuilder - private func compilers(for xcode: Xcode) -> some View { - if let compilers = xcode.compilers { - VStack(alignment: .leading) { - Text("Compilers") - .font(.headline) - .frame(maxWidth: .infinity, alignment: .leading) - - ForEach([ - ("Swift", \Compilers.swift), - ("Clang", \.clang), - ("LLVM", \.llvm), - ("LLVM GCC", \.llvm_gcc), - ("GCC", \.gcc), - ], id: \.0) { row in - if let sdk = compilers[keyPath: row.1] { - Text("\(row.0): \(sdk.compactMap { $0.number }.joined(separator: ", "))") - .font(.subheadline) - .frame(maxWidth: .infinity, alignment: .leading) - } - } - } - } else { - EmptyView() - } - } - @ViewBuilder private func downloadFileSize(for xcode: Xcode) -> some View { // if we've downloaded it no need to show the download size