Adds keychain support
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
// Created by James Magahern on 8/24/25.
|
||||
//
|
||||
|
||||
import KeychainAccess
|
||||
import SwiftUI
|
||||
|
||||
struct PreferencesView: View
|
||||
@@ -56,6 +57,7 @@ struct AccountSettings: View
|
||||
var password: String
|
||||
|
||||
private let xpc = XPCClient()
|
||||
private let keychain = Keychain(service: "net.buzzert.kordophonecd")
|
||||
|
||||
init(serverURL: String = "", username: String = "", password: String = "") {
|
||||
self.serverURL = serverURL
|
||||
@@ -70,6 +72,7 @@ struct AccountSettings: View
|
||||
let settings = try await xpc.getSettings()
|
||||
self.serverURL = settings.serverUrl
|
||||
self.username = settings.username
|
||||
self.password = keychain[settings.username] ?? ""
|
||||
} catch {
|
||||
print("Error getting settings: \(error)")
|
||||
}
|
||||
@@ -93,6 +96,8 @@ struct AccountSettings: View
|
||||
username: username
|
||||
))
|
||||
}
|
||||
|
||||
keychain[username] = password
|
||||
} catch {
|
||||
print("Error saving settings: \(error)")
|
||||
}
|
||||
|
||||
@@ -71,16 +71,51 @@ struct ImageItemView: View
|
||||
@State private var img: NSImage?
|
||||
@Environment(\.xpcClient) var xpcClient
|
||||
|
||||
@State private var containerWidth: CGFloat? = nil
|
||||
|
||||
var aspectRatio: CGFloat {
|
||||
if let size = attachment.size, size.height > 0 {
|
||||
return size.width / size.height
|
||||
} else {
|
||||
return 1.0
|
||||
}
|
||||
}
|
||||
|
||||
var preferredSize: CGSize {
|
||||
return CGSize(
|
||||
width: preferredWidth,
|
||||
height: preferredWidth / aspectRatio
|
||||
)
|
||||
}
|
||||
|
||||
var preferredWidth: CGFloat {
|
||||
if let containerWidth, let attachmentWidth = attachment.size?.width {
|
||||
return CGFloat.minimum(containerWidth, attachmentWidth)
|
||||
} else if let containerWidth {
|
||||
return containerWidth
|
||||
} else {
|
||||
return 200.0 // fallback
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
BubbleView(isFromMe: isFromMe) {
|
||||
if let img {
|
||||
Image(nsImage: img)
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(
|
||||
maxWidth: containerWidth
|
||||
)
|
||||
} else {
|
||||
ProgressView()
|
||||
Rectangle()
|
||||
.fill(.gray)
|
||||
|
||||
}
|
||||
}
|
||||
.onGeometryChange(for: CGFloat.self,
|
||||
of: { $0.size.width },
|
||||
action: { containerWidth = $0 })
|
||||
.task {
|
||||
do {
|
||||
let handle = try await xpcClient.openAttachmentFileHandle(
|
||||
|
||||
Reference in New Issue
Block a user