Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.

Conversation

@diegoreymendez
Copy link
Contributor

@diegoreymendez diegoreymendez commented Jul 21, 2023

Task/Issue URL: https://app.asana.com/0/0/1205112155849082/f

Stack:

Description

This PR:

  • Moves the debug logic that's currently in NetworkProtectionTunnelProvider into its own class.
  • Moves the login item management logic into its own class.

This will have the following advantages:

  • Since most of the debug logic is platform specific, moving it out of NetworkProtectionTunnelProvider means we're closer to being able to share it with iOS, which IMHO would be great many ways.
  • I'll be able to tackle fixes to the login items quicker, without having to deal with unrelated code. Additionally I'll be able to add unit tests more easily.

Testing

Test 1: Debug Menu

Test the debug menu and make sure all works well.

  1. Reset NetP's status.
  2. Remove the system extension and login items.
  3. Change your selected server
  4. Simulate a failure.

Test 2: Login Items

  1. Reset NetP's status.
  2. Launch the app.
  3. Start NetP.
  4. Make sure the login items are launched.

Internal references:

Pull Request Review Checklist
Software Engineering Expectations
Technical Design Template
Pull Request Documentation

@github-actions
Copy link
Contributor

github-actions bot commented Jul 21, 2023

Warnings
⚠️ PR has more than 500 lines of code changing. Consider splitting into smaller PRs if possible.

Generated by 🚫 dangerJS against d2ff642

@diegoreymendez diegoreymendez changed the title Makes several changes to our login items and NetP startup logic Modularize debug and login items logic Jul 21, 2023
@diegoreymendez diegoreymendez changed the title Modularize debug and login items logic Modularize debug menu and login items logic Jul 21, 2023
@diegoreymendez diegoreymendez requested a review from graeme July 21, 2023 15:14
@diegoreymendez diegoreymendez self-assigned this Jul 21, 2023
@diegoreymendez diegoreymendez marked this pull request as ready for review July 21, 2023 15:14
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.

A few comments. Nothing blocking, mainly cosmetic. If you do change anything else and want me to have another look, gimme a shout.

Copy link
Collaborator

@mallexxx mallexxx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the changes, that‘s so much cleaner! 🥳 See some comments inline

@diegoreymendez
Copy link
Contributor Author

For history and context: the remaining feedback is addressed in a follow up PR here: #1389

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#if NETWORK_PROTECTION import NetworkProtection #endif can now be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

/// Controller for the Network Protection debug menu.
///
@objc
final class NetworkProtectionDebugMenuController: NSObject {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other places menu items are managed by subclassing NSMenu (ApplicationDockMenu, MainMenu, HistoryMenu, MoreoptionsMenu, SharingMenu etc..)
Let‘s convert this into : NSMenu subclass - this will remove the need of an extra object in MainMenu, networkProtectionMenuItem and networkProtectionDebugMenuController outlets

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could also use self.supermenu()?.remove(at: self.supermenu()!.indexOfItem(withSubmenu: self)) in awakeFromNib() inside the !NETWORK_PROTECTION block to remove the menu management code from MainMenu - not strong on this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in #1397


// MARK: - Registration Key Validity

static let registrationKeyValidityKey = "com.duckduckgo.network-protection.NetworkProtectionTunnelController.registrationKeyValidityKey"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be replaced with @UserDefaultsWrapper?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in #1397

/// - validity: the default registration key validity time interval. A `nil` value means it will be automatically
/// defined by NetP using its standard configuration.
///
func setRegistrationKeyValidity(_ validity: TimeInterval?, defaults: UserDefaults = .standard) async throws {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this call is raising "Non-sendable type 'UserDefaults' exiting main actor-isolated context in call to non-isolated instance method 'setRegistrationKeyValidity(_:defaults:)' cannot cross actor boundary" warning in NetworkProtectionDebugMenuController - could we use @UserDefaultsWrapper instead of direct UserDefaults passing here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in #1397

/// Sets the selected server.
///
@IBAction
func setSelectedServer(_ sender: Any?) {
Copy link
Collaborator

@mallexxx mallexxx Jul 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NSMenuItem sender type can be directly set in the definition instead of casting - not something critical but reduces unneeded code

Copy link
Contributor Author

@diegoreymendez diegoreymendez Jul 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I don't mind either way but the reason I don't worry too much about these is that the guard below is staying, just in a slightly different form.

Either way I'm pushing this change since the guard becomes slightly nicer to read.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean we could get rid of the guard statement entirely by making the sender argument non- optional since it isn't meant to be called from outside

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in #1397

Comment on lines +149 to +153
if menuItem.state == .on {
menuItem.state = .off
} else {
menuItem.state = .on
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be set in the update() method - item state is not reset after the simulationOptions is reset

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tackled in #1397

Comment on lines +167 to +171
if menuItem.state == .on {
menuItem.state = .off
} else {
menuItem.state = .on
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tackled in #1397

@IBOutlet weak var networkProtectionMenuItem: NSMenuItem?
@IBOutlet weak var networkProtectionMenuItem: NSMenuItem? {
didSet {
networkProtectionMenuItem?.target = networkProtectionDebugMenuController
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is it needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's actually not - I think it was necessary at some point when the code was mostly living here, but after moving it I lost track of coming back to remove this. Good catch.

<scene sceneID="JPo-4y-FX3">
<objects>
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="DuckDuckGo_Privacy_Browser" customModuleProvider="target"/>
<customObject id="Ady-hI-5gd" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not related but since you‘re touching it, could you remove an empty Menu object from the storyboard? It seemingly got there by mistake and not used anywhere

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tackled in #1397

func ensureLoginItemsAreRunning(_ condition: LoginItemCheckCondition = .none, after interval: TimeInterval = .seconds(5)) {

Task {
try? await Task.sleep(interval: interval)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thrown error shouldn‘t be ignored for Task.sleep (meaning cancellation)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tackled in #1397

diegoreymendez and others added 2 commits July 26, 2023 12:28
Task/Issue URL: https://app.asana.com/0/0/1205135296966627/f
This is a follow up to:
#1378

## Stack:
- #1378
   - #1389 <- This PR

## Description:

Implements some changes based on the feedback received in these two
comments:
-
#1378 (comment)
-
#1378 (comment)

These changes were tackled separately for these reasons:
- The base PR was mostly about moving existing code to a different
location.
- The base PR works fine.
- Reviewing these changes separately guarantees a faster and more
focused feedback loop.
@diegoreymendez
Copy link
Contributor Author

@mallexxx - All feedback (but one item since I think it's ok to leave as-is, has been addressed). Most of it is in #1397 since it required huge changes and I wanted to avoid this PR going out of control.

@diegoreymendez diegoreymendez requested a review from mallexxx July 26, 2023 14:12
@mallexxx
Copy link
Collaborator

@diegoreymendez, not really huge 🤷‍♂️ especially having #1397 based on develop 🙂 - but certainly makes it harder to review the requested changes
Approved.

@diegoreymendez
Copy link
Contributor Author

@mallexxx - Part of the issue is that this PR's scope exploded, and I should've pushed back on it. A lot of the requested changes in this review are really out of scope.

I'll bring this up for discussion separately as a PR is probably not the best place for it.

@diegoreymendez
Copy link
Contributor Author

I'm merging as the issues I'm seeing in CI have absolutely nothing to do with my changes.

@diegoreymendez diegoreymendez merged commit 0ba31be into develop Jul 27, 2023
@diegoreymendez diegoreymendez deleted the diego/agents-debug-menu branch July 27, 2023 10:57
diegoreymendez added a commit that referenced this pull request Jul 27, 2023
samsymons added a commit that referenced this pull request Jul 28, 2023
# By Dominik Kapusta (7) and others
# Via Sam Symons (2) and others
* develop:
  Modularize debug menu and login items logic #3 (#1397)
  Modularize debug menu and login items logic (#1378)
  Fixes of minor issues with Fire Button after the new logic release (#1395)
  Fire Window (#1357)
  Fix reordering favorites in the last row when it's not fully populated (#1401)
  Close the window when cmd+w is pressed on a pinned tab and there are no regular tabs (#1390)
  update sparkle to 2.4.2 (#1362)
  disable trailing_comma (#1394)
  Add support for per-model Sync Data Providers initialization (#1387)
  update favicon logic to fix gsuite icons (#1380)
  Update minor version by default in code_freeze lane (#1392)
  Upload dSYMs from release builds to S3 for Sentry (#1393)
  Set version to 1.48.2.
  Hide Cards UI on macOS Catalina (#1386)
  Hide Cards UI on macOS Catalina (#1386)
  update shield icon only after navigation ended and tab is selected (#1314)
  Add Debug menu option back in for resetting the Email Protection InContext prompt (#1373)
  Bump version to 1.49.0 (42)
  Update embedded files

# Conflicts:
#	DuckDuckGo.xcodeproj/project.pbxproj
#	DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants