Redesign:
- Nach Login landet User direkt im neuen DeviceHubView statt
Auto-Mac-Registrierung. Hub zeigt: User-Email, X/5-Slot-Counter,
Liste aller registrierten Geraete + 'Geraet hinzufuegen' mit
iPhone/iPad vs Mac Wahl.
- Mac wird NUR registriert wenn User aktiv 'Mac' im Hub waehlt
(frueher: auto on app-start, frass Slot).
- iOS-Pfad: Hub -> Welcome/Preflight/Supervise/Enroll/Configure
-> Done -> 'Zurueck zur Geraete-Uebersicht'.
- Mac-Pfad: Hub -> MacRegistrationView (Register+DNS-Install)
-> 'Fertig -> Hub'.
- Wizard-Header hat jetzt Grid-Icon 'Zur Geraete-Uebersicht' als
Escape-Hatch jederzeit.
- Per-Device-Loeschung im Hub: Trash-Icon -> Confirm-Dialog
('Auf X muss Freigabe bestaetigt werden, 24h Cooldown') ->
request-release-Endpoint (existing infra).
- Device-Limit 3 -> 5 in backend (Staging-Testing + Legend-Wert
fuer spaeter).
- StepIndicator/Step-Counter: macRegistration zaehlt nicht im
iOS-Flow.
246 lines
8.5 KiB
Swift
246 lines
8.5 KiB
Swift
import SwiftUI
|
|
|
|
struct MacRegistrationView: View {
|
|
@Environment(WizardModel.self) private var model
|
|
|
|
@State private var macInfo: MacDeviceInfo?
|
|
@State private var isRegistering = false
|
|
@State private var isInstallingProfile = false
|
|
@State private var errorMessage: String?
|
|
@State private var successMessage: String?
|
|
@State private var profileInstalled = false
|
|
@State private var checkingProfile = false
|
|
|
|
var body: some View {
|
|
VStack(spacing: 24) {
|
|
Image(systemName: "desktopcomputer.and.arrow.down")
|
|
.font(.system(size: 80))
|
|
.foregroundStyle(.blue)
|
|
|
|
Text("Mac mit DNS-Schutz registrieren")
|
|
.font(.title)
|
|
.bold()
|
|
|
|
Text("Dieser Mac wird als geschütztes Gerät registriert. ReBreak installiert ein DNS-Filter-Profil — Glücksspiel-Domains werden auf System-Ebene blockiert.")
|
|
.multilineTextAlignment(.center)
|
|
.foregroundStyle(.secondary)
|
|
.padding(.horizontal, 40)
|
|
|
|
if let info = macInfo {
|
|
macInfoCard(info)
|
|
} else {
|
|
ProgressView("Lese Mac-Informationen...")
|
|
.progressViewStyle(.circular)
|
|
}
|
|
|
|
if let error = errorMessage {
|
|
errorCard(error)
|
|
}
|
|
|
|
if let success = successMessage {
|
|
successCard(success)
|
|
}
|
|
|
|
if let registration = model.magicRegistration {
|
|
VStack(spacing: 12) {
|
|
HStack(spacing: 8) {
|
|
Image(systemName: profileInstalled ? "checkmark.shield.fill" : "checkmark.circle.fill")
|
|
.foregroundStyle(.green)
|
|
Text(profileInstalled ? "Mac geschützt + registriert" : "Mac registriert")
|
|
.font(.headline)
|
|
.foregroundStyle(.green)
|
|
}
|
|
|
|
VStack(alignment: .leading, spacing: 6) {
|
|
Text("✓ Device registriert: \(registration.deviceId.prefix(8))...")
|
|
if profileInstalled {
|
|
Text("✓ DNS-Filter-Profil installiert")
|
|
}
|
|
}
|
|
.font(.caption)
|
|
.foregroundStyle(.secondary)
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
}
|
|
.padding()
|
|
.background(Color.green.opacity(0.1))
|
|
.cornerRadius(8)
|
|
.frame(maxWidth: 400)
|
|
}
|
|
|
|
HStack(spacing: 12) {
|
|
Button("← Abbrechen") { model.returnToHub() }
|
|
.buttonStyle(.bordered)
|
|
.disabled(isRegistering || isInstallingProfile)
|
|
|
|
if model.magicRegistration == nil {
|
|
Button("Mac registrieren") { handleRegistration() }
|
|
.buttonStyle(.borderedProminent)
|
|
.disabled(isRegistering || macInfo == nil || isInstallingProfile)
|
|
} else if !profileInstalled {
|
|
Button("DNS-Schutz installieren") { handleProfileInstall() }
|
|
.buttonStyle(.borderedProminent)
|
|
.disabled(isInstallingProfile)
|
|
} else {
|
|
Button("✓ Fertig — zurück zur Übersicht") { model.returnToHub() }
|
|
.buttonStyle(.borderedProminent)
|
|
}
|
|
|
|
if isRegistering || isInstallingProfile {
|
|
ProgressView()
|
|
.controlSize(.small)
|
|
}
|
|
}
|
|
}
|
|
.padding(40)
|
|
.onAppear {
|
|
loadMacInfo()
|
|
checkProfileStatus()
|
|
}
|
|
}
|
|
|
|
@ViewBuilder
|
|
private func macInfoCard(_ info: MacDeviceInfo) -> some View {
|
|
VStack(alignment: .leading, spacing: 8) {
|
|
HStack {
|
|
Image(systemName: "desktopcomputer")
|
|
.foregroundStyle(.blue)
|
|
Text(info.hostname)
|
|
.font(.headline)
|
|
}
|
|
|
|
Text("\(info.model) · macOS \(info.osVersion)")
|
|
.font(.callout)
|
|
.foregroundStyle(.secondary)
|
|
|
|
Text("Device-ID: \(info.deviceId.prefix(8))...\(info.deviceId.suffix(8))")
|
|
.font(.system(.caption, design: .monospaced))
|
|
.foregroundStyle(.tertiary)
|
|
}
|
|
.padding()
|
|
.frame(maxWidth: 400, alignment: .leading)
|
|
.background(Color.blue.opacity(0.08))
|
|
.cornerRadius(8)
|
|
}
|
|
|
|
@ViewBuilder
|
|
private func errorCard(_ error: String) -> some View {
|
|
VStack(spacing: 8) {
|
|
HStack(spacing: 8) {
|
|
Image(systemName: "exclamationmark.triangle.fill")
|
|
.foregroundStyle(.red)
|
|
Text(error)
|
|
.font(.callout)
|
|
.foregroundStyle(.red)
|
|
.multilineTextAlignment(.leading)
|
|
}
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
}
|
|
.padding()
|
|
.background(Color.red.opacity(0.1))
|
|
.cornerRadius(8)
|
|
.frame(maxWidth: 400)
|
|
}
|
|
|
|
@ViewBuilder
|
|
private func successCard(_ message: String) -> some View {
|
|
HStack(spacing: 8) {
|
|
Image(systemName: "checkmark.circle.fill")
|
|
.foregroundStyle(.green)
|
|
Text(message)
|
|
.font(.callout)
|
|
.foregroundStyle(.green)
|
|
}
|
|
.padding()
|
|
.background(Color.green.opacity(0.1))
|
|
.cornerRadius(8)
|
|
.frame(maxWidth: 400)
|
|
}
|
|
|
|
private func loadMacInfo() {
|
|
Task {
|
|
do {
|
|
let info = try MacDeviceDetector.detect()
|
|
await MainActor.run {
|
|
macInfo = info
|
|
}
|
|
} catch {
|
|
await MainActor.run {
|
|
errorMessage = "Mac-Info konnte nicht gelesen werden: \(error.localizedDescription)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private func checkProfileStatus() {
|
|
Task {
|
|
checkingProfile = true
|
|
let installed = await MacProfileInstaller.isInstalled()
|
|
await MainActor.run {
|
|
profileInstalled = installed
|
|
checkingProfile = false
|
|
}
|
|
}
|
|
}
|
|
|
|
private func handleRegistration() {
|
|
Task {
|
|
isRegistering = true
|
|
errorMessage = nil
|
|
successMessage = nil
|
|
|
|
do {
|
|
try await model.registerMac()
|
|
|
|
await MainActor.run {
|
|
isRegistering = false
|
|
}
|
|
// KEIN Auto-Profile-Install mehr — DNS-Schutz ist optional.
|
|
// User entscheidet selbst via Button.
|
|
|
|
} catch {
|
|
await MainActor.run {
|
|
isRegistering = false
|
|
errorMessage = error.localizedDescription
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private func handleProfileInstall() {
|
|
guard let registration = model.magicRegistration else {
|
|
errorMessage = "Keine Registrierung vorhanden. Bitte zuerst registrieren."
|
|
return
|
|
}
|
|
|
|
Task {
|
|
isInstallingProfile = true
|
|
errorMessage = nil
|
|
|
|
do {
|
|
try await MacProfileInstaller.downloadAndInstall(registration: registration)
|
|
|
|
await MainActor.run {
|
|
isInstallingProfile = false
|
|
successMessage = "System Settings → Profile geöffnet. Bitte dort „Installieren" klicken und Admin-Passwort eingeben."
|
|
}
|
|
|
|
// Re-check profile status nach kurzer Wartezeit (User muss in UI bestätigen)
|
|
try? await Task.sleep(nanoseconds: 3_000_000_000)
|
|
await checkProfileStatus()
|
|
|
|
} catch {
|
|
await MainActor.run {
|
|
isInstallingProfile = false
|
|
errorMessage = "Profil-Installation fehlgeschlagen: \(error.localizedDescription)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
MacRegistrationView()
|
|
.environment(WizardModel())
|
|
.frame(width: 720, height: 600)
|
|
}
|