Add the site, with a settings reference made from the code (#26)

tools/settings_ref.py writes docs/settings.md from the apps'
ModemSettings: on Android each setting's DataStore key, kind, default and
comment (and it fails on a setting with no key); on iOS each setting and
the Keychain name of the secrets. The iOS settings that took the comment
of the one above them get their own.

The Pages workflow builds docs/ and the README with brand's theme, and
fails if docs/settings.md is out of date; the Android and Apple workflows
skip the site's files.


Claude-Session: https://claude.ai/code/session_01B82eRSqjp9Pn2KBr9N9LAn

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
NeoandClaude authored and GitHub committed 2026-11-05 18:12:28 -08:00
1 parent 30cd2e2289
commit 5a2ca6e164
9 files changed
+334 -5

No files matched your search

+4 -3
View File
@@ -27,14 +27,15 @@
name: Android
# (a branch's commits run once, as its pull request: pushed, only main's;
# a change to docs alone runs nothing: the Markdown, docs/ and COPYING)
# a change to docs alone runs nothing: the Markdown, docs/, COPYING and
# the site's files, which pages.yml builds)
on:
push:
branches: [main]
tags: ["v*"]
paths: ['**', '!**.md', '!docs/**', '!COPYING']
paths: ['**', '!**.md', '!docs/**', '!COPYING', '!mkdocs.yml', '!.github/workflows/pages.yml', '!tools/settings_ref.py']
pull_request:
paths: ['**', '!**.md', '!docs/**', '!COPYING']
paths: ['**', '!**.md', '!docs/**', '!COPYING', '!mkdocs.yml', '!.github/workflows/pages.yml', '!tools/settings_ref.py']
workflow_dispatch:
# a newer commit on a pull request cancels the run before it (main's all run)
+2 -2
View File
@@ -13,9 +13,9 @@ name: Apple
on:
push:
branches: [main]
paths: ['**', '!**.md', '!docs/**', '!COPYING']
paths: ['**', '!**.md', '!docs/**', '!COPYING', '!mkdocs.yml', '!.github/workflows/pages.yml', '!tools/settings_ref.py']
pull_request:
paths: ['**', '!**.md', '!docs/**', '!COPYING']
paths: ['**', '!**.md', '!docs/**', '!COPYING', '!mkdocs.yml', '!.github/workflows/pages.yml', '!tools/settings_ref.py']
workflow_dispatch:
# a newer commit on a pull request cancels the run before it (main's all run)
+22
View File
@@ -0,0 +1,22 @@
# The app's site, https://d-modem.github.io/app/: docs/ and the README with
# brand's shared theme and workflow (brand's docs/sites.md). A pull request
# builds it, main deploys it. It fails if docs/settings.md isn't what the
# apps' ModemSettings make now (tools/settings_ref.py).
name: Pages
on:
push:
branches: [main]
pull_request:
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: pages-${{ github.ref }}
cancel-in-progress: true
jobs:
site:
uses: D-Modem/brand/.github/workflows/site.yml@main
with:
prepare: python3 tools/settings_ref.py --check
+4
View File
@@ -28,3 +28,7 @@ ios/DModem/Tunnel/DModemTunnel.entitlements
# the Dockerfile's APKs (docker build --target apk --output out .)
/out/
# the site, built with brand's tools/site.sh
/.site/
/site/
+1
View File
@@ -4,6 +4,7 @@
- [Fax](fax.md)
- [Serial adapters and real phone lines](adapters.md): pico-serial, USB modems, a modem on a USB serial adapter, a Bluetooth modem
- [The app, screen by screen](features.md)
- [Settings reference](settings.md): every setting, its key and default, made from the code (`tools/settings_ref.py`)
- [Building the Android app](building.md)
- [The iOS app](ios.md): building and running on iPhone and iPad
- [Source layout](layout.md)
+76
View File
@@ -0,0 +1,76 @@
<!-- Made by tools/settings_ref.py from the apps' ModemSettings: change the code (or the script), not this page. -->
# Settings reference
Every setting the apps keep, from their code. [The app, screen by screen](features.md) shows where each is set, and [The modem's line](lines.md) what the lines are.
## Android
`ModemSettings` ([`ModemSettings.kt`](../app/src/main/java/org/dmodem/app/android/settings/ModemSettings.kt)), kept in the app's private DataStore `modem` under the key beside each.
| setting | key | kind | default | what it is |
|---|---|---|---|---|
| `user` | `user` | text | (empty) | The SIP account: user, password, registrar or proxy (host[:port]). |
| `password` | `password` | text | (empty) | As above. |
| `domain` | `domain` | text | (empty) | As above. |
| `sipPort` | `sip_port` | number | `5060` | The local SIP port. |
| `listen` | `listen` | on/off | `false` | Register, and answer calls (RING on the DTE, ATA or ATS0=n). |
| `t38` | `t38` | on/off | `true` | Fax calls may go over to T.38. |
| `country` | `country` | text | (empty) | The modem's country by name (empty: USA). |
| `initCommands` | `init_commands` | text | `ATX3` | AT commands sent to the modem each time it starts (empty: none). |
| `logLevel` | `log_level` | number | `0` | The modem's log level (0 errors .. 5), SIP's (0 none .. 4 the SIP messages). |
| `sipLogLevel` | `sip_log_level` | number | `1` | As above. |
| `logTimestamp` | `log_timestamp` | text | `[HH:mm:ss.SSS]` | The log's time stamp before each line, a date pattern (SimpleDateFormat's; empty: none). |
| `line` | `line` | text | `sip` | The modem's line: a SIP account, or another phone with the app over Wi-Fi or Bluetooth. |
| `peerAddress` | `peer_address` | text | (empty) | The other phone to call: host[:port] on Wi-Fi, a paired phone's address on Bluetooth. |
| `peerName` | `peer_name` | text | (empty) | The paired phone's name, to show. |
| `peerPort` | `peer_port` | number | `5070` | The TCP port phones call each other on. |
| `peerPin` | `peer_pin` | text | (empty) | The PIN between the two phones (empty: none): callers must know this phone's, ours answers the other's. |
| `speaker` | `speaker` | on/off | `true` | The modem's speaker on the phone's: the dialling and the handshake heard (as ATM and ATL have it). |
| `callTones` | `callTones` | on/off | `true` | The country's call progress tones (dial, ringing, busy, congestion) where the line has none of its own. |
| `adaptiveAnswer` | `adaptiveAnswer` | on/off | `true` | Calls answered as fax or data by what they turn out to be (D-Modem's adaptive answer, AT+FAA=1): a fax machine's to the fax receiver, a modem's to the terminal. |
| `callerId` | `callerId` | on/off | `true` | Caller ID on (AT+VCID=1): a ringing call's number and name in the terminal, its popup and notification. |
| `cellSpeed` | `cell_speed` | text | `VCVM` | The modulation on mobile calls (+MS): VCVM (V.cvm, made for speech codecs: about 1200 bit/s through AMR 12.2, to another D-Modem; V.22 or V.21 to other modems), V21 (300 bit/s), V22, V22B. |
| `btModemAddress` | `bt_modem_address` | text | (empty) | The Bluetooth modem's (LINE_BT_MODEM): the paired device's address, its name to show. |
| `btModemName` | `bt_modem_name` | text | (empty) | As above. |
| `serialModemBaud` | `serial_modem_baud` | number | `115200` | The modem on a USB serial adapter's (LINE_SERIAL_MODEM): the adapter's speed, and RTS/CTS flow control (8N1). |
| `serialModemRtsCts` | `serial_modem_rtscts` | on/off | `true` | As above. |
| `recordLine` | `record_line` | on/off | `false` | Each call on a USB modem's line recorded (LineRecordings), for a bug report. |
| `usbTxGain` | `usb_tx_gain` | number | `0` | A USB modem's line: the modem's sound to it louder or softer, dB (-20 to 20; D-Modem's DMODEM_USB_TX_GAIN). |
| `usbTxAuto` | `usb_tx_auto` | on/off | `true` | A USB modem's line: its transmit level set for each call from the remote's answer tone (DMODEM_USB_TX_GAIN=auto), not [usbTxGain]. |
`line` is one of: `bluetooth`, `bt_modem`, `cell`, `none`, `serial_modem`, `sip`, `usb`, `wifi`.
## iOS
`ModemSettings` ([`ModemSettings.swift`](../ios/DModemKit/Sources/DModemKit/ModemSettings.swift)), kept as JSON under each setting's own name; the secrets go in the Keychain instead, under the name beside them.
| setting | Keychain | kind | default | what it is |
|---|---|---|---|---|
| `user` | | text | (empty) | The SIP account. |
| `password` | `sip-password` | text | (empty) | As above. |
| `domain` | | text | (empty) | The registrar's or proxy's host[:port]. |
| `sipPort` | | number | `5060` | The local SIP port. |
| `listen` | | on/off | `false` | Register and take calls (on Wi-Fi: take the other phone's). |
| `t38` | | on/off | `true` | Fax calls may go over to T.38. |
| `country` | | text | (empty) | The modem's country (empty: USA). |
| `initCommands` | | text | `ATX3` | AT commands sent each time it starts (SIP has no dial tone: ATX3). |
| `logLevel` | | number | `0` | The modem's log level (0 errors .. 5), SIP's (0 none .. 4 the SIP messages). |
| `sipLogLevel` | | number | `1` | As above. |
| `speaker` | | on/off | `true` | The modem's speaker on the phone's: the dialling and the handshake heard. |
| `line` | | choice | `sip` | The modem's line: a SIP account, another phone with the app on Wi-Fi, or none. |
| `peerAddress` | | text | (empty) | The other phone to call (host[:port]), and the PIN between the two. |
| `peerPort` | | number | `5070` | As above. |
| `peerPin` | `peer-pin` | text | (empty) | As above. |
| `faxIdent` | | text | (empty) | Fax: the identity sent (CSI/TSI), error correction, the fastest rate, fine resolution, ringing calls answered as faxes. |
| `faxEcm` | | on/off | `true` | As above. |
| `faxMaxBps` | | number | `14400` | As above. |
| `faxFine` | | on/off | `true` | As above. |
| `faxAutoAnswer` | | on/off | `false` | As above. |
| `ispNumber` | | text | (empty) | Dial-up internet: the ISP's number, login, its login script (chat, if any), the modem's commands first. |
| `ispUser` | | text | (empty) | As above. |
| `ispPassword` | `isp-password` | text | (empty) | As above. |
| `ispScript` | | text | (empty) | As above. |
| `ispInit` | | text | (empty) | As above. |
`line` is one of: `sip`, `wifi`, `none`.
@@ -15,18 +15,22 @@ public struct ModemSettings: Codable, Equatable, Sendable {
public var password = ""
/// the registrar's or proxy's host[:port]
public var domain = ""
/// the local SIP port
public var sipPort = 5060
/// register and take calls (on Wi-Fi: take the other phone's)
public var listen = false
/// fax calls may go over to T.38
public var t38 = true
/// the modem's country (empty: USA)
public var country = ""
/// AT commands sent each time it starts (SIP has no dial tone: ATX3)
public var initCommands = "ATX3"
/// the modem's log level (0 errors .. 5), SIP's (0 none .. 4 the SIP messages)
public var logLevel = 0
public var sipLogLevel = 1
/// the modem's speaker on the phone's: the dialling and the handshake heard
public var speaker = true
/// the modem's line: a SIP account, another phone with the app on Wi-Fi, or none
public var line = Line.sip
/// the other phone to call (host[:port]), and the PIN between the two
public var peerAddress = ""
+23
View File
@@ -0,0 +1,23 @@
INHERIT: .site/mkdocs-base.yml
# The app's site, https://d-modem.github.io/app/: docs/ and the README with
# brand's shared theme and workflow (brand's docs/sites.md).
# docs/settings.md is made from the apps' ModemSettings (tools/settings_ref.py).
site_name: D-Modem app
site_description: A dial-up modem in your pocket, on Android and iOS
site_url: https://d-modem.github.io/app/
repo_url: https://github.com/D-Modem/app
repo_name: D-Modem/app
docs_dir: .site/docs
extra:
repo: app
nav:
- Home: index.md
- The app, screen by screen: features.md
- The modem's line: lines.md
- Fax: fax.md
- Serial adapters and phone lines: adapters.md
- Settings reference: settings.md
- Building for Android: building.md
- The iOS app: ios.md
- Source layout: layout.md
- Documentation index: README.md
+198
View File
@@ -0,0 +1,198 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright (C) 2026 Neo-Desktop
#
# settings_ref.py - docs/settings.md, the apps' settings from their code:
# Android's ModemSettings and the DataStore key each
# is kept under (SettingsStore), iOS's ModemSettings
# and the Keychain names of its secrets
#
# tools/settings_ref.py writes the page
# tools/settings_ref.py --check exit 1 if it is out of date, or an
# Android setting has no key
"""docs/settings.md from the apps' ModemSettings."""
import os
import re
import sys
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
OUT = os.path.join(ROOT, "docs", "settings.md")
KOTLIN = "app/src/main/java/org/dmodem/app/android/settings/ModemSettings.kt"
LOGFORMAT = "app/src/main/java/org/dmodem/app/android/modem/LogFormat.kt"
SWIFT = "ios/DModemKit/Sources/DModemKit/ModemSettings.swift"
def read(rel):
"""A file of the repository, by its path from the root."""
with open(os.path.join(ROOT, rel), encoding="utf-8") as f:
return f.read()
def cell(s):
"""Text for a table cell."""
s = s.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
return " ".join(s.replace("|", "\\|").split())
def sentence(s):
"""Text as a sentence: a capital, a full stop."""
s = " ".join(s.split())
if not s:
return ""
s = s[0].upper() + s[1:]
return s if s.endswith(".") else s + "."
def doc_text(lines):
"""A doc comment's text, its markers gone."""
out = []
for l in lines:
l = l.strip()
l = re.sub(r"^(/\*\*|\*/|\*|///)", "", l)
l = re.sub(r"\*/$", "", l).strip()
if l:
out.append(l)
return " ".join(out)
def fields(body, pattern):
"""(name, type, default, doc, first) for each field matching pattern.
A doc comment covers the fields right after it, up to a blank line or
the next doc; first is whether the field is the first it covers."""
out, doc, first = [], "", False
lines = body.splitlines()
i = 0
while i < len(lines):
s = lines[i].strip()
if s.startswith(("/**", "///")):
block = [s]
if s.startswith("/**"):
while "*/" not in lines[i]:
i += 1
block.append(lines[i])
else:
while i + 1 < len(lines) and lines[i + 1].strip().startswith("///"):
i += 1
block.append(lines[i])
doc, first = doc_text(block), True
elif not s:
doc = ""
else:
m = re.match(pattern, s)
if m:
out.append((m.group("name"), m.group("type") or "", m.group("default").strip(), doc, first))
first = False
i += 1
return out
def what(doc, first):
"""A field's what-it-is cell: its doc, or As above after the first field it covers."""
if not doc:
return ""
return cell(sentence(doc)) if first else "As above."
def android():
"""Android's settings, keys, store name, constants and lines."""
src = read(KOTLIN)
start = src.index("data class ModemSettings(")
end = src.index(") {", start)
fs = fields(src[start:end], r"val (?P<name>\w+): (?P<type>[\w?]+) = (?P<default>.*?),?$")
keys = dict(re.findall(r"val (\w+) = \w+PreferencesKey\(\"([^\"]+)\"\)", src))
store = re.search(r'preferencesDataStore\("([^"]+)"\)', src).group(1)
consts = dict(re.findall(r"const val (\w+) = (\"[^\"]*\")", src))
consts.update({"LogFormat." + k: v for k, v in
re.findall(r"const val (\w+) = (\"[^\"]*\")", read(LOGFORMAT))})
lines = sorted((k, v) for k, v in consts.items() if k.startswith("LINE_"))
return fs, keys, store, consts, lines
def ios():
"""iOS's settings, Keychain names and lines."""
src = read(SWIFT)
start = src.index("public struct ModemSettings")
end = src.index("/// the defaults", start)
fs = fields(src[start:end], r"public var (?P<name>\w+)(?:: (?P<type>\w+))? = (?P<default>.*)$")
secrets = {f: k for k, f in re.findall(r'\("([^"]+)", \\\.(\w+)\)', src)}
m = re.search(r"case ([\w, ]+)$", src, re.M)
lines = [c.strip() for c in m.group(1).split(",")] if m else []
return fs, secrets, lines
def kind(typ, default):
"""A setting's kind (text, number, on/off, choice) from its type or default."""
if typ:
return typ.rstrip("?").replace("Int", "number").replace("Boolean", "on/off").replace("String", "text")
if default in ("true", "false"):
return "on/off"
if re.fullmatch(r"-?\d+", default):
return "number"
if default.startswith('"'):
return "text"
return "choice"
def show_default(d, consts):
"""A default as the page shows it, constants resolved."""
d = consts.get(d, d)
if d == '""':
return "(empty)"
return "`%s`" % d.strip('"')
def page(problems):
"""The page; what is wrong goes in problems."""
fs, keys, store, consts, alines = android()
ifs, secrets, ilines = ios()
b = ["<!-- Made by tools/settings_ref.py from the apps' ModemSettings: "
"change the code (or the script), not this page. -->\n\n",
"# Settings reference\n\n",
"Every setting the apps keep, from their code. "
"[The app, screen by screen](features.md) shows where each is set, "
"and [The modem's line](lines.md) what the lines are.\n\n",
"## Android\n\n",
"`ModemSettings` ([`ModemSettings.kt`](../%s)), kept in the app's "
"private DataStore `%s` under the key beside each.\n\n" % (KOTLIN, store),
"| setting | key | kind | default | what it is |\n|---|---|---|---|---|\n"]
for name, typ, default, doc, first in fs:
key = keys.get(name)
if not key:
problems.append("%s: the setting %s has no DataStore key in SettingsStore.Keys" % (KOTLIN, name))
b.append("| `%s` | %s | %s | %s | %s |\n" % (
name, "`%s`" % key if key else "", kind(typ, default), cell(show_default(default, consts)),
what(doc, first)))
b += ["\n`line` is one of: %s.\n\n" % ", ".join("`%s`" % v.strip('"') for _, v in alines),
"## iOS\n\n",
"`ModemSettings` ([`ModemSettings.swift`](../%s)), kept as JSON "
"under each setting's own name; the secrets go in the Keychain "
"instead, under the name beside them.\n\n" % SWIFT,
"| setting | Keychain | kind | default | what it is |\n|---|---|---|---|---|\n"]
for name, typ, default, doc, first in ifs:
default = re.sub(r"^Line\.", "", default)
b.append("| `%s` | %s | %s | %s | %s |\n" % (
name, "`%s`" % secrets[name] if name in secrets else "", kind(typ, default),
cell(show_default(default, {})), what(doc, first)))
b.append("\n`line` is one of: %s.\n" % ", ".join("`%s`" % l for l in ilines))
return "".join(b)
def main():
"""Write or check the page."""
problems = []
text = page(problems)
old = open(OUT, encoding="utf-8").read() if os.path.exists(OUT) else None
if "--check" in sys.argv[1:]:
if old != text:
problems.append("docs/settings.md is out of date: run tools/settings_ref.py")
elif old != text:
with open(OUT, "w", encoding="utf-8") as f:
f.write(text)
for p in problems:
print("settings_ref: " + p, file=sys.stderr)
return 1 if problems else 0
if __name__ == "__main__":
sys.exit(main())