54 lines
2.0 KiB
Swift
54 lines
2.0 KiB
Swift
import ImageIO
|
|
import SwiftUI
|
|
|
|
enum DebugLaunch {
|
|
static func apply(to model: AppModel) {
|
|
#if DEBUG
|
|
applyContent(to: model, from: .standard)
|
|
applyFlags(to: model, from: ProcessInfo.processInfo.arguments)
|
|
#endif
|
|
}
|
|
|
|
#if DEBUG
|
|
private static func applyContent(to model: AppModel, from defaults: UserDefaults) {
|
|
if let path = defaults.string(forKey: "image"),
|
|
let source = CGImageSourceCreateWithURL(URL(fileURLWithPath: path) as CFURL, nil),
|
|
let image = CGImageSourceCreateImageAtIndex(source, 0, nil) {
|
|
model.photo.load(image)
|
|
}
|
|
if let look = defaults.string(forKey: "look").flatMap(Look.init) {
|
|
model.photo.look = look
|
|
}
|
|
if let algorithm = defaults.string(forKey: "algorithm").flatMap(DitherAlgorithm.init) {
|
|
model.photo.settings.style = .dots(algorithm)
|
|
}
|
|
if let text = defaults.string(forKey: "text") {
|
|
model.text.text = text.replacingOccurrences(of: "\\n", with: "\n")
|
|
model.text.style.checklist = defaults.bool(forKey: "checklist")
|
|
}
|
|
switch defaults.string(forKey: "section") {
|
|
case "text": model.section = .text
|
|
case "printer": model.section = .printer
|
|
default: break
|
|
}
|
|
}
|
|
|
|
private static func applyFlags(to model: AppModel, from arguments: [String]) {
|
|
if arguments.contains("-unpaired") {
|
|
model.printer.forgetPrinter()
|
|
} else if model.printer.isDemo {
|
|
model.printer.connect(.init(id: UUID(), name: "MXW01", rssi: -48))
|
|
}
|
|
if arguments.contains("-pairing") {
|
|
model.isPairing = true
|
|
}
|
|
if arguments.contains("-printing") {
|
|
Task {
|
|
try? await Task.sleep(for: .seconds(2.5))
|
|
model.print()
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
}
|