Fix preview
This commit is contained in:
@@ -24,60 +24,68 @@ public struct ActiveDashboardView: View {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
VStack {
|
||||
#if os(iOS) || os(tvOS)
|
||||
if ApplicationLibrary.inPreview || profile.status.isConnectedStrict {
|
||||
Picker("Page", selection: $selection) {
|
||||
ForEach(DashboardPage.allCases) { page in
|
||||
page.label
|
||||
if ApplicationLibrary.inPreview {
|
||||
body1
|
||||
} else {
|
||||
body1
|
||||
.onChangeCompat(of: profile.status) { newStatus in
|
||||
if newStatus == .connected {
|
||||
Task.detached {
|
||||
await doReloadSystemProxy()
|
||||
}
|
||||
}
|
||||
.pickerStyle(.segmented)
|
||||
#if os(iOS)
|
||||
.padding([.leading, .trailing])
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
#endif
|
||||
TabView(selection: $selection) {
|
||||
ForEach(DashboardPage.allCases) { page in
|
||||
page.contentView($profileList, $selectedProfileID, $systemProxyAvailable, $systemProxyEnabled)
|
||||
.tag(page)
|
||||
}
|
||||
}
|
||||
.tabViewStyle(.page(indexDisplayMode: .always))
|
||||
} else {
|
||||
OverviewView($profileList, $selectedProfileID, $systemProxyAvailable, $systemProxyEnabled)
|
||||
}
|
||||
#elseif os(macOS)
|
||||
OverviewView($profileList, $selectedProfileID, $systemProxyAvailable, $systemProxyEnabled)
|
||||
#endif
|
||||
}
|
||||
#if os(iOS) || os(tvOS)
|
||||
.onChangeCompat(of: scenePhase) { newValue in
|
||||
if newValue == .active {
|
||||
Task.detached {
|
||||
await doReload()
|
||||
}
|
||||
}
|
||||
}
|
||||
.onChangeCompat(of: parentSelection.wrappedValue) { newValue in
|
||||
if newValue == .dashboard {
|
||||
Task.detached {
|
||||
await doReload()
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
.onChangeCompat(of: profile.status) { newStatus in
|
||||
if newStatus == .connected {
|
||||
Task.detached {
|
||||
await doReloadSystemProxy()
|
||||
}
|
||||
}
|
||||
}
|
||||
.alertBinding($alert)
|
||||
}
|
||||
}
|
||||
|
||||
private var body1: some View {
|
||||
VStack {
|
||||
#if os(iOS) || os(tvOS)
|
||||
if ApplicationLibrary.inPreview || profile.status.isConnectedStrict {
|
||||
Picker("Page", selection: $selection) {
|
||||
ForEach(DashboardPage.allCases) { page in
|
||||
page.label
|
||||
}
|
||||
}
|
||||
.pickerStyle(.segmented)
|
||||
#if os(iOS)
|
||||
.padding([.leading, .trailing])
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
#endif
|
||||
TabView(selection: $selection) {
|
||||
ForEach(DashboardPage.allCases) { page in
|
||||
page.contentView($profileList, $selectedProfileID, $systemProxyAvailable, $systemProxyEnabled)
|
||||
.tag(page)
|
||||
}
|
||||
}
|
||||
.tabViewStyle(.page(indexDisplayMode: .always))
|
||||
} else {
|
||||
OverviewView($profileList, $selectedProfileID, $systemProxyAvailable, $systemProxyEnabled)
|
||||
}
|
||||
#elseif os(macOS)
|
||||
OverviewView($profileList, $selectedProfileID, $systemProxyAvailable, $systemProxyEnabled)
|
||||
#endif
|
||||
}
|
||||
#if os(iOS) || os(tvOS)
|
||||
.onChangeCompat(of: scenePhase) { newValue in
|
||||
if newValue == .active {
|
||||
Task.detached {
|
||||
await doReload()
|
||||
}
|
||||
}
|
||||
}
|
||||
.onChangeCompat(of: parentSelection.wrappedValue) { newValue in
|
||||
if newValue == .dashboard {
|
||||
Task.detached {
|
||||
await doReload()
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
.alertBinding($alert)
|
||||
}
|
||||
|
||||
private func doReload() {
|
||||
defer {
|
||||
isLoading = false
|
||||
@@ -87,6 +95,8 @@ public struct ActiveDashboardView: View {
|
||||
Profile(id: 0, name: "profile local", type: .local, path: ""),
|
||||
Profile(id: 1, name: "profile remote", type: .remote, path: "", lastUpdated: Date(timeIntervalSince1970: 0)),
|
||||
]
|
||||
systemProxyAvailable = true
|
||||
systemProxyEnabled = true
|
||||
selectedProfileID = 0
|
||||
} else {
|
||||
do {
|
||||
|
||||
@@ -27,7 +27,7 @@ public struct ExtensionStatusView: View {
|
||||
LazyVGrid(columns: Array(repeating: GridItem(.flexible()), count: columnCount), alignment: .leading) {
|
||||
if ApplicationLibrary.inPreview {
|
||||
StatusItem("Status") {
|
||||
StatusLine("Memory", "6.4 MiB")
|
||||
StatusLine("Memory", "6.4 MB")
|
||||
StatusLine("Goroutines", "89")
|
||||
}
|
||||
StatusItem("Connections") {
|
||||
@@ -36,15 +36,15 @@ public struct ExtensionStatusView: View {
|
||||
}
|
||||
StatusItem("Traffic") {
|
||||
StatusLine("Uplink", "38 B/s")
|
||||
StatusLine("Downlink", "249 MiB/s")
|
||||
StatusLine("Downlink", "249 MB/s")
|
||||
}
|
||||
StatusItem("TrafficTotal") {
|
||||
StatusLine("Uplink", "52 MiB")
|
||||
StatusLine("Downlink", "5.6 GiB")
|
||||
StatusLine("Uplink", "52 MB")
|
||||
StatusLine("Downlink", "5.6 GB")
|
||||
}
|
||||
} else if let message = commandClient.status {
|
||||
StatusItem("Status") {
|
||||
StatusLine("Memory", LibboxFormatBytes(message.memory))
|
||||
StatusLine("Memory", LibboxFormatMemoryBytes(message.memory))
|
||||
StatusLine("Goroutines", "\(message.goroutines)")
|
||||
}
|
||||
StatusItem("Connections") {
|
||||
|
||||
@@ -35,7 +35,7 @@ public struct OverviewView: View {
|
||||
FormView {
|
||||
#if os(iOS) || os(tvOS)
|
||||
StartStopButton()
|
||||
if profile.status.isConnectedStrict, systemProxyAvailable {
|
||||
if ApplicationLibrary.inPreview || profile.status.isConnectedStrict, systemProxyAvailable {
|
||||
Toggle("HTTP Proxy", isOn: $systemProxyEnabled)
|
||||
.onChangeCompat(of: systemProxyEnabled) { newValue in
|
||||
Task.detached {
|
||||
@@ -52,7 +52,7 @@ public struct OverviewView: View {
|
||||
.pickerStyle(.inline)
|
||||
}
|
||||
#elseif os(macOS)
|
||||
if profile.status.isConnectedStrict, systemProxyAvailable {
|
||||
if ApplicationLibrary.inPreview || profile.status.isConnectedStrict, systemProxyAvailable {
|
||||
Toggle("HTTP Proxy", isOn: $systemProxyEnabled)
|
||||
.onChangeCompat(of: systemProxyEnabled) { newValue in
|
||||
Task.detached {
|
||||
@@ -72,7 +72,6 @@ public struct OverviewView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center)
|
||||
.alertBinding($alert)
|
||||
.onChangeCompat(of: selectedProfileID) {
|
||||
reasserting = true
|
||||
|
||||
@@ -25,7 +25,6 @@ public struct GroupListView: View {
|
||||
Text("Empty groups")
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center)
|
||||
.onAppear {
|
||||
connect()
|
||||
}
|
||||
@@ -54,7 +53,7 @@ public struct GroupListView: View {
|
||||
OutboundGroupItem(tag: "server2", type: "WireGuard", urlTestTime: .now, urlTestDelay: 34),
|
||||
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
|
||||
OutboundGroupItem(tag: "client\(index)", type: "Shadowsocks", urlTestTime: .now, urlTestDelay: UInt16(100 + index * 10))
|
||||
}),
|
||||
|
||||
@@ -10,7 +10,34 @@ public struct LogView: View {
|
||||
public init() {}
|
||||
|
||||
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 {
|
||||
if environments.logClient.isConnected {
|
||||
Text("Empty logs")
|
||||
@@ -19,7 +46,7 @@ public struct LogView: View {
|
||||
environments.connectLog()
|
||||
}
|
||||
}
|
||||
}.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center)
|
||||
}
|
||||
} else {
|
||||
ScrollViewReader { reader in
|
||||
ScrollView {
|
||||
|
||||
@@ -76,8 +76,9 @@ public extension NavigationPage {
|
||||
SettingView()
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center)
|
||||
#if os(iOS)
|
||||
.background(Color(uiColor: .systemGroupedBackground))
|
||||
.background(Color(uiColor: .systemGroupedBackground))
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,11 @@ public struct SettingView: View {
|
||||
|
||||
@State private var alwaysOn = false
|
||||
@State private var disableMemoryLimit = false
|
||||
@State private var includeAllNetworks = false
|
||||
|
||||
#if !os(tvOS)
|
||||
@State private var includeAllNetworks = false
|
||||
#endif
|
||||
|
||||
@State private var version = ""
|
||||
@State private var dataSize = ""
|
||||
@State private var taiwanFlagAvailable = false
|
||||
@@ -81,12 +85,14 @@ public struct SettingView: View {
|
||||
SharedPreferences.disableMemoryLimit = newValue
|
||||
}
|
||||
}
|
||||
Toggle("Include All Networks", isOn: $includeAllNetworks)
|
||||
.onChangeCompat(of: includeAllNetworks) { newValue in
|
||||
Task.detached {
|
||||
SharedPreferences.includeAllNetworks = newValue
|
||||
#if !os(tvOS)
|
||||
Toggle("Include All Networks", isOn: $includeAllNetworks)
|
||||
.onChangeCompat(of: includeAllNetworks) { newValue in
|
||||
Task.detached {
|
||||
SharedPreferences.includeAllNetworks = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if os(macOS)
|
||||
if Variant.useSystemExtension {
|
||||
HStack {
|
||||
@@ -172,13 +178,16 @@ public struct SettingView: View {
|
||||
#endif
|
||||
alwaysOn = SharedPreferences.alwaysOn
|
||||
disableMemoryLimit = SharedPreferences.disableMemoryLimit
|
||||
includeAllNetworks = SharedPreferences.includeAllNetworks
|
||||
version = LibboxVersion()
|
||||
#if !os(tvOS)
|
||||
includeAllNetworks = SharedPreferences.includeAllNetworks
|
||||
#endif
|
||||
if ApplicationLibrary.inPreview {
|
||||
dataSize = LibboxFormatBytes(1024 * 1024 * 10)
|
||||
version = "<redacted>"
|
||||
dataSize = LibboxFormatBytes(1000 * 1000 * 10)
|
||||
taiwanFlagAvailable = true
|
||||
isLoading = false
|
||||
} else {
|
||||
version = LibboxVersion()
|
||||
dataSize = "Loading..."
|
||||
taiwanFlagAvailable = !DeviceCensorship.isChinaDevice()
|
||||
isLoading = false
|
||||
|
||||
Reference in New Issue
Block a user