Minor fixes

This commit is contained in:
世界
2026-04-20 05:28:31 +08:00
parent 142e82034e
commit a09170256d
10 changed files with 69 additions and 61 deletions
@@ -87,20 +87,26 @@ public func FormItem(_ title: String, @ViewBuilder content: () -> some View) ->
#endif #endif
} }
public func FormToggle(_ titleKey: LocalizedStringKey, _ subtitleKey: LocalizedStringKey, _ isOn: Binding<Bool>, _ action: @escaping (_ newValue: Bool) async -> Void) -> some View { public func FormToggle(_ titleKey: LocalizedStringKey, _ subtitleKey: LocalizedStringKey, _ isOn: Binding<Bool>, header: LocalizedStringKey? = nil, _ action: @escaping (_ newValue: Bool) async -> Void) -> some View {
#if os(macOS) #if os(macOS)
Toggle(isOn: isOn) { Section {
VStack(alignment: .leading) { Toggle(isOn: isOn) {
Text(titleKey) VStack(alignment: .leading) {
Spacer() Text(titleKey)
Text(subtitleKey) Spacer()
.font(.subheadline) Text(subtitleKey)
.foregroundStyle(.secondary) .font(.subheadline)
.foregroundStyle(.secondary)
}
} }
} .onChangeCompat(of: isOn.wrappedValue) { newValue in
.onChangeCompat(of: isOn.wrappedValue) { newValue in Task {
Task { await action(newValue)
await action(newValue) }
}
} header: {
if let header {
Text(header)
} }
} }
#else #else
@@ -111,6 +117,10 @@ public func FormToggle(_ titleKey: LocalizedStringKey, _ subtitleKey: LocalizedS
await action(newValue) await action(newValue)
} }
} }
} header: {
if let header {
Text(header)
}
} footer: { } footer: {
Text(subtitleKey) Text(subtitleKey)
.frame(maxWidth: .infinity, alignment: .leading) .frame(maxWidth: .infinity, alignment: .leading)
@@ -193,15 +193,6 @@ public struct GlobalChecksModifier: ViewModifier {
} }
#if os(tvOS) #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( var state = AlertState(
title: String(localized: "Deprecated Warning"), title: String(localized: "Deprecated Warning"),
message: report.message(), message: report.message(),
@@ -209,17 +200,26 @@ public struct GlobalChecksModifier: ViewModifier {
) )
state.onDismiss = continueChain state.onDismiss = continueChain
alert = state alert = state
} else { #else
alert = AlertState( if report.migrationLink.isEmpty {
title: String(localized: "Deprecated Warning"), var state = AlertState(
message: report.message(), title: String(localized: "Deprecated Warning"),
primaryButton: .default(String(localized: "Documentation")) { message: report.message(),
openURL(URL(string: report.migrationLink)!) dismissButton: .cancel(String(localized: "Ok"))
}, )
secondaryButton: .cancel(String(localized: "Ok")), state.onDismiss = continueChain
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 #endif
} }
@@ -3,10 +3,10 @@ import SwiftUI
@MainActor @MainActor
public struct SheetContent<Content: View>: View { public struct SheetContent<Content: View>: View {
private let title: String private let title: LocalizedStringKey
private let content: Content private let content: Content
public init(_ title: String, @ViewBuilder content: () -> Content) { public init(_ title: LocalizedStringKey, @ViewBuilder content: () -> Content) {
self.title = title self.title = title
self.content = content() self.content = content()
} }
@@ -60,8 +60,8 @@ public struct CoreView: View {
} }
if Variant.isBeta { if Variant.isBeta {
Section {} FormToggle("Disable Deprecated Warnings", "Do not show warnings about usages of deprecated features.", $disableDeprecatedWarnings, header: "Beta Settings") {
FormToggle("Disable Deprecated Warnings", "Do not show warnings about usages of deprecated features.", $disableDeprecatedWarnings) { newValue in newValue in
await SharedPreferences.disableDeprecatedWarnings.set(newValue) await SharedPreferences.disableDeprecatedWarnings.set(newValue)
} }
} }
-6
View File
@@ -139,10 +139,4 @@ public enum SharedPreferences {
public static let enabledDashboardCards = Preference<[String]>("enabled_dashboard_cards", defaultValue: []) public static let enabledDashboardCards = Preference<[String]>("enabled_dashboard_cards", defaultValue: [])
public static let dashboardCardOrder = Preference<[String]>("dashboard_card_order", 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
} }
+7 -1
View File
@@ -16,7 +16,13 @@ public enum Variant {
public static let applicationName = "SFT" public static let applicationName = "SFT"
#endif #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) #if os(iOS)
public static var debugNoIOS26 = false public static var debugNoIOS26 = false
+2 -2
View File
@@ -32,7 +32,7 @@ open class ApplicationDelegate: NSObject, NSApplicationDelegate, UNUserNotificat
event?.eventID == kAEOpenApplication && event?.eventID == kAEOpenApplication &&
event?.paramDescriptor(forKeyword: keyAEPropData)?.enumCodeValue == keyAELaunchedAsLogInItem event?.paramDescriptor(forKeyword: keyAEPropData)?.enumCodeValue == keyAELaunchedAsLogInItem
let shouldShowWindow = Variant.screenshotMode || let shouldShowWindow = Variant.screenshotMode ||
SharedPreferences.inDebug || Variant.inDebug ||
!launchedAsLogInItem || !launchedAsLogInItem ||
!SharedPreferences.showMenuBarExtra.getBlocking() || !SharedPreferences.showMenuBarExtra.getBlocking() ||
!SharedPreferences.menuBarExtraInBackground.getBlocking() !SharedPreferences.menuBarExtraInBackground.getBlocking()
@@ -74,7 +74,7 @@ open class ApplicationDelegate: NSObject, NSApplicationDelegate, UNUserNotificat
} }
public func applicationShouldTerminateAfterLastWindowClosed(_: NSApplication) -> Bool { public func applicationShouldTerminateAfterLastWindowClosed(_: NSApplication) -> Bool {
SharedPreferences.inDebug || !SharedPreferences.menuBarExtraInBackground.getBlocking() Variant.inDebug || !SharedPreferences.menuBarExtraInBackground.getBlocking()
} }
public func applicationShouldHandleReopen(_: NSApplication, hasVisibleWindows flag: Bool) -> Bool { public func applicationShouldHandleReopen(_: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
+10 -11
View File
@@ -195,29 +195,28 @@ struct MainView: View {
@ObservedObject var profile: ExtensionProfile @ObservedObject var profile: ExtensionProfile
var body: some View { var body: some View {
Text(statusText) statusText
.font(.subheadline) .font(.subheadline)
.foregroundStyle(.secondary) .foregroundStyle(.secondary)
.lineLimit(1) .lineLimit(1)
.fixedSize() .fixedSize()
} }
private var statusText: String { private var statusText: Text {
switch profile.status { switch profile.status {
case .invalid:
return String(localized: "Invalid")
case .disconnected: case .disconnected:
return String(localized: "Stopped") return Text("Stopped")
case .connecting: case .connecting:
return String(localized: "Starting") return Text("Starting")
case .connected: case .connected:
return String(localized: "Started") return Text("Started")
case .reasserting: case .reasserting:
return String(localized: "Reasserting") return Text("Reasserting")
case .disconnecting: case .disconnecting:
return String(localized: "Stopping") return Text("Stopping")
@unknown default: default:
return String(localized: "Unknown") return Text("Unknown")
.foregroundColor(.red)
} }
} }
} }
@@ -7,7 +7,6 @@ import MacLibrary
class StandaloneApplicationDelegate: ApplicationDelegate { class StandaloneApplicationDelegate: ApplicationDelegate {
func applicationWillFinishLaunching(_: Notification) { func applicationWillFinishLaunching(_: Notification) {
Variant.useSystemExtension = true Variant.useSystemExtension = true
Variant.isBeta = false
LibboxSetXPCDialer(CommandXPCDialer.shared) LibboxSetXPCDialer(CommandXPCDialer.shared)
UserServiceEndpointPublisher.shared.start() UserServiceEndpointPublisher.shared.start()
Task { Task {
+4 -4
View File
@@ -2672,7 +2672,7 @@
PRODUCT_NAME = "sing-box"; PRODUCT_NAME = "sing-box";
PROVISIONING_PROFILE_SPECIFIER = ""; PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = iphoneos; SDKROOT = iphoneos;
SWIFT_EMIT_LOC_STRINGS = NO; SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0; SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2"; TARGETED_DEVICE_FAMILY = "1,2";
}; };
@@ -2714,7 +2714,7 @@
PRODUCT_NAME = "sing-box"; PRODUCT_NAME = "sing-box";
PROVISIONING_PROFILE_SPECIFIER = ""; PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = iphoneos; SDKROOT = iphoneos;
SWIFT_EMIT_LOC_STRINGS = NO; SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0; SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2"; TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES; VALIDATE_PRODUCT = YES;
@@ -2755,7 +2755,7 @@
PROVISIONING_PROFILE_SPECIFIER = ""; PROVISIONING_PROFILE_SPECIFIER = "";
REEXPORTED_LIBRARY_PATHS = ""; REEXPORTED_LIBRARY_PATHS = "";
SDKROOT = macosx; SDKROOT = macosx;
SWIFT_EMIT_LOC_STRINGS = NO; SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0; SWIFT_VERSION = 5.0;
}; };
name = Debug; name = Debug;
@@ -2794,7 +2794,7 @@
PROVISIONING_PROFILE_SPECIFIER = ""; PROVISIONING_PROFILE_SPECIFIER = "";
REEXPORTED_LIBRARY_PATHS = ""; REEXPORTED_LIBRARY_PATHS = "";
SDKROOT = macosx; SDKROOT = macosx;
SWIFT_EMIT_LOC_STRINGS = NO; SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0; SWIFT_VERSION = 5.0;
}; };
name = Release; name = Release;