-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3c5f860
commit b968149
Showing
19 changed files
with
513 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// | ||
// PlatformsListView.swift | ||
// Xcodes | ||
// | ||
// Created by Matt Kiazyk on 2023-12-20. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
import Path | ||
import XcodesKit | ||
import OrderedCollections | ||
|
||
struct PlatformsListView: View { | ||
@EnvironmentObject var appState: AppState | ||
@State private var runtimes: OrderedDictionary<DownloadableRuntime.Platform, [DownloadableRuntime]> = [:] | ||
@State private var selectedRuntime: DownloadableRuntime? | ||
|
||
var body: some View { | ||
List(selection: $selectedRuntime) { | ||
Text("PlatformsList.Title") | ||
.font(.body) | ||
ForEach(runtimes.elements.sorted(\.key.order), id: \.key) { platform, runtimeList in | ||
Section { | ||
ForEach(runtimeList, id: \.self) { runtime in | ||
HStack { | ||
Text(runtime.name) | ||
Spacer() | ||
Text(runtime.downloadFileSizeString) | ||
Button { | ||
deleteRuntime(runtime: runtime) | ||
} label: { | ||
Image(systemName: "trash") | ||
} | ||
.foregroundStyle(.red) | ||
.buttonStyle(.plain) | ||
} | ||
.frame(height: 30) | ||
} | ||
|
||
} header: { | ||
HStack { | ||
runtimeList.first!.icon() | ||
.aspectRatio(contentMode: .fit) | ||
.frame(width: 20) | ||
Text(platform.shortName) | ||
.font(.headline) | ||
} | ||
} footer: { | ||
EmptyView() | ||
} | ||
} | ||
} | ||
.listStyle(.inset(alternatesRowBackgrounds: true)) | ||
.task { | ||
loadRuntimes() | ||
} | ||
.onChange(of: appState.installedRuntimes) { _ in | ||
loadRuntimes() | ||
} | ||
} | ||
|
||
func loadRuntimes() { | ||
let filteredRuntimes = appState.downloadableRuntimes.filter { runtime in | ||
appState.installedRuntimes.contains { $0.runtimeInfo.build == runtime.simulatorVersion.buildUpdate | ||
} | ||
} | ||
runtimes = OrderedDictionary(grouping: filteredRuntimes, by: { $0.platform }) | ||
} | ||
|
||
func deleteRuntime(runtime: DownloadableRuntime) { | ||
appState.presentedPreferenceAlert = .deletePlatform(runtime: runtime) | ||
} | ||
} | ||
|
||
|
||
#Preview { | ||
PlatformsListView() | ||
.environmentObject({ () -> AppState in | ||
let a = AppState() | ||
|
||
a.installedRuntimes = installedRuntimes | ||
a.downloadableRuntimes = downloadableRuntimes | ||
|
||
return a | ||
|
||
}()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.