Skip to content

Commit 03eb166

Browse files
committed
move icon to IconView.swift
1 parent e56d83d commit 03eb166

3 files changed

Lines changed: 69 additions & 13 deletions

File tree

Xcodes.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
63EAA4EB259944450046AB8F /* ProgressButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63EAA4EA259944450046AB8F /* ProgressButton.swift */; };
1616
B0C6AD042AD6E65700E64698 /* ReleaseDateView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C6AD032AD6E65700E64698 /* ReleaseDateView.swift */; };
1717
B0C6AD0B2AD9178E00E64698 /* IdenticalBuildView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C6AD0A2AD9178E00E64698 /* IdenticalBuildView.swift */; };
18+
B0C6AD0D2AD91D7900E64698 /* IconView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C6AD0C2AD91D7900E64698 /* IconView.swift */; };
1819
CA11E7BA2598476C00D2EE1C /* XcodeCommands.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA11E7B92598476C00D2EE1C /* XcodeCommands.swift */; };
1920
CA2518EC25A7FF2B00F08414 /* AppStateUpdateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA2518EB25A7FF2B00F08414 /* AppStateUpdateTests.swift */; };
2021
CA25192A25A9644800F08414 /* XcodeInstallState.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA25192925A9644800F08414 /* XcodeInstallState.swift */; };
@@ -196,6 +197,7 @@
196197
AB4EB0DE28541FA000FF3B1D /* ja */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ja; path = ja.lproj/Localizable.strings; sourceTree = "<group>"; };
197198
B0C6AD032AD6E65700E64698 /* ReleaseDateView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReleaseDateView.swift; sourceTree = "<group>"; };
198199
B0C6AD0A2AD9178E00E64698 /* IdenticalBuildView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IdenticalBuildView.swift; sourceTree = "<group>"; };
200+
B0C6AD0C2AD91D7900E64698 /* IconView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IconView.swift; sourceTree = "<group>"; };
199201
B648F22B2810C1130096781B /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/Localizable.strings; sourceTree = "<group>"; };
200202
C0AE7FA4283002DC00DA63D2 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = "<group>"; };
201203
CA11E7B92598476C00D2EE1C /* XcodeCommands.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XcodeCommands.swift; sourceTree = "<group>"; };
@@ -623,6 +625,7 @@
623625
E8E98A9525D863D700EC89A0 /* InstallationStepDetailView.swift */,
624626
B0C6AD032AD6E65700E64698 /* ReleaseDateView.swift */,
625627
B0C6AD0A2AD9178E00E64698 /* IdenticalBuildView.swift */,
628+
B0C6AD0C2AD91D7900E64698 /* IconView.swift */,
626629
);
627630
path = InfoPane;
628631
sourceTree = "<group>";
@@ -847,6 +850,7 @@
847850
CABFAA492593162500380FEE /* Bundle+InfoPlistValues.swift in Sources */,
848851
CA9FF8662595130600E47BAF /* View+IsHidden.swift in Sources */,
849852
CAE4248C259A68B800B8B246 /* Optional+IsNotNil.swift in Sources */,
853+
B0C6AD0D2AD91D7900E64698 /* IconView.swift in Sources */,
850854
CA9FF9362595B44700E47BAF /* HelperClient.swift in Sources */,
851855
B0C6AD042AD6E65700E64698 /* ReleaseDateView.swift in Sources */,
852856
CAA8587C25A2B37900ACF8C0 /* IsTesting.swift in Sources */,
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
//
2+
// IconView.swift
3+
// Xcodes
4+
//
5+
// Created by Duong Thai on 11/10/2023.
6+
// Copyright © 2023 Robots and Pencils. All rights reserved.
7+
//
8+
9+
import SwiftUI
10+
import Path
11+
12+
struct IconView: View {
13+
let installState: XcodeInstallState
14+
15+
var body: some View {
16+
if case let .installed(path) = installState {
17+
Image(nsImage: NSWorkspace.shared.icon(forFile: path.string))
18+
} else {
19+
Image(systemName: "app.fill")
20+
.resizable()
21+
.frame(width: 32, height: 32)
22+
.foregroundColor(.secondary)
23+
}
24+
}
25+
}
26+
27+
//#Preview {
28+
// Group {
29+
// IconView(path: "/Applications/Xcode.app")
30+
// IconView()
31+
// }
32+
// .padding()
33+
//}
34+
35+
struct IconView_Preview: PreviewProvider {
36+
static var previews: some View {
37+
WrapperView()
38+
}
39+
}
40+
41+
private struct WrapperView: View {
42+
@State var isIcon = false
43+
var state: XcodeInstallState {
44+
isIcon
45+
? XcodeInstallState.notInstalled
46+
: XcodeInstallState.installed(Path("/Applications/Xcode.app")!)
47+
}
48+
49+
var body: some View {
50+
VStack {
51+
HStack {
52+
IconView(installState: state)
53+
.border(.red)
54+
}
55+
Spacer()
56+
Toggle(isOn: $isIcon) {
57+
Text("Is an Icon?")
58+
}
59+
}
60+
.animation(.default)
61+
.frame(width: 300, height: 100)
62+
.padding()
63+
}
64+
}

Xcodes/Frontend/InfoPane/InfoPane.swift

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ struct InfoPane: View {
1414
if let xcode = appState.allXcodes.first(where: { $0.id == selectedXcodeID }) {
1515
ScrollView {
1616
VStack(alignment: .leading, spacing: 16) {
17-
icon(for: xcode)
17+
IconView(installState: xcode.installState)
1818
.frame(maxWidth: .infinity, alignment: .center)
1919

2020
Text(verbatim: "Xcode \(xcode.description) \(xcode.version.buildMetadataIdentifiersDisplay)")
@@ -74,18 +74,6 @@ struct InfoPane: View {
7474
}
7575
}
7676

77-
@ViewBuilder
78-
private func icon(for xcode: Xcode) -> some View {
79-
if case let .installed(path) = xcode.installState {
80-
Image(nsImage: NSWorkspace.shared.icon(forFile: path.string))
81-
} else {
82-
Image(systemName: "app.fill")
83-
.resizable()
84-
.frame(width: 32, height: 32)
85-
.foregroundColor(.secondary)
86-
}
87-
}
88-
8977
@ViewBuilder
9078
private func releaseNotes(for xcode: Xcode) -> some View {
9179
if let releaseNotesURL = xcode.releaseNotesURL {

0 commit comments

Comments
 (0)