-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Removes unused code and makes some other code platform specific #419
Removes unused code and makes some other code platform specific #419
Conversation
Sources/NetworkProtection/Notifications/NetworkProtectionNotification.swift
Show resolved
Hide resolved
Sources/NetworkProtection/Notifications/NetworkProtectionNotification.swift
Show resolved
Hide resolved
public var connectionStatus: ConnectionStatus = .disconnected { | ||
didSet { | ||
if oldValue != connectionStatus { | ||
lastStatusChangeDate = Date() | ||
broadcastConnectionStatus() | ||
guard connectionStatus != oldValue else { | ||
return | ||
} | ||
|
||
connectionStatusPublisher.send(connectionStatus) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slightly different structure, we now just publish to any interested subscriber that the value was changed instead of broadcasting distributed notifications (which aren't relevant for iOS).
private func broadcastConnectionStatus() { | ||
let lastStatusChange = ConnectionStatusChange(status: connectionStatus, on: lastStatusChangeDate) | ||
let payload = ConnectionStatusChangeEncoder().encode(lastStatusChange) | ||
public let connectionStatusPublisher = CurrentValueSubject<ConnectionStatus, Never>(.disconnected) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CurrentValueSubject
publishes the last known value to any new subscriber, and any updates after the subscription is started.
private func broadcastLastSelectedServerInfo() { | ||
guard let serverInfo = lastSelectedServerInfo else { | ||
return | ||
} | ||
|
||
let serverStatusInfo = NetworkProtectionStatusServerInfo(serverLocation: serverInfo.serverLocation, serverAddress: serverInfo.endpoint?.description) | ||
let payload = ServerSelectedNotificationObjectEncoder().encode(serverStatusInfo) | ||
|
||
notificationCenter.post(.serverSelected, object: payload) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now more broadcasting distributed notifications from this class.
public init(notificationCenter: NetworkProtectionNotificationCenter, | ||
notificationsPresenter: NetworkProtectionNotificationsPresenter, | ||
public init(notificationsPresenter: NetworkProtectionNotificationsPresenter, | ||
tunnelHealthStore: NetworkProtectionTunnelHealthStore, | ||
controllerErrorStore: NetworkProtectionTunnelErrorStore, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes should be fine because they make this class more testable in theory.
} | ||
|
||
#endif | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code could be much nicer IMO if we had MacNetworkProtectionTunnelErrorStore
sending out the distributed notifications and composing internally NetworkprotectionTunnelErrorStore
.
But before doing that I think we may want to discuss a bit where we want the MacOS code to live.
private func postLastErrorMessageChangedNotification(_ errorMessage: String?) { | ||
notificationCenter.post(.tunnelErrorChanged, object: errorMessage) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was moved up to be placed inside the platform specific section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I’ll need this for my final project PR, FYI
Task/Issue URL: https://app.asana.com/0/1203512625915051/1205074419464907/f BSK PR: duckduckgo/BrowserServicesKit#419 iOS PR: duckduckgo/iOS#1837 ## Description: Network Protection module cleanup: - We're not using the `CFMessagePort` IPC mechanism so we can delete the code for that. - We're not using the distributed notifications code in iOS, so we can make that code platform-specific.
Task/Issue URL: https://app.asana.com/0/1203512625915051/1205074419464907/f BSK PR: duckduckgo/BrowserServicesKit#419 macOS PR: duckduckgo/macos-browser#1359 Description: Network Protection module cleanup: We're not using the CFMessagePort IPC mechanism. We're not using the distributed notifications code in iOS.
* main: Fix publisher, add option to override internal user state in debug (#422) Removes unused code and makes some other code platform specific (#419) Optimize first load of Content Rule Lists (#406) Automatically add the PR link to the Asana task (#311) NetP: Move bundle prefix to x-platform code (#418)
Required:
Task/Issue URL: https://app.asana.com/0/1203512625915051/1205074419464907/f
iOS PR: duckduckgo/iOS#1837
macOS PR: duckduckgo/macos-browser#1359
What kind of version bump will this require?: Major
Description:
Network Protection module cleanup:
CFMessagePort
IPC mechanism.Testing:
Refer to the instructions in the macOS and iOS PRs.
Internal references:
Software Engineering Expectations
Technical Design Template