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

Commit f3ab4cc

Browse files
Move changes to extensions
1 parent 8467795 commit f3ab4cc

File tree

5 files changed

+86
-32
lines changed

5 files changed

+86
-32
lines changed

DuckDuckGo-iOS.xcodeproj/project.pbxproj

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,6 @@
421421
7B1604E82CB685B400A44EC6 /* Logger+TipKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B1604E72CB685B400A44EC6 /* Logger+TipKit.swift */; };
422422
7B1604EC2CB68BDA00A44EC6 /* TipKitController+ConvenienceInitializers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B1604EB2CB68BDA00A44EC6 /* TipKitController+ConvenienceInitializers.swift */; };
423423
7B1604EE2CB68D2600A44EC6 /* TipKitDebugOptionsUIActionHandling.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B1604ED2CB68D2600A44EC6 /* TipKitDebugOptionsUIActionHandling.swift */; };
424-
7B70CC3C2D15C0BC0096A1C6 /* AutomationServer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B70CC3B2D15C0BC0096A1C6 /* AutomationServer.swift */; };
425424
7B1681012D106CB9005EAE24 /* UserTextShared.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B1681002D106CB4005EAE24 /* UserTextShared.swift */; };
426425
7B1681022D106CCC005EAE24 /* UserTextShared.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B1681002D106CB4005EAE24 /* UserTextShared.swift */; };
427426
7B1681062D10BC96005EAE24 /* VPNShortcutIntents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B1681042D10BC7B005EAE24 /* VPNShortcutIntents.swift */; };
@@ -440,7 +439,10 @@
440439
7B4F87EA2D0738F90010B18F /* SiriEducationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B4F87E92D0738F40010B18F /* SiriEducationView.swift */; };
441440
7B4F87EC2D07396A0010B18F /* SiriEducation.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7B4F87EB2D07396A0010B18F /* SiriEducation.xcassets */; };
442441
7B4F87EE2D0739EB0010B18F /* SiriBubbleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B4F87ED2D0739E80010B18F /* SiriBubbleView.swift */; };
442+
7B70CC3C2D15C0BC0096A1C6 /* AutomationServer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B70CC3B2D15C0BC0096A1C6 /* AutomationServer.swift */; };
443443
7B8E0EC62CC81B4900B2B722 /* TipKitController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B8E0EC52CC81B4800B2B722 /* TipKitController.swift */; };
444+
7B9D532F2D5431E400D9E937 /* MainViewController+Automation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B9D532E2D5431E400D9E937 /* MainViewController+Automation.swift */; };
445+
7B9D53312D54321200D9E937 /* TabViewController+Automation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B9D53302D54321200D9E937 /* TabViewController+Automation.swift */; };
444446
7BC571202BDBB877003B0CCE /* VPNActivationDateStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BC5711F2BDBB877003B0CCE /* VPNActivationDateStore.swift */; };
445447
7BC571212BDBB977003B0CCE /* VPNActivationDateStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BC5711F2BDBB877003B0CCE /* VPNActivationDateStore.swift */; };
446448
7BDBAD0E2CBFB3F1000379B7 /* VPN.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7BDBAD0D2CBFB3F1000379B7 /* VPN.xcassets */; };
@@ -1832,7 +1834,6 @@
18321834
7B1604E72CB685B400A44EC6 /* Logger+TipKit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Logger+TipKit.swift"; sourceTree = "<group>"; };
18331835
7B1604EB2CB68BDA00A44EC6 /* TipKitController+ConvenienceInitializers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TipKitController+ConvenienceInitializers.swift"; sourceTree = "<group>"; };
18341836
7B1604ED2CB68D2600A44EC6 /* TipKitDebugOptionsUIActionHandling.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TipKitDebugOptionsUIActionHandling.swift; sourceTree = "<group>"; };
1835-
7B70CC3B2D15C0BC0096A1C6 /* AutomationServer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutomationServer.swift; sourceTree = "<group>"; };
18361837
7B1681002D106CB4005EAE24 /* UserTextShared.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserTextShared.swift; sourceTree = "<group>"; };
18371838
7B1681042D10BC7B005EAE24 /* VPNShortcutIntents.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VPNShortcutIntents.swift; sourceTree = "<group>"; };
18381839
7B16810B2D10CF44005EAE24 /* WidgetVPNIntents.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WidgetVPNIntents.swift; sourceTree = "<group>"; };
@@ -1844,7 +1845,10 @@
18441845
7B4F87E92D0738F40010B18F /* SiriEducationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SiriEducationView.swift; sourceTree = "<group>"; };
18451846
7B4F87EB2D07396A0010B18F /* SiriEducation.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = SiriEducation.xcassets; sourceTree = "<group>"; };
18461847
7B4F87ED2D0739E80010B18F /* SiriBubbleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SiriBubbleView.swift; sourceTree = "<group>"; };
1848+
7B70CC3B2D15C0BC0096A1C6 /* AutomationServer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutomationServer.swift; sourceTree = "<group>"; };
18471849
7B8E0EC52CC81B4800B2B722 /* TipKitController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TipKitController.swift; sourceTree = "<group>"; };
1850+
7B9D532E2D5431E400D9E937 /* MainViewController+Automation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MainViewController+Automation.swift"; sourceTree = "<group>"; };
1851+
7B9D53302D54321200D9E937 /* TabViewController+Automation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TabViewController+Automation.swift"; sourceTree = "<group>"; };
18481852
7BC5711F2BDBB877003B0CCE /* VPNActivationDateStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VPNActivationDateStore.swift; sourceTree = "<group>"; };
18491853
7BDBAD0D2CBFB3F1000379B7 /* VPN.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = VPN.xcassets; sourceTree = "<group>"; };
18501854
7BF78E012CA2CC3E0026A1FC /* TipKitAppEventHandling.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TipKitAppEventHandling.swift; sourceTree = "<group>"; };
@@ -6378,6 +6382,7 @@
63786382
984147C224F026A300362052 /* Tab.storyboard */,
63796383
F1386BA31E6846C40062FC3C /* TabDelegate.swift */,
63806384
F159BDA31F0BDB5A00B4A01D /* TabViewController.swift */,
6385+
7B9D53302D54321200D9E937 /* TabViewController+Automation.swift */,
63816386
CBC88EE42C8097B500F0F8C5 /* URLCredentialCreator.swift */,
63826387
CB2A7EEE283D185100885F67 /* RulesCompilationMonitor.swift */,
63836388
9820EAF422613CD30089094D /* WebProgressWorker.swift */,
@@ -6778,6 +6783,7 @@
67786783
8577A1C4255D2C0D00D43FCD /* HitTestingToolbar.swift */,
67796784
85DDE03F2AC6FF65006ABCA2 /* MainView.swift */,
67806785
F17669D61E43401C003D3222 /* MainViewController.swift */,
6786+
7B9D532E2D5431E400D9E937 /* MainViewController+Automation.swift */,
67816787
566B736F2BECD46800FF1959 /* MainViewController+SyncAlerts.swift */,
67826788
981CA7E92617797500E119D5 /* MainViewController+AddFavoriteFlow.swift */,
67836789
1E4F4A59297193DE00625985 /* MainViewController+CookiesManaged.swift */,
@@ -7960,6 +7966,7 @@
79607966
851672D12BED1FC900592F24 /* AutocompleteView.swift in Sources */,
79617967
7B1681022D106CCC005EAE24 /* UserTextShared.swift in Sources */,
79627968
3161D13227AC161B00285CF6 /* DownloadMetadata.swift in Sources */,
7969+
7B9D532F2D5431E400D9E937 /* MainViewController+Automation.swift in Sources */,
79637970
D664C7C72B289AA200CBFA76 /* PurchaseInProgressView.swift in Sources */,
79647971
7BFD5FD72C9DB9D7000FF959 /* VPNGeoswitchingTip.swift in Sources */,
79657972
F1668BCE1E798081008CBA04 /* BookmarksViewController.swift in Sources */,
@@ -8289,6 +8296,7 @@
82898296
1EDE39D22705D4A200C99C72 /* FileSizeDebugViewController.swift in Sources */,
82908297
4B412ACC2BBB3D0900A39F5E /* LazyView.swift in Sources */,
82918298
7B10FF252D11A56300F36BF2 /* ControlWidgetVPNIntents.swift in Sources */,
8299+
7B9D53312D54321200D9E937 /* TabViewController+Automation.swift in Sources */,
82928300
85047C772A0D5D3D00D2FF3F /* SyncSettingsViewController+SyncDelegate.swift in Sources */,
82938301
C12552972D0B06A100A0FDAA /* FreeTrialsFeatureFlagExperiment.swift in Sources */,
82948302
85DDE0402AC6FF65006ABCA2 /* MainView.swift in Sources */,
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// MainViewController+Automation.swift
3+
// DuckDuckGo
4+
//
5+
// Copyright © 2025 DuckDuckGo. All rights reserved.
6+
//
7+
// Licensed under the Apache License, Version 2.0 (the "License");
8+
// you may not use this file except in compliance with the License.
9+
// You may obtain a copy of the License at
10+
//
11+
// http://www.apache.org/licenses/LICENSE-2.0
12+
//
13+
// Unless required by applicable law or agreed to in writing, software
14+
// distributed under the License is distributed on an "AS IS" BASIS,
15+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
// See the License for the specific language governing permissions and
17+
// limitations under the License.
18+
//
19+
20+
import UIKit
21+
22+
extension MainViewController {
23+
24+
func executeScript(_ javaScriptString: String,
25+
args: [String: Any] = [:]) async -> Result<Any, any Error>? {
26+
var result = await currentTab?.executeScript(javaScriptString, args: args)
27+
return result! // TODO fix !
28+
}
29+
30+
func currentUrl() -> String? {
31+
return currentTab?.getUrl()
32+
}
33+
34+
}

DuckDuckGo/MainViewController.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,16 +1015,6 @@ class MainViewController: UIViewController {
10151015
currentTab?.executeBookmarklet(url: url)
10161016
}
10171017
}
1018-
1019-
func executeScript(_ javaScriptString: String,
1020-
args: [String: Any] = [:]) async -> Result<Any, any Error>? {
1021-
var result = await currentTab?.executeScript(javaScriptString, args: args)
1022-
return result! // TODO fix !
1023-
}
1024-
1025-
func currentUrl() -> String? {
1026-
return currentTab?.getUrl()
1027-
}
10281018

10291019
private func loadBackForwardItem(_ item: WKBackForwardListItem) {
10301020
prepareTabForRequest {
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//
2+
// TabViewController+Automation.swift
3+
// DuckDuckGo
4+
//
5+
// Copyright © 2025 DuckDuckGo. All rights reserved.
6+
//
7+
// Licensed under the Apache License, Version 2.0 (the "License");
8+
// you may not use this file except in compliance with the License.
9+
// You may obtain a copy of the License at
10+
//
11+
// http://www.apache.org/licenses/LICENSE-2.0
12+
//
13+
// Unless required by applicable law or agreed to in writing, software
14+
// distributed under the License is distributed on an "AS IS" BASIS,
15+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
// See the License for the specific language governing permissions and
17+
// limitations under the License.
18+
//
19+
20+
extension TabViewController {
21+
22+
@MainActor
23+
public func executeScript(_ javaScriptString: String,
24+
args: [String: Any] = [:]) async -> Result<Any, any Error> {
25+
do {
26+
var result = try await webView.callAsyncJavaScript(
27+
javaScriptString,
28+
arguments: args,
29+
in: nil,
30+
contentWorld: .page
31+
)
32+
return .success(result)
33+
} catch {
34+
return .failure(error)
35+
}
36+
}
37+
38+
public func getUrl() -> String? {
39+
return webView.url?.absoluteString
40+
}
41+
42+
}

DuckDuckGo/TabViewController.swift

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -737,26 +737,6 @@ class TabViewController: UIViewController {
737737
}
738738
}
739739

740-
@MainActor
741-
public func executeScript(_ javaScriptString: String,
742-
args: [String: Any] = [:]) async -> Result<Any, any Error> {
743-
do {
744-
var result = try await webView.callAsyncJavaScript(
745-
javaScriptString,
746-
arguments: args,
747-
in: nil,
748-
contentWorld: .page // .defaultClient,
749-
)
750-
return .success(result)
751-
} catch {
752-
return .failure(error)
753-
}
754-
}
755-
756-
public func getUrl() -> String? {
757-
return webView.url?.absoluteString
758-
}
759-
760740
public func load(url: URL) {
761741
wasLoadingStoppedExternally = false
762742
webView.stopLoading()

0 commit comments

Comments
 (0)