Files
app/ios/DModem/Sources/Jobs.swift
T
Claude a6a2f5ef50 iOS: CallKit, and the fax, file transfer and dial-up screens
- CallKit: the modem's RING rings as a phone call (answered with ATA or
  turned down on the phone's screen); a call the modem dials is an
  outgoing call, hung up from the call screen; both in Recents
- Fax tab: PDFs, images and text drawn at the fax's width (CoreGraphics,
  then the shared FaxImage), sent; a ringing call answered as a fax, by
  hand or every one; received faxes as PDFs in Documents/Faxes
- File transfers from the terminal's toolbar: ZMODEM, YMODEM, XMODEM,
  Kermit; a remote's sz or kermit -s starts receiving by itself, its rz
  asks for files; received files in Documents/Received (the Files app)
- Internet tab: dial-up to an ISP on the shared DialUpJob, the phone's
  traffic through the new DModemTunnel packet tunnel extension, its
  packets to the app's PPP over the loopback
- the log moves to a button on Home; tabs: Home, Terminal, Fax,
  Internet, Settings
- PeerLine passes LogOut objects (Kotlin lambdas aren't plain closures)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0172Hejd12i4aYikYW9vgpZs
2026-10-18 04:17:48 +00:00

74 lines
2.7 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright (C) 2026 Neo-Desktop
import DModemKit
import DModemShared
import Foundation
/// What a shared Kotlin job calls back (DteOut, LogOut, Changed): its
/// octets to the modem's DTE (lent to it), its log to the modem's, its
/// changes to the main thread.
final class JobLink: NSObject, DteOut, LogOut, Changed, @unchecked Sendable {
private let session: ModemSession
private let onChange: @MainActor () -> Void
init(session: ModemSession, onChange: @escaping @MainActor () -> Void) {
self.session = session
self.onChange = onChange
}
func write(latin1: String) -> Bool {
guard let d = latin1.data(using: .isoLatin1) else { return false }
return session.send(d)
}
func log(line: String) { session.engineLog(line) }
func changed() {
let f = onChange
Task { @MainActor in f() }
}
}
/// a line for the log, from Kotlin
final class LogLink: NSObject, LogOut, @unchecked Sendable {
private let f: (String) -> Void
init(_ f: @escaping (String) -> Void) { self.f = f }
func log(line: String) { f(line) }
}
/// octets between Swift and Kotlin: Latin-1 text, a character an octet
enum Octets {
static func latin1(_ d: Data) -> String { String(data: d, encoding: .isoLatin1) ?? "" }
static func data(_ s: String) -> Data { s.data(using: .isoLatin1) ?? Data() }
}
/// where the app keeps files: in its Documents (the Files app shows them, "On My iPhone › D-Modem")
enum AppFolders {
static var documents: URL {
FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
}
/// received files (transfers)
static var received: URL { folder("Received") }
/// faxes received, as PDFs
static var faxes: URL { folder("Faxes") }
private static func folder(_ name: String) -> URL {
let u = documents.appendingPathComponent(name, isDirectory: true)
try? FileManager.default.createDirectory(at: u, withIntermediateDirectories: true)
return u
}
/// the files in [dir], newest first
static func files(_ dir: URL) -> [URL] {
let keys: [URLResourceKey] = [.contentModificationDateKey, .isRegularFileKey]
let all = (try? FileManager.default.contentsOfDirectory(at: dir, includingPropertiesForKeys: keys)) ?? []
return all.filter { (try? $0.resourceValues(forKeys: [.isRegularFileKey]).isRegularFile) == true }
.sorted {
let a = (try? $0.resourceValues(forKeys: [.contentModificationDateKey]).contentModificationDate) ?? .distantPast
let b = (try? $1.resourceValues(forKeys: [.contentModificationDateKey]).contentModificationDate) ?? .distantPast
return a > b
}
}
}