summaryrefslogtreecommitdiff
path: root/Sources/BubombUI/Settings
diff options
context:
space:
mode:
Diffstat (limited to 'Sources/BubombUI/Settings')
-rw-r--r--Sources/BubombUI/Settings/ExecutionStatusView.swift308
-rw-r--r--Sources/BubombUI/Settings/GeneralSettingsView.swift217
-rw-r--r--Sources/BubombUI/Settings/PayloadEditorView.swift724
-rw-r--r--Sources/BubombUI/Settings/SequenceStepEditorView.swift184
-rw-r--r--Sources/BubombUI/Settings/SettingsView.swift95
-rw-r--r--Sources/BubombUI/Settings/Theme.swift42
6 files changed, 1570 insertions, 0 deletions
diff --git a/Sources/BubombUI/Settings/ExecutionStatusView.swift b/Sources/BubombUI/Settings/ExecutionStatusView.swift
new file mode 100644
index 0000000..f55df66
--- /dev/null
+++ b/Sources/BubombUI/Settings/ExecutionStatusView.swift
@@ -0,0 +1,308 @@
+import SwiftUI
+import BubombCore
+#if canImport(AppKit)
+import AppKit
+#endif
+
+/// Displays execution results, live console output, status badges, and history.
+@MainActor
+public struct ExecutionStatusView: View {
+ @ObservedObject var settingsStore: SettingsStore
+ @ObservedObject var executor: PayloadExecutor
+
+ @State private var selectedRecordId: UUID? = nil
+ @State private var copiedNotice: Bool = false
+
+ public init(settingsStore: SettingsStore = .shared, executor: PayloadExecutor? = nil) {
+ self.settingsStore = settingsStore
+ self.executor = executor ?? PayloadExecutor.shared
+ }
+
+ private var activeRecord: ExecutionRecord? {
+ if let id = selectedRecordId {
+ return settingsStore.settings.recentExecutions.first(where: { $0.id == id })
+ }
+ return settingsStore.settings.recentExecutions.first
+ }
+
+ public var body: some View {
+ ScrollView {
+ VStack(alignment: .leading, spacing: 18) {
+ liveStatusSection
+ currentRecordDetailsSection
+ outputConsoleSection
+ historySection
+ }
+ .padding(18)
+ }
+ .background(BubombTheme.windowBackground)
+ }
+
+ // MARK: - Live Status Section
+
+ private var liveStatusSection: some View {
+ HStack(spacing: 12) {
+ switch executor.currentState {
+ case .idle:
+ Image(systemName: "checkmark.shield.fill")
+ .font(.title2)
+ .foregroundColor(BubombTheme.accentOrange)
+ VStack(alignment: .leading, spacing: 2) {
+ Text("Bubomb Armed & Ready")
+ .font(.headline)
+ .foregroundColor(BubombTheme.textPrimary)
+ Text("Click the bomb in your menu bar to detonate.")
+ .font(.caption)
+ .foregroundColor(BubombTheme.textSecondary)
+ }
+
+ case .burning(let name, let info):
+ ProgressView()
+ .progressViewStyle(.circular)
+ .scaleEffect(0.8)
+ VStack(alignment: .leading, spacing: 2) {
+ Text("Detonating: \(name)")
+ .font(.headline)
+ .foregroundColor(BubombTheme.accentOrange)
+ Text(info ?? "Executing action...")
+ .font(.caption)
+ .foregroundColor(BubombTheme.textSecondary)
+ }
+
+ case .exploded(let record):
+ Image(systemName: "flame.fill")
+ .font(.title2)
+ .foregroundColor(BubombTheme.successGreen)
+ VStack(alignment: .leading, spacing: 2) {
+ Text("Detonation Succeeded!")
+ .font(.headline)
+ .foregroundColor(BubombTheme.successGreen)
+ Text("Finished in \(record.formattedDuration)")
+ .font(.caption)
+ .foregroundColor(BubombTheme.textSecondary)
+ }
+
+ case .failed(let record):
+ Image(systemName: "xmark.octagon.fill")
+ .font(.title2)
+ .foregroundColor(BubombTheme.failureRed)
+ VStack(alignment: .leading, spacing: 2) {
+ Text("Detonation Failed")
+ .font(.headline)
+ .foregroundColor(BubombTheme.failureRed)
+ Text(record.errorMessage ?? "An error occurred during execution.")
+ .font(.caption)
+ .foregroundColor(BubombTheme.failureRed)
+ }
+ }
+
+ Spacer()
+
+ if executor.currentState.isRunning {
+ Button("Cancel") {
+ executor.cancel()
+ }
+ .buttonStyle(.bordered)
+ .tint(BubombTheme.failureRed)
+ }
+ }
+ .bubombCard()
+ }
+
+ // MARK: - Current Record Details
+
+ @ViewBuilder
+ private var currentRecordDetailsSection: some View {
+ if let record = activeRecord {
+ VStack(alignment: .leading, spacing: 10) {
+ HStack {
+ Text("Execution Details: \(record.payloadName)")
+ .font(.subheadline.bold())
+ .foregroundColor(BubombTheme.textPrimary)
+ Spacer()
+ statusBadge(for: record.status)
+ }
+
+ Divider().background(BubombTheme.borderSubtle)
+
+ Grid(alignment: .leading, horizontalSpacing: 16, verticalSpacing: 6) {
+ GridRow {
+ Text("Payload Type:").font(.caption).foregroundColor(BubombTheme.textSecondary)
+ Text(record.payloadTypeDescription).font(.caption.bold()).foregroundColor(BubombTheme.textPrimary)
+ }
+ GridRow {
+ Text("Timestamp:").font(.caption).foregroundColor(BubombTheme.textSecondary)
+ Text(record.startedAt.formatted(date: .abbreviated, time: .standard)).font(.caption).foregroundColor(BubombTheme.textPrimary)
+ }
+ GridRow {
+ Text("Duration:").font(.caption).foregroundColor(BubombTheme.textSecondary)
+ Text(record.formattedDuration).font(.caption.monospaced()).foregroundColor(BubombTheme.accentOrange)
+ }
+ if let code = record.exitCode {
+ GridRow {
+ Text("Exit Status:").font(.caption).foregroundColor(BubombTheme.textSecondary)
+ Text("\(code)").font(.caption.monospaced().bold()).foregroundColor(code == 0 ? BubombTheme.successGreen : BubombTheme.failureRed)
+ }
+ }
+ if let err = record.errorMessage {
+ GridRow {
+ Text("Error Details:").font(.caption).foregroundColor(BubombTheme.failureRed)
+ Text(err).font(.caption).foregroundColor(BubombTheme.failureRed)
+ }
+ }
+ }
+ }
+ .bubombCard()
+ }
+ }
+
+ // MARK: - Output Console
+
+ private var outputConsoleSection: some View {
+ VStack(alignment: .leading, spacing: 8) {
+ HStack {
+ Text("Detonation Log Output")
+ .font(.caption.bold())
+ .foregroundColor(BubombTheme.textSecondary)
+
+ Spacer()
+
+ if copiedNotice {
+ Text("Copied!").font(.caption).foregroundColor(BubombTheme.successGreen)
+ }
+
+ Button(action: {
+ copyOutputToClipboard()
+ }) {
+ HStack(spacing: 4) {
+ Image(systemName: "doc.on.doc").font(.caption)
+ Text("Copy").font(.caption)
+ }
+ }
+ .buttonStyle(.plain)
+ .foregroundColor(BubombTheme.accentAmber)
+ }
+
+ let log = activeRecord?.combinedOutput ?? "No logs recorded yet. Detonate a payload to see captured stdout/stderr here."
+
+ ScrollView(.vertical) {
+ Text(log)
+ .font(.system(.caption, design: .monospaced))
+ .foregroundColor(Color.green.opacity(0.9))
+ .frame(maxWidth: .infinity, alignment: .leading)
+ .padding(10)
+ }
+ .frame(height: 140)
+ .background(Color.black.opacity(0.6))
+ .cornerRadius(6)
+ .overlay(RoundedRectangle(cornerRadius: 6).stroke(BubombTheme.borderSubtle, lineWidth: 1))
+ }
+ .bubombCard()
+ }
+
+ // MARK: - History Section
+
+ private var historySection: some View {
+ VStack(alignment: .leading, spacing: 10) {
+ HStack {
+ Text("Recent Detonations (\(settingsStore.settings.recentExecutions.count))")
+ .font(.subheadline.bold())
+ .foregroundColor(BubombTheme.textPrimary)
+
+ Spacer()
+
+ if !settingsStore.settings.recentExecutions.isEmpty {
+ Button("Clear History") {
+ settingsStore.clearHistory()
+ selectedRecordId = nil
+ }
+ .font(.caption)
+ .buttonStyle(.plain)
+ .foregroundColor(BubombTheme.failureRed)
+ }
+ }
+
+ if settingsStore.settings.recentExecutions.isEmpty {
+ Text("No detonations recorded yet.")
+ .font(.caption)
+ .foregroundColor(BubombTheme.textMuted)
+ .padding(.vertical, 8)
+ } else {
+ VStack(spacing: 4) {
+ ForEach(settingsStore.settings.recentExecutions) { item in
+ Button(action: {
+ selectedRecordId = item.id
+ }) {
+ HStack {
+ Circle()
+ .fill(statusColor(for: item.status))
+ .frame(width: 8, height: 8)
+
+ Text(item.payloadName)
+ .font(.caption.bold())
+ .foregroundColor(BubombTheme.textPrimary)
+
+ Text("(\(item.payloadTypeDescription))")
+ .font(.caption2)
+ .foregroundColor(BubombTheme.textMuted)
+
+ Spacer()
+
+ Text(item.formattedDuration)
+ .font(.caption2.monospaced())
+ .foregroundColor(BubombTheme.textSecondary)
+
+ Text(item.startedAt.formatted(date: .omitted, time: .shortened))
+ .font(.caption2)
+ .foregroundColor(BubombTheme.textSecondary)
+ }
+ .padding(8)
+ .background(
+ (selectedRecordId == item.id || (selectedRecordId == nil && settingsStore.settings.recentExecutions.first?.id == item.id))
+ ? BubombTheme.accentOrange.opacity(0.15)
+ : Color.black.opacity(0.2)
+ )
+ .cornerRadius(6)
+ }
+ .buttonStyle(.plain)
+ }
+ }
+ }
+ }
+ .bubombCard()
+ }
+
+ // MARK: - Helpers
+
+ private func statusBadge(for status: ExecutionStatus) -> some View {
+ Text(status.rawValue)
+ .font(.caption2.bold())
+ .padding(.horizontal, 8)
+ .padding(.vertical, 3)
+ .background(statusColor(for: status).opacity(0.2))
+ .foregroundColor(statusColor(for: status))
+ .cornerRadius(4)
+ }
+
+ private func statusColor(for status: ExecutionStatus) -> Color {
+ switch status {
+ case .succeeded: return BubombTheme.successGreen
+ case .failed: return BubombTheme.failureRed
+ case .cancelled: return BubombTheme.accentAmber
+ case .timedOut: return BubombTheme.accentPurple
+ }
+ }
+
+ private func copyOutputToClipboard() {
+ #if canImport(AppKit)
+ let pasteboard = NSPasteboard.general
+ pasteboard.clearContents()
+ let content = activeRecord?.combinedOutput ?? ""
+ pasteboard.setString(content, forType: .string)
+ copiedNotice = true
+ DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
+ copiedNotice = false
+ }
+ #endif
+ }
+}
diff --git a/Sources/BubombUI/Settings/GeneralSettingsView.swift b/Sources/BubombUI/Settings/GeneralSettingsView.swift
new file mode 100644
index 0000000..4f5948d
--- /dev/null
+++ b/Sources/BubombUI/Settings/GeneralSettingsView.swift
@@ -0,0 +1,217 @@
+import SwiftUI
+import BubombCore
+#if canImport(ServiceManagement)
+import ServiceManagement
+#endif
+
+/// General application preferences including login item, animations, and safety toggles.
+@MainActor
+public struct GeneralSettingsView: View {
+ @ObservedObject var settingsStore: SettingsStore
+ @State private var showResetConfirmation: Bool = false
+
+ public init(settingsStore: SettingsStore = .shared) {
+ self.settingsStore = settingsStore
+ }
+
+ public var body: some View {
+ ScrollView {
+ VStack(alignment: .leading, spacing: 18) {
+ appIdentitySection
+ systemIntegrationSection
+ animationPreferenceSection
+ safetySection
+ dangerZoneSection
+ }
+ .padding(18)
+ }
+ .background(BubombTheme.windowBackground)
+ .alert("Reset All Settings?", isPresented: $showResetConfirmation) {
+ Button("Cancel", role: .cancel) {}
+ Button("Reset Everything", role: .destructive) {
+ settingsStore.resetToDefaults()
+ }
+ } message: {
+ Text("This will remove your configured payload, execution history, and restore factory defaults.")
+ }
+ }
+
+ // MARK: - Sections
+
+ private var appIdentitySection: some View {
+ HStack(spacing: 16) {
+ AnimatedBombView(size: 56)
+
+ VStack(alignment: .leading, spacing: 3) {
+ Text("Bubomb")
+ .font(.title2.bold())
+ .foregroundColor(BubombTheme.textPrimary)
+
+ Text("Configure the boom.")
+ .font(.subheadline)
+ .foregroundColor(BubombTheme.accentOrange)
+
+ Text("Version \(AppSettings.currentVersion) (Build \(AppSettings.buildNumber)) • Native macOS")
+ .font(.caption2)
+ .foregroundColor(BubombTheme.textMuted)
+ }
+ Spacer()
+ }
+ .bubombCard()
+ }
+
+ private var systemIntegrationSection: some View {
+ VStack(alignment: .leading, spacing: 12) {
+ Text("System & Startup")
+ .font(.subheadline.bold())
+ .foregroundColor(BubombTheme.accentOrange)
+
+ Toggle("Launch Bubomb at Login", isOn: Binding(
+ get: { settingsStore.settings.launchAtLogin },
+ set: { newValue in
+ var s = settingsStore.settings
+ s.launchAtLogin = newValue
+ settingsStore.update(s)
+ toggleLaunchAtLogin(newValue)
+ }
+ ))
+ .font(.subheadline)
+ .foregroundColor(BubombTheme.textPrimary)
+
+ Text("Automatically arms your menu bar bomb when your Mac starts.")
+ .font(.caption)
+ .foregroundColor(BubombTheme.textSecondary)
+
+ Divider().background(BubombTheme.borderSubtle)
+
+ Toggle("Start Silently in Menu Bar", isOn: Binding(
+ get: { settingsStore.settings.startSilentlyInMenuBar },
+ set: { newValue in
+ var s = settingsStore.settings
+ s.startSilentlyInMenuBar = newValue
+ settingsStore.update(s)
+ }
+ ))
+ .font(.subheadline)
+ .foregroundColor(BubombTheme.textPrimary)
+
+ Text("When enabled, Bubomb starts without opening the Settings window.")
+ .font(.caption)
+ .foregroundColor(BubombTheme.textSecondary)
+ }
+ .bubombCard()
+ }
+
+ private var animationPreferenceSection: some View {
+ VStack(alignment: .leading, spacing: 12) {
+ Text("Visuals & Feedback")
+ .font(.subheadline.bold())
+ .foregroundColor(BubombTheme.accentOrange)
+
+ Text("Menu Bar Animation Style:")
+ .font(.caption)
+ .foregroundColor(BubombTheme.textSecondary)
+
+ Picker("", selection: Binding(
+ get: { settingsStore.settings.animationPreference },
+ set: { newValue in
+ var s = settingsStore.settings
+ s.animationPreference = newValue
+ settingsStore.update(s)
+ }
+ )) {
+ ForEach(AnimationPreference.allCases, id: \.self) { pref in
+ Text(pref.rawValue).tag(pref)
+ }
+ }
+ .labelsHidden()
+
+ Divider().background(BubombTheme.borderSubtle)
+
+ Toggle("Play subtle completion sound / haptic feedback", isOn: Binding(
+ get: { settingsStore.settings.playCompletionFeedback },
+ set: { newValue in
+ var s = settingsStore.settings
+ s.playCompletionFeedback = newValue
+ settingsStore.update(s)
+ }
+ ))
+ .font(.subheadline)
+ .foregroundColor(BubombTheme.textPrimary)
+ }
+ .bubombCard()
+ }
+
+ private var safetySection: some View {
+ VStack(alignment: .leading, spacing: 12) {
+ Text("Safety & Protection")
+ .font(.subheadline.bold())
+ .foregroundColor(BubombTheme.accentOrange)
+
+ Toggle("Require explicit confirmation for destructive actions", isOn: Binding(
+ get: { settingsStore.settings.confirmDestructiveActions },
+ set: { newValue in
+ var s = settingsStore.settings
+ s.confirmDestructiveActions = newValue
+ settingsStore.update(s)
+ }
+ ))
+ .font(.subheadline)
+ .foregroundColor(BubombTheme.textPrimary)
+
+ Text("Guards against accidental execution of destructive patterns (e.g. recursive removals, raw disk writes).")
+ .font(.caption)
+ .foregroundColor(BubombTheme.textSecondary)
+ }
+ .bubombCard()
+ }
+
+ private var dangerZoneSection: some View {
+ VStack(alignment: .leading, spacing: 12) {
+ Text("Reset")
+ .font(.subheadline.bold())
+ .foregroundColor(BubombTheme.failureRed)
+
+ HStack {
+ VStack(alignment: .leading, spacing: 2) {
+ Text("Reset Bubomb Settings")
+ .font(.subheadline)
+ .foregroundColor(BubombTheme.textPrimary)
+ Text("Restores all settings, clears history, and unarms active payload.")
+ .font(.caption)
+ .foregroundColor(BubombTheme.textSecondary)
+ }
+ Spacer()
+ Button("Reset Defaults...") {
+ showResetConfirmation = true
+ }
+ .buttonStyle(.bordered)
+ .tint(BubombTheme.failureRed)
+ }
+ }
+ .bubombCard()
+ }
+
+ // MARK: - Helper
+
+ private func toggleLaunchAtLogin(_ enable: Bool) {
+ #if canImport(ServiceManagement)
+ if #available(macOS 13.0, *) {
+ do {
+ if enable {
+ if SMAppService.mainApp.status != .enabled {
+ try SMAppService.mainApp.register()
+ }
+ } else {
+ if SMAppService.mainApp.status == .enabled {
+ try SMAppService.mainApp.unregister()
+ }
+ }
+ } catch {
+ // If service management registration fails in dev mode, non-fatal
+ print("Launch at login registration notice: \(error)")
+ }
+ }
+ #endif
+ }
+}
diff --git a/Sources/BubombUI/Settings/PayloadEditorView.swift b/Sources/BubombUI/Settings/PayloadEditorView.swift
new file mode 100644
index 0000000..dd71959
--- /dev/null
+++ b/Sources/BubombUI/Settings/PayloadEditorView.swift
@@ -0,0 +1,724 @@
+import SwiftUI
+import BubombCore
+#if canImport(AppKit)
+import AppKit
+import UniformTypeIdentifiers
+#endif
+
+/// Comprehensive editor for configuring Bubomb payloads.
+@MainActor
+public struct PayloadEditorView: View {
+ @ObservedObject var settingsStore: SettingsStore
+ @ObservedObject var executor: PayloadExecutor
+
+ @State private var payloadName: String = ""
+ @State private var selectedTypeIndex: Int = 0
+
+ // Shell state
+ @State private var shellCommand: String = ""
+ @State private var shellPath: String = "/bin/zsh"
+ @State private var shellWorkDir: String = ""
+ @State private var shellArgs: String = ""
+ @State private var shellTimeout: TimeInterval = 30
+ @State private var envKeyInput: String = ""
+ @State private var envValInput: String = ""
+ @State private var envVars: [String: String] = [:]
+
+ // App state
+ @State private var appPath: String = ""
+ @State private var appArgs: String = ""
+
+ // URL state
+ @State private var urlString: String = "https://"
+
+ // Script state
+ @State private var scriptPath: String = ""
+ @State private var scriptArgs: String = ""
+ @State private var scriptWorkDir: String = ""
+ @State private var scriptTimeout: TimeInterval = 60
+
+ // Sequence state
+ @State private var sequenceSteps: [SequenceStep] = []
+ @State private var sequenceStopOnError: Bool = true
+ @State private var editingStepIndex: Int? = nil
+ @State private var showStepEditor: Bool = false
+ @State private var tempStep: SequenceStep = SequenceStep(name: "New Step", action: .openURL(urlString: "https://apple.com"))
+
+ // Feedback & Validation
+ @State private var feedbackMessage: String? = nil
+ @State private var isErrorFeedback: Bool = false
+ @State private var showDestructiveConfirmation: Bool = false
+ @State private var pendingDestructiveActionReason: String? = nil
+
+ public init(settingsStore: SettingsStore = .shared, executor: PayloadExecutor? = nil) {
+ self.settingsStore = settingsStore
+ self.executor = executor ?? PayloadExecutor.shared
+ }
+
+ public var body: some View {
+ ScrollView {
+ VStack(alignment: .leading, spacing: 18) {
+ headerStatusSection
+ payloadTypeSelector
+ configurationFormSection
+ safetyNoticeSection
+ actionButtonsSection
+ }
+ .padding(18)
+ }
+ .background(BubombTheme.windowBackground)
+ .onAppear {
+ loadFromActivePayload()
+ }
+ .sheet(isPresented: $showStepEditor) {
+ SequenceStepEditorView(
+ step: $tempStep,
+ onSave: {
+ if let idx = editingStepIndex, idx < sequenceSteps.count {
+ sequenceSteps[idx] = tempStep
+ } else {
+ sequenceSteps.append(tempStep)
+ }
+ showStepEditor = false
+ },
+ onCancel: {
+ showStepEditor = false
+ }
+ )
+ }
+ .alert("⚠️ Confirm Destructive Action", isPresented: $showDestructiveConfirmation) {
+ Button("Cancel", role: .cancel) {}
+ Button("Detonate Anyway", role: .destructive) {
+ executeDetonation(bypassConfirmation: true)
+ }
+ } message: {
+ Text(pendingDestructiveActionReason ?? "This action may perform irreversible changes.")
+ }
+ }
+
+ // MARK: - Sections
+
+ private var headerStatusSection: some View {
+ HStack(spacing: 12) {
+ VStack(alignment: .leading, spacing: 4) {
+ HStack(spacing: 8) {
+ Text("Configured Payload:")
+ .font(.headline)
+ .foregroundColor(BubombTheme.textPrimary)
+
+ if let active = settingsStore.settings.activePayload {
+ HStack(spacing: 4) {
+ Circle().fill(BubombTheme.successGreen).frame(width: 8, height: 8)
+ Text(active.name)
+ .font(.subheadline.bold())
+ .foregroundColor(BubombTheme.accentOrange)
+ }
+ } else {
+ HStack(spacing: 4) {
+ Circle().fill(BubombTheme.accentAmber).frame(width: 8, height: 8)
+ Text("Unconfigured")
+ .font(.subheadline)
+ .foregroundColor(BubombTheme.textMuted)
+ }
+ }
+ }
+
+ Text("Configure the boom. One click on the menu bar bomb detonates this action instantly.")
+ .font(.caption)
+ .foregroundColor(BubombTheme.textSecondary)
+ }
+
+ Spacer()
+
+ AnimatedBombView(size: 44, isDetonating: executor.currentState.isRunning) {
+ detonateOrConfirm()
+ }
+ }
+ .bubombCard()
+ }
+
+ private var payloadTypeSelector: some View {
+ VStack(alignment: .leading, spacing: 10) {
+ HStack {
+ Text("Payload Name")
+ .font(.caption.bold())
+ .foregroundColor(BubombTheme.textSecondary)
+ Spacer()
+ }
+
+ TextField("e.g. Build & Start Servers", text: $payloadName)
+ .textFieldStyle(.roundedBorder)
+
+ Text("Payload Type")
+ .font(.caption.bold())
+ .foregroundColor(BubombTheme.textSecondary)
+ .padding(.top, 4)
+
+ Picker("Type", selection: $selectedTypeIndex) {
+ Text("Shell Command").tag(0)
+ Text("Open Application").tag(1)
+ Text("Open URL").tag(2)
+ Text("Run Script").tag(3)
+ Text("Multi-step Sequence").tag(4)
+ }
+ .pickerStyle(.segmented)
+ }
+ .bubombCard()
+ }
+
+ @ViewBuilder
+ private var configurationFormSection: some View {
+ VStack(alignment: .leading, spacing: 14) {
+ switch selectedTypeIndex {
+ case 0:
+ shellConfigurationForm
+ case 1:
+ applicationConfigurationForm
+ case 2:
+ urlConfigurationForm
+ case 3:
+ scriptConfigurationForm
+ case 4:
+ sequenceConfigurationForm
+ default:
+ EmptyView()
+ }
+ }
+ .bubombCard()
+ }
+
+ // MARK: - Type Specific Forms
+
+ private var shellConfigurationForm: some View {
+ VStack(alignment: .leading, spacing: 12) {
+ Text("Shell Command Configuration")
+ .font(.subheadline.bold())
+ .foregroundColor(BubombTheme.accentOrange)
+
+ VStack(alignment: .leading, spacing: 4) {
+ Text("Command:").font(.caption).foregroundColor(BubombTheme.textSecondary)
+ TextEditor(text: $shellCommand)
+ .font(.system(.body, design: .monospaced))
+ .frame(height: 70)
+ .padding(4)
+ .background(Color.black.opacity(0.3))
+ .cornerRadius(6)
+ .overlay(RoundedRectangle(cornerRadius: 6).stroke(BubombTheme.borderSubtle, lineWidth: 1))
+ }
+
+ HStack(spacing: 12) {
+ VStack(alignment: .leading, spacing: 4) {
+ Text("Shell Environment:").font(.caption).foregroundColor(BubombTheme.textSecondary)
+ Picker("", selection: $shellPath) {
+ Text("Zsh (/bin/zsh)").tag("/bin/zsh")
+ Text("Bash (/bin/bash)").tag("/bin/bash")
+ Text("Sh (/bin/sh)").tag("/bin/sh")
+ Text("Direct Executable (no shell)").tag("")
+ }
+ .labelsHidden()
+ }
+
+ VStack(alignment: .leading, spacing: 4) {
+ Text("Timeout (Seconds):").font(.caption).foregroundColor(BubombTheme.textSecondary)
+ Picker("", selection: $shellTimeout) {
+ Text("5s").tag(TimeInterval(5))
+ Text("10s").tag(TimeInterval(10))
+ Text("30s (Default)").tag(TimeInterval(30))
+ Text("60s").tag(TimeInterval(60))
+ Text("120s").tag(TimeInterval(120))
+ Text("No Timeout").tag(TimeInterval(0))
+ }
+ .labelsHidden()
+ }
+ }
+
+ VStack(alignment: .leading, spacing: 4) {
+ Text("Working Directory:").font(.caption).foregroundColor(BubombTheme.textSecondary)
+ HStack {
+ TextField("/Users/... (Leave empty for home)", text: $shellWorkDir)
+ .textFieldStyle(.roundedBorder)
+ Button("Browse...") {
+ chooseDirectory(target: $shellWorkDir)
+ }
+ }
+ }
+
+ VStack(alignment: .leading, spacing: 4) {
+ Text("Environment Variables:").font(.caption).foregroundColor(BubombTheme.textSecondary)
+ HStack {
+ TextField("KEY", text: $envKeyInput)
+ .textFieldStyle(.roundedBorder)
+ .frame(width: 120)
+ TextField("VALUE", text: $envValInput)
+ .textFieldStyle(.roundedBorder)
+ Button("Add") {
+ let k = envKeyInput.trimmingCharacters(in: .whitespaces)
+ if !k.isEmpty {
+ envVars[k] = envValInput
+ envKeyInput = ""
+ envValInput = ""
+ }
+ }
+ }
+
+ if !envVars.isEmpty {
+ VStack(alignment: .leading, spacing: 4) {
+ ForEach(Array(envVars.keys.sorted()), id: \.self) { key in
+ HStack {
+ Text("\(key)=\(envVars[key] ?? "")")
+ .font(.system(.caption, design: .monospaced))
+ .foregroundColor(BubombTheme.accentPurple)
+ Spacer()
+ Button(action: { envVars.removeValue(forKey: key) }) {
+ Image(systemName: "trash").font(.caption)
+ }
+ .buttonStyle(.plain)
+ }
+ .padding(.horizontal, 6)
+ .padding(.vertical, 2)
+ .background(Color.black.opacity(0.2))
+ .cornerRadius(4)
+ }
+ }
+ .padding(.top, 4)
+ }
+ }
+ }
+ }
+
+ private var applicationConfigurationForm: some View {
+ VStack(alignment: .leading, spacing: 12) {
+ Text("Open Application Configuration")
+ .font(.subheadline.bold())
+ .foregroundColor(BubombTheme.accentOrange)
+
+ VStack(alignment: .leading, spacing: 4) {
+ Text("Target Application:").font(.caption).foregroundColor(BubombTheme.textSecondary)
+ HStack {
+ TextField("/Applications/Xcode.app", text: $appPath)
+ .textFieldStyle(.roundedBorder)
+ Button("Choose App...") {
+ chooseApplication()
+ }
+ }
+ }
+
+ VStack(alignment: .leading, spacing: 4) {
+ Text("Optional Launch Arguments (Space separated):").font(.caption).foregroundColor(BubombTheme.textSecondary)
+ TextField("--new-window", text: $appArgs)
+ .textFieldStyle(.roundedBorder)
+ }
+ }
+ }
+
+ private var urlConfigurationForm: some View {
+ VStack(alignment: .leading, spacing: 12) {
+ Text("Open URL Configuration")
+ .font(.subheadline.bold())
+ .foregroundColor(BubombTheme.accentOrange)
+
+ VStack(alignment: .leading, spacing: 4) {
+ Text("Web Destination URL:").font(.caption).foregroundColor(BubombTheme.textSecondary)
+ HStack {
+ TextField("https://", text: $urlString)
+ .textFieldStyle(.roundedBorder)
+
+ // URL Validation badge
+ if case .success = PathValidator.validateURL(urlString) {
+ Image(systemName: "checkmark.circle.fill")
+ .foregroundColor(BubombTheme.successGreen)
+ } else {
+ Image(systemName: "exclamationmark.triangle.fill")
+ .foregroundColor(BubombTheme.failureRed)
+ }
+ }
+ }
+
+ Text("Detonating this payload will instantly open the validated destination in your default browser.")
+ .font(.caption)
+ .foregroundColor(BubombTheme.textSecondary)
+ }
+ }
+
+ private var scriptConfigurationForm: some View {
+ VStack(alignment: .leading, spacing: 12) {
+ Text("Run Script Configuration")
+ .font(.subheadline.bold())
+ .foregroundColor(BubombTheme.accentOrange)
+
+ VStack(alignment: .leading, spacing: 4) {
+ Text("Script File:").font(.caption).foregroundColor(BubombTheme.textSecondary)
+ HStack {
+ TextField("/path/to/script.sh", text: $scriptPath)
+ .textFieldStyle(.roundedBorder)
+ Button("Browse...") {
+ chooseScript()
+ }
+ }
+ }
+
+ VStack(alignment: .leading, spacing: 4) {
+ Text("Arguments:").font(.caption).foregroundColor(BubombTheme.textSecondary)
+ TextField("--env production --verbose", text: $scriptArgs)
+ .textFieldStyle(.roundedBorder)
+ }
+
+ VStack(alignment: .leading, spacing: 4) {
+ Text("Working Directory:").font(.caption).foregroundColor(BubombTheme.textSecondary)
+ HStack {
+ TextField("(Optional directory)", text: $scriptWorkDir)
+ .textFieldStyle(.roundedBorder)
+ Button("Browse...") {
+ chooseDirectory(target: $scriptWorkDir)
+ }
+ }
+ }
+ }
+ }
+
+ private var sequenceConfigurationForm: some View {
+ VStack(alignment: .leading, spacing: 12) {
+ HStack {
+ Text("Sequence Steps (\(sequenceSteps.count))")
+ .font(.subheadline.bold())
+ .foregroundColor(BubombTheme.accentOrange)
+ Spacer()
+ Button("+ Add Step") {
+ tempStep = SequenceStep(name: "Step \(sequenceSteps.count + 1)", action: .runCommand(command: "echo 'Step'", workingDirectory: nil, timeoutSeconds: 30))
+ editingStepIndex = nil
+ showStepEditor = true
+ }
+ .buttonStyle(.bordered)
+ }
+
+ Toggle("Stop sequence immediately if any step fails", isOn: $sequenceStopOnError)
+ .font(.caption)
+ .foregroundColor(BubombTheme.textSecondary)
+
+ if sequenceSteps.isEmpty {
+ Text("No steps configured. Click '+ Add Step' to build your multi-action detonation sequence.")
+ .font(.caption)
+ .foregroundColor(BubombTheme.textMuted)
+ .padding(.vertical, 8)
+ } else {
+ VStack(spacing: 6) {
+ ForEach(Array(sequenceSteps.enumerated()), id: \.element.id) { index, step in
+ HStack(spacing: 8) {
+ Text("\(index + 1).")
+ .font(.caption.bold())
+ .foregroundColor(BubombTheme.accentOrange)
+ .frame(width: 20)
+
+ VStack(alignment: .leading, spacing: 2) {
+ Text(step.name)
+ .font(.subheadline.bold())
+ .foregroundColor(BubombTheme.textPrimary)
+ Text("[\(step.actionTypeTitle)] \(step.summary)")
+ .font(.caption)
+ .foregroundColor(BubombTheme.textSecondary)
+ .lineLimit(1)
+ }
+
+ Spacer()
+
+ Button(action: {
+ if index > 0 {
+ sequenceSteps.swapAt(index, index - 1)
+ }
+ }) {
+ Image(systemName: "arrow.up").font(.caption)
+ }
+ .disabled(index == 0)
+
+ Button(action: {
+ if index < sequenceSteps.count - 1 {
+ sequenceSteps.swapAt(index, index + 1)
+ }
+ }) {
+ Image(systemName: "arrow.down").font(.caption)
+ }
+ .disabled(index == sequenceSteps.count - 1)
+
+ Button(action: {
+ tempStep = step
+ editingStepIndex = index
+ showStepEditor = true
+ }) {
+ Image(systemName: "pencil").font(.caption)
+ }
+
+ Button(action: {
+ sequenceSteps.remove(at: index)
+ }) {
+ Image(systemName: "trash").font(.caption).foregroundColor(BubombTheme.failureRed)
+ }
+ }
+ .padding(8)
+ .background(Color.black.opacity(0.2))
+ .cornerRadius(6)
+ }
+ }
+ }
+ }
+ }
+
+ // MARK: - Safety Notice
+
+ private var safetyNoticeSection: some View {
+ let currentPayload = assemblePayload()
+ let risk = currentPayload.safetyRisk
+
+ return Group {
+ if risk.isDestructive {
+ HStack(spacing: 8) {
+ Image(systemName: "exclamationmark.octagon.fill")
+ .foregroundColor(BubombTheme.failureRed)
+ Text("Destructive command detected: \(risk.warningMessage ?? ""). Bubomb will confirm before detonation.")
+ .font(.caption)
+ .foregroundColor(BubombTheme.failureRed)
+ }
+ .padding(10)
+ .background(BubombTheme.failureRed.opacity(0.12))
+ .cornerRadius(8)
+ } else if let warning = risk.warningMessage {
+ HStack(spacing: 8) {
+ Image(systemName: "exclamationmark.triangle.fill")
+ .foregroundColor(BubombTheme.accentAmber)
+ Text("Safety notice: \(warning)")
+ .font(.caption)
+ .foregroundColor(BubombTheme.accentAmber)
+ }
+ .padding(10)
+ .background(BubombTheme.accentAmber.opacity(0.12))
+ .cornerRadius(8)
+ }
+ }
+ }
+
+ // MARK: - Action Buttons
+
+ private var actionButtonsSection: some View {
+ VStack(spacing: 12) {
+ if let feedback = feedbackMessage {
+ HStack {
+ Image(systemName: isErrorFeedback ? "xmark.circle.fill" : "checkmark.circle.fill")
+ .foregroundColor(isErrorFeedback ? BubombTheme.failureRed : BubombTheme.successGreen)
+ Text(feedback)
+ .font(.caption.bold())
+ .foregroundColor(isErrorFeedback ? BubombTheme.failureRed : BubombTheme.successGreen)
+ Spacer()
+ }
+ }
+
+ HStack(spacing: 14) {
+ Button(action: {
+ savePayload()
+ }) {
+ HStack {
+ Image(systemName: "checkmark")
+ Text("Save Payload")
+ }
+ .frame(maxWidth: .infinity)
+ }
+ .buttonStyle(.borderedProminent)
+ .tint(BubombTheme.accentOrange)
+ .keyboardShortcut("s", modifiers: .command)
+
+ Button(action: {
+ detonateOrConfirm()
+ }) {
+ HStack {
+ Image(systemName: "flame.fill")
+ Text(executor.currentState.isRunning ? "Detonating..." : "Test Payload")
+ }
+ .frame(maxWidth: .infinity)
+ }
+ .buttonStyle(.bordered)
+ .tint(BubombTheme.accentAmber)
+ .disabled(executor.currentState.isRunning)
+ .keyboardShortcut(.return, modifiers: .command)
+ }
+ }
+ .bubombCard()
+ }
+
+ // MARK: - Actions & File Pickers
+
+ private func assemblePayload() -> Payload {
+ let type: PayloadType
+ switch selectedTypeIndex {
+ case 0:
+ let args = shellArgs.components(separatedBy: .whitespaces).filter { !$0.isEmpty }
+ let dir = shellWorkDir.isEmpty ? nil : shellWorkDir
+ let timeout = shellTimeout > 0 ? shellTimeout : nil
+ type = .shellCommand(ShellConfig(
+ command: shellCommand,
+ shellPath: shellPath,
+ arguments: args,
+ workingDirectory: dir,
+ environmentVariables: envVars,
+ timeoutSeconds: timeout
+ ))
+ case 1:
+ let args = appArgs.components(separatedBy: .whitespaces).filter { !$0.isEmpty }
+ type = .openApplication(AppConfig(applicationPath: appPath, arguments: args))
+ case 2:
+ type = .openURL(URLConfig(urlString: urlString))
+ case 3:
+ let args = scriptArgs.components(separatedBy: .whitespaces).filter { !$0.isEmpty }
+ let dir = scriptWorkDir.isEmpty ? nil : scriptWorkDir
+ let timeout = scriptTimeout > 0 ? scriptTimeout : nil
+ type = .runScript(ScriptConfig(
+ scriptPath: scriptPath,
+ arguments: args,
+ workingDirectory: dir,
+ timeoutSeconds: timeout
+ ))
+ case 4:
+ type = .sequence(SequenceConfig(steps: sequenceSteps, stopOnError: sequenceStopOnError))
+ default:
+ type = .shellCommand(ShellConfig())
+ }
+
+ return Payload(
+ name: payloadName.trimmingCharacters(in: .whitespaces).isEmpty ? "My Action" : payloadName,
+ type: type
+ )
+ }
+
+ private func savePayload() {
+ let payload = assemblePayload()
+ do {
+ try payload.validate()
+ settingsStore.setActivePayload(payload)
+ feedbackMessage = "Payload '\(payload.name)' saved and armed!"
+ isErrorFeedback = false
+ } catch {
+ feedbackMessage = error.localizedDescription
+ isErrorFeedback = true
+ }
+ }
+
+ private func detonateOrConfirm() {
+ let payload = assemblePayload()
+ do {
+ try payload.validate()
+ } catch {
+ feedbackMessage = error.localizedDescription
+ isErrorFeedback = true
+ return
+ }
+
+ let alwaysConfirm = settingsStore.settings.confirmDestructiveActions
+ let (requiresConfirm, reason) = SafetyPolicy.requiresConfirmation(
+ command: shellCommand,
+ userSettingAlwaysConfirmDestructive: alwaysConfirm || payload.requiresConfirmation
+ )
+
+ if requiresConfirm {
+ pendingDestructiveActionReason = reason
+ showDestructiveConfirmation = true
+ } else {
+ executeDetonation(bypassConfirmation: false)
+ }
+ }
+
+ private func executeDetonation(bypassConfirmation: Bool) {
+ let payload = assemblePayload()
+ Task {
+ do {
+ _ = try await executor.detonate(payload: payload, ignoreSafetyConfirmation: bypassConfirmation)
+ await MainActor.run {
+ feedbackMessage = "Detonation complete!"
+ isErrorFeedback = false
+ }
+ } catch {
+ await MainActor.run {
+ feedbackMessage = "Detonation error: \(error.localizedDescription)"
+ isErrorFeedback = true
+ }
+ }
+ }
+ }
+
+ private func loadFromActivePayload() {
+ guard let payload = settingsStore.settings.activePayload else {
+ payloadName = "Quick Build"
+ shellCommand = "echo 'Boom! Bubomb is ready.'"
+ return
+ }
+
+ payloadName = payload.name
+ switch payload.type {
+ case .shellCommand(let cfg):
+ selectedTypeIndex = 0
+ shellCommand = cfg.command
+ shellPath = cfg.shellPath
+ shellWorkDir = cfg.workingDirectory ?? ""
+ shellArgs = cfg.arguments.joined(separator: " ")
+ shellTimeout = cfg.timeoutSeconds ?? 0
+ envVars = cfg.environmentVariables
+ case .openApplication(let cfg):
+ selectedTypeIndex = 1
+ appPath = cfg.applicationPath
+ appArgs = cfg.arguments.joined(separator: " ")
+ case .openURL(let cfg):
+ selectedTypeIndex = 2
+ urlString = cfg.urlString
+ case .runScript(let cfg):
+ selectedTypeIndex = 3
+ scriptPath = cfg.scriptPath
+ scriptArgs = cfg.arguments.joined(separator: " ")
+ scriptWorkDir = cfg.workingDirectory ?? ""
+ scriptTimeout = cfg.timeoutSeconds ?? 0
+ case .sequence(let cfg):
+ selectedTypeIndex = 4
+ sequenceSteps = cfg.steps
+ sequenceStopOnError = cfg.stopOnError
+ }
+ }
+
+ private func chooseApplication() {
+ #if canImport(AppKit)
+ let panel = NSOpenPanel()
+ panel.canChooseFiles = true
+ panel.canChooseDirectories = false
+ panel.allowsMultipleSelection = false
+ panel.allowedContentTypes = [.application]
+ panel.directoryURL = URL(fileURLWithPath: "/Applications")
+ if panel.runModal() == .OK, let url = panel.url {
+ appPath = url.path
+ if payloadName.isEmpty || payloadName == "Quick Build" {
+ payloadName = url.deletingPathExtension().lastPathComponent
+ }
+ }
+ #endif
+ }
+
+ private func chooseScript() {
+ #if canImport(AppKit)
+ let panel = NSOpenPanel()
+ panel.canChooseFiles = true
+ panel.canChooseDirectories = false
+ panel.allowsMultipleSelection = false
+ if panel.runModal() == .OK, let url = panel.url {
+ scriptPath = url.path
+ if payloadName.isEmpty || payloadName == "Quick Build" {
+ payloadName = url.lastPathComponent
+ }
+ }
+ #endif
+ }
+
+ private func chooseDirectory(target: Binding<String>) {
+ #if canImport(AppKit)
+ let panel = NSOpenPanel()
+ panel.canChooseFiles = false
+ panel.canChooseDirectories = true
+ panel.allowsMultipleSelection = false
+ if panel.runModal() == .OK, let url = panel.url {
+ target.wrappedValue = url.path
+ }
+ #endif
+ }
+}
diff --git a/Sources/BubombUI/Settings/SequenceStepEditorView.swift b/Sources/BubombUI/Settings/SequenceStepEditorView.swift
new file mode 100644
index 0000000..2a063b7
--- /dev/null
+++ b/Sources/BubombUI/Settings/SequenceStepEditorView.swift
@@ -0,0 +1,184 @@
+import SwiftUI
+import BubombCore
+#if canImport(AppKit)
+import AppKit
+#endif
+
+/// Sheet or inline editor for an individual Sequence Step.
+public struct SequenceStepEditorView: View {
+ @Binding var step: SequenceStep
+ var onSave: () -> Void
+ var onCancel: () -> Void
+
+ @State private var stepTypeIndex: Int = 0
+ @State private var appPath: String = ""
+ @State private var urlString: String = "https://"
+ @State private var commandString: String = ""
+ @State private var commandWorkDir: String = ""
+ @State private var scriptPath: String = ""
+ @State private var scriptArgs: String = ""
+
+ public init(step: Binding<SequenceStep>, onSave: @escaping () -> Void, onCancel: @escaping () -> Void) {
+ self._step = step
+ self.onSave = onSave
+ self.onCancel = onCancel
+ }
+
+ public var body: some View {
+ VStack(alignment: .leading, spacing: 16) {
+ Text("Edit Step")
+ .font(.headline)
+ .foregroundColor(BubombTheme.textPrimary)
+
+ TextField("Step Name", text: $step.name)
+ .textFieldStyle(.roundedBorder)
+
+ Picker("Action Type", selection: $stepTypeIndex) {
+ Text("Open Application").tag(0)
+ Text("Open URL").tag(1)
+ Text("Run Command").tag(2)
+ Text("Run Script").tag(3)
+ }
+ .pickerStyle(.segmented)
+
+ Divider().background(BubombTheme.borderSubtle)
+
+ Group {
+ if stepTypeIndex == 0 {
+ VStack(alignment: .leading, spacing: 8) {
+ Text("Application Path:").font(.caption).foregroundColor(BubombTheme.textSecondary)
+ HStack {
+ TextField("/Applications/Safari.app", text: $appPath)
+ .textFieldStyle(.roundedBorder)
+ Button("Choose...") {
+ chooseApplication()
+ }
+ }
+ }
+ } else if stepTypeIndex == 1 {
+ VStack(alignment: .leading, spacing: 8) {
+ Text("URL Destination:").font(.caption).foregroundColor(BubombTheme.textSecondary)
+ TextField("https://apple.com", text: $urlString)
+ .textFieldStyle(.roundedBorder)
+ }
+ } else if stepTypeIndex == 2 {
+ VStack(alignment: .leading, spacing: 8) {
+ Text("Shell Command:").font(.caption).foregroundColor(BubombTheme.textSecondary)
+ TextField("e.g. npm run build", text: $commandString)
+ .textFieldStyle(.roundedBorder)
+ Text("Working Directory (Optional):").font(.caption).foregroundColor(BubombTheme.textSecondary)
+ TextField("/path/to/project", text: $commandWorkDir)
+ .textFieldStyle(.roundedBorder)
+ }
+ } else {
+ VStack(alignment: .leading, spacing: 8) {
+ Text("Script Path:").font(.caption).foregroundColor(BubombTheme.textSecondary)
+ HStack {
+ TextField("/path/to/script.sh", text: $scriptPath)
+ .textFieldStyle(.roundedBorder)
+ Button("Browse...") {
+ chooseScript()
+ }
+ }
+ Text("Arguments (Space separated):").font(.caption).foregroundColor(BubombTheme.textSecondary)
+ TextField("--verbose", text: $scriptArgs)
+ .textFieldStyle(.roundedBorder)
+ }
+ }
+ }
+
+ Spacer()
+
+ HStack {
+ Button("Cancel") {
+ onCancel()
+ }
+ .keyboardShortcut(.cancelAction)
+
+ Spacer()
+
+ Button("Save Step") {
+ commitStep()
+ onSave()
+ }
+ .keyboardShortcut(.defaultAction)
+ .buttonStyle(.borderedProminent)
+ .tint(BubombTheme.accentOrange)
+ }
+ }
+ .padding(20)
+ .frame(width: 460, height: 350)
+ .background(BubombTheme.surface)
+ .onAppear {
+ loadFromStep()
+ }
+ }
+
+ private func loadFromStep() {
+ switch step.action {
+ case .openApplication(let path):
+ stepTypeIndex = 0
+ appPath = path
+ case .openURL(let url):
+ stepTypeIndex = 1
+ urlString = url
+ case .runCommand(let cmd, let workDir, _):
+ stepTypeIndex = 2
+ commandString = cmd
+ commandWorkDir = workDir ?? ""
+ case .runScript(let path, let args, _, _):
+ stepTypeIndex = 3
+ scriptPath = path
+ scriptArgs = args.joined(separator: " ")
+ }
+ }
+
+ private func commitStep() {
+ switch stepTypeIndex {
+ case 0:
+ step.action = .openApplication(applicationPath: appPath)
+ case 1:
+ step.action = .openURL(urlString: urlString)
+ case 2:
+ let dir = commandWorkDir.isEmpty ? nil : commandWorkDir
+ step.action = .runCommand(command: commandString, workingDirectory: dir, timeoutSeconds: 30)
+ case 3:
+ let args = scriptArgs.components(separatedBy: .whitespaces).filter { !$0.isEmpty }
+ step.action = .runScript(scriptPath: scriptPath, arguments: args, workingDirectory: nil, timeoutSeconds: 60)
+ default:
+ break
+ }
+ }
+
+ private func chooseApplication() {
+ #if canImport(AppKit)
+ let panel = NSOpenPanel()
+ panel.canChooseFiles = true
+ panel.canChooseDirectories = false
+ panel.allowsMultipleSelection = false
+ panel.allowedContentTypes = [.application]
+ panel.directoryURL = URL(fileURLWithPath: "/Applications")
+ if panel.runModal() == .OK, let url = panel.url {
+ appPath = url.path
+ if step.name.isEmpty || step.name == "New Step" {
+ step.name = url.deletingPathExtension().lastPathComponent
+ }
+ }
+ #endif
+ }
+
+ private func chooseScript() {
+ #if canImport(AppKit)
+ let panel = NSOpenPanel()
+ panel.canChooseFiles = true
+ panel.canChooseDirectories = false
+ panel.allowsMultipleSelection = false
+ if panel.runModal() == .OK, let url = panel.url {
+ scriptPath = url.path
+ if step.name.isEmpty || step.name == "New Step" {
+ step.name = url.lastPathComponent
+ }
+ }
+ #endif
+ }
+}
diff --git a/Sources/BubombUI/Settings/SettingsView.swift b/Sources/BubombUI/Settings/SettingsView.swift
new file mode 100644
index 0000000..02d2287
--- /dev/null
+++ b/Sources/BubombUI/Settings/SettingsView.swift
@@ -0,0 +1,95 @@
+import SwiftUI
+import BubombCore
+
+/// Main Settings Window for Bubomb.
+@MainActor
+public struct SettingsView: View {
+ @ObservedObject var settingsStore: SettingsStore
+ @ObservedObject var executor: PayloadExecutor
+
+ @State private var selectedTab: Int = 0
+
+ public init(settingsStore: SettingsStore = .shared, executor: PayloadExecutor? = nil) {
+ self.settingsStore = settingsStore
+ self.executor = executor ?? PayloadExecutor.shared
+ }
+
+ public var body: some View {
+ VStack(spacing: 0) {
+ topTabBar
+
+ Divider().background(BubombTheme.borderSubtle)
+
+ Group {
+ switch selectedTab {
+ case 0:
+ PayloadEditorView(settingsStore: settingsStore, executor: executor)
+ case 1:
+ ExecutionStatusView(settingsStore: settingsStore, executor: executor)
+ case 2:
+ GeneralSettingsView(settingsStore: settingsStore)
+ default:
+ EmptyView()
+ }
+ }
+ .frame(maxWidth: .infinity, maxHeight: .infinity)
+ }
+ .frame(minWidth: 620, idealWidth: 680, minHeight: 520, idealHeight: 580)
+ .background(BubombTheme.windowBackground)
+ }
+
+ // MARK: - Top Tab Bar
+
+ private var topTabBar: some View {
+ HStack(spacing: 16) {
+ HStack(spacing: 8) {
+ AnimatedBombView(size: 28, isDetonating: executor.currentState.isRunning)
+ Text("Bubomb")
+ .font(.headline.bold())
+ .foregroundColor(BubombTheme.textPrimary)
+ }
+ .padding(.leading, 8)
+
+ Spacer()
+
+ Picker("", selection: $selectedTab) {
+ Label("Payload", systemImage: "flame.fill").tag(0)
+ Label("Execution", systemImage: "clock.arrow.circlepath").tag(1)
+ Label("General", systemImage: "gearshape.fill").tag(2)
+ }
+ .pickerStyle(.segmented)
+ .frame(width: 320)
+ .labelsHidden()
+
+ Spacer()
+
+ // Armed Status Pill
+ if settingsStore.settings.activePayload != nil {
+ HStack(spacing: 5) {
+ Circle().fill(BubombTheme.successGreen).frame(width: 6, height: 6)
+ Text("Armed")
+ .font(.caption2.bold())
+ .foregroundColor(BubombTheme.successGreen)
+ }
+ .padding(.horizontal, 8)
+ .padding(.vertical, 4)
+ .background(BubombTheme.successGreen.opacity(0.12))
+ .cornerRadius(12)
+ } else {
+ HStack(spacing: 5) {
+ Circle().fill(BubombTheme.accentAmber).frame(width: 6, height: 6)
+ Text("Unarmed")
+ .font(.caption2.bold())
+ .foregroundColor(BubombTheme.accentAmber)
+ }
+ .padding(.horizontal, 8)
+ .padding(.vertical, 4)
+ .background(BubombTheme.accentAmber.opacity(0.12))
+ .cornerRadius(12)
+ }
+ }
+ .padding(.horizontal, 16)
+ .padding(.vertical, 12)
+ .background(BubombTheme.surface)
+ }
+}
diff --git a/Sources/BubombUI/Settings/Theme.swift b/Sources/BubombUI/Settings/Theme.swift
new file mode 100644
index 0000000..adc8b63
--- /dev/null
+++ b/Sources/BubombUI/Settings/Theme.swift
@@ -0,0 +1,42 @@
+import SwiftUI
+
+public enum BubombTheme {
+ public static let windowBackground = Color(red: 0.08, green: 0.08, blue: 0.10)
+ public static let surface = Color(red: 0.12, green: 0.12, blue: 0.15)
+ public static let surfaceElevated = Color(red: 0.16, green: 0.16, blue: 0.20)
+ public static let border = Color(red: 0.22, green: 0.22, blue: 0.28)
+ public static let borderSubtle = Color(red: 0.18, green: 0.18, blue: 0.23)
+
+ public static let accentOrange = Color(red: 1.0, green: 0.42, blue: 0.0)
+ public static let accentAmber = Color(red: 1.0, green: 0.65, blue: 0.0)
+ public static let accentPurple = Color(red: 0.52, green: 0.40, blue: 0.95)
+ public static let successGreen = Color(red: 0.20, green: 0.78, blue: 0.35)
+ public static let failureRed = Color(red: 1.0, green: 0.27, blue: 0.23)
+
+ public static let textPrimary = Color.white
+ public static let textSecondary = Color.white.opacity(0.65)
+ public static let textMuted = Color.white.opacity(0.40)
+}
+
+public struct CardModifier: ViewModifier {
+ var padding: CGFloat = 14
+
+ public func body(content: Content) -> some View {
+ content
+ .padding(padding)
+ .background(
+ RoundedRectangle(cornerRadius: 10, style: .continuous)
+ .fill(BubombTheme.surface)
+ )
+ .overlay(
+ RoundedRectangle(cornerRadius: 10, style: .continuous)
+ .stroke(BubombTheme.borderSubtle, lineWidth: 1)
+ )
+ }
+}
+
+public extension View {
+ func bubombCard(padding: CGFloat = 14) -> some View {
+ self.modifier(CardModifier(padding: padding))
+ }
+}