From fa9d0b7c40a263f52df2f91a9feb4d1823d137f5 Mon Sep 17 00:00:00 2001 From: F1248 Date: Wed, 15 Jan 2025 14:33:05 +0100 Subject: [PATCH] Add package SFSafeSymbols to manage SF Symbols --- Genius.xcodeproj/project.pbxproj | 16 ++++++++ .../Models/SystemInformation/Hardware.swift | 37 ++++++++++--------- Genius/ViewModels/SFSymbolManager.swift | 17 --------- .../SystemInformationHardwareView.swift | 3 +- .../SystemInformationSoftwareView.swift | 3 +- 5 files changed, 40 insertions(+), 36 deletions(-) delete mode 100644 Genius/ViewModels/SFSymbolManager.swift diff --git a/Genius.xcodeproj/project.pbxproj b/Genius.xcodeproj/project.pbxproj index e15d9f9..0854883 100644 --- a/Genius.xcodeproj/project.pbxproj +++ b/Genius.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ A46854972D1729B500DB3E87 /* Defaults in Frameworks */ = {isa = PBXBuildFile; productRef = A46854962D1729B500DB3E87 /* Defaults */; }; + A4D6DC6E2D37EE4700E9A61D /* SFSafeSymbols in Frameworks */ = {isa = PBXBuildFile; productRef = A4D6DC6D2D37EE4700E9A61D /* SFSafeSymbols */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -81,6 +82,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + A4D6DC6E2D37EE4700E9A61D /* SFSafeSymbols in Frameworks */, A46854972D1729B500DB3E87 /* Defaults in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -204,6 +206,7 @@ packageReferences = ( A4672DD92C61205000C933CB /* XCRemoteSwiftPackageReference "SwiftLintPlugins" */, A46854952D1729B500DB3E87 /* XCRemoteSwiftPackageReference "Defaults" */, + A4D6DC6C2D37EE4700E9A61D /* XCRemoteSwiftPackageReference "SFSafeSymbols" */, ); preferredProjectObjectVersion = 77; productRefGroup = A42B353E2BA2185B009E81AD /* Products */; @@ -589,6 +592,14 @@ kind = branch; }; }; + A4D6DC6C2D37EE4700E9A61D /* XCRemoteSwiftPackageReference "SFSafeSymbols" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/SFSafeSymbols/SFSafeSymbols"; + requirement = { + branch = stable; + kind = branch; + }; + }; /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ @@ -602,6 +613,11 @@ package = A46854952D1729B500DB3E87 /* XCRemoteSwiftPackageReference "Defaults" */; productName = Defaults; }; + A4D6DC6D2D37EE4700E9A61D /* SFSafeSymbols */ = { + isa = XCSwiftPackageProductDependency; + package = A4D6DC6C2D37EE4700E9A61D /* XCRemoteSwiftPackageReference "SFSafeSymbols" */; + productName = SFSafeSymbols; + }; A4D9A1BC2D257090008D91E7 /* SwiftLintBuildToolPlugin */ = { isa = XCSwiftPackageProductDependency; package = A4672DD92C61205000C933CB /* XCRemoteSwiftPackageReference "SwiftLintPlugins" */; diff --git a/Genius/Models/SystemInformation/Hardware.swift b/Genius/Models/SystemInformation/Hardware.swift index cfd608a..b0b0165 100644 --- a/Genius/Models/SystemInformation/Hardware.swift +++ b/Genius/Models/SystemInformation/Hardware.swift @@ -8,6 +8,7 @@ import Foundation import IOKit +import SFSafeSymbols extension SystemInformation { @@ -46,29 +47,31 @@ extension SystemInformation { // swiftlint:disable:next unused_declaration static let isLaptop = SystemInformationData(name.value?.hasPrefix("MacBook")) static let isVirtualMachine = SystemInformationData(Sysctl.read("kern.hv_vmm_present")) - static let sfSymbol = SystemInformationData(sfSymbolFallback({ + static let sfSymbol = SystemInformationData({ switch true { - case isVirtualMachine.value: "macwindow" + case isVirtualMachine.value: .macwindow case name.value.hasPrefix("MacBook"): - switch identifier.value { - case "Mac14,7": "macbook.gen1" - case _ where identifier.value.hasPrefix("MacBookPro18"): "macbook.gen2" - case _ where identifier.value.hasPrefix("MacBook"): "macbook.gen1" - default: "macbook.gen2" - } - case name.value.hasPrefix("iMac"): "desktopcomputer" - case name.value.hasPrefix("Mac mini"): "macmini" - case name.value.hasPrefix("Mac Studio"): "macstudio" + if #available(macOS 14, *) { + switch identifier.value { + case "Mac14,7": .macbookGen1 + case _ where identifier.value.hasPrefix("MacBookPro18"): .macbookGen2 + case _ where identifier.value.hasPrefix("MacBook"): .macbookGen1 + default: .macbookGen2 + } + } else { .laptopcomputer } + case name.value.hasPrefix("iMac"): .desktopcomputer + case name.value.hasPrefix("Mac mini"): .macmini + case name.value.hasPrefix("Mac Studio"): if #available(macOS 13, *) { .macstudio } else { .macmini } case name.value.hasPrefix("Mac Pro"): switch identifier.value { - case "MacPro3,1", "MacPro4,1", "MacPro5,1": "macpro.gen1" - case "MacPro6,1": "macpro.gen2" - default: ["A2304", "A2787"].contains(regulatoryNumber.value) ? "macpro.gen3.server" : "macpro.gen3" + case "MacPro3,1", "MacPro4,1", "MacPro5,1": .macproGen1 + case "MacPro6,1": .macproGen2 + default: ["A2304", "A2787"].contains(regulatoryNumber.value) ? .macproGen3Server : .macproGen3 } - case name.value.hasPrefix("Xserve"): "xserve" - default: "desktopcomputer.and.macbook" + case name.value.hasPrefix("Xserve"): .xserve + default: if #available(macOS 15, *) { .desktopcomputerAndMacbook } else { .desktopcomputer } } - }())) + }()) } static let securityChip = SystemInformationData({ diff --git a/Genius/ViewModels/SFSymbolManager.swift b/Genius/ViewModels/SFSymbolManager.swift deleted file mode 100644 index 5dc4d98..0000000 --- a/Genius/ViewModels/SFSymbolManager.swift +++ /dev/null @@ -1,17 +0,0 @@ -// -// SFSymbolManager.swift -// Genius -// -// © 2024 F1248 -// See LICENSE.txt for license information. -// - -func sfSymbolFallback(_ name: String) -> String { - switch name { - case "desktopcomputer.and.macbook": if #unavailable(macOS 15) { return "desktopcomputer" } - case "macbook.gen1", "macbook.gen2": if #unavailable(macOS 14) { return "laptopcomputer" } - case "macstudio": if #unavailable(macOS 13) { return "macmini" } - default: break - } - return name -} diff --git a/Genius/Views/SystemInformation/SystemInformationHardwareView.swift b/Genius/Views/SystemInformation/SystemInformationHardwareView.swift index bf57e28..541a561 100644 --- a/Genius/Views/SystemInformation/SystemInformationHardwareView.swift +++ b/Genius/Views/SystemInformation/SystemInformationHardwareView.swift @@ -6,13 +6,14 @@ // See LICENSE.txt for license information. // +import SFSafeSymbols import SwiftUI import SwiftUICore struct SystemInformationHardwareView: View { var body: some View { - Label("Hardware", systemImage: SystemInformation.Hardware.Model.sfSymbol.value) + Label("Hardware", systemSymbol: SystemInformation.Hardware.Model.sfSymbol.value) .font(.title) .padding() SystemInformationTabView(content: [ diff --git a/Genius/Views/SystemInformation/SystemInformationSoftwareView.swift b/Genius/Views/SystemInformation/SystemInformationSoftwareView.swift index 258f719..efa9803 100644 --- a/Genius/Views/SystemInformation/SystemInformationSoftwareView.swift +++ b/Genius/Views/SystemInformation/SystemInformationSoftwareView.swift @@ -6,13 +6,14 @@ // See LICENSE.txt for license information. // +import SFSafeSymbols import SwiftUI import SwiftUICore struct SystemInformationSoftwareView: View { var body: some View { - Label("Software", systemImage: "macwindow.on.rectangle") + Label("Software", systemSymbol: .macwindowOnRectangle) .font(.title) .padding() SystemInformationTabView(content: [