chore: lint and format cleanup
This commit is contained in:
@@ -7,6 +7,7 @@ import SwiftUI
|
||||
private let onboardingWizardLogger = Logger(subsystem: "com.clawdbot", category: "onboarding.wizard")
|
||||
|
||||
// MARK: - Swift 6 AnyCodable Bridging Helpers
|
||||
|
||||
// Bridge between ClawdbotProtocol.AnyCodable and the local module to avoid
|
||||
// Swift 6 strict concurrency type conflicts.
|
||||
|
||||
@@ -62,7 +63,7 @@ final class OnboardingWizardModel {
|
||||
let res: WizardStartResult = try await GatewayConnection.shared.requestDecoded(
|
||||
method: .wizardStart,
|
||||
params: params)
|
||||
applyStartResult(res)
|
||||
self.applyStartResult(res)
|
||||
} catch {
|
||||
self.status = "error"
|
||||
self.errorMessage = error.localizedDescription
|
||||
@@ -86,7 +87,7 @@ final class OnboardingWizardModel {
|
||||
let res: WizardNextResult = try await GatewayConnection.shared.requestDecoded(
|
||||
method: .wizardNext,
|
||||
params: params)
|
||||
applyNextResult(res)
|
||||
self.applyNextResult(res)
|
||||
} catch {
|
||||
self.status = "error"
|
||||
self.errorMessage = error.localizedDescription
|
||||
@@ -100,7 +101,7 @@ final class OnboardingWizardModel {
|
||||
let res: WizardStatusResult = try await GatewayConnection.shared.requestDecoded(
|
||||
method: .wizardCancel,
|
||||
params: ["sessionId": AnyCodable(sessionId)])
|
||||
applyStatusResult(res)
|
||||
self.applyStatusResult(res)
|
||||
} catch {
|
||||
self.status = "error"
|
||||
self.errorMessage = error.localizedDescription
|
||||
@@ -122,7 +123,8 @@ final class OnboardingWizardModel {
|
||||
self.currentStep = decodeWizardStep(res.step)
|
||||
if res.done { self.currentStep = nil }
|
||||
if res.done || anyCodableStringValue(res.status) == "done" || anyCodableStringValue(res.status) == "cancelled"
|
||||
|| anyCodableStringValue(res.status) == "error" {
|
||||
|| anyCodableStringValue(res.status) == "error"
|
||||
{
|
||||
self.sessionId = nil
|
||||
}
|
||||
}
|
||||
@@ -161,8 +163,7 @@ struct OnboardingWizardStepView: View {
|
||||
let initialMulti = Set(
|
||||
options.filter { option in
|
||||
anyCodableArray(step.initialvalue).contains { anyCodableEqual($0, option.option.value) }
|
||||
}.map { $0.index }
|
||||
)
|
||||
}.map(\.index))
|
||||
|
||||
_textValue = State(initialValue: initialText)
|
||||
_confirmValue = State(initialValue: initialConfirm)
|
||||
@@ -183,18 +184,18 @@ struct OnboardingWizardStepView: View {
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
}
|
||||
|
||||
switch wizardStepType(step) {
|
||||
switch wizardStepType(self.step) {
|
||||
case "note":
|
||||
EmptyView()
|
||||
case "text":
|
||||
textField
|
||||
self.textField
|
||||
case "confirm":
|
||||
Toggle("", isOn: $confirmValue)
|
||||
Toggle("", isOn: self.$confirmValue)
|
||||
.toggleStyle(.switch)
|
||||
case "select":
|
||||
selectOptions
|
||||
self.selectOptions
|
||||
case "multiselect":
|
||||
multiselectOptions
|
||||
self.multiselectOptions
|
||||
case "progress":
|
||||
ProgressView()
|
||||
.controlSize(.small)
|
||||
@@ -205,25 +206,25 @@ struct OnboardingWizardStepView: View {
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
|
||||
Button(action: submit) {
|
||||
Text(wizardStepType(step) == "action" ? "Run" : "Continue")
|
||||
Button(action: self.submit) {
|
||||
Text(wizardStepType(self.step) == "action" ? "Run" : "Continue")
|
||||
.frame(minWidth: 120)
|
||||
}
|
||||
.buttonStyle(.borderedProminent)
|
||||
.disabled(isSubmitting || isBlocked)
|
||||
.disabled(self.isSubmitting || self.isBlocked)
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var textField: some View {
|
||||
let isSensitive = step.sensitive == true
|
||||
let isSensitive = self.step.sensitive == true
|
||||
if isSensitive {
|
||||
SecureField(step.placeholder ?? "", text: $textValue)
|
||||
SecureField(self.step.placeholder ?? "", text: self.$textValue)
|
||||
.textFieldStyle(.roundedBorder)
|
||||
.frame(maxWidth: 360)
|
||||
} else {
|
||||
TextField(step.placeholder ?? "", text: $textValue)
|
||||
TextField(self.step.placeholder ?? "", text: self.$textValue)
|
||||
.textFieldStyle(.roundedBorder)
|
||||
.frame(maxWidth: 360)
|
||||
}
|
||||
@@ -231,12 +232,12 @@ struct OnboardingWizardStepView: View {
|
||||
|
||||
private var selectOptions: some View {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
ForEach(optionItems) { item in
|
||||
ForEach(self.optionItems) { item in
|
||||
Button {
|
||||
selectedIndex = item.index
|
||||
self.selectedIndex = item.index
|
||||
} label: {
|
||||
HStack(alignment: .top, spacing: 8) {
|
||||
Image(systemName: selectedIndex == item.index ? "largecircle.fill.circle" : "circle")
|
||||
Image(systemName: self.selectedIndex == item.index ? "largecircle.fill.circle" : "circle")
|
||||
.foregroundStyle(.accent)
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text(item.option.label)
|
||||
@@ -256,8 +257,8 @@ struct OnboardingWizardStepView: View {
|
||||
|
||||
private var multiselectOptions: some View {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
ForEach(optionItems) { item in
|
||||
Toggle(isOn: bindingForOption(item)) {
|
||||
ForEach(self.optionItems) { item in
|
||||
Toggle(isOn: self.bindingForOption(item)) {
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text(item.option.label)
|
||||
if let hint = item.option.hint, !hint.isEmpty {
|
||||
@@ -273,47 +274,47 @@ struct OnboardingWizardStepView: View {
|
||||
|
||||
private func bindingForOption(_ item: WizardOptionItem) -> Binding<Bool> {
|
||||
Binding(get: {
|
||||
selectedIndices.contains(item.index)
|
||||
self.selectedIndices.contains(item.index)
|
||||
}, set: { newValue in
|
||||
if newValue {
|
||||
selectedIndices.insert(item.index)
|
||||
self.selectedIndices.insert(item.index)
|
||||
} else {
|
||||
selectedIndices.remove(item.index)
|
||||
self.selectedIndices.remove(item.index)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private var isBlocked: Bool {
|
||||
let type = wizardStepType(step)
|
||||
if type == "select" { return optionItems.isEmpty }
|
||||
if type == "multiselect" { return optionItems.isEmpty }
|
||||
if type == "select" { return self.optionItems.isEmpty }
|
||||
if type == "multiselect" { return self.optionItems.isEmpty }
|
||||
return false
|
||||
}
|
||||
|
||||
private func submit() {
|
||||
switch wizardStepType(step) {
|
||||
switch wizardStepType(self.step) {
|
||||
case "note", "progress":
|
||||
onSubmit(nil)
|
||||
self.onSubmit(nil)
|
||||
case "text":
|
||||
onSubmit(AnyCodable(textValue))
|
||||
self.onSubmit(AnyCodable(self.textValue))
|
||||
case "confirm":
|
||||
onSubmit(AnyCodable(confirmValue))
|
||||
self.onSubmit(AnyCodable(self.confirmValue))
|
||||
case "select":
|
||||
guard optionItems.indices.contains(selectedIndex) else {
|
||||
onSubmit(nil)
|
||||
guard self.optionItems.indices.contains(self.selectedIndex) else {
|
||||
self.onSubmit(nil)
|
||||
return
|
||||
}
|
||||
let option = optionItems[selectedIndex].option
|
||||
onSubmit(bridgeToLocal(option.value) ?? AnyCodable(option.label))
|
||||
let option = self.optionItems[self.selectedIndex].option
|
||||
self.onSubmit(bridgeToLocal(option.value) ?? AnyCodable(option.label))
|
||||
case "multiselect":
|
||||
let values = optionItems
|
||||
.filter { selectedIndices.contains($0.index) }
|
||||
let values = self.optionItems
|
||||
.filter { self.selectedIndices.contains($0.index) }
|
||||
.map { bridgeToLocal($0.option.value) ?? AnyCodable($0.option.label) }
|
||||
onSubmit(AnyCodable(values))
|
||||
self.onSubmit(AnyCodable(values))
|
||||
case "action":
|
||||
onSubmit(AnyCodable(true))
|
||||
self.onSubmit(AnyCodable(true))
|
||||
default:
|
||||
onSubmit(nil)
|
||||
self.onSubmit(nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -322,7 +323,7 @@ private struct WizardOptionItem: Identifiable {
|
||||
let index: Int
|
||||
let option: WizardOption
|
||||
|
||||
var id: Int { index }
|
||||
var id: Int { self.index }
|
||||
}
|
||||
|
||||
private struct WizardOption {
|
||||
@@ -359,15 +360,15 @@ private func wizardStepType(_ step: WizardStep) -> String {
|
||||
private func anyCodableString(_ value: ProtocolAnyCodable?) -> String {
|
||||
switch value?.value {
|
||||
case let string as String:
|
||||
return string
|
||||
string
|
||||
case let int as Int:
|
||||
return String(int)
|
||||
String(int)
|
||||
case let double as Double:
|
||||
return String(double)
|
||||
String(double)
|
||||
case let bool as Bool:
|
||||
return bool ? "true" : "false"
|
||||
bool ? "true" : "false"
|
||||
default:
|
||||
return ""
|
||||
""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -378,44 +379,44 @@ private func anyCodableStringValue(_ value: ProtocolAnyCodable?) -> String? {
|
||||
private func anyCodableBool(_ value: ProtocolAnyCodable?) -> Bool {
|
||||
switch value?.value {
|
||||
case let bool as Bool:
|
||||
return bool
|
||||
bool
|
||||
case let string as String:
|
||||
return string.lowercased() == "true"
|
||||
string.lowercased() == "true"
|
||||
default:
|
||||
return false
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
private func anyCodableArray(_ value: ProtocolAnyCodable?) -> [ProtocolAnyCodable] {
|
||||
switch value?.value {
|
||||
case let arr as [ProtocolAnyCodable]:
|
||||
return arr
|
||||
arr
|
||||
case let arr as [Any]:
|
||||
return arr.map { ProtocolAnyCodable($0) }
|
||||
arr.map { ProtocolAnyCodable($0) }
|
||||
default:
|
||||
return []
|
||||
[]
|
||||
}
|
||||
}
|
||||
|
||||
private func anyCodableEqual(_ lhs: ProtocolAnyCodable?, _ rhs: ProtocolAnyCodable?) -> Bool {
|
||||
switch (lhs?.value, rhs?.value) {
|
||||
case let (l as String, r as String):
|
||||
return l == r
|
||||
l == r
|
||||
case let (l as Int, r as Int):
|
||||
return l == r
|
||||
l == r
|
||||
case let (l as Double, r as Double):
|
||||
return l == r
|
||||
l == r
|
||||
case let (l as Bool, r as Bool):
|
||||
return l == r
|
||||
l == r
|
||||
case let (l as String, r as Int):
|
||||
return l == String(r)
|
||||
l == String(r)
|
||||
case let (l as Int, r as String):
|
||||
return String(l) == r
|
||||
String(l) == r
|
||||
case let (l as String, r as Double):
|
||||
return l == String(r)
|
||||
l == String(r)
|
||||
case let (l as Double, r as String):
|
||||
return String(l) == r
|
||||
String(l) == r
|
||||
default:
|
||||
return false
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user