@@ -1,30 +1,33 @@
|
||||
|
||||
import Library
|
||||
import SwiftUI
|
||||
|
||||
#if os(macOS)
|
||||
|
||||
import AppKit
|
||||
import Library
|
||||
import ServiceManagement
|
||||
import SwiftUI
|
||||
#endif
|
||||
|
||||
public struct MacAppView: View {
|
||||
@State private var isLoading = true
|
||||
public struct AppView: View {
|
||||
@State private var isLoading = true
|
||||
|
||||
@State private var startAtLogin = false
|
||||
@Environment(\.showMenuBarExtra) private var showMenuBarExtra
|
||||
@State private var menuBarExtraInBackground = false
|
||||
@State private var startAtLogin = false
|
||||
@Environment(\.showMenuBarExtra) private var showMenuBarExtra
|
||||
@State private var menuBarExtraInBackground = false
|
||||
|
||||
@State private var alert: Alert?
|
||||
@State private var alert: Alert?
|
||||
|
||||
public init() {}
|
||||
public var body: some View {
|
||||
viewBuilder {
|
||||
if isLoading {
|
||||
ProgressView().onAppear {
|
||||
Task {
|
||||
await loadSettings()
|
||||
}
|
||||
public init() {}
|
||||
public var body: some View {
|
||||
viewBuilder {
|
||||
if isLoading {
|
||||
ProgressView().onAppear {
|
||||
Task {
|
||||
await loadSettings()
|
||||
}
|
||||
} else {
|
||||
FormView {
|
||||
}
|
||||
} else {
|
||||
FormView {
|
||||
#if os(macOS)
|
||||
FormToggle("Start At Login", "Launch the application when the system is logged in. If enabled at the same time as `Show in Menu Bar` and `Keep Menu Bar in Background`, the application interface will not be opened automatically.", $startAtLogin) { newValue in
|
||||
updateLoginItems(newValue)
|
||||
}
|
||||
@@ -66,21 +69,26 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
.alertBinding($alert)
|
||||
.navigationTitle("App")
|
||||
#if os(iOS)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
#endif
|
||||
}
|
||||
.alertBinding($alert)
|
||||
.navigationTitle("App")
|
||||
#if os(iOS)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
#endif
|
||||
}
|
||||
|
||||
private func loadSettings() async {
|
||||
private func loadSettings() async {
|
||||
#if os(macOS)
|
||||
startAtLogin = SMAppService.mainApp.status == .enabled
|
||||
menuBarExtraInBackground = await SharedPreferences.menuBarExtraInBackground.get()
|
||||
isLoading = false
|
||||
}
|
||||
#endif
|
||||
isLoading = false
|
||||
}
|
||||
|
||||
#if os(macOS)
|
||||
|
||||
private func updateLoginItems(_ startAtLogin: Bool) {
|
||||
do {
|
||||
@@ -143,6 +151,6 @@
|
||||
alert = Alert(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -87,11 +87,11 @@ public struct ServiceLogView: View {
|
||||
guard let value = element.value as? Int8, value != 0 else { return identifier }
|
||||
return identifier + String(UnicodeScalar(UInt8(value)))
|
||||
}
|
||||
var deviceInfo = "Machine: " + machineName + "\n"
|
||||
var deviceInfo = String("Machine: ") + machineName + "\n"
|
||||
#if os(iOS)
|
||||
await deviceInfo += "System: " + (UIDevice.current.systemName) + " " + (UIDevice.current.systemVersion) + "\n"
|
||||
await deviceInfo += String("System: ") + (UIDevice.current.systemName) + " " + (UIDevice.current.systemVersion) + "\n"
|
||||
#elseif os(macOS)
|
||||
deviceInfo += "System: macOS " + ProcessInfo().operatingSystemVersionString + "\n"
|
||||
deviceInfo += String("System: ") + "macOS " + ProcessInfo().operatingSystemVersionString + "\n"
|
||||
#endif
|
||||
content = deviceInfo + "\n" + content
|
||||
}
|
||||
|
||||
@@ -22,18 +22,18 @@ public struct SettingView: View {
|
||||
switch self {
|
||||
#if os(macOS)
|
||||
case .app:
|
||||
return NSLocalizedString("App", comment: "")
|
||||
return String(localized: "App")
|
||||
#endif
|
||||
case .core:
|
||||
return NSLocalizedString("Core", comment: "")
|
||||
return String(localized: "Core")
|
||||
case .packetTunnel:
|
||||
return NSLocalizedString("Packet Tunnel", comment: "")
|
||||
return String(localized: "Packet Tunnel")
|
||||
case .onDemandRules:
|
||||
return NSLocalizedString("On Demand Rules", comment: "")
|
||||
return String(localized: "On Demand Rules")
|
||||
case .profileOverride:
|
||||
return NSLocalizedString("Profile Override", comment: "")
|
||||
return String(localized: "Profile Override")
|
||||
case .sponsors:
|
||||
return NSLocalizedString("Sponsors", comment: "")
|
||||
return String(localized: "Sponsors")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public struct SettingView: View {
|
||||
switch self {
|
||||
#if os(macOS)
|
||||
case .app:
|
||||
MacAppView()
|
||||
AppView()
|
||||
#endif
|
||||
case .core:
|
||||
CoreView()
|
||||
@@ -106,11 +106,29 @@ public struct SettingView: View {
|
||||
}
|
||||
#if !os(tvOS)
|
||||
Section("About") {
|
||||
Link(destination: URL(string: "https://sing-box.sagernet.org/")!) {
|
||||
Link(destination: URL(string: String(localized: "https://sing-box.sagernet.org/"))!) {
|
||||
Label("Documentation", systemImage: "doc.on.doc.fill")
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.foregroundColor(.accentColor)
|
||||
.contextMenu {
|
||||
Link(destination: URL(string: String(localized: "https://sing-box.sagernet.org/changelog/"))!) {
|
||||
Text("Changelog")
|
||||
}
|
||||
Link(destination: URL(string: String(localized: "https://sing-box.sagernet.org/configuration/"))!) {
|
||||
Text("Configuration")
|
||||
}
|
||||
}
|
||||
Link(destination: URL(string: String("https://github.com/SagerNet/sing-box"))!) {
|
||||
Label("Source Code", systemImage: "pills.fill")
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.foregroundColor(.accentColor)
|
||||
.contextMenu {
|
||||
Link(destination: URL(string: String("https://github.com/SagerNet/sing-box/releases"))!) {
|
||||
Text("Releases")
|
||||
}
|
||||
}
|
||||
RequestReviewButton {
|
||||
Label("Rate on the App Store", systemImage: "text.bubble.fill")
|
||||
}
|
||||
@@ -145,7 +163,7 @@ public struct SettingView: View {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Text(taiwanFlagAvailable.description)
|
||||
Text(taiwanFlagAvailable.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,10 +14,10 @@ public struct SponsorsView: View {
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
|
||||
FormButton("GitHub Sponsor (recommended)") {
|
||||
FormButton(String(localized: "GitHub Sponsors (recommended)")) {
|
||||
openURL(URL(string: "https://github.com/sponsors/nekohasekai")!)
|
||||
}
|
||||
FormButton("Other methods") {
|
||||
FormButton(String(localized: "Other methods")) {
|
||||
openURL(URL(string: "https://sekai.icu/sponsors/")!)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user