Fix preview

This commit is contained in:
世界
2023-09-20 21:17:05 +08:00
parent 9dc7713bd0
commit 390e063f20
13 changed files with 150 additions and 80 deletions
@@ -24,6 +24,22 @@ public struct ActiveDashboardView: View {
} }
} }
} else { } else {
if ApplicationLibrary.inPreview {
body1
} else {
body1
.onChangeCompat(of: profile.status) { newStatus in
if newStatus == .connected {
Task.detached {
await doReloadSystemProxy()
}
}
}
}
}
}
private var body1: some View {
VStack { VStack {
#if os(iOS) || os(tvOS) #if os(iOS) || os(tvOS)
if ApplicationLibrary.inPreview || profile.status.isConnectedStrict { if ApplicationLibrary.inPreview || profile.status.isConnectedStrict {
@@ -67,16 +83,8 @@ public struct ActiveDashboardView: View {
} }
} }
#endif #endif
.onChangeCompat(of: profile.status) { newStatus in
if newStatus == .connected {
Task.detached {
await doReloadSystemProxy()
}
}
}
.alertBinding($alert) .alertBinding($alert)
} }
}
private func doReload() { private func doReload() {
defer { defer {
@@ -87,6 +95,8 @@ public struct ActiveDashboardView: View {
Profile(id: 0, name: "profile local", type: .local, path: ""), Profile(id: 0, name: "profile local", type: .local, path: ""),
Profile(id: 1, name: "profile remote", type: .remote, path: "", lastUpdated: Date(timeIntervalSince1970: 0)), Profile(id: 1, name: "profile remote", type: .remote, path: "", lastUpdated: Date(timeIntervalSince1970: 0)),
] ]
systemProxyAvailable = true
systemProxyEnabled = true
selectedProfileID = 0 selectedProfileID = 0
} else { } else {
do { do {
@@ -27,7 +27,7 @@ public struct ExtensionStatusView: View {
LazyVGrid(columns: Array(repeating: GridItem(.flexible()), count: columnCount), alignment: .leading) { LazyVGrid(columns: Array(repeating: GridItem(.flexible()), count: columnCount), alignment: .leading) {
if ApplicationLibrary.inPreview { if ApplicationLibrary.inPreview {
StatusItem("Status") { StatusItem("Status") {
StatusLine("Memory", "6.4 MiB") StatusLine("Memory", "6.4 MB")
StatusLine("Goroutines", "89") StatusLine("Goroutines", "89")
} }
StatusItem("Connections") { StatusItem("Connections") {
@@ -36,15 +36,15 @@ public struct ExtensionStatusView: View {
} }
StatusItem("Traffic") { StatusItem("Traffic") {
StatusLine("Uplink", "38 B/s") StatusLine("Uplink", "38 B/s")
StatusLine("Downlink", "249 MiB/s") StatusLine("Downlink", "249 MB/s")
} }
StatusItem("TrafficTotal") { StatusItem("TrafficTotal") {
StatusLine("Uplink", "52 MiB") StatusLine("Uplink", "52 MB")
StatusLine("Downlink", "5.6 GiB") StatusLine("Downlink", "5.6 GB")
} }
} else if let message = commandClient.status { } else if let message = commandClient.status {
StatusItem("Status") { StatusItem("Status") {
StatusLine("Memory", LibboxFormatBytes(message.memory)) StatusLine("Memory", LibboxFormatMemoryBytes(message.memory))
StatusLine("Goroutines", "\(message.goroutines)") StatusLine("Goroutines", "\(message.goroutines)")
} }
StatusItem("Connections") { StatusItem("Connections") {
@@ -35,7 +35,7 @@ public struct OverviewView: View {
FormView { FormView {
#if os(iOS) || os(tvOS) #if os(iOS) || os(tvOS)
StartStopButton() StartStopButton()
if profile.status.isConnectedStrict, systemProxyAvailable { if ApplicationLibrary.inPreview || profile.status.isConnectedStrict, systemProxyAvailable {
Toggle("HTTP Proxy", isOn: $systemProxyEnabled) Toggle("HTTP Proxy", isOn: $systemProxyEnabled)
.onChangeCompat(of: systemProxyEnabled) { newValue in .onChangeCompat(of: systemProxyEnabled) { newValue in
Task.detached { Task.detached {
@@ -52,7 +52,7 @@ public struct OverviewView: View {
.pickerStyle(.inline) .pickerStyle(.inline)
} }
#elseif os(macOS) #elseif os(macOS)
if profile.status.isConnectedStrict, systemProxyAvailable { if ApplicationLibrary.inPreview || profile.status.isConnectedStrict, systemProxyAvailable {
Toggle("HTTP Proxy", isOn: $systemProxyEnabled) Toggle("HTTP Proxy", isOn: $systemProxyEnabled)
.onChangeCompat(of: systemProxyEnabled) { newValue in .onChangeCompat(of: systemProxyEnabled) { newValue in
Task.detached { Task.detached {
@@ -72,7 +72,6 @@ public struct OverviewView: View {
} }
} }
} }
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center)
.alertBinding($alert) .alertBinding($alert)
.onChangeCompat(of: selectedProfileID) { .onChangeCompat(of: selectedProfileID) {
reasserting = true reasserting = true
@@ -25,7 +25,6 @@ public struct GroupListView: View {
Text("Empty groups") Text("Empty groups")
} }
} }
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center)
.onAppear { .onAppear {
connect() connect()
} }
@@ -54,7 +53,7 @@ public struct GroupListView: View {
OutboundGroupItem(tag: "server2", type: "WireGuard", urlTestTime: .now, urlTestDelay: 34), OutboundGroupItem(tag: "server2", type: "WireGuard", urlTestTime: .now, urlTestDelay: 34),
OutboundGroupItem(tag: "auto", type: "URLTest", urlTestTime: .now, urlTestDelay: 100), OutboundGroupItem(tag: "auto", type: "URLTest", urlTestTime: .now, urlTestDelay: 100),
]), ]),
OutboundGroup(tag: "group2", type: "urltest", selected: "client", selectable: true, isExpand: true, items: OutboundGroup(tag: "group2", type: "urltest", selected: "client", selectable: true, isExpand: false, items:
(0 ..< 234).map { index in (0 ..< 234).map { index in
OutboundGroupItem(tag: "client\(index)", type: "Shadowsocks", urlTestTime: .now, urlTestDelay: UInt16(100 + index * 10)) OutboundGroupItem(tag: "client\(index)", type: "Shadowsocks", urlTestTime: .now, urlTestDelay: UInt16(100 + index * 10))
}), }),
+29 -2
View File
@@ -10,7 +10,34 @@ public struct LogView: View {
public init() {} public init() {}
public var body: some View { public var body: some View {
if environments.logClient.logList.isEmpty { if ApplicationLibrary.inPreview {
let logList = [
"(packet-tunnel) log server started",
"INFO[0000] router: loaded geoip database: 250 codes",
"INFO[0000] router: loaded geosite database: 1400 codes",
"INFO[0000] router: updated default interface en0, index 11",
"inbound/tun[0]: started at utun3",
"sing-box started (1.666s)",
]
ScrollView {
VStack(alignment: .leading, spacing: 0) {
ForEach(Array(logList.enumerated()), id: \.offset) { it in
Text(it.element)
.font(logFont)
#if os(tvOS)
.focusable()
#endif
Spacer(minLength: 8)
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
.padding()
}
#if os(tvOS)
.focusEffectDisabled()
.focusSection()
#endif
} else if environments.logClient.logList.isEmpty {
VStack { VStack {
if environments.logClient.isConnected { if environments.logClient.isConnected {
Text("Empty logs") Text("Empty logs")
@@ -19,7 +46,7 @@ public struct LogView: View {
environments.connectLog() environments.connectLog()
} }
} }
}.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center) }
} else { } else {
ScrollViewReader { reader in ScrollViewReader { reader in
ScrollView { ScrollView {
@@ -76,6 +76,7 @@ public extension NavigationPage {
SettingView() SettingView()
} }
} }
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center)
#if os(iOS) #if os(iOS)
.background(Color(uiColor: .systemGroupedBackground)) .background(Color(uiColor: .systemGroupedBackground))
#endif #endif
@@ -22,7 +22,11 @@ public struct SettingView: View {
@State private var alwaysOn = false @State private var alwaysOn = false
@State private var disableMemoryLimit = false @State private var disableMemoryLimit = false
#if !os(tvOS)
@State private var includeAllNetworks = false @State private var includeAllNetworks = false
#endif
@State private var version = "" @State private var version = ""
@State private var dataSize = "" @State private var dataSize = ""
@State private var taiwanFlagAvailable = false @State private var taiwanFlagAvailable = false
@@ -81,12 +85,14 @@ public struct SettingView: View {
SharedPreferences.disableMemoryLimit = newValue SharedPreferences.disableMemoryLimit = newValue
} }
} }
#if !os(tvOS)
Toggle("Include All Networks", isOn: $includeAllNetworks) Toggle("Include All Networks", isOn: $includeAllNetworks)
.onChangeCompat(of: includeAllNetworks) { newValue in .onChangeCompat(of: includeAllNetworks) { newValue in
Task.detached { Task.detached {
SharedPreferences.includeAllNetworks = newValue SharedPreferences.includeAllNetworks = newValue
} }
} }
#endif
#if os(macOS) #if os(macOS)
if Variant.useSystemExtension { if Variant.useSystemExtension {
HStack { HStack {
@@ -172,13 +178,16 @@ public struct SettingView: View {
#endif #endif
alwaysOn = SharedPreferences.alwaysOn alwaysOn = SharedPreferences.alwaysOn
disableMemoryLimit = SharedPreferences.disableMemoryLimit disableMemoryLimit = SharedPreferences.disableMemoryLimit
#if !os(tvOS)
includeAllNetworks = SharedPreferences.includeAllNetworks includeAllNetworks = SharedPreferences.includeAllNetworks
version = LibboxVersion() #endif
if ApplicationLibrary.inPreview { if ApplicationLibrary.inPreview {
dataSize = LibboxFormatBytes(1024 * 1024 * 10) version = "<redacted>"
dataSize = LibboxFormatBytes(1000 * 1000 * 10)
taiwanFlagAvailable = true taiwanFlagAvailable = true
isLoading = false isLoading = false
} else { } else {
version = LibboxVersion()
dataSize = "Loading..." dataSize = "Loading..."
taiwanFlagAvailable = !DeviceCensorship.isChinaDevice() taiwanFlagAvailable = !DeviceCensorship.isChinaDevice()
isLoading = false isLoading = false
+3
View File
@@ -9,7 +9,10 @@ public enum SharedPreferences {
private static let disableMemoryLimitByDefault = false private static let disableMemoryLimitByDefault = false
#endif #endif
@Preference<Bool>("disable_memory_limit", defaultValue: disableMemoryLimitByDefault) public static var disableMemoryLimit @Preference<Bool>("disable_memory_limit", defaultValue: disableMemoryLimitByDefault) public static var disableMemoryLimit
#if !os(tvOS)
@Preference<Bool>("include_all_networks", defaultValue: false) public static var includeAllNetworks @Preference<Bool>("include_all_networks", defaultValue: false) public static var includeAllNetworks
#endif
@Preference<Int>("max_log_lines", defaultValue: 300) public static var maxLogLines @Preference<Int>("max_log_lines", defaultValue: 300) public static var maxLogLines
@Preference<Bool>("always_on", defaultValue: false) public static var alwaysOn @Preference<Bool>("always_on", defaultValue: false) public static var alwaysOn
+7 -1
View File
@@ -58,9 +58,15 @@ public class ExtensionProfile: ObservableObject {
manager.isOnDemandEnabled = true manager.isOnDemandEnabled = true
setOnDemandRules() setOnDemandRules()
} }
#if !os(tvOS)
if let protocolConfiguration = manager.protocolConfiguration { if let protocolConfiguration = manager.protocolConfiguration {
protocolConfiguration.includeAllNetworks = SharedPreferences.includeAllNetworks let includeAllNetworks = SharedPreferences.includeAllNetworks
protocolConfiguration.includeAllNetworks = includeAllNetworks
if #available(iOS 16.4, macOS 13.3, *) {
protocolConfiguration.excludeCellularServices = !includeAllNetworks
} }
}
#endif
try await manager.saveToPreferences() try await manager.saveToPreferences()
#if os(macOS) #if os(macOS)
if Variant.useSystemExtension { if Variant.useSystemExtension {
+1 -1
View File
@@ -46,7 +46,7 @@ public extension FilePath {
#endif #endif
static var iCloudDirectory: URL! = FileManager.default.url(forUbiquityContainerIdentifier: nil)!.appendingPathComponent("Documents", isDirectory: true) static var iCloudDirectory = FileManager.default.url(forUbiquityContainerIdentifier: nil)?.appendingPathComponent("Documents", isDirectory: true) ?? URL(string: "stub")!
} }
public extension URL { public extension URL {
+8
View File
@@ -14,6 +14,14 @@ public struct MainView: View {
public init() {} public init() {}
public var body: some View { public var body: some View {
if ApplicationLibrary.inPreview {
body1.frame(width: 1280, height: 750, alignment: .topLeading)
} else {
body1
}
}
private var body1: some View {
NavigationSplitView { NavigationSplitView {
SidebarView() SidebarView()
} detail: { } detail: {
+8
View File
@@ -13,6 +13,14 @@ struct MainView: View {
@State private var alert: Alert? @State private var alert: Alert?
var body: some View { var body: some View {
if ApplicationLibrary.inPreview {
body1.preferredColorScheme(.dark)
} else {
body1
}
}
var body1: some View {
TabView(selection: $selection) { TabView(selection: $selection) {
ForEach(NavigationPage.allCases, id: \.self) { page in ForEach(NavigationPage.allCases, id: \.self) { page in
NavigationStackCompat { NavigationStackCompat {
+6 -6
View File
@@ -2293,7 +2293,7 @@
CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 54; CURRENT_PROJECT_VERSION = 55;
DEAD_CODE_STRIPPING = YES; DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = Z56Z6NYZN2; DEVELOPMENT_TEAM = Z56Z6NYZN2;
ENABLE_HARDENED_RUNTIME = YES; ENABLE_HARDENED_RUNTIME = YES;
@@ -2331,7 +2331,7 @@
CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 54; CURRENT_PROJECT_VERSION = 55;
DEAD_CODE_STRIPPING = YES; DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = Z56Z6NYZN2; DEVELOPMENT_TEAM = Z56Z6NYZN2;
ENABLE_HARDENED_RUNTIME = YES; ENABLE_HARDENED_RUNTIME = YES;
@@ -2489,7 +2489,7 @@
"@executable_path/../../../../Frameworks", "@executable_path/../../../../Frameworks",
); );
MACOSX_DEPLOYMENT_TARGET = 13.0; MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 1.5.0-beta.11; MARKETING_VERSION = 1.5.0-rc.1;
PRODUCT_BUNDLE_IDENTIFIER = io.nekohasekai.sfa.system; PRODUCT_BUNDLE_IDENTIFIER = io.nekohasekai.sfa.system;
PRODUCT_NAME = "$(inherited)"; PRODUCT_NAME = "$(inherited)";
PROVISIONING_PROFILE_SPECIFIER = ""; PROVISIONING_PROFILE_SPECIFIER = "";
@@ -2525,7 +2525,7 @@
"@executable_path/../../../../Frameworks", "@executable_path/../../../../Frameworks",
); );
MACOSX_DEPLOYMENT_TARGET = 13.0; MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 1.5.0-beta.11; MARKETING_VERSION = 1.5.0-rc.1;
PRODUCT_BUNDLE_IDENTIFIER = io.nekohasekai.sfa.system; PRODUCT_BUNDLE_IDENTIFIER = io.nekohasekai.sfa.system;
PRODUCT_NAME = "$(inherited)"; PRODUCT_NAME = "$(inherited)";
PROVISIONING_PROFILE_SPECIFIER = ""; PROVISIONING_PROFILE_SPECIFIER = "";
@@ -2565,7 +2565,7 @@
"@executable_path/../Frameworks", "@executable_path/../Frameworks",
); );
MACOSX_DEPLOYMENT_TARGET = 13.0; MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 1.5.0-beta.11; MARKETING_VERSION = 1.5.0-rc.1;
PRODUCT_BUNDLE_IDENTIFIER = io.nekohasekai.sfa.independent; PRODUCT_BUNDLE_IDENTIFIER = io.nekohasekai.sfa.independent;
PRODUCT_NAME = SFM; PRODUCT_NAME = SFM;
PROVISIONING_PROFILE_SPECIFIER = ""; PROVISIONING_PROFILE_SPECIFIER = "";
@@ -2604,7 +2604,7 @@
"@executable_path/../Frameworks", "@executable_path/../Frameworks",
); );
MACOSX_DEPLOYMENT_TARGET = 13.0; MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 1.5.0-beta.11; MARKETING_VERSION = 1.5.0-rc.1;
PRODUCT_BUNDLE_IDENTIFIER = io.nekohasekai.sfa.independent; PRODUCT_BUNDLE_IDENTIFIER = io.nekohasekai.sfa.independent;
PRODUCT_NAME = SFM; PRODUCT_NAME = SFM;
PROVISIONING_PROFILE_SPECIFIER = ""; PROVISIONING_PROFILE_SPECIFIER = "";