mirror of
https://github.com/D-Modem/app.git
synced 2026-11-28 17:38:05 -08:00
ios/DModem (XcodeGen's project.yml, iOS 16): Home (the modem's state, the rates and what the CONNECT was, the call's time, start, hang up, stop, an AT command line and its last words), the terminal (the shared Kotlin emulator through TerminalBridge, drawn run by run in a Canvas; CP437 and the VGA colours; the keyboard and a hardware one's arrows and Esc; Esc, a sticky Ctrl, Tab and the arrows on a bar; pinch for the font), the log (shared as text) and the settings (the SIP account or user:password@host, incoming calls, T.38, the speaker, the AT commands at start, the log levels). The modem's speaker on AVAudioEngine; the audio session (its sound, or quiet) keeps a call going in the background. The DNS servers from the resolver's state (SystemDNS.c: iOS has no resolv.conf for the engine). shared: TerminalBridge, the terminal for Swift (octets as Latin-1 strings both ways, rows as runs, keys, replies, the title, the look and the character set), tested on the JVM and natively; the framework also as an XCFramework (assembleDModemSharedXCFramework). CI: the macOS job builds the shared XCFramework, runs DModemKit's tests and builds the app for the simulator; the Linux job runs DModemKit's tests on the host engine. Not built here: no Xcode on Linux (DModemKit, TerminalBridge and SystemDNS.c are). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0172Hejd12i4aYikYW9vgpZs
133 lines
5.3 KiB
Swift
133 lines
5.3 KiB
Swift
// SPDX-License-Identifier: AGPL-3.0-only
|
|
// Copyright (C) 2026 Neo-Desktop
|
|
import DModemKit
|
|
import SwiftUI
|
|
|
|
/// What the modem is doing and the one thing to do about it (start, hang
|
|
/// up, stop); its rates online and what the CONNECT was; an AT command line
|
|
/// and the modem's last words.
|
|
struct HomeView: View {
|
|
@ObservedObject var model: AppModel
|
|
@State private var at = ""
|
|
|
|
var body: some View {
|
|
List {
|
|
Section {
|
|
VStack(alignment: .leading, spacing: 10) {
|
|
HStack {
|
|
Circle().fill(dotColor).frame(width: 12, height: 12)
|
|
Text(title).font(.title2.weight(.semibold))
|
|
Spacer()
|
|
if let since = model.onlineSince {
|
|
TimelineView(.periodic(from: since, by: 1)) { ctx in
|
|
Text(elapsed(since, ctx.date)).font(.title3.monospacedDigit())
|
|
}
|
|
}
|
|
}
|
|
if model.status.link == .online {
|
|
HStack(spacing: 28) {
|
|
rate("↓ down", model.status.rxRate)
|
|
rate("↑ up", model.status.txRate)
|
|
}
|
|
if !model.connectLabel.isEmpty {
|
|
Text(model.connectLabel).font(.body).foregroundStyle(.secondary)
|
|
}
|
|
} else {
|
|
Text(subtitle).foregroundStyle(.secondary)
|
|
}
|
|
if let e = model.error {
|
|
Text(e).foregroundStyle(.red).font(.callout)
|
|
}
|
|
actions
|
|
}
|
|
.padding(.vertical, 6)
|
|
}
|
|
Section("Line") {
|
|
LabeledContent("SIP account", value: model.settings.complete ? "\(model.settings.user)@\(model.settings.domain)" : "not set up")
|
|
LabeledContent("Incoming calls", value: model.settings.listen ? "taken" : "off")
|
|
LabeledContent("Fax", value: model.settings.t38 ? "audio or T.38" : "audio")
|
|
}
|
|
if model.run == .running {
|
|
Section("AT command") {
|
|
HStack {
|
|
TextField("ATI3", text: $at)
|
|
.textInputAutocapitalization(.characters)
|
|
.autocorrectionDisabled()
|
|
.font(.body.monospaced())
|
|
.onSubmit(sendAt)
|
|
Button("Send", action: sendAt).disabled(at.isEmpty)
|
|
}
|
|
Text(lastLines).font(.caption.monospaced()).foregroundStyle(.secondary)
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
}
|
|
}
|
|
}
|
|
.navigationTitle("D-Modem")
|
|
}
|
|
|
|
@ViewBuilder private var actions: some View {
|
|
HStack {
|
|
switch model.run {
|
|
case .stopped:
|
|
Button("Start the modem") { model.start() }
|
|
.buttonStyle(.borderedProminent)
|
|
.disabled(!model.settings.complete)
|
|
case .running:
|
|
if model.status.offHook {
|
|
Button("Hang up") { model.hangUp() }.buttonStyle(.borderedProminent)
|
|
}
|
|
Button("Stop") { model.stop() }.buttonStyle(.bordered)
|
|
}
|
|
}
|
|
}
|
|
|
|
private var title: String {
|
|
switch (model.run, model.status.link) {
|
|
case (.stopped, _): return "Modem off"
|
|
case (_, .online): return "Online"
|
|
case (_, .connecting): return "Connecting…"
|
|
case (_, .hangingUp): return "Hanging up…"
|
|
default: return model.status.offHook ? "Off hook" : "Ready"
|
|
}
|
|
}
|
|
|
|
private var subtitle: String {
|
|
switch (model.run, model.status.link) {
|
|
case (.stopped, _): return model.settings.complete ? "Ready to start" : "Set up a SIP account to start"
|
|
case (_, .connecting): return "Training the line"
|
|
default: return model.status.offHook ? "Dialling" : "On hook, waiting for a dial (the Terminal: ATD)"
|
|
}
|
|
}
|
|
|
|
private var dotColor: Color {
|
|
if model.run == .stopped { return .gray }
|
|
// (online, or ready on hook: green; anything on its way: orange)
|
|
if model.status.link == .online || (model.status.link == .idle && !model.status.offHook) { return .green }
|
|
return .orange
|
|
}
|
|
|
|
private var lastLines: String {
|
|
model.console.split(whereSeparator: \.isNewline).suffix(6).joined(separator: "\n")
|
|
}
|
|
|
|
private func rate(_ label: String, _ bps: Int) -> some View {
|
|
VStack(alignment: .leading) {
|
|
Text(label).font(.caption)
|
|
Text(bps >= 1000 ? String(format: "%.1f kbit/s", Double(bps) / 1000) : "\(bps) bit/s")
|
|
.font(.title.weight(.bold))
|
|
}
|
|
}
|
|
|
|
private func elapsed(_ since: Date, _ now: Date) -> String {
|
|
let s = max(0, Int(now.timeIntervalSince(since)))
|
|
return String(format: "%d:%02d", s / 60, s % 60)
|
|
}
|
|
|
|
private func sendAt() {
|
|
let c = at.trimmingCharacters(in: .whitespaces)
|
|
guard !c.isEmpty else { return }
|
|
model.command(c.uppercased().hasPrefix("AT") ? c : "AT" + c)
|
|
at = ""
|
|
}
|
|
}
|