Skip to content

Create URLOpenerService protocol in Shared module - #3958

Closed
bgoncal with Copilot wants to merge 3 commits into
masterfrom
copilot/create-url-opener-service
Closed

Create URLOpenerService protocol in Shared module#3958
bgoncal with Copilot wants to merge 3 commits into
masterfrom
copilot/create-url-opener-service

Conversation

Copilot AI commented Nov 11, 2025

Copy link
Copy Markdown
Contributor

Implementation: URLOpenerService

This PR creates a URLOpenerService behind a protocol in the Shared module and refactors the entire app to use it instead of direct UIApplication.shared.open calls.

Plan Checklist:

  • Create URLOpenerService protocol in Shared module
  • Create URLOpenerServiceImpl implementation in Shared module
  • Add URLOpenerService to the Current environment
  • Add tests for URLOpenerService
  • Refactor all UIApplication.shared.open calls in App target to use the service
  • Refactor all UIApplication.shared.open calls in Extensions target (Widgets)
  • Refactor UIApplication+OpenSettings extension to use the service
  • Refactor OpenInChromeController to use the service
  • Refactor Utils.swift openURLInBrowser function to use the service
  • Build and test the changes
  • Run code review
  • Run CodeQL security check
  • Fix lint issues

Implementation Summary:

New Files Created:

  • Sources/Shared/Services/URLOpenerService.swift - Protocol and implementation
  • Tests/Shared/URLOpenerService.test.swift - Unit tests

Files Modified (19 total):

  • Environment.swift - Added urlOpener property to Current
  • All App utilities and settings that used UIApplication.shared.open
  • All WebView components that opened URLs
  • Widget extensions (OpenEntityAppIntent, OpenPageAppIntent)

Architecture:

  • Protocol: URLOpenerServiceProtocol with open(_:options:completionHandler:) and canOpenURL(_:) methods
  • Implementation: URLOpenerServiceImpl that wraps UIApplication.shared for iOS, with fallback for other platforms
  • Integration: Available via Current.urlOpener following the pattern of existing services

Benefits:

  • ✅ Better testability - can mock URL opening behavior in tests
  • ✅ Consistent with existing service architecture (AreasService, AssistService)
  • ✅ Single point of control for URL opening across the entire app
  • ✅ Platform-aware with #if os(iOS) guards
  • ✅ All ~30 direct UIApplication.shared.open calls now use the service
  • ✅ All lint issues resolved

Security Summary:

  • CodeQL security check completed with no issues
  • No new vulnerabilities introduced
  • All changes are refactoring existing functionality
Original prompt

Create a "URLOpenerService" behind a protocol and put it inside Shared, then make the whole App use it instead of calling UIApplication.shared.open


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI self-assigned this Nov 11, 2025
Co-authored-by: bgoncal <5808343+bgoncal@users.noreply.github.com>
Copilot AI changed the title [WIP] Add URLOpenerService for better URL handling Create URLOpenerService protocol in Shared module Nov 11, 2025
Copilot AI requested a review from bgoncal November 11, 2025 14:53
@bgoncal

bgoncal commented Nov 11, 2025

Copy link
Copy Markdown
Member

@copilot fix lint issues:

/home/runner/work/iOS/iOS/Tests/Shared/URLOpenerService.test.swift:11:1: warning: (trailingSpace) Remove trailing space at end of a line.
/home/runner/work/iOS/iOS/Tests/Shared/URLOpenerService.test.swift:14:1: warning: (trailingSpace) Remove trailing space at end of a line.
/home/runner/work/iOS/iOS/Tests/Shared/URLOpenerService.test.swift:22:1: warning: (trailingSpace) Remove trailing space at end of a line.
/home/runner/work/iOS/iOS/Tests/Shared/URLOpenerService.test.swift:25:1: warning: (trailingSpace) Remove trailing space at end of a line.
/home/runner/work/iOS/iOS/Tests/Shared/URLOpenerService.test.swift:32:1: warning: (trailingSpace) Remove trailing space at end of a line.
/home/runner/work/iOS/iOS/Tests/Shared/URLOpenerService.test.swift:35:1: warning: (redundantSelf) Insert/remove explicit self where applicable.
/home/runner/work/iOS/iOS/Tests/Shared/URLOpenerService.test.swift:36:1: warning: (trailingSpace) Remove trailing space at end of a line.
/home/runner/work/iOS/iOS/Tests/Shared/URLOpenerService.test.swift:38:1: warning: (unusedArguments) Mark unused function arguments with _.
/home/runner/work/iOS/iOS/Tests/Shared/URLOpenerService.test.swift:42:1: warning: (trailingSpace) Remove trailing space at end of a line.
/home/runner/work/iOS/iOS/Sources/Shared/Services/URLOpenerService.swift:11:1: warning: (trailingSpace) Remove trailing space at end of a line.
/home/runner/work/iOS/iOS/Sources/Shared/Services/URLOpenerService.swift:17:1: warning: (trailingSpace) Remove trailing space at end of a line.
/home/runner/work/iOS/iOS/Sources/Shared/Services/URLOpenerService.swift:32:1: warning: (trailingSpace) Remove trailing space at end of a line.
/home/runner/work/iOS/iOS/Sources/App/WebView/Views/ConnectionSecurityLevelBlock/ConnectionSecurityLevelBlockView.swift:78:1: warning: (wrap) Wrap lines that exceed the specified maximum width.

… and wrap long lines

Co-authored-by: bgoncal <5808343+bgoncal@users.noreply.github.com>

Copilot AI commented Nov 11, 2025

Copy link
Copy Markdown
Contributor Author

@copilot fix lint issues:

...

Fixed all lint issues in commit 20ecd84:

  • Removed trailing spaces from all files
  • Removed redundant self. in test expectation
  • Marked unused closure parameter with _
  • Wrapped long line in ConnectionSecurityLevelBlockView.swift

@bgoncal

bgoncal commented Nov 11, 2025

Copy link
Copy Markdown
Member

@copilot now that the service is in Shared you had to import Shared when you use it, please double check you work and provide update.

Copilot AI commented Nov 11, 2025

Copy link
Copy Markdown
Contributor Author

@copilot now that the service is in Shared you had to import Shared when you use it, please double check you work and provide update.

I've verified all files using Current.urlOpener already have import Shared:

  • All 16 files that use Current.urlOpener have the import
  • The service protocol and implementation are marked public in Shared module
  • The Current.urlOpener property is marked public in Environment.swift

No changes needed - the imports were already correct from the initial implementation.

@bgoncal bgoncal closed this Nov 12, 2025
@bgoncal
bgoncal deleted the copilot/create-url-opener-service branch September 3, 2026 10:45
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