Skip to content

Commit

Permalink
Add functionality to accounts view
Browse files Browse the repository at this point in the history
  • Loading branch information
vapidinfinity committed Mar 16, 2024
1 parent 95389a7 commit ed31eec
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 24 deletions.
14 changes: 4 additions & 10 deletions Mythic/Deprecated/Views/Auth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,6 @@ struct AuthView: View {
}
}

// MARK: - Initializer
/**
Initializes the AuthView.

- Parameters:
- isPresented: Binding to control the presentation of the view.
- authSuccessful: Binding to track the authentication success state.
*/
init(isPresented: Binding<Bool>, authSuccessful: Binding<Bool?> = .constant(false)) {
_isPresented = isPresented
_authSuccessful = authSuccessful
Expand Down Expand Up @@ -99,19 +91,20 @@ struct AuthView: View {
.buttonStyle(.borderedProminent)
}
.fixedSize()

HStack {
Button(action: { // TODO: implement question mark popover
isHelpPopoverPresented.toggle()
}, label: {
Image(systemName: "questionmark")
.controlSize(.small)
})
.clipShape(Circle())
.clipShape(.circle)
.popover(isPresented: $isHelpPopoverPresented) {
VStack {
NotImplementedView()
}
.padding()
.padding()
}

Spacer()
Expand All @@ -123,6 +116,7 @@ struct AuthView: View {
}
.padding()
.fixedSize()
.task(priority: .userInitiated) { workspace.open(URL(string: "http://legendary.gl/epiclogin")!) }
}
}

Expand Down
6 changes: 6 additions & 0 deletions Mythic/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,9 @@
},
"Not implemented yet" : {

},
"Not signed in" : {

},
"OK" : {

Expand Down Expand Up @@ -494,6 +497,9 @@
},
"Sign Out" : {

},
"Signed in as \"%@\"." : {

},
"Skip" : {

Expand Down
91 changes: 79 additions & 12 deletions Mythic/Views/Navigation/Accounts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,87 @@ import SwiftUI
import SwordRPC

struct AccountsView: View {
@State private var isSignOutConfirmationPresented: Bool = false
@State private var isAuthViewPresented: Bool = false
@State private var isHoveringOverDestructiveEpicButton: Bool = false
@State private var signedIn: Bool = false

var body: some View {
NotImplementedView()
.navigationTitle("Accounts")
.task(priority: .background) {
discordRPC.setPresence({
var presence: RichPresence = .init()
presence.details = "Currently in the accounts section."
presence.state = "Checking out all their accounts"
presence.timestamps.start = .now
presence.assets.largeImage = "macos_512x512_2x"

return presence
}())
List {
// MARK: Epic account View
HStack {
Image("EGFaceless")
.resizable()
.frame(width: 30, height: 30)

VStack {
HStack {
Text("Epic")
Spacer()
}
HStack {
Text(signedIn ? "Signed in as \"\(Legendary.whoAmI())\"." : "Not signed in")
.font(.bold(.title3)())
Spacer()
}
}

Spacer()

Button {
if signedIn {
isSignOutConfirmationPresented = true
} else {
isAuthViewPresented = true
}
} label: {
Image(systemName: signedIn ? "person.slash" : "person")
.foregroundStyle(isHoveringOverDestructiveEpicButton ? .red : .primary)
.padding(5)

}
.clipShape(.circle)
.onHover { hovering in
withAnimation(.easeInOut(duration: 0.1)) {
isHoveringOverDestructiveEpicButton = (hovering && signedIn)
}
}
.sheet(isPresented: $isAuthViewPresented, onDismiss: { signedIn = Legendary.signedIn() }, content: {
AuthView(isPresented: $isAuthViewPresented)
})
.alert(isPresented: $isSignOutConfirmationPresented) {
Alert(
title: .init("Are you sure you want to sign out?"),
message: .init("This will sign you out of the account \"\(Legendary.whoAmI())\"."),
primaryButton: .destructive(.init("Sign Out")) {
Task.sync(priority: .high) {
await Legendary.command(
args: ["auth", "--delete"],
useCache: false,
identifier: "userAreaSignOut"
)
}

signedIn = Legendary.signedIn()
},
secondaryButton: .cancel(.init("Cancel"))
)
}
}
.task { signedIn = Legendary.signedIn() }
}
.navigationTitle("Accounts")
.task(priority: .background) {
discordRPC.setPresence({
var presence: RichPresence = .init()
presence.details = "Currently in the accounts section."
presence.state = "Checking out all their accounts"
presence.timestamps.start = .now
presence.assets.largeImage = "macos_512x512_2x"

return presence
}())
}
}
}

Expand Down
2 changes: 0 additions & 2 deletions Mythic/Views/Navigation/Library/Extensions/GameImport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ extension LibraryView {
isPresented: $isPresented,
isGameListRefreshCalled: $isGameListRefreshCalled
)
#if !targetEnvironment(simulator) // https://arc.net/l/quote/noenvbmd
.padding(.bottom) // FIXME: dirtyfix for padding issue
#endif
}
}

Expand Down

0 comments on commit ed31eec

Please sign in to comment.