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

Commit 0ba31be

Browse files
Modularize debug menu and login items logic (#1378)
Task/Issue URL: https://app.asana.com/0/0/1205112155849082/f ## Stack: - #1378 <- This PR - #1389 - #1397 ## 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 closing 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.
1 parent 5b5e4d5 commit 0ba31be

File tree

10 files changed

+700
-495
lines changed

10 files changed

+700
-495
lines changed

DuckDuckGo.xcodeproj/project.pbxproj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,12 @@
13331333
7B838C382A1DD8DD00E05A13 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4B2D06522A11D19B00DE1F49 /* Assets.xcassets */; };
13341334
7BA4727D26F01BC400EAA165 /* CoreDataTestUtilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B9292C42667104B00AD2C21 /* CoreDataTestUtilities.swift */; };
13351335
7BB108592A43375D000AB95F /* PFMoveApplication.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BB108582A43375D000AB95F /* PFMoveApplication.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
1336+
7BBD45B12A691AB500C83CA9 /* NetworkProtectionDebugUtilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BBD45B02A691AB500C83CA9 /* NetworkProtectionDebugUtilities.swift */; };
1337+
7BBD45B22A691AB500C83CA9 /* NetworkProtectionDebugUtilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BBD45B02A691AB500C83CA9 /* NetworkProtectionDebugUtilities.swift */; };
1338+
7BBD45B42A691C3A00C83CA9 /* NetworkProtectionLoginItemsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BBD45B32A691C3A00C83CA9 /* NetworkProtectionLoginItemsManager.swift */; };
1339+
7BBD45B52A691C3A00C83CA9 /* NetworkProtectionLoginItemsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BBD45B32A691C3A00C83CA9 /* NetworkProtectionLoginItemsManager.swift */; };
1340+
7BE146072A6A83C700C313B8 /* NetworkProtectionDebugMenuController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BE146062A6A83C700C313B8 /* NetworkProtectionDebugMenuController.swift */; };
1341+
7BE146082A6A83C700C313B8 /* NetworkProtectionDebugMenuController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BE146062A6A83C700C313B8 /* NetworkProtectionDebugMenuController.swift */; };
13361342
85012B0229133F9F003D0DCC /* NavigationBarPopovers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85012B0129133F9F003D0DCC /* NavigationBarPopovers.swift */; };
13371343
8511E18425F82B34002F516B /* 01_Fire_really_small.json in Resources */ = {isa = PBXBuildFile; fileRef = 8511E18325F82B34002F516B /* 01_Fire_really_small.json */; };
13381344
853014D625E671A000FB8205 /* PageObserverUserScript.swift in Sources */ = {isa = PBXBuildFile; fileRef = 853014D525E671A000FB8205 /* PageObserverUserScript.swift */; };
@@ -2555,6 +2561,9 @@
25552561
7B9459632A4A5BAF0012535A /* NetworkProtectionEnableOnDemand.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = NetworkProtectionEnableOnDemand.xcconfig; sourceTree = "<group>"; };
25562562
7BB108572A43375D000AB95F /* PFMoveApplication.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PFMoveApplication.h; sourceTree = "<group>"; };
25572563
7BB108582A43375D000AB95F /* PFMoveApplication.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PFMoveApplication.m; sourceTree = "<group>"; };
2564+
7BBD45B02A691AB500C83CA9 /* NetworkProtectionDebugUtilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkProtectionDebugUtilities.swift; sourceTree = "<group>"; };
2565+
7BBD45B32A691C3A00C83CA9 /* NetworkProtectionLoginItemsManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkProtectionLoginItemsManager.swift; sourceTree = "<group>"; };
2566+
7BE146062A6A83C700C313B8 /* NetworkProtectionDebugMenuController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkProtectionDebugMenuController.swift; sourceTree = "<group>"; };
25582567
85012B0129133F9F003D0DCC /* NavigationBarPopovers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationBarPopovers.swift; sourceTree = "<group>"; };
25592568
8511E18325F82B34002F516B /* 01_Fire_really_small.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = 01_Fire_really_small.json; sourceTree = "<group>"; };
25602569
853014D525E671A000FB8205 /* PageObserverUserScript.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PageObserverUserScript.swift; sourceTree = "<group>"; };
@@ -3948,6 +3957,9 @@
39483957
isa = PBXGroup;
39493958
children = (
39503959
4B4D60642A0B29FA00BCD287 /* LoginItem.swift */,
3960+
7BE146062A6A83C700C313B8 /* NetworkProtectionDebugMenuController.swift */,
3961+
7BBD45B02A691AB500C83CA9 /* NetworkProtectionDebugUtilities.swift */,
3962+
7BBD45B32A691C3A00C83CA9 /* NetworkProtectionLoginItemsManager.swift */,
39513963
B602E81C2A1E25B0006D261F /* NEOnDemandRuleExtension.swift */,
39523964
4B4D60652A0B29FA00BCD287 /* NetworkProtectionNavBarButtonModel.swift */,
39533965
4B8F52402A18326600BE7131 /* NetworkProtectionTunnelController.swift */,
@@ -7662,6 +7674,7 @@
76627674
3706FB7E293F65D500E42796 /* FireCoordinator.swift in Sources */,
76637675
3706FB7F293F65D500E42796 /* GeolocationProvider.swift in Sources */,
76647676
B603FD9F2A02712E00F3FCA9 /* CIImageExtension.swift in Sources */,
7677+
7BBD45B52A691C3A00C83CA9 /* NetworkProtectionLoginItemsManager.swift in Sources */,
76657678
3706FB80293F65D500E42796 /* NSAlert+ActiveDownloadsTermination.swift in Sources */,
76667679
3707C717294B5D0F00682A9F /* FindInPageTabExtension.swift in Sources */,
76677680
3706FB81293F65D500E42796 /* IndexPathExtension.swift in Sources */,
@@ -7675,6 +7688,7 @@
76757688
3706FB84293F65D500E42796 /* NSWindowExtension.swift in Sources */,
76767689
3706FB85293F65D500E42796 /* BookmarkPopover.swift in Sources */,
76777690
3706FB86293F65D500E42796 /* PreferencesDownloadsView.swift in Sources */,
7691+
7BBD45B22A691AB500C83CA9 /* NetworkProtectionDebugUtilities.swift in Sources */,
76787692
3706FB87293F65D500E42796 /* ProcessExtension.swift in Sources */,
76797693
3706FB88293F65D500E42796 /* PermissionAuthorizationQuery.swift in Sources */,
76807694
3706FB89293F65D500E42796 /* BadgeAnimationView.swift in Sources */,
@@ -7921,6 +7935,7 @@
79217935
3706FC5C293F65D500E42796 /* AppDelegate.swift in Sources */,
79227936
3706FC5D293F65D500E42796 /* ContentOverlayViewController.swift in Sources */,
79237937
3706FC5E293F65D500E42796 /* OnboardingViewController.swift in Sources */,
7938+
7BE146082A6A83C700C313B8 /* NetworkProtectionDebugMenuController.swift in Sources */,
79247939
3706FC5F293F65D500E42796 /* DeviceAuthenticator.swift in Sources */,
79257940
3706FEB9293F6EFF00E42796 /* BWVault.swift in Sources */,
79267941
3706FC60293F65D500E42796 /* TabBarCollectionView.swift in Sources */,
@@ -8526,6 +8541,7 @@
85268541
4B59024026B35F3600489384 /* ChromiumDataImporter.swift in Sources */,
85278542
B6A924DE2664CA09001A28CA /* LegacyWebKitDownloadDelegate.swift in Sources */,
85288543
AAA0CC3C25337FAB0079BC96 /* WKBackForwardListItemViewModel.swift in Sources */,
8544+
7BBD45B42A691C3A00C83CA9 /* NetworkProtectionLoginItemsManager.swift in Sources */,
85298545
1D43EB3429297D760065E5D6 /* BWNotRespondingAlert.swift in Sources */,
85308546
4BB88B4525B7B55C006F6B06 /* DebugUserScript.swift in Sources */,
85318547
AAC6881928626BF800D54247 /* RecentlyClosedTab.swift in Sources */,
@@ -8641,6 +8657,7 @@
86418657
AA840A9827319D1600E63CDD /* FirePopoverWrapperViewController.swift in Sources */,
86428658
4B85A48028821CC500FC4C39 /* NSPasteboardItemExtension.swift in Sources */,
86438659
37CD54CA27F2FDD100F1F7B9 /* AutofillPreferencesModel.swift in Sources */,
8660+
7BBD45B12A691AB500C83CA9 /* NetworkProtectionDebugUtilities.swift in Sources */,
86448661
B657841F25FA497600D8DB33 /* NSException+Catch.swift in Sources */,
86458662
4BE65481271FCD4D008D1D63 /* PasswordManagementNoteModel.swift in Sources */,
86468663
3184AC6F288F2A1100C35E4B /* CookieNotificationAnimationModel.swift in Sources */,
@@ -8755,6 +8772,7 @@
87558772
B63D466925BEB6C200874977 /* WKWebView+SessionState.swift in Sources */,
87568773
4B4D60C02A0C848D00BCD287 /* NetworkProtectionControllerErrorStore.swift in Sources */,
87578774
4B723E1226B0006E00E14D75 /* DataImport.swift in Sources */,
8775+
7BE146072A6A83C700C313B8 /* NetworkProtectionDebugMenuController.swift in Sources */,
87588776
B6085D092743AAB600A9C456 /* FireproofDomains.xcdatamodeld in Sources */,
87598777
3106AD76287F000600159FE5 /* CookieConsentUserPermissionViewController.swift in Sources */,
87608778
85589E8227BBB8630038AD11 /* HomePageView.swift in Sources */,

DuckDuckGo/AppDelegate/AppDelegate.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -306,19 +306,20 @@ final class AppDelegate: NSObject, NSApplicationDelegate, FileDownloadManagerDel
306306
#if NETWORK_PROTECTION
307307

308308
private func startupNetworkProtection() {
309+
let loginItemsManager = NetworkProtectionLoginItemsManager()
309310
let networkProtectionFeatureVisibility = NetworkProtectionKeychainTokenStore()
310311

311312
guard networkProtectionFeatureVisibility.isFeatureActivated else {
312-
NetworkProtectionTunnelController.disableLoginItems()
313+
loginItemsManager.disableLoginItems()
313314
LocalPinningManager.shared.unpin(.networkProtection)
314315
return
315316
}
316317

317-
updateNetworkProtectionIfVersionChanged()
318+
restartNetworkProtectionIfVersionChanged(using: loginItemsManager)
318319
refreshNetworkProtectionServers()
319320
}
320321

321-
private func updateNetworkProtectionIfVersionChanged() {
322+
private func restartNetworkProtectionIfVersionChanged(using loginItemsManager: NetworkProtectionLoginItemsManager) {
322323
let currentVersion = AppVersion.shared.versionNumber
323324
let versionStore = NetworkProtectionLastVersionRunStore()
324325
defer {
@@ -333,15 +334,15 @@ final class AppDelegate: NSObject, NSApplicationDelegate, FileDownloadManagerDel
333334

334335
if lastVersionRun != currentVersion {
335336
os_log(.info, log: .networkProtection, "App updated from %{public}s to %{public}s: updating login items", lastVersionRun, currentVersion)
336-
updateNetworkProtectionTunnelAndMenu()
337+
restartNetworkProtectionTunnelAndMenu(using: loginItemsManager)
337338
} else {
338339
// If login items failed to launch (e.g. because of the App bundle rename), launch using NSWorkspace
339-
NetworkProtectionTunnelController.ensureLoginItemsAreRunning(.ifLoginItemsAreEnabled, after: 1)
340+
loginItemsManager.ensureLoginItemsAreRunning(.ifLoginItemsAreEnabled, after: 1)
340341
}
341342
}
342343

343-
private func updateNetworkProtectionTunnelAndMenu() {
344-
NetworkProtectionTunnelController.resetLoginItems()
344+
private func restartNetworkProtectionTunnelAndMenu(using loginItemsManager: NetworkProtectionLoginItemsManager) {
345+
loginItemsManager.restartLoginItems()
345346

346347
Task {
347348
let provider = NetworkProtectionTunnelController()

0 commit comments

Comments
 (0)