Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Xcodes.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
14d2f5a1273f6c350cad4406 /* NewVersionNotificationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 884f01aed2f43048ab4d3323 /* NewVersionNotificationTests.swift */; };
15F5B8902CCF09B900705E2F /* CryptoKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 15F5B88F2CCF09B900705E2F /* CryptoKit.framework */; };
3328073F2CA5E2C80036F691 /* SignInSecurityKeyPinView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3328073E2CA5E2C80036F691 /* SignInSecurityKeyPinView.swift */; };
332807412CA5EA820036F691 /* SignInSecurityKeyTouchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 332807402CA5EA820036F691 /* SignInSecurityKeyTouchView.swift */; };
Expand All @@ -31,7 +32,6 @@
BDBAB7452B9FF55800694B0B /* TrailingIconLabelStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDBAB7442B9FF55800694B0B /* TrailingIconLabelStyle.swift */; };
CA11E7BA2598476C00D2EE1C /* XcodeCommands.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA11E7B92598476C00D2EE1C /* XcodeCommands.swift */; };
CA2518EC25A7FF2B00F08414 /* AppStateUpdateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA2518EB25A7FF2B00F08414 /* AppStateUpdateTests.swift */; };
14d2f5a1273f6c350cad4406 /* NewVersionNotificationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 884f01aed2f43048ab4d3323 /* NewVersionNotificationTests.swift */; };
CA378F992466567600A58CE0 /* AppState.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA378F982466567600A58CE0 /* AppState.swift */; };
CA39711924495F0E00AFFB77 /* AppStoreButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA39711824495F0E00AFFB77 /* AppStoreButtonStyle.swift */; };
CA42DD7325AEB04300BC0B0C /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA42DD7225AEB04300BC0B0C /* Logger.swift */; };
Expand Down Expand Up @@ -194,6 +194,7 @@
536CFDD3263C9A8000026CE0 /* XcodesSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XcodesSheet.swift; sourceTree = "<group>"; };
53CBAB2B263DCC9100410495 /* XcodesAlert.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XcodesAlert.swift; sourceTree = "<group>"; };
63EAA4EA259944450046AB8F /* ProgressButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgressButton.swift; sourceTree = "<group>"; };
884f01aed2f43048ab4d3323 /* NewVersionNotificationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewVersionNotificationTests.swift; sourceTree = "<group>"; };
9DD4FFCA2B13EC1800C974F1 /* Localizable.xcstrings */ = {isa = PBXFileReference; lastKnownFileType = text.json.xcstrings; path = Localizable.xcstrings; sourceTree = "<group>"; };
B0403CEF2AD92D7B00137C09 /* ReleaseNotesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReleaseNotesView.swift; sourceTree = "<group>"; };
B0403CF12AD934B600137C09 /* CompatibilityView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompatibilityView.swift; sourceTree = "<group>"; };
Expand All @@ -209,7 +210,6 @@
BDBAB7442B9FF55800694B0B /* TrailingIconLabelStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrailingIconLabelStyle.swift; sourceTree = "<group>"; };
CA11E7B92598476C00D2EE1C /* XcodeCommands.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XcodeCommands.swift; sourceTree = "<group>"; };
CA2518EB25A7FF2B00F08414 /* AppStateUpdateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppStateUpdateTests.swift; sourceTree = "<group>"; };
884f01aed2f43048ab4d3323 /* NewVersionNotificationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewVersionNotificationTests.swift; sourceTree = "<group>"; };
CA378F982466567600A58CE0 /* AppState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppState.swift; sourceTree = "<group>"; };
CA39711824495F0E00AFFB77 /* AppStoreButtonStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppStoreButtonStyle.swift; sourceTree = "<group>"; };
CA42DD7225AEB04300BC0B0C /* Logger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1521,7 +1521,7 @@
repositoryURL = "https://github.com/XcodesOrg/XcodesKit";
requirement = {
kind = upToNextMinorVersion;
minimumVersion = 1.0.4;
minimumVersion = 1.1.0;
};
};
E89CBD3B2D5FC0B10037ED95 /* XCRemoteSwiftPackageReference "XcodesLoginKit" */ = {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 23 additions & 2 deletions Xcodes/Backend/AppState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ class AppState: ObservableObject {
}
setupAutoInstallTimer()
setupDefaults()
startAuthenticationTask {
try await self.restoreAuthenticationStateIfNeeded()
}
}

func setupDefaults() {
Expand Down Expand Up @@ -286,13 +289,19 @@ class AppState: ObservableObject {
).validateADCSession(path: path)
}

func validateSessionAsync() async throws {
@discardableResult
func validateSessionAsync() async throws -> AuthenticationState {
try await Current.network.validateSessionAsync()
}

func signInIfNeededAsync() async throws {
do {
try await validateSessionAsync()
let authenticationState = try await validateSessionAsync()
try Task.checkCancellation()
self.authenticationState = authenticationState
handleAuthenticationFlowSuccess()
} catch is CancellationError {
throw CancellationError()
} catch {
guard
let username = savedUsername,
Expand All @@ -305,6 +314,11 @@ class AppState: ObservableObject {
}
}

func restoreAuthenticationStateIfNeeded() async throws {
guard hasSavedUsername else { return }
try await signInIfNeededAsync()
}

func signIn(username: String, password: String?) {
authError = nil
startAuthenticationTask {
Expand Down Expand Up @@ -681,6 +695,10 @@ class AppState: ObservableObject {
func uninstall(xcode: Xcode) {
guard let installedXcodePath = xcode.installedPath else { return }

if let index = allXcodes.firstIndex(where: { $0.id == xcode.id }) {
allXcodes[index].installState = .uninstalling(installedXcodePath)
}

uninstallTask?.cancel()
let taskID = UUID()
uninstallTaskID = taskID
Expand All @@ -699,6 +717,9 @@ class AppState: ObservableObject {
await updateInstalledXcodesAsync()
} catch is CancellationError {
} catch {
if let index = allXcodes.firstIndex(where: { $0.id == xcode.id }) {
allXcodes[index].installState = .installed(installedXcodePath)
}
self.error = error
self.presentedAlert = .generic(title: localizeString("Alert.Uninstall.Error.Title"), message: error.legibleLocalizedDescription)
}
Expand Down
8 changes: 4 additions & 4 deletions Xcodes/Backend/Environment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,15 @@ public struct Network: Sendable {
downloadTaskAsync(url, saveLocation, resumeData)
}

public var validateSessionAsync: @Sendable () async throws -> Void
public var validateSessionAsync: @Sendable () async throws -> AuthenticationState

public var signout: @Sendable () -> Void

public init(
session: URLSession? = nil,
loadData: (@Sendable (URLRequest) async throws -> (Data, URLResponse))? = nil,
downloadTaskAsync: (@Sendable (URL, URL, Data?) -> (Progress, Task<(saveLocation: URL, response: URLResponse), Error>))? = nil,
validateSessionAsync: (@Sendable () async throws -> Void)? = nil,
validateSessionAsync: (@Sendable () async throws -> AuthenticationState)? = nil,
signout: (@Sendable () -> Void)? = nil
) {
let loginClient: XcodesLoginKit.Client
Expand All @@ -193,7 +193,7 @@ public struct Network: Sendable {
loginClient.urlSession.downloadTaskAsync(with: url, to: saveLocation, resumingWith: resumeData)
}
self.validateSessionAsync = validateSessionAsync ?? {
_ = try await loginClient.validateSession()
try await loginClient.validateSession()
}
self.signout = signout ?? {
loginClient.signout()
Expand All @@ -208,7 +208,7 @@ public struct Network: Sendable {
loginClient.urlSession.downloadTaskAsync(with: url, to: saveLocation, resumingWith: resumeData)
}
self.validateSessionAsync = {
_ = try await loginClient.validateSession()
try await loginClient.validateSession()
}
self.signout = {
loginClient.signout()
Expand Down
9 changes: 9 additions & 0 deletions Xcodes/Frontend/InfoPane/InfoPaneControls.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ struct InfoPaneControls: View {
}
case .installed(_):
InstalledStateButtons(xcode: xcode)
case .uninstalling:
HStack {
Spacer()
ProgressView()
.scaleEffect(0.5)
Text("Uninstalling")
.font(.caption)
.foregroundStyle(.secondary)
}
}
}
}
Expand Down
18 changes: 17 additions & 1 deletion Xcodes/Frontend/MainWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,16 @@ struct MainWindow: View {
.toolbar {
ToolbarItemGroup {
Button(action: { appState.presentedSheet = .signIn }, label: {
Label("Login", systemImage: "person.circle")
Label {
if let authenticatedUserName {
Text(verbatim: authenticatedUserName)
} else {
Text("Login")
}
} icon: {
Image(systemName: "person.circle")
}
.labelStyle(.titleAndIcon)
})
.help("LoginDescription")
if #available(macOS 14, *) {
Expand Down Expand Up @@ -95,6 +104,13 @@ struct MainWindow: View {
appState.allXcodes.first(where: { $0.id == selectedXcodeID })
}

private var authenticatedUserName: String? {
guard case let .authenticated(appleSession) = appState.authenticationState else {
return nil
}
return appleSession.user.fullName ?? appState.savedUsername
}

private var subtitleText: Text {
if let lastUpdated = lastUpdated.map(Date.init(timeIntervalSince1970:)) {
return Text("\(localizeString("UpdatedAt")) \(lastUpdated, style: .date) \(lastUpdated, style: .time)")
Expand Down
6 changes: 3 additions & 3 deletions Xcodes/Frontend/XcodeList/XcodeListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ private struct XcodeVersionGroupRow: View {
Image(systemName: "checkmark.circle.fill")
.foregroundColor(.yellow)
.help(staleSelectedHelpText(selectedVersion: selectedVersion, latestRelease: latestSelectableRelease, selectionTarget: latestSelectionTarget))
case .installing, .none:
case .installing, .uninstalling, .none:
EmptyView()
}
} else if selectedVersion?.selected == true {
Expand Down Expand Up @@ -316,7 +316,7 @@ private struct XcodeVersionGroupRow: View {
} else {
return Text(verbatim: "\(selectedVersion.description) selected, \(latestRelease.description) available.")
}
case .installing, .none:
case .installing, .uninstalling, .none:
return Text(verbatim: "\(selectedVersion.description) selected, \(latestRelease.description) available.")
}
}
Expand Down Expand Up @@ -344,7 +344,7 @@ private struct XcodeVersionGroupRow: View {
.textCase(.uppercase)
.buttonStyle(AppStoreButtonStyle(primary: false, highlighted: false))
.help("InstallDescription")
case .installing:
case .installing, .uninstalling:
EmptyView()
}
}
Expand Down
14 changes: 12 additions & 2 deletions Xcodes/Frontend/XcodeList/XcodeListViewRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ struct XcodeListViewRow: View {
InstallButton(xcode: xcode)
case .installing:
CancelInstallButton(xcode: xcode)
case .uninstalling:
EmptyView()
case let .installed(path):
SelectButton(xcode: xcode)
OpenButton(xcode: xcode)
Expand Down Expand Up @@ -119,7 +121,7 @@ struct XcodeListViewRow: View {
Image(systemName: "checkmark.circle.fill")
.foregroundColor(.yellow)
.help(staleSelectedHelpText)
case .installing:
case .installing, .uninstalling:
EmptyView()
}
} else if xcode.selected {
Expand Down Expand Up @@ -170,6 +172,14 @@ struct XcodeListViewRow: View {
highlighted: selected,
cancel: { appState.presentedAlert = .cancelInstall(xcode: xcode) }
)
case .uninstalling:
HStack(spacing: 4) {
ProgressView()
.scaleEffect(0.5)
Text("Uninstalling")
.font(.caption)
.foregroundStyle(.secondary)
}
}
}

Expand All @@ -182,7 +192,7 @@ struct XcodeListViewRow: View {
return Text(verbatim: "\(selectedVersion) selected, \(latestVersion) available. Click to select \(latestVersion).")
case .notInstalled:
return Text(verbatim: "\(selectedVersion) selected, \(latestVersion) available. Install \(latestVersion) to select it.")
case .installing, .none:
case .installing, .uninstalling, .none:
return Text("ActiveVersionDescription")
}
}
Expand Down
29 changes: 1 addition & 28 deletions Xcodes/Resources/Licenses.rtf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{\rtf1\ansi\ansicpg1252\cocoartf2869
{\rtf1\ansi\ansicpg1252\cocoartf2870
\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fnil\fcharset0 .SFNS-Regular;}
{\colortbl;\red255\green255\blue255;}
{\*\expandedcolortbl;;}
Expand Down Expand Up @@ -1090,33 +1090,6 @@ SOFTWARE.\
\
\

\fs34 data\
\

\fs26 MIT License\
\
Copyright (c) 2018 \
\
Permission is hereby granted, free of charge, to any person obtaining a copy\
of this software and associated documentation files (the "Software"), to deal\
in the Software without restriction, including without limitation the rights\
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\
copies of the Software, and to permit persons to whom the Software is\
furnished to do so, subject to the following conditions:\
\
The above copyright notice and this permission notice shall be included in all\
copies or substantial portions of the Software.\
\
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\
SOFTWARE.\
\
\

\fs34 Sparkle\
\

Expand Down
Loading
Loading