From 3662fd3b1ef509ce13657eb5edcef9bb38f57c85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Helge=20He=C3=9F?= Date: Mon, 5 Oct 2020 16:54:33 +0200 Subject: [PATCH] Improve details popover ... --- 5GUIs.xcodeproj/project.pbxproj | 4 ++ .../5GUIs/Views/Reusable/PropertiesView.swift | 55 +++++++++++++++++++ .../Windows/MainWindow/DetailsPopover.swift | 43 ++++++++++++--- 3 files changed, 94 insertions(+), 8 deletions(-) create mode 100644 Sources/5GUIs/Views/Reusable/PropertiesView.swift diff --git a/5GUIs.xcodeproj/project.pbxproj b/5GUIs.xcodeproj/project.pbxproj index 407e05f..7c784ed 100644 --- a/5GUIs.xcodeproj/project.pbxproj +++ b/5GUIs.xcodeproj/project.pbxproj @@ -11,6 +11,7 @@ E83E32C225220277009BE980 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E83E32C125220277009BE980 /* Preview Assets.xcassets */; }; E83E32C525220277009BE980 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E83E32C325220277009BE980 /* Main.storyboard */; }; E88C60C6252B482B008B3272 /* DetectedTechnologies.swift in Sources */ = {isa = PBXBuildFile; fileRef = E88C60C5252B482B008B3272 /* DetectedTechnologies.swift */; }; + E8E01B6F252B6A8A005B7CCF /* PropertiesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E8E01B6E252B6A8A005B7CCF /* PropertiesView.swift */; }; E8F1C3F72524EAFB000B517B /* LLVM-LICENSE.TXT in Resources */ = {isa = PBXBuildFile; fileRef = E8F1C3F62524EAFB000B517B /* LLVM-LICENSE.TXT */; }; E8F1C41C25260051000B517B /* OTool.swift in Sources */ = {isa = PBXBuildFile; fileRef = E8F1C40225260051000B517B /* OTool.swift */; }; E8F1C41D25260051000B517B /* WindowEnvironmentKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = E8F1C40325260051000B517B /* WindowEnvironmentKey.swift */; }; @@ -46,6 +47,7 @@ E83E32C625220277009BE980 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; E83E32C725220277009BE980 /* _GUIs.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = _GUIs.entitlements; sourceTree = ""; }; E88C60C5252B482B008B3272 /* DetectedTechnologies.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetectedTechnologies.swift; sourceTree = ""; }; + E8E01B6E252B6A8A005B7CCF /* PropertiesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PropertiesView.swift; sourceTree = ""; }; E8E5B7572526299400FF9B14 /* llvm-objdump.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "llvm-objdump.entitlements"; sourceTree = ""; }; E8F1C3D82524BA3F000B517B /* llvm-objdump */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.executable"; path = "llvm-objdump"; sourceTree = ""; }; E8F1C3F62524EAFB000B517B /* LLVM-LICENSE.TXT */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "LLVM-LICENSE.TXT"; sourceTree = ""; }; @@ -187,6 +189,7 @@ isa = PBXGroup; children = ( E8F1C40925260051000B517B /* SpinnerView.swift */, + E8E01B6E252B6A8A005B7CCF /* PropertiesView.swift */, ); path = Reusable; sourceTree = ""; @@ -347,6 +350,7 @@ E8F1C42625260051000B517B /* ThirdPartyLicensesView.swift in Sources */, E8F1C42D25260051000B517B /* FakeDetectionStepper.swift in Sources */, E8F1C42425260051000B517B /* DetectionStepsView.swift in Sources */, + E8E01B6F252B6A8A005B7CCF /* PropertiesView.swift in Sources */, E8F1C42A25260051000B517B /* MainFileView.swift in Sources */, E8F1C42225260051000B517B /* SpinnerView.swift in Sources */, E8F1C42325260051000B517B /* PleaseDropAFileView.swift in Sources */, diff --git a/Sources/5GUIs/Views/Reusable/PropertiesView.swift b/Sources/5GUIs/Views/Reusable/PropertiesView.swift new file mode 100644 index 0000000..f1a8375 --- /dev/null +++ b/Sources/5GUIs/Views/Reusable/PropertiesView.swift @@ -0,0 +1,55 @@ +// +// PropertiesView.swift +// 5GUIs +// +// Created by Helge Heß on 05.10.20. +// + +import SwiftUI + +struct PropertyLine: View { + + let name : String + let value : Any? + var showMissing : Bool { false } + + var body: some View { + Group { + if showMissing { + HStack { + Text(name + ": ") + Spacer() + if let value = value { + Text(verbatim: String(describing: value)) + } + else { + Text("-") + } + } + } + else { + if let value = value { + HStack { + Text(name + ": ") + Spacer() + Text(verbatim: String(describing: value)) + } + } + } + } + } +} + +struct PropertiesView: View { + + let properties : [ ( name: String, value: Any? ) ] + + var body: some View { + Group { + ForEach(properties, id: \.name) { item in + PropertyLine(name: item.name, value: item.value) + } + } + } +} + diff --git a/Sources/5GUIs/Views/Windows/MainWindow/DetailsPopover.swift b/Sources/5GUIs/Views/Windows/MainWindow/DetailsPopover.swift index 47db0bf..40bf886 100644 --- a/Sources/5GUIs/Views/Windows/MainWindow/DetailsPopover.swift +++ b/Sources/5GUIs/Views/Windows/MainWindow/DetailsPopover.swift @@ -26,12 +26,14 @@ struct DetailsPopover: View { .padding() VStack(alignment: .leading, spacing: 4) { - info.id .flatMap { Text("ID: \($0)") } - info.name .flatMap { Text("Name: \($0)") } - info.info .flatMap { Text("Info: \($0)") } - info.version .flatMap { Text("Version: \($0)") } - info.shortVersion .flatMap { Text("Short Version: \($0)") } - info.applicationCategory.flatMap { Text("App Category: \($0)") } + PropertiesView(properties: [ + ( "Bundle ID", info.id ), + ( "Name", info.name ), + ( "Info", info.info ), + ( "Version", info.version ), + ( "Short Version", info.shortVersion ), + ( "Application Category", info.applicationCategory ), + ]) if info.appleScriptEnabled { Text("Fancy, AppleScript is enabled!") } @@ -81,9 +83,8 @@ struct DetailsPopover: View { else { Text("No Bundle Info?") } - if let url = info.executableURL { - Text("Executable: \(url.path)") + PropertyLine(name: "Executable", value: url.path) } if hasReceipt { @@ -99,3 +100,29 @@ struct DetailsPopover: View { } } } + +struct DetailsPopover_Previews: PreviewProvider { + static var previews: some View { + DetailsPopover(info: + ExecutableFileTechnologyInfo( + fileURL: URL(fileURLWithPath: "/Applications/Xcode.app"), + infoDictionary: InfoDict([ + "CFBundleIdentifier" : "blub.blab.blum", + "CFBundleName" : "VisualStudio" + ]), + executableURL: URL(fileURLWithPath: + "/Applications/Xcode.app/Contents/MacOS/VisualStudio"), + receiptURL: nil, + appImage: nil, + dependencies: [ + "@rpath/DVTCocoaAdditionsKit.framework/Versions/A/DVTCocoaAdditionsKit", + "/usr/lib/libobjc.A.dylib", + "/usr/lib/swift/libswiftUniformTypeIdentifiers.dylib", + "/usr/lib/swift/libswiftXPC.dylib" + ], + embeddedExecutables: [], + detectedTechnologies: [ .appkit, .swift ] + ) + ) + } +}