From a09170256d7f40e6a9dc99ea2798766ebd051a45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Mon, 20 Apr 2026 03:31:36 +0800 Subject: [PATCH] Minor fixes --- .../Views/Abstract/FormItem.swift | 34 ++++++++++------ .../Views/Abstract/GlobalChecksModifier.swift | 40 +++++++++---------- .../Abstract/NavigationSheetContent.swift | 4 +- .../Views/Setting/CoreView.swift | 4 +- Library/Database/SharedPreferences.swift | 6 --- Library/Shared/Variant.swift | 8 +++- MacLibrary/ApplicationDelegate.swift | 4 +- SFI/MainView.swift | 21 +++++----- .../StandaloneApplicationDelegate.swift | 1 - sing-box.xcodeproj/project.pbxproj | 8 ++-- 10 files changed, 69 insertions(+), 61 deletions(-) diff --git a/ApplicationLibrary/Views/Abstract/FormItem.swift b/ApplicationLibrary/Views/Abstract/FormItem.swift index 49e4b67..50f56b9 100644 --- a/ApplicationLibrary/Views/Abstract/FormItem.swift +++ b/ApplicationLibrary/Views/Abstract/FormItem.swift @@ -87,20 +87,26 @@ public func FormItem(_ title: String, @ViewBuilder content: () -> some View) -> #endif } -public func FormToggle(_ titleKey: LocalizedStringKey, _ subtitleKey: LocalizedStringKey, _ isOn: Binding, _ action: @escaping (_ newValue: Bool) async -> Void) -> some View { +public func FormToggle(_ titleKey: LocalizedStringKey, _ subtitleKey: LocalizedStringKey, _ isOn: Binding, header: LocalizedStringKey? = nil, _ action: @escaping (_ newValue: Bool) async -> Void) -> some View { #if os(macOS) - Toggle(isOn: isOn) { - VStack(alignment: .leading) { - Text(titleKey) - Spacer() - Text(subtitleKey) - .font(.subheadline) - .foregroundStyle(.secondary) + Section { + Toggle(isOn: isOn) { + VStack(alignment: .leading) { + Text(titleKey) + Spacer() + Text(subtitleKey) + .font(.subheadline) + .foregroundStyle(.secondary) + } } - } - .onChangeCompat(of: isOn.wrappedValue) { newValue in - Task { - await action(newValue) + .onChangeCompat(of: isOn.wrappedValue) { newValue in + Task { + await action(newValue) + } + } + } header: { + if let header { + Text(header) } } #else @@ -111,6 +117,10 @@ public func FormToggle(_ titleKey: LocalizedStringKey, _ subtitleKey: LocalizedS await action(newValue) } } + } header: { + if let header { + Text(header) + } } footer: { Text(subtitleKey) .frame(maxWidth: .infinity, alignment: .leading) diff --git a/ApplicationLibrary/Views/Abstract/GlobalChecksModifier.swift b/ApplicationLibrary/Views/Abstract/GlobalChecksModifier.swift index 648dc5b..340529f 100644 --- a/ApplicationLibrary/Views/Abstract/GlobalChecksModifier.swift +++ b/ApplicationLibrary/Views/Abstract/GlobalChecksModifier.swift @@ -193,15 +193,6 @@ public struct GlobalChecksModifier: ViewModifier { } #if os(tvOS) - var state = AlertState( - title: String(localized: "Deprecated Warning"), - message: report.message(), - dismissButton: .cancel(String(localized: "Ok")) - ) - state.onDismiss = continueChain - alert = state - #else - if report.migrationLink.isEmpty { var state = AlertState( title: String(localized: "Deprecated Warning"), message: report.message(), @@ -209,17 +200,26 @@ public struct GlobalChecksModifier: ViewModifier { ) state.onDismiss = continueChain alert = state - } else { - alert = AlertState( - title: String(localized: "Deprecated Warning"), - message: report.message(), - primaryButton: .default(String(localized: "Documentation")) { - openURL(URL(string: report.migrationLink)!) - }, - secondaryButton: .cancel(String(localized: "Ok")), - onDismiss: continueChain - ) - } + #else + if report.migrationLink.isEmpty { + var state = AlertState( + title: String(localized: "Deprecated Warning"), + message: report.message(), + dismissButton: .cancel(String(localized: "Ok")) + ) + state.onDismiss = continueChain + alert = state + } else { + alert = AlertState( + title: String(localized: "Deprecated Warning"), + message: report.message(), + primaryButton: .default(String(localized: "Documentation")) { + openURL(URL(string: report.migrationLink)!) + }, + secondaryButton: .cancel(String(localized: "Ok")), + onDismiss: continueChain + ) + } #endif } diff --git a/ApplicationLibrary/Views/Abstract/NavigationSheetContent.swift b/ApplicationLibrary/Views/Abstract/NavigationSheetContent.swift index c086787..fb0c618 100644 --- a/ApplicationLibrary/Views/Abstract/NavigationSheetContent.swift +++ b/ApplicationLibrary/Views/Abstract/NavigationSheetContent.swift @@ -3,10 +3,10 @@ import SwiftUI @MainActor public struct SheetContent: View { - private let title: String + private let title: LocalizedStringKey private let content: Content - public init(_ title: String, @ViewBuilder content: () -> Content) { + public init(_ title: LocalizedStringKey, @ViewBuilder content: () -> Content) { self.title = title self.content = content() } diff --git a/ApplicationLibrary/Views/Setting/CoreView.swift b/ApplicationLibrary/Views/Setting/CoreView.swift index 86afc0d..4fa6676 100644 --- a/ApplicationLibrary/Views/Setting/CoreView.swift +++ b/ApplicationLibrary/Views/Setting/CoreView.swift @@ -60,8 +60,8 @@ public struct CoreView: View { } if Variant.isBeta { - Section {} - FormToggle("Disable Deprecated Warnings", "Do not show warnings about usages of deprecated features.", $disableDeprecatedWarnings) { newValue in + FormToggle("Disable Deprecated Warnings", "Do not show warnings about usages of deprecated features.", $disableDeprecatedWarnings, header: "Beta Settings") { + newValue in await SharedPreferences.disableDeprecatedWarnings.set(newValue) } } diff --git a/Library/Database/SharedPreferences.swift b/Library/Database/SharedPreferences.swift index 277a272..173f7f2 100644 --- a/Library/Database/SharedPreferences.swift +++ b/Library/Database/SharedPreferences.swift @@ -139,10 +139,4 @@ public enum SharedPreferences { public static let enabledDashboardCards = Preference<[String]>("enabled_dashboard_cards", defaultValue: []) public static let dashboardCardOrder = Preference<[String]>("dashboard_card_order", defaultValue: []) - - #if DEBUG - public static let inDebug = true - #else - public static let inDebug = false - #endif } diff --git a/Library/Shared/Variant.swift b/Library/Shared/Variant.swift index 0a35c58..dd7d620 100644 --- a/Library/Shared/Variant.swift +++ b/Library/Shared/Variant.swift @@ -16,7 +16,13 @@ public enum Variant { public static let applicationName = "SFT" #endif - public static var isBeta = LibboxVersion().contains("-") + public static let isBeta = LibboxVersion().contains("-") + + #if DEBUG + public static let inDebug = true + #else + public static let inDebug = false + #endif #if os(iOS) public static var debugNoIOS26 = false diff --git a/MacLibrary/ApplicationDelegate.swift b/MacLibrary/ApplicationDelegate.swift index 17135f1..db2a949 100644 --- a/MacLibrary/ApplicationDelegate.swift +++ b/MacLibrary/ApplicationDelegate.swift @@ -32,7 +32,7 @@ open class ApplicationDelegate: NSObject, NSApplicationDelegate, UNUserNotificat event?.eventID == kAEOpenApplication && event?.paramDescriptor(forKeyword: keyAEPropData)?.enumCodeValue == keyAELaunchedAsLogInItem let shouldShowWindow = Variant.screenshotMode || - SharedPreferences.inDebug || + Variant.inDebug || !launchedAsLogInItem || !SharedPreferences.showMenuBarExtra.getBlocking() || !SharedPreferences.menuBarExtraInBackground.getBlocking() @@ -74,7 +74,7 @@ open class ApplicationDelegate: NSObject, NSApplicationDelegate, UNUserNotificat } public func applicationShouldTerminateAfterLastWindowClosed(_: NSApplication) -> Bool { - SharedPreferences.inDebug || !SharedPreferences.menuBarExtraInBackground.getBlocking() + Variant.inDebug || !SharedPreferences.menuBarExtraInBackground.getBlocking() } public func applicationShouldHandleReopen(_: NSApplication, hasVisibleWindows flag: Bool) -> Bool { diff --git a/SFI/MainView.swift b/SFI/MainView.swift index cc7b429..15e9544 100644 --- a/SFI/MainView.swift +++ b/SFI/MainView.swift @@ -195,29 +195,28 @@ struct MainView: View { @ObservedObject var profile: ExtensionProfile var body: some View { - Text(statusText) + statusText .font(.subheadline) .foregroundStyle(.secondary) .lineLimit(1) .fixedSize() } - private var statusText: String { + private var statusText: Text { switch profile.status { - case .invalid: - return String(localized: "Invalid") case .disconnected: - return String(localized: "Stopped") + return Text("Stopped") case .connecting: - return String(localized: "Starting") + return Text("Starting") case .connected: - return String(localized: "Started") + return Text("Started") case .reasserting: - return String(localized: "Reasserting") + return Text("Reasserting") case .disconnecting: - return String(localized: "Stopping") - @unknown default: - return String(localized: "Unknown") + return Text("Stopping") + default: + return Text("Unknown") + .foregroundColor(.red) } } } diff --git a/SFM.System/StandaloneApplicationDelegate.swift b/SFM.System/StandaloneApplicationDelegate.swift index d3cbf54..6b833b0 100644 --- a/SFM.System/StandaloneApplicationDelegate.swift +++ b/SFM.System/StandaloneApplicationDelegate.swift @@ -7,7 +7,6 @@ import MacLibrary class StandaloneApplicationDelegate: ApplicationDelegate { func applicationWillFinishLaunching(_: Notification) { Variant.useSystemExtension = true - Variant.isBeta = false LibboxSetXPCDialer(CommandXPCDialer.shared) UserServiceEndpointPublisher.shared.start() Task { diff --git a/sing-box.xcodeproj/project.pbxproj b/sing-box.xcodeproj/project.pbxproj index 3f7df49..43a1aef 100644 --- a/sing-box.xcodeproj/project.pbxproj +++ b/sing-box.xcodeproj/project.pbxproj @@ -2672,7 +2672,7 @@ PRODUCT_NAME = "sing-box"; PROVISIONING_PROFILE_SPECIFIER = ""; SDKROOT = iphoneos; - SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; @@ -2714,7 +2714,7 @@ PRODUCT_NAME = "sing-box"; PROVISIONING_PROFILE_SPECIFIER = ""; SDKROOT = iphoneos; - SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; @@ -2755,7 +2755,7 @@ PROVISIONING_PROFILE_SPECIFIER = ""; REEXPORTED_LIBRARY_PATHS = ""; SDKROOT = macosx; - SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; }; name = Debug; @@ -2794,7 +2794,7 @@ PROVISIONING_PROFILE_SPECIFIER = ""; REEXPORTED_LIBRARY_PATHS = ""; SDKROOT = macosx; - SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; }; name = Release;