From 975358f98a66716d686ab09ac22eac7bb3df5e9c Mon Sep 17 00:00:00 2001 From: Kaede Akino Date: Thu, 8 Oct 2026 10:51:48 +0800 Subject: [PATCH] refactor: remove redundant code and over-defensive branches Consolidate code that existed twice and drop code nothing reaches. - SSH: hoist the duplicated ASCII hex-nibble decoder out of RemoteCharsetConverter and SSHPTYChannel into SSHWireEncoding.hexDigit. - Transcript: AgentToolDetail.Tint shares BatchTint's vocabulary, so the byte-identical detailColor map now delegates to batchColor. - Commerce: replace ProPaywallState's unreachable default branch and its `preconditionFailure("Handled above")` with an exhaustive switch the compiler can prove complete. - Strings: delete the unreferenced Workspace.closePaneAction (the live help text uses closePane) and its orphan catalog entry. - Drop the unused SwiftData and UniformTypeIdentifiers imports. Co-Authored-By: Claude Code --- Frameworks/Resources/Localizable.xcstrings | 23 ------------ .../TerminalPreferences+Defaults.swift | 1 - .../TermindPresentation/ProPaywallState.swift | 37 ++++++++++++------- .../SingleLineTextInput.swift | 1 - .../Strings/Workspace.swift | 4 -- .../SSH/RemoteCharsetConverter.swift | 12 +----- .../SSH/SSHPTYChannel.swift | 12 +----- .../SSH/SSHWireEncoding.swift | 10 +++++ TFM/Features/AI/TranscriptNativeRows.swift | 10 +++-- 9 files changed, 43 insertions(+), 67 deletions(-) diff --git a/Frameworks/Resources/Localizable.xcstrings b/Frameworks/Resources/Localizable.xcstrings index 8e173103..56db14a5 100644 --- a/Frameworks/Resources/Localizable.xcstrings +++ b/Frameworks/Resources/Localizable.xcstrings @@ -7897,29 +7897,6 @@ } } }, - "Close Pane" : { - "extractionState" : "manual", - "localizations" : { - "ja" : { - "stringUnit" : { - "state" : "translated", - "value" : "ペインを閉じる" - } - }, - "zh-Hans" : { - "stringUnit" : { - "state" : "translated", - "value" : "关闭窗格" - } - }, - "zh-Hant" : { - "stringUnit" : { - "state" : "translated", - "value" : "關閉窗格" - } - } - } - }, "Close Window" : { "extractionState" : "manual", "localizations" : { diff --git a/Frameworks/TermindPersistence/TerminalPreferences+Defaults.swift b/Frameworks/TermindPersistence/TerminalPreferences+Defaults.swift index 9c5628d3..e6190125 100644 --- a/Frameworks/TermindPersistence/TerminalPreferences+Defaults.swift +++ b/Frameworks/TermindPersistence/TerminalPreferences+Defaults.swift @@ -1,5 +1,4 @@ import Foundation -import SwiftData import TermindApplication import TermindDomain diff --git a/Frameworks/TermindPresentation/ProPaywallState.swift b/Frameworks/TermindPresentation/ProPaywallState.swift index 57bfc24e..d4176c99 100644 --- a/Frameworks/TermindPresentation/ProPaywallState.swift +++ b/Frameworks/TermindPresentation/ProPaywallState.swift @@ -30,22 +30,31 @@ public nonisolated struct ProPaywallState { case .expired: state = "expired" case .revoked: state = "revoked" } - default: + case .purchased(let ownership): canManageSubscription = false + isFamilyShared = ownership == .familyShared expiresAt = nil - if case .purchased(.familyShared) = status { - isFamilyShared = true - } else { - isFamilyShared = false - } - switch status { - case .loading: state = "loading" - case .free: state = "free" - case .purchased: state = "lifetime" - case .verificationFailed: state = "unverified" - case .unrestrictedForTesting: state = "development" - case .subscription: preconditionFailure("Handled above") - } + state = "lifetime" + case .loading: + canManageSubscription = false + isFamilyShared = false + expiresAt = nil + state = "loading" + case .free: + canManageSubscription = false + isFamilyShared = false + expiresAt = nil + state = "free" + case .verificationFailed: + canManageSubscription = false + isFamilyShared = false + expiresAt = nil + state = "unverified" + case .unrestrictedForTesting: + canManageSubscription = false + isFamilyShared = false + expiresAt = nil + state = "development" } } } diff --git a/Frameworks/TermindPresentation/SingleLineTextInput.swift b/Frameworks/TermindPresentation/SingleLineTextInput.swift index 57c2e01f..9c5e7bf7 100644 --- a/Frameworks/TermindPresentation/SingleLineTextInput.swift +++ b/Frameworks/TermindPresentation/SingleLineTextInput.swift @@ -1,6 +1,5 @@ import Foundation import SwiftUI -import UniformTypeIdentifiers /// Editing policy for single-line UI fields, not a transformation of stored data or secrets. public nonisolated enum SingleLineTextInput { diff --git a/Frameworks/TermindPresentation/Strings/Workspace.swift b/Frameworks/TermindPresentation/Strings/Workspace.swift index e87db38c..735f70fc 100644 --- a/Frameworks/TermindPresentation/Strings/Workspace.swift +++ b/Frameworks/TermindPresentation/Strings/Workspace.swift @@ -258,10 +258,6 @@ extension AppStrings { "Cancel operation" } - public static var closePaneAction: LocalizedStringResource { - "Close Pane" - } - public static var closeWindow: LocalizedStringResource { "Close Window" } diff --git a/Frameworks/TermindRemoteInfrastructure/SSH/RemoteCharsetConverter.swift b/Frameworks/TermindRemoteInfrastructure/SSH/RemoteCharsetConverter.swift index fd614623..0f3b2731 100644 --- a/Frameworks/TermindRemoteInfrastructure/SSH/RemoteCharsetConverter.swift +++ b/Frameworks/TermindRemoteInfrastructure/SSH/RemoteCharsetConverter.swift @@ -235,7 +235,8 @@ nonisolated struct RemoteOSC7CharsetFilter: Sendable { var index = 0 while index < bytes.count { if bytes[index] == 0x25, index + 2 < bytes.count, - let high = hex(bytes[index + 1]), let low = hex(bytes[index + 2]) + let high = SSHWireEncoding.hexDigit(bytes[index + 1]), + let low = SSHWireEncoding.hexDigit(bytes[index + 2]) { decoded.append(high << 4 | low) index += 3 @@ -271,13 +272,4 @@ nonisolated struct RemoteOSC7CharsetFilter: Sendable { } return 0 } - - private func hex(_ byte: UInt8) -> UInt8? { - switch byte { - case 0x30...0x39: byte - 0x30 - case 0x41...0x46: byte - 0x41 + 10 - case 0x61...0x66: byte - 0x61 + 10 - default: nil - } - } } diff --git a/Frameworks/TermindRemoteInfrastructure/SSH/SSHPTYChannel.swift b/Frameworks/TermindRemoteInfrastructure/SSH/SSHPTYChannel.swift index d598edd9..174e17dc 100644 --- a/Frameworks/TermindRemoteInfrastructure/SSH/SSHPTYChannel.swift +++ b/Frameworks/TermindRemoteInfrastructure/SSH/SSHPTYChannel.swift @@ -625,7 +625,8 @@ public nonisolated struct RemoteCommandEventFilter: Sendable { var index = 0 while index < bytes.count { if bytes[index] == 0x25, index + 2 < bytes.count, - let high = hex(bytes[index + 1]), let low = hex(bytes[index + 2]) + let high = SSHWireEncoding.hexDigit(bytes[index + 1]), + let low = SSHWireEncoding.hexDigit(bytes[index + 2]) { decoded.append(high << 4 | low) index += 3 @@ -639,15 +640,6 @@ public nonisolated struct RemoteCommandEventFilter: Sendable { ?? String(decoding: decodedData, as: UTF8.self) } - private static func hex(_ byte: UInt8) -> UInt8? { - switch byte { - case 0x30...0x39: byte - 0x30 - case 0x41...0x46: byte - 0x41 + 10 - case 0x61...0x66: byte - 0x61 + 10 - default: nil - } - } - private static func duration(milliseconds text: Substring) -> TimeInterval? { guard let milliseconds = UInt64(text), milliseconds <= 31_536_000_000 else { return nil diff --git a/Frameworks/TermindRemoteInfrastructure/SSH/SSHWireEncoding.swift b/Frameworks/TermindRemoteInfrastructure/SSH/SSHWireEncoding.swift index 0343d937..036b0823 100644 --- a/Frameworks/TermindRemoteInfrastructure/SSH/SSHWireEncoding.swift +++ b/Frameworks/TermindRemoteInfrastructure/SSH/SSHWireEncoding.swift @@ -22,4 +22,14 @@ nonisolated enum SSHWireEncoding { .replacingOccurrences(of: "=", with: "") return "SHA256:\(digest)" } + + /// The value of one ASCII hexadecimal digit, or nil for any other byte. + static func hexDigit(_ byte: UInt8) -> UInt8? { + switch byte { + case 0x30...0x39: byte - 0x30 + case 0x41...0x46: byte - 0x41 + 10 + case 0x61...0x66: byte - 0x61 + 10 + default: nil + } + } } diff --git a/TFM/Features/AI/TranscriptNativeRows.swift b/TFM/Features/AI/TranscriptNativeRows.swift index a03b0597..f24f0a0c 100644 --- a/TFM/Features/AI/TranscriptNativeRows.swift +++ b/TFM/Features/AI/TranscriptNativeRows.swift @@ -1602,12 +1602,14 @@ private enum NativeTranscriptFactory { } } + /// `AgentToolDetail.Tint` shares `BatchTint`'s vocabulary, so the color + /// mapping has one owner. private static func detailColor(_ tint: AgentToolDetail.Tint) -> NSColor { switch tint { - case .secondary: .secondaryLabelColor - case .warning: .systemOrange - case .success: .systemGreen - case .failure: .systemRed + case .secondary: batchColor(.secondary) + case .warning: batchColor(.warning) + case .success: batchColor(.success) + case .failure: batchColor(.failure) } }