Limit tunnel updates (#843)
- Do not observe tunnel in grid/list - Only observe .$currentProfile for grid selection - Move row tunnel updates to MarkerView - Debug InstalledProfileView
This commit is contained in:
parent
bd4aeed97a
commit
7719630cdd
|
@ -163,7 +163,8 @@ private struct StatusText: View {
|
|||
let isOpaque: Bool
|
||||
|
||||
var body: some View {
|
||||
ConnectionStatusText(tunnel: tunnel)
|
||||
debugChanges()
|
||||
return ConnectionStatusText(tunnel: tunnel)
|
||||
.font(.body)
|
||||
.foregroundStyle(tunnel.statusColor(theme))
|
||||
.opaque(isOpaque)
|
||||
|
|
|
@ -36,8 +36,7 @@ struct ProfileGridView: View, Routable, TunnelInstallationProviding {
|
|||
@ObservedObject
|
||||
var profileManager: ProfileManager
|
||||
|
||||
@ObservedObject
|
||||
var tunnel: ExtendedTunnel
|
||||
let tunnel: ExtendedTunnel
|
||||
|
||||
let interactiveManager: InteractiveManager
|
||||
|
||||
|
@ -48,6 +47,9 @@ struct ProfileGridView: View, Routable, TunnelInstallationProviding {
|
|||
@State
|
||||
private var nextProfileId: Profile.ID?
|
||||
|
||||
@State
|
||||
private var currentProfile: TunnelCurrentProfile?
|
||||
|
||||
private let columns: [GridItem] = [GridItem(.adaptive(minimum: 300.0))]
|
||||
|
||||
var body: some View {
|
||||
|
@ -73,6 +75,9 @@ struct ProfileGridView: View, Routable, TunnelInstallationProviding {
|
|||
.padding(.horizontal)
|
||||
}
|
||||
}
|
||||
.onReceive(tunnel.currentProfilePublisher) {
|
||||
currentProfile = $0
|
||||
}
|
||||
#if os(macOS)
|
||||
.padding(.top)
|
||||
#endif
|
||||
|
@ -124,7 +129,7 @@ private extension ProfileGridView {
|
|||
withMarker: true,
|
||||
flow: flow
|
||||
)
|
||||
.themeGridCell(isSelected: header.id == nextProfileId ?? tunnel.currentProfile?.id)
|
||||
.themeGridCell(isSelected: header.id == nextProfileId ?? currentProfile?.id)
|
||||
.contextMenu {
|
||||
ProfileContextMenu(
|
||||
profileManager: profileManager,
|
||||
|
|
|
@ -42,8 +42,7 @@ struct ProfileListView: View, Routable, TunnelInstallationProviding {
|
|||
@ObservedObject
|
||||
var profileManager: ProfileManager
|
||||
|
||||
@ObservedObject
|
||||
var tunnel: ExtendedTunnel
|
||||
let tunnel: ExtendedTunnel
|
||||
|
||||
let interactiveManager: InteractiveManager
|
||||
|
||||
|
|
|
@ -38,8 +38,7 @@ struct ProfileRowView: View, Routable {
|
|||
@ObservedObject
|
||||
var profileManager: ProfileManager
|
||||
|
||||
@ObservedObject
|
||||
var tunnel: ExtendedTunnel
|
||||
let tunnel: ExtendedTunnel
|
||||
|
||||
let header: ProfileHeader
|
||||
|
||||
|
@ -74,13 +73,43 @@ struct ProfileRowView: View, Routable {
|
|||
}
|
||||
}
|
||||
|
||||
// MARK: - Layout
|
||||
// MARK: - Subviews (observing)
|
||||
|
||||
private struct MarkerView: View {
|
||||
let headerId: Profile.ID
|
||||
|
||||
let nextProfileId: Profile.ID?
|
||||
|
||||
@ObservedObject
|
||||
var tunnel: ExtendedTunnel
|
||||
|
||||
var body: some View {
|
||||
ThemeImage(headerId == nextProfileId ? .pending : statusImage)
|
||||
.opaque(headerId == nextProfileId || headerId == tunnel.currentProfile?.id)
|
||||
.frame(width: 24.0)
|
||||
}
|
||||
|
||||
var statusImage: Theme.ImageName {
|
||||
switch tunnel.connectionStatus {
|
||||
case .active:
|
||||
return .marked
|
||||
|
||||
case .activating, .deactivating:
|
||||
return .pending
|
||||
|
||||
case .inactive:
|
||||
return .sleeping
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private extension ProfileRowView {
|
||||
var markerView: some View {
|
||||
ThemeImage(header.id == nextProfileId ? .pending : statusImage)
|
||||
.opaque(header.id == nextProfileId || header.id == tunnel.currentProfile?.id)
|
||||
.frame(width: 24.0)
|
||||
MarkerView(
|
||||
headerId: header.id,
|
||||
nextProfileId: nextProfileId,
|
||||
tunnel: tunnel
|
||||
)
|
||||
}
|
||||
|
||||
var cardView: some View {
|
||||
|
@ -102,19 +131,6 @@ private extension ProfileRowView {
|
|||
)
|
||||
.foregroundStyle(.primary)
|
||||
}
|
||||
|
||||
var statusImage: Theme.ImageName {
|
||||
switch tunnel.connectionStatus {
|
||||
case .active:
|
||||
return .marked
|
||||
|
||||
case .activating, .deactivating:
|
||||
return .pending
|
||||
|
||||
case .inactive:
|
||||
return .sleeping
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Attributes
|
||||
|
|
|
@ -98,6 +98,12 @@ extension ExtendedTunnel {
|
|||
tunnel.currentProfile
|
||||
}
|
||||
|
||||
public var currentProfilePublisher: AnyPublisher<TunnelCurrentProfile?, Never> {
|
||||
tunnel
|
||||
.$currentProfile
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
public func install(_ profile: Profile) async throws {
|
||||
pp_log(.app, .notice, "Install profile \(profile.id)...")
|
||||
let newProfile = try processedProfile(profile)
|
||||
|
|
Loading…
Reference in New Issue