mirror of
https://github.com/D-Modem/app.git
synced 2026-11-29 01:48:05 -08:00
Settings now opens with how a call is made: the terminal (and what else shares the modem: dial-up internet, dial-in, the bridges), the modem, the line and what it reaches; for a modem of its own, the USB serial adapter or Bluetooth it's reached by, the modem and its line. Each step's role is above its icon and what it is below, one line joining them. Idle it shows the settings as they are (a step still to set in red, its line dashed, and a line saying what); starting, dialling and online it lights as the call goes. On Android a step opens its page. The shared Kotlin's ConnectionPath has the steps and their words, tested, for Android (Compose) and iOS (SwiftUI) alike. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B82eRTvKupDGEromPgYtjG
219 lines
9.3 KiB
Swift
219 lines
9.3 KiB
Swift
// SPDX-License-Identifier: AGPL-3.0-only
|
|
// Copyright (C) 2026 Neo-Desktop
|
|
import DModemKit
|
|
import DModemShared
|
|
import SwiftUI
|
|
|
|
/// The SIP account (or pasted as user:password@host), incoming calls, T.38,
|
|
/// the AT commands at start, the speaker, the log levels. Kept as they're
|
|
/// changed; they apply the next time the modem starts.
|
|
struct SettingsView: View {
|
|
@ObservedObject var model: AppModel
|
|
@State private var login = ""
|
|
|
|
var body: some View {
|
|
Form {
|
|
// (how a call is made, step by step: as set up when idle, as it is in a call)
|
|
Section {
|
|
ConnectionPathView(model: model, jobs: model.jobs)
|
|
}
|
|
Section {
|
|
Picker("Line", selection: $model.settings.line) {
|
|
Text("SIP account").tag(ModemSettings.Line.sip)
|
|
Text("Another phone (Wi-Fi)").tag(ModemSettings.Line.wifi)
|
|
Text("No line (the modem on its own)").tag(ModemSettings.Line.none)
|
|
}
|
|
} footer: {
|
|
switch model.settings.line {
|
|
case .sip: Text("The modem calls through a SIP provider to the phone network.")
|
|
case .wifi: Text("The two phones' modems call each other as on a perfect phone line, no SIP account: each dials (ATD) or answers as usual. The other phone needs D-Modem (Android or iOS) on the same Wi-Fi, taking calls.")
|
|
case .none: Text("The modem starts with nothing on its line, no SIP account or network: it answers AT commands in the terminal; a dial gets NO DIALTONE, as a modem with no phone cable plugged in.")
|
|
}
|
|
}
|
|
if model.settings.line == .wifi {
|
|
PeerSection(model: model)
|
|
} else if model.settings.line == .sip {
|
|
sipSection
|
|
}
|
|
Section("Calls") {
|
|
if !model.settings.noLine {
|
|
Toggle(model.settings.line == .sip ? "Take incoming calls" : "Take calls from the other phone", isOn: $model.settings.listen)
|
|
}
|
|
if model.settings.line == .sip {
|
|
Toggle("Fax over T.38", isOn: $model.settings.t38)
|
|
Stepper("Local SIP port: \(model.settings.sipPort)", value: $model.settings.sipPort, in: 1024...65535)
|
|
}
|
|
Toggle("Speaker (the dialling and the handshake)", isOn: $model.settings.speaker)
|
|
}
|
|
TerminalSection()
|
|
modemSections
|
|
}
|
|
.navigationTitle("Settings")
|
|
}
|
|
|
|
@ViewBuilder private var sipSection: some View {
|
|
Section {
|
|
Toggle("No account: anonymous SIP", isOn: $model.settings.anonymous)
|
|
if !model.settings.anonymous {
|
|
TextField("User", text: $model.settings.user)
|
|
.textInputAutocapitalization(.never).autocorrectionDisabled()
|
|
SecureField("Password", text: $model.settings.password)
|
|
TextField("Server (host[:port])", text: $model.settings.domain)
|
|
.textInputAutocapitalization(.never).autocorrectionDisabled().keyboardType(.URL)
|
|
TextField("Or paste user:password@host", text: $login)
|
|
.textInputAutocapitalization(.never).autocorrectionDisabled()
|
|
.onSubmit {
|
|
if let l = ModemSettings.parseLogin(login) {
|
|
model.settings.user = l.user
|
|
model.settings.password = l.password
|
|
model.settings.domain = l.domain
|
|
login = ""
|
|
}
|
|
}
|
|
}
|
|
} header: {
|
|
Text("SIP account")
|
|
} footer: {
|
|
Text(model.settings.anonymous
|
|
? "Calls go straight to a SIP address from \"Anonymous\": in the Terminal, ATDsip:user@host (or ATDuser@host); voice calls too. Nothing is registered, and numbers can't be dialled without an account."
|
|
: "The provider must carry G.711 (PCMU/PCMA) to the phone network. A SIP address (ATDsip:user@host) is dialled as it is with an account too; the password only goes to the account's own server.")
|
|
}
|
|
}
|
|
|
|
@ViewBuilder private var modemSections: some View {
|
|
Section {
|
|
NavigationLink {
|
|
CountryList(selection: $model.settings.country)
|
|
} label: {
|
|
LabeledContent("Country", value: CountryTones.companion.find(name: model.settings.country)?.label ?? model.settings.country)
|
|
}
|
|
TextField("AT commands at start", text: $model.settings.initCommands)
|
|
.textInputAutocapitalization(.characters).autocorrectionDisabled().font(.body.monospaced())
|
|
} header: {
|
|
Text("Modem")
|
|
} footer: {
|
|
Text("ATX3 by default: a SIP line has no dial tone.")
|
|
}
|
|
Section("Log") {
|
|
Stepper("Modem's level: \(model.settings.logLevel)", value: $model.settings.logLevel, in: 0...5)
|
|
Stepper("SIP's level: \(model.settings.sipLogLevel)", value: $model.settings.sipLogLevel, in: 0...4)
|
|
}
|
|
if model.run == .running {
|
|
Section {
|
|
Text("Changes apply when the modem starts again.").foregroundStyle(.secondary)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// the terminal: the kind of terminal it is (its sequences and what it answers)
|
|
private struct TerminalSection: View {
|
|
@AppStorage("terminalProfile") private var profile = "xterm"
|
|
/// (only for the profiles' ids and names)
|
|
private let bridge = TerminalBridge(cols: 1, rows: 1)
|
|
|
|
var body: some View {
|
|
Section("Terminal") {
|
|
Picker("Terminal type", selection: $profile) {
|
|
ForEach(bridge.profileIds, id: \.self) { id in
|
|
Text(bridge.profileLabel(id: id)).tag(id)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// a phone found taking calls
|
|
private struct Found: Identifiable {
|
|
let name: String
|
|
let address: String
|
|
var id: String { address }
|
|
}
|
|
|
|
/// the other phone: whom ATD calls (or found on the network), the port, the PIN
|
|
private struct PeerSection: View {
|
|
@ObservedObject var model: AppModel
|
|
@State private var finding = false
|
|
@State private var found: [Found] = []
|
|
@State private var finder: PeerFinder?
|
|
|
|
var body: some View {
|
|
Section {
|
|
TextField("Phone to call (host[:port])", text: $model.settings.peerAddress)
|
|
.textInputAutocapitalization(.never).autocorrectionDisabled().keyboardType(.URL)
|
|
Button(finding ? "Stop looking" : "Find phones on this network") { finding ? stop() : find() }
|
|
if finding {
|
|
if found.isEmpty {
|
|
Text("Looking… (phones taking calls on this Wi-Fi show here)").foregroundStyle(.secondary)
|
|
}
|
|
ForEach(found) { p in
|
|
Button {
|
|
model.settings.peerAddress = p.address
|
|
stop()
|
|
} label: {
|
|
VStack(alignment: .leading) {
|
|
Text(p.name)
|
|
Text(p.address).font(.caption).foregroundStyle(.secondary)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Stepper("Port calls come in on: \(model.settings.peerPort)", value: $model.settings.peerPort, in: 1024...65535)
|
|
SecureField("PIN (optional)", text: $model.settings.peerPin)
|
|
} header: {
|
|
Text("The other phone")
|
|
} footer: {
|
|
Text("ATD with any number calls this phone; ATD192*168*1*20 calls that address instead. Set the same PIN on both phones: calls without it are turned down.")
|
|
}
|
|
.onDisappear(perform: stop)
|
|
}
|
|
|
|
/// phones taking calls on this network looked for, each address listed once
|
|
private func find() {
|
|
found = []
|
|
let f = PeerFinder { name, address in
|
|
if !found.contains(where: { $0.address == address }) { found.append(Found(name: name, address: address)) }
|
|
}
|
|
finder = f
|
|
finding = true
|
|
f.start()
|
|
}
|
|
|
|
/// the looking stopped
|
|
private func stop() {
|
|
finder?.stop()
|
|
finder = nil
|
|
finding = false
|
|
}
|
|
}
|
|
|
|
/// the modem's country (D-Modem's ITU list: its line settings, how it hears busy), searched by name
|
|
private struct CountryList: View {
|
|
@Binding var selection: String
|
|
@Environment(\.dismiss) private var dismiss
|
|
@State private var query = ""
|
|
|
|
private var countries: [CountryTones] {
|
|
let q = query.trimmingCharacters(in: .whitespaces).lowercased()
|
|
return CountryTones.companion.all
|
|
.filter { q.isEmpty || $0.label.lowercased().contains(q) }
|
|
.sorted { $0.label < $1.label }
|
|
}
|
|
|
|
var body: some View {
|
|
List(countries, id: \.name) { c in
|
|
Button {
|
|
selection = c.name == CountryTones.companion.DEFAULT ? "" : c.name
|
|
dismiss()
|
|
} label: {
|
|
VStack(alignment: .leading) {
|
|
Text(c.label).foregroundStyle(.primary)
|
|
Text("Dial tone \(c.dial.description), busy \(c.busy.description)").font(.caption).foregroundStyle(.secondary)
|
|
}
|
|
}
|
|
}
|
|
.searchable(text: $query)
|
|
.navigationTitle("Country")
|
|
}
|
|
}
|