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