mirror of
https://github.com/sudosylabs/vnidrop.git
synced 2026-08-05 10:29:58 +02:00
Replaces every stringly-typed localization key in the Apple app with compile-time-checked accessors generated from localization/strings.json. A mistyped key is now a build error instead of a silent fallback to the raw key at runtime. The runtime path is unchanged: plain keys are String.LocalizationValue constants resolved with String(localized:) and Apple's String Catalog still does the lookup; keys with arguments become typed, named functions applying args through String(format:). Generator: new renderSwiftAccessors emits apple/VniDrop/Generated/L10n.swift, wired into generate. Renamed generic arg1/arg2 tokens on four keys to semantic names (receiver, transferName, deviceId) and updated their context notes; positional output is unchanged so .xcstrings (bar the 4 comments) and the Android XML regenerate identical. Migration: every key-carrying value flipped to String.LocalizationValue end to end, resolved only at the leaf. Zero key literals and zero LocalizedStringKey remain in app or test code. macOS build passes; iOS test run pending.
138 lines
3.6 KiB
Swift
138 lines
3.6 KiB
Swift
import SwiftUI
|
|
|
|
/// Settings screen, rebuilt on a native `Form` with `NavigationStack` push
|
|
/// navigation. The model stays the source of truth via a derived path binding.
|
|
struct SettingsScreen: View {
|
|
@ObservedObject var model: SettingsModel
|
|
let windowClass: WindowClass
|
|
@State private var showBugReport = false
|
|
|
|
private var path: Binding<[SettingsSection]> {
|
|
Binding(
|
|
get: {
|
|
switch model.state.selectedSection {
|
|
case .overview: return []
|
|
case .bugReport: return [.about, .bugReport]
|
|
case let section: return [section]
|
|
}
|
|
},
|
|
set: { newPath in model.selectSection(newPath.last ?? .overview) }
|
|
)
|
|
}
|
|
|
|
var body: some View {
|
|
NavigationStack(path: path) {
|
|
Form {
|
|
Section {
|
|
NavigationLink(value: SettingsSection.preferences) {
|
|
SettingsRow(icon: "person.crop.circle", title: String(localized: L10n.Preferences.title), value: model.state.username)
|
|
}
|
|
NavigationLink(value: SettingsSection.appearance) {
|
|
SettingsRow(icon: "sun.max", title: String(localized: L10n.Appearance.title), value: themeModeLabel(model.state.themeMode))
|
|
}
|
|
}
|
|
Section {
|
|
NavigationLink(value: SettingsSection.notifications) {
|
|
SettingsRow(icon: "bell", title: String(localized: L10n.Notifications.title), value: nil)
|
|
}
|
|
NavigationLink(value: SettingsSection.storage) {
|
|
SettingsRow(icon: "internaldrive", title: String(localized: L10n.Storage.title), value: nil)
|
|
}
|
|
NavigationLink(value: SettingsSection.about) {
|
|
SettingsRow(icon: "info.circle", title: String(localized: L10n.About.title), value: nil)
|
|
}
|
|
}
|
|
}
|
|
.formStyle(.grouped)
|
|
.navigationTitle(Text(String(localized: L10n.Settings.title)))
|
|
.navigationDestination(for: SettingsSection.self) { section in
|
|
sectionForm(section)
|
|
}
|
|
}
|
|
}
|
|
|
|
@ViewBuilder
|
|
private func sectionForm(_ section: SettingsSection) -> some View {
|
|
let content = Form {
|
|
SettingsSectionContent(model: model, section: section)
|
|
}
|
|
.formStyle(.grouped)
|
|
.navigationTitle(Text(String(localized: section.titleKey)))
|
|
|
|
if section == .about {
|
|
content
|
|
#if os(iOS)
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
#endif
|
|
.toolbar {
|
|
ToolbarItem(placement: .primaryAction) {
|
|
Button {
|
|
showBugReport = true
|
|
} label: {
|
|
Label(String(localized: L10n.About.bugReport), systemImage: "ladybug")
|
|
}
|
|
}
|
|
}
|
|
.sheet(isPresented: $showBugReport) {
|
|
BugReportSheet(model: model)
|
|
}
|
|
} else {
|
|
content
|
|
#if os(iOS)
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
#endif
|
|
}
|
|
}
|
|
}
|
|
|
|
private struct SettingsSectionContent: View {
|
|
@ObservedObject var model: SettingsModel
|
|
let section: SettingsSection
|
|
|
|
var body: some View {
|
|
switch section {
|
|
case .overview:
|
|
EmptyView()
|
|
case .preferences:
|
|
PreferencesSettings(model: model)
|
|
case .appearance:
|
|
AppearanceSettings(model: model)
|
|
case .notifications:
|
|
NotificationSettings(model: model)
|
|
case .storage:
|
|
StorageSettings(model: model)
|
|
case .about:
|
|
AboutSettings(model: model)
|
|
case .bugReport:
|
|
BugReportSettings(model: model)
|
|
}
|
|
}
|
|
}
|
|
|
|
struct SettingsRow: View {
|
|
let icon: String
|
|
let title: String
|
|
let value: String?
|
|
|
|
var body: some View {
|
|
HStack(spacing: 12) {
|
|
Image(systemName: icon)
|
|
.foregroundStyle(.tint)
|
|
.frame(width: 26)
|
|
Text(title).foregroundStyle(.primary)
|
|
Spacer()
|
|
if let value {
|
|
Text(value).foregroundStyle(.secondary).lineLimit(1)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func themeModeLabel(_ mode: ThemeMode) -> String {
|
|
switch mode {
|
|
case .system: return String(localized: L10n.Appearance.systemMode)
|
|
case .light: return String(localized: L10n.Appearance.lightMode)
|
|
case .dark: return String(localized: L10n.Appearance.darkMode)
|
|
}
|
|
}
|