Skip to content

Linux + iPhone Continuity / iMessage / SMS

use correct device name

Zack Bartele7ae5562a07a
diff --git a/apple/Tether/Services/CertificateManager.swift b/apple/Tether/Services/CertificateManager.swift
index d728ae6..80d4eb5 100644
--- a/apple/Tether/Services/CertificateManager.swift
+++ b/apple/Tether/Services/CertificateManager.swift
@@ -17,6 +17,7 @@ final class CertificateManager {
private static let keyTag = "net.jeedup.Tether.key"
private static let certLabel = "net.jeedup.Tether.cert"
private static let knownHostsKey = "TetherKnownHosts"
+ private static let localDeviceNameKey = "TetherLocalDeviceName"
/// SHA-256 fingerprint of our own certificate (lowercase hex, no separators).
private(set) var myFingerprint: String = ""
@@ -24,6 +25,13 @@ final class CertificateManager {
/// Map of known host fingerprints → device name.
private(set) var knownHosts: [String: String] = [:]
+ /// Name of this device as presented to others.
+ var localDeviceName: String = "" {
+ didSet {
+ UserDefaults.standard.set(localDeviceName, forKey: Self.localDeviceNameKey)
+ }
+ }
+
/// The `SecIdentity` used for mTLS client authentication.
private var identity: SecIdentity?
@@ -32,6 +40,7 @@ final class CertificateManager {
/// Load or create the TLS identity and populate known hosts.
func initialize() {
loadKnownHosts()
+ loadLocalDeviceName()
if let existing = loadIdentityFromKeychain() {
identity = existing
@@ -129,6 +138,19 @@ final class CertificateManager {
}
}
+ private func loadLocalDeviceName() {
+ if let name = UserDefaults.standard.string(forKey: Self.localDeviceNameKey) {
+ localDeviceName = name
+ } else {
+ // Default name
+ #if canImport(UIKit)
+ localDeviceName = UIDevice.current.name
+ #else
+ localDeviceName = Host.current().localizedName ?? "Mac"
+ #endif
+ }
+ }
+
// MARK: - Private — Certificate Generation
/// Generate a 2048-bit RSA keypair + self-signed X.509v3 certificate and
diff --git a/apple/Tether/ViewModels/TetherViewModel.swift b/apple/Tether/ViewModels/TetherViewModel.swift
index 84ac953..05a00a1 100644
--- a/apple/Tether/ViewModels/TetherViewModel.swift
+++ b/apple/Tether/ViewModels/TetherViewModel.swift
@@ -26,9 +26,16 @@ struct ClipboardEntry: Identifiable {
let timestamp: Date
let source: ClipboardSource
- enum ClipboardSource: String {
- case local = "iPhone"
- case remote = "Desktop"
+ enum ClipboardSource: Equatable {
+ case local(String)
+ case remote(String)
+
+ var displayName: String {
+ switch self {
+ case .local(let name): return name
+ case .remote(let name): return name
+ }
+ }
}
}
@@ -158,7 +165,8 @@ final class TetherViewModel {
connection.send(.clipboardSet(text))
- let entry = ClipboardEntry(content: text, timestamp: Date(), source: .local)
+ let localName = certificateManager.localDeviceName
+ let entry = ClipboardEntry(content: text, timestamp: Date(), source: .local(localName))
clipboardHistory.insert(entry, at: 0)
// Keep the history manageable
@@ -299,12 +307,7 @@ final class TetherViewModel {
showPairingSheet = true
pairingStatus = "Sending pairing request..."
- let deviceName: String
- #if canImport(UIKit)
- deviceName = UIDevice.current.name
- #else
- deviceName = Host.current().localizedName ?? "Mac"
- #endif
+ let deviceName = certificateManager.localDeviceName
connection.send(.pairRequest(deviceName: deviceName))
}
@@ -314,7 +317,8 @@ final class TetherViewModel {
switch message.parsedCommand {
case .clipboardUpdated:
if let content = message.content {
- let entry = ClipboardEntry(content: content, timestamp: Date(), source: .remote)
+ let sourceName = connectedDeviceName ?? "Desktop"
+ let entry = ClipboardEntry(content: content, timestamp: Date(), source: .remote(sourceName))
clipboardHistory.insert(entry, at: 0)
if clipboardHistory.count > 50 {
clipboardHistory = Array(clipboardHistory.prefix(50))
@@ -323,7 +327,8 @@ final class TetherViewModel {
case .clipboardContent:
if let content = message.content {
- let entry = ClipboardEntry(content: content, timestamp: Date(), source: .remote)
+ let sourceName = connectedDeviceName ?? "Desktop"
+ let entry = ClipboardEntry(content: content, timestamp: Date(), source: .remote(sourceName))
clipboardHistory.insert(entry, at: 0)
}
diff --git a/apple/Tether/Views/ClipboardView.swift b/apple/Tether/Views/ClipboardView.swift
index f83da9b..9ab42ea 100644
--- a/apple/Tether/Views/ClipboardView.swift
+++ b/apple/Tether/Views/ClipboardView.swift
@@ -154,7 +154,7 @@ struct ClipboardView: View {
.lineLimit(3)
HStack(spacing: 6) {
- Text(entry.source.rawValue)
+ Text(entry.source.displayName)
.font(.caption2.weight(.medium))
.foregroundStyle(entry.source == .remote ? .indigo : .teal)
diff --git a/apple/Tether/Views/SettingsView.swift b/apple/Tether/Views/SettingsView.swift
index 6c0ebb7..1717b6b 100644
--- a/apple/Tether/Views/SettingsView.swift
+++ b/apple/Tether/Views/SettingsView.swift
@@ -36,13 +36,9 @@ struct SettingsView: View {
}
VStack(alignment: .leading, spacing: 2) {
- #if canImport(UIKit)
- Text(UIDevice.current.name)
+ TextField("Device Name", text: Bindable(viewModel.certificateManager).localDeviceName)
.font(.body.weight(.medium))
- #else
- Text(Host.current().localizedName ?? "This Mac")
- .font(.body.weight(.medium))
- #endif
+ .submitLabel(.done)
Text("This device")
.font(.caption)