Add preview support

This commit is contained in:
世界
2023-07-20 13:15:13 +08:00
parent fdbf50d875
commit 251f441a25
14 changed files with 135 additions and 59 deletions
@@ -36,7 +36,7 @@ public struct ActiveDashboardView: View {
} else {
VStack {
#if os(iOS)
if profile.status.isConnected {
if ApplicationLibrary.inPreview || profile.status.isConnected {
ExtensionStatusView()
.listStyle(.automatic)
.navigationBarTitleDisplayMode(.inline)
@@ -53,7 +53,7 @@ public struct ActiveDashboardView: View {
}
}
#else
if profile.status.isConnected {
if ApplicationLibrary.inPreview || profile.status.isConnected {
ExtensionStatusView()
}
FormView {
@@ -74,7 +74,7 @@ public struct ActiveDashboardView: View {
await switchProfile(selectedProfileID!)
}
}
.disabled(!profile.status.isSwitchable || reasserting)
.disabled(!ApplicationLibrary.inPreview && (!profile.status.isSwitchable || reasserting))
}
}
}
@@ -115,24 +115,32 @@ public struct ActiveDashboardView: View {
defer {
isLoading = false
}
do {
profileList = try ProfileManager.list()
} catch {
errorMessage = error.localizedDescription
errorPresented = true
return
}
if profileList.isEmpty {
return
}
if ApplicationLibrary.inPreview {
profileList = [
Profile(id: 0, name: "profile local", type: .local, path: ""),
Profile(id: 1, name: "profile remote", type: .remote, path: "", lastUpdated: Date(timeIntervalSince1970: 0)),
]
selectedProfileID = 0
} else {
do {
profileList = try ProfileManager.list()
} catch {
errorMessage = error.localizedDescription
errorPresented = true
return
}
if profileList.isEmpty {
return
}
selectedProfileID = SharedPreferences.selectedProfileID
if profileList.filter({ profile in
profile.id == selectedProfileID
})
.isEmpty {
selectedProfileID = profileList[0].id!
SharedPreferences.selectedProfileID = selectedProfileID
selectedProfileID = SharedPreferences.selectedProfileID
if profileList.filter({ profile in
profile.id == selectedProfileID
})
.isEmpty {
selectedProfileID = profileList[0].id!
SharedPreferences.selectedProfileID = selectedProfileID
}
}
}
@@ -7,7 +7,9 @@ public struct DashboardView: View {
public var body: some View {
viewBuilder {
if let profile = extensionProfile.wrappedValue {
if ApplicationLibrary.inPreview {
ActiveDashboardView()
} else if let profile = extensionProfile.wrappedValue {
ActiveDashboardView().environmentObject(profile)
} else {
FormView {
@@ -18,7 +18,16 @@ public struct ExtensionStatusView: View {
viewBuilder {
VStack {
LazyVGrid(columns: Array(repeating: GridItem(.flexible()), count: columnCount), alignment: .leading) {
if let message {
if ApplicationLibrary.inPreview {
StatusItem("Memory", "6.4 MiB")
StatusItem("Goroutines", "89")
StatusItem("Inbound Connections", "34")
StatusItem("Outbound Connections", "28")
StatusItem("Uplink", "38 B/s")
StatusItem("Downlink", "249 MiB/s")
StatusItem("Uplink Total", "52 MiB")
StatusItem("Downlink Total", "5.6 GiB")
} else if let message {
StatusItem("Memory", LibboxFormatBytes(message.memory))
StatusItem("Goroutines", "\(message.goroutines)")
if message.trafficAvailable {
@@ -9,7 +9,18 @@ public struct StartStopButton: View {
public var body: some View {
viewBuilder {
if let profile = extensionProfile.wrappedValue {
if ApplicationLibrary.inPreview {
#if os(iOS)
Toggle(isOn: .constant(true)) {
Text("Enabled")
}
#elseif os(macOS)
Button(action: {}, label: {
Label("Stop", systemImage: "stop.fill")
})
#endif
} else if let profile = extensionProfile.wrappedValue {
Button0(profile)
} else {
#if os(iOS)
@@ -17,6 +28,7 @@ public struct StartStopButton: View {
Text("Enabled")
}
#elseif os(macOS)
Button(action: {}, label: {
Label("Start", systemImage: "play.fill")
})