Skip to content
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

Merged

Conversation

diegoreymendez
Copy link
Contributor

@diegoreymendez diegoreymendez commented Jul 17, 2023

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:

  • We're not using the CFMessagePort IPC mechanism.
  • We're not using the distributed notifications code in iOS.

Testing:

Refer to the instructions in the macOS and iOS PRs.


Internal references:

Software Engineering Expectations
Technical Design Template

@diegoreymendez diegoreymendez changed the title Removes a few unused files and wraps some code to be macOS specific Removes unused code and makes some other code platform specific. Jul 17, 2023
@diegoreymendez diegoreymendez requested a review from graeme July 17, 2023 20:19
@diegoreymendez diegoreymendez self-assigned this Jul 17, 2023
@diegoreymendez diegoreymendez marked this pull request as ready for review July 17, 2023 20:19
Comment on lines +92 to +98
public var connectionStatus: ConnectionStatus = .disconnected {
didSet {
if oldValue != connectionStatus {
lastStatusChangeDate = Date()
broadcastConnectionStatus()
guard connectionStatus != oldValue else {
return
}

connectionStatusPublisher.send(connectionStatus)
Copy link
Contributor Author

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)
Copy link
Contributor Author

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.

Comment on lines -123 to -132
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)
}
Copy link
Contributor Author

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.

Comment on lines -317 to +297
public init(notificationCenter: NetworkProtectionNotificationCenter,
notificationsPresenter: NetworkProtectionNotificationsPresenter,
public init(notificationsPresenter: NetworkProtectionNotificationsPresenter,
tunnelHealthStore: NetworkProtectionTunnelHealthStore,
controllerErrorStore: NetworkProtectionTunnelErrorStore,
Copy link
Contributor Author

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

Copy link
Contributor Author

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.

Comment on lines -49 to -51
private func postLastErrorMessageChangedNotification(_ errorMessage: String?) {
notificationCenter.post(.tunnelErrorChanged, object: errorMessage)
}
Copy link
Contributor Author

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.

@diegoreymendez diegoreymendez changed the title Removes unused code and makes some other code platform specific. Removes unused code and makes some other code platform specific Jul 17, 2023
Copy link
Contributor

@graeme graeme left a 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

@diegoreymendez diegoreymendez merged commit d2b6c76 into main Jul 19, 2023
@diegoreymendez diegoreymendez deleted the diego/remove-distributed-notification-code-from-netp-bsk branch July 19, 2023 07:46
diegoreymendez added a commit to duckduckgo/macos-browser that referenced this pull request Jul 19, 2023
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.
diegoreymendez added a commit to duckduckgo/iOS that referenced this pull request Jul 19, 2023
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.
samsymons added a commit that referenced this pull request Jul 20, 2023
* 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants