Skip to content

Linux + iPhone Continuity / iMessage / SMS

feat(ios): dark/light/system theme

Zack Bartel8381b0a91e8a
diff --git a/apple/Tether/TetherApp.swift b/apple/Tether/TetherApp.swift
index 6b414d1..adc78cf 100644
--- a/apple/Tether/TetherApp.swift
+++ b/apple/Tether/TetherApp.swift
@@ -6,17 +6,20 @@
//
import SwiftUI
+import TetherFramework
@main
struct TetherApp: App {
@State private var viewModel = TetherViewModel()
@Environment(\.scenePhase) private var scenePhase
+ @AppStorage(AppearancePreference.storageKey, store: AppearancePreference.sharedDefaults)
+ private var appearance: AppearancePreference = .system
var body: some Scene {
WindowGroup {
ContentView()
.environment(viewModel)
- .preferredColorScheme(.dark)
+ .preferredColorScheme(appearance.colorScheme)
.onAppear {
viewModel.initialize()
}
diff --git a/apple/Tether/Views/SettingsView.swift b/apple/Tether/Views/SettingsView.swift
index 124c6cb..2ff803d 100644
--- a/apple/Tether/Views/SettingsView.swift
+++ b/apple/Tether/Views/SettingsView.swift
@@ -11,6 +11,9 @@ import TetherFramework
struct SettingsView: View {
@Environment(TetherViewModel.self) private var viewModel
+ @AppStorage(AppearancePreference.storageKey, store: AppearancePreference.sharedDefaults)
+ private var appearance: AppearancePreference = .system
+
@State private var showDeleteConfirm = false
@State private var fingerprintToDelete: String?
@@ -150,6 +153,30 @@ struct SettingsView: View {
Text("When enabled, the iPhone's clipboard will be updated immediately when a connected desktop clipboard changes.")
}
+ // Appearance
+ Section {
+ Picker(selection: $appearance) {
+ ForEach(AppearancePreference.allCases) { option in
+ Text(option.label).tag(option)
+ }
+ } label: {
+ HStack(spacing: 14) {
+ Image(systemName: "circle.lefthalf.filled")
+ .font(.title3)
+ .foregroundStyle(.teal)
+ .frame(width: 32)
+ .accessibilityHidden(true)
+
+ Text("Appearance")
+ .font(.body.weight(.medium))
+ }
+ }
+ } header: {
+ Text("Appearance")
+ } footer: {
+ Text("Also applies to the Share extension.")
+ }
+
// Connection
Section {
HStack {
@@ -239,6 +266,16 @@ struct SettingsView: View {
}
}
+private extension AppearancePreference {
+ var label: LocalizedStringKey {
+ switch self {
+ case .system: "System"
+ case .light: "Light"
+ case .dark: "Dark"
+ }
+ }
+}
+
#Preview {
SettingsView()
.environment(TetherViewModel())
diff --git a/apple/TetherFramework/Sources/TetherFramework/AppearancePreference.swift b/apple/TetherFramework/Sources/TetherFramework/AppearancePreference.swift
new file mode 100644
index 0000000..09c676d
--- /dev/null
+++ b/apple/TetherFramework/Sources/TetherFramework/AppearancePreference.swift
@@ -0,0 +1,38 @@
+//
+// AppearancePreference.swift
+// TetherFramework
+//
+// The user's light/dark choice, stored in the App Group so the Share
+// Extension renders in the same appearance as the main app.
+//
+
+import SwiftUI
+
+public enum AppearancePreference: String, CaseIterable, Identifiable, Sendable {
+ case system
+ case light
+ case dark
+
+ public static let storageKey = "TetherAppearance"
+
+ // Shared UserDefaults suite backed by the App Group container.
+ public static var sharedDefaults: UserDefaults {
+ UserDefaults(suiteName: CertificateManager.appGroupID) ?? .standard
+ }
+
+ /// The stored preference, or `.system` when unset or unrecognized.
+ public static var current: AppearancePreference {
+ sharedDefaults.string(forKey: storageKey).flatMap(Self.init(rawValue:)) ?? .system
+ }
+
+ public var id: String { rawValue }
+
+ /// The scheme to force, or nil to follow the system.
+ public var colorScheme: ColorScheme? {
+ switch self {
+ case .system: nil
+ case .light: .light
+ case .dark: .dark
+ }
+ }
+}
diff --git a/apple/TetherFramework/Tests/TetherFrameworkTests/AppearancePreferenceTests.swift b/apple/TetherFramework/Tests/TetherFrameworkTests/AppearancePreferenceTests.swift
new file mode 100644
index 0000000..1efd324
--- /dev/null
+++ b/apple/TetherFramework/Tests/TetherFrameworkTests/AppearancePreferenceTests.swift
@@ -0,0 +1,33 @@
+//
+// AppearancePreferenceTests.swift
+// TetherFrameworkTests
+//
+
+import Foundation
+import Testing
+@testable import TetherFramework
+
+struct AppearancePreferenceTests {
+ @Test func mapsToColorScheme() {
+ #expect(AppearancePreference.system.colorScheme == nil)
+ #expect(AppearancePreference.light.colorScheme == .light)
+ #expect(AppearancePreference.dark.colorScheme == .dark)
+ }
+
+ // A fresh install (or a value from a future version) must follow the system.
+ @Test func defaultsToSystem() {
+ let defaults = AppearancePreference.sharedDefaults
+ let key = AppearancePreference.storageKey
+ let saved = defaults.string(forKey: key)
+ defer { defaults.set(saved, forKey: key) }
+
+ defaults.removeObject(forKey: key)
+ #expect(AppearancePreference.current == .system)
+
+ defaults.set("sepia", forKey: key)
+ #expect(AppearancePreference.current == .system)
+
+ defaults.set(AppearancePreference.light.rawValue, forKey: key)
+ #expect(AppearancePreference.current == .light)
+ }
+}
diff --git a/apple/TetherShareExtension/ShareViewController.swift b/apple/TetherShareExtension/ShareViewController.swift
index 6f1ea99..a8e03f6 100644
--- a/apple/TetherShareExtension/ShareViewController.swift
+++ b/apple/TetherShareExtension/ShareViewController.swift
@@ -34,14 +34,20 @@ final class ShareViewController: UIViewController {
super.viewDidAppear(animated)
loadPayload { [weak self] payload in
guard let self else { return }
+ let appearance = AppearancePreference.current
let hostingVC = UIHostingController(
rootView: ShareSheetView(
payload: payload,
onComplete: { [weak self] in self?.completeRequest() },
onCancel: { [weak self] in self?.cancelRequest() }
)
- .preferredColorScheme(.dark)
+ .preferredColorScheme(appearance.colorScheme)
)
+ hostingVC.overrideUserInterfaceStyle = switch appearance {
+ case .system: .unspecified
+ case .light: .light
+ case .dark: .dark
+ }
hostingVC.modalPresentationStyle = .pageSheet
if let sheet = hostingVC.sheetPresentationController {
sheet.detents = [.medium()]
@@ -290,16 +296,21 @@ private struct ShareSheetView: View {
@State private var didFail = false
@State private var progress: (completed: Int, total: Int)?
@Environment(\.accessibilityReduceMotion) private var reduceMotion
+ @Environment(\.colorScheme) private var colorScheme
var body: some View {
NavigationStack {
ZStack {
- // Dark gradient background
LinearGradient(
- colors: [
- Color(hue: 0.6, saturation: 0.3, brightness: 0.12),
- Color(hue: 0.62, saturation: 0.4, brightness: 0.08),
- ],
+ colors: colorScheme == .dark
+ ? [
+ Color(hue: 0.6, saturation: 0.3, brightness: 0.12),
+ Color(hue: 0.62, saturation: 0.4, brightness: 0.08),
+ ]
+ : [
+ Color(hue: 0.6, saturation: 0.06, brightness: 0.98),
+ Color(hue: 0.62, saturation: 0.1, brightness: 0.93),
+ ],
startPoint: .topLeading,
endPoint: .bottomTrailing
)
@@ -326,7 +337,7 @@ private struct ShareSheetView: View {
.accessibilityHidden(true)
Text("Tether")
.font(.headline)
- .foregroundStyle(.white)
+ .foregroundStyle(.primary)
}
}
}
@@ -342,7 +353,7 @@ private struct ShareSheetView: View {
contentPreview
.padding(.top, 8)
- Divider().background(.white.opacity(0.15))
+ Divider().background(.primary.opacity(0.15))
// Route buttons — only show relevant ones
VStack(spacing: 12) {
@@ -399,7 +410,7 @@ private struct ShareSheetView: View {
icon: "key.fill",
label: "Send as OTP",
subtitle: "Stores in the Tether OTP vault",
- color: Color(hue: 0.15, saturation: 0.8, brightness: 0.9)
+ color: Color(hue: 0.15, saturation: 0.8, brightness: colorScheme == .dark ? 0.9 : 0.7)
) {
perform(.otp(text, source: "iPhone Share"))
}
@@ -460,7 +471,7 @@ private struct ShareSheetView: View {
.accessibilityHidden(true)
Text("\(items.count) items")
.font(.subheadline)
- .foregroundStyle(.white)
+ .foregroundStyle(.primary)
Text(multiItemSummary(items))
.font(.caption)
.foregroundStyle(.secondary)
@@ -486,10 +497,10 @@ private struct ShareSheetView: View {
Text(text)
.lineLimit(3)
.font(.body)
- .foregroundStyle(.white)
+ .foregroundStyle(.primary)
.padding(10)
.frame(maxWidth: .infinity, alignment: .leading)
- .background(.white.opacity(0.07))
+ .background(.primary.opacity(0.06))
.clipShape(RoundedRectangle(cornerRadius: 10))
}
.padding(.horizontal)
@@ -502,7 +513,7 @@ private struct ShareSheetView: View {
.accessibilityHidden(true)
Text(filename)
.font(.subheadline)
- .foregroundStyle(.white)
+ .foregroundStyle(.primary)
}
.padding()
}
@@ -551,7 +562,7 @@ private struct ShareSheetView: View {
.accessibilityHidden(true)
Text(message)
.multilineTextAlignment(.center)
- .foregroundStyle(.white)
+ .foregroundStyle(.primary)
.padding(.horizontal)
if failed {
Button("Close") { onCancel() }
@@ -676,7 +687,7 @@ private struct ActionButton: View {
VStack(alignment: .leading, spacing: 2) {
Text(label)
.font(.body.weight(.semibold))
- .foregroundStyle(.white)
+ .foregroundStyle(.primary)
Text(subtitle)
.font(.caption)
.foregroundStyle(.secondary)
@@ -690,11 +701,11 @@ private struct ActionButton: View {
}
.padding(.horizontal, 14)
.padding(.vertical, 12)
- .background(.white.opacity(0.06))
+ .background(.primary.opacity(0.05))
.clipShape(RoundedRectangle(cornerRadius: 14))
.overlay(
RoundedRectangle(cornerRadius: 14)
- .stroke(.white.opacity(0.08), lineWidth: 1)
+ .stroke(.primary.opacity(0.08), lineWidth: 1)
)
}
.buttonStyle(.plain)