Skip to content
17 changes: 17 additions & 0 deletions Sources/Jetpack/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,23 @@
<array>
<string>Noticons.ttf</string>
</array>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>WordPressSceneDelegate</string>
</dict>
</array>
</dict>
</dict>
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
Expand Down
17 changes: 17 additions & 0 deletions Sources/Reader/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>WordPressSceneDelegate</string>
</dict>
</array>
</dict>
</dict>
<key>WPAppBrand</key>
<string>reader</string>
<key>WPAppGroupName</key>
Expand Down
17 changes: 17 additions & 0 deletions Sources/WordPress/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,23 @@
<array>
<string>Noticons.ttf</string>
</array>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>WordPressSceneDelegate</string>
</dict>
</array>
</dict>
</dict>
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ class WP3DTouchShortcutCreatorTests: XCTestCase {
}

extension UIApplication {
// The test host adopts the UIScene life cycle (the app Info.plist declares a scene
// manifest) but never connects a window scene, so `keyWindow` is nil here. Fall back to
// the app delegate's window (`TestingAppDelegate` creates one) so `mainWindow` resolves
// during tests. This override is loaded after the framework copies, so it wins.
@objc var mainWindow: UIWindow? {
connectedScenes
.compactMap { ($0 as? UIWindowScene)?.keyWindow }
.first
?? (delegate?.window ?? nil) // swiftlint:disable:this redundant_nil_coalescing
}
}
14 changes: 10 additions & 4 deletions WordPress/Classes/System/WindowManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class WindowManager: NSObject {
/// The root view controller for the window.
///
var rootViewController: UIViewController? {
return window.rootViewController
window.rootViewController
}

init(window: UIWindow) {
Expand Down Expand Up @@ -103,7 +103,8 @@ class WindowManager: NSObject {
animations: nil,
completion: { _ in
completion?()
})
}
)
}

// MARK: Temporary Overlaying Window
Expand All @@ -113,8 +114,13 @@ class WindowManager: NSObject {
///
func displayOverlayingWindow(with rootViewController: UIViewController) {
clearOverlayingWindow()
let windowFrame = window.frame
let window = UIWindow(frame: windowFrame)
let window: UIWindow
if let windowScene = self.window.windowScene {
window = UIWindow(windowScene: windowScene)
} else {
// Unreachable in practice: the app's main window is always scene-attached.
window = UIWindow(frame: self.window.frame)
}
window.rootViewController = rootViewController
window.windowLevel = .alert
window.isHidden = false
Expand Down
57 changes: 39 additions & 18 deletions WordPress/Classes/System/WordPressAppDelegate+openURL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import WordPressData
import WordPressShared

@objc extension WordPressAppDelegate {
public func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {

/// Routes an inbound URL (custom scheme deep links, magic-login, migration, OAuth).
/// Called by `WordPressSceneDelegate` for inbound URLs.
@discardableResult
func handle(url: URL) -> Bool {
let redactedURL = LoggingURLRedactor.redactedURL(url)
DDLogInfo("Application launched with URL: \(redactedURL)")

Expand All @@ -20,10 +22,13 @@ import WordPressShared
}

/// WordPress only. Handle deeplink from JP that requests data export.
let wordPressExportRouter = MigrationDeepLinkRouter(urlForScheme: URL(string: AppScheme.wordpressMigrationV1.rawValue),
routes: [WordPressExportRoute()])
let wordPressExportRouter = MigrationDeepLinkRouter(
urlForScheme: URL(string: AppScheme.wordpressMigrationV1.rawValue),
routes: [WordPressExportRoute()]
)
if AppConfiguration.isWordPress,
wordPressExportRouter.canHandle(url: url) {
wordPressExportRouter.canHandle(url: url)
{
wordPressExportRouter.handle(url: url)
return true
}
Expand Down Expand Up @@ -63,7 +68,9 @@ import WordPressShared
DDLogInfo("App launched with authentication link")

guard AccountHelper.noWordPressDotComAccount || url.isJetpackConnect else {
DDLogInfo("The user clicked on a login or signup magic link when already logged into a WPCom account. Since this is not a Jetpack connection attempt we're cancelling the operation.")
DDLogInfo(
"The user clicked on a login or signup magic link when already logged into a WPCom account. Since this is not a Jetpack connection attempt we're cancelling the operation."
)
return false
}

Expand All @@ -77,7 +84,8 @@ import WordPressShared
private func handleViewPost(url: URL) -> Bool {
guard let params = url.queryItems,
let blogId = params.intValue(of: "blogId"),
let postId = params.intValue(of: "postId") else {
let postId = params.intValue(of: "postId")
else {
return false
}
RootViewCoordinator.sharedPresenter.showReader(path: .post(postID: postId, siteID: blogId))
Expand All @@ -89,7 +97,8 @@ import WordPressShared

guard let params = url.queryItems,
let siteId = params.intValue(of: "siteId"),
let blog = try? Blog.lookup(withID: siteId, in: ContextManager.shared.mainContext) else {
let blog = try? Blog.lookup(withID: siteId, in: ContextManager.shared.mainContext)
else {
return false
}

Expand Down Expand Up @@ -128,7 +137,8 @@ import WordPressShared
private func handleDebugging(url: URL) -> Bool {
guard let params = url.queryItems,
let debugType = params.value(of: "type"),
let debugKey = params.value(of: "key") else {
let debugKey = params.value(of: "key")
else {
return false
}

Expand All @@ -149,8 +159,9 @@ import WordPressShared
/// This is mostly a return of the old functionality: https://github.com/wordpress-mobile/WordPress-iOS/blob/d89b7ec712be1f2e11fb1228089771a25f5587c5/WordPress/Classes/ViewRelated/System/WPTabBarController.m#L388```
private func handleNewPost(url: URL) -> Bool {
guard let params = url.queryItems,
let contentRaw = params.value(of: NewPostKey.content) else {
return false
let contentRaw = params.value(of: NewPostKey.content)
else {
return false
}

let title = params.value(of: NewPostKey.title)
Expand All @@ -174,7 +185,10 @@ import WordPressShared

RootViewCoordinator.sharedPresenter.rootViewController.present(postVC, animated: true, completion: nil)

WPAppAnalytics.track(.editorCreatedPost, withProperties: [WPAppAnalyticsKeyTapSource: "url_scheme", WPAppAnalyticsKeyPostType: "post"])
WPAppAnalytics.track(
.editorCreatedPost,
withProperties: [WPAppAnalyticsKeyTapSource: "url_scheme", WPAppAnalyticsKeyPostType: "post"]
)

return true
}
Expand All @@ -187,8 +201,9 @@ import WordPressShared
/// text. May support other formats, such as HTML or Markdown in the future.
private func handleNewPage(url: URL) -> Bool {
guard let params = url.queryItems,
let contentRaw = params.value(of: NewPostKey.content) else {
return false
let contentRaw = params.value(of: NewPostKey.content)
else {
return false
}

let title = params.value(of: NewPostKey.title)
Expand All @@ -201,7 +216,12 @@ import WordPressShared
// Should more formats be accepted be accepted in the future, this line would have to be expanded to accomodate it.
let contentEscaped = contentRaw.escapeHtmlNamedEntities()

RootViewCoordinator.sharedPresenter.showPageEditor(blog: blog, title: title, content: contentEscaped, source: "url_scheme")
RootViewCoordinator.sharedPresenter.showPageEditor(
blog: blog,
title: title,
content: contentEscaped,
source: "url_scheme"
)

return true
}
Expand All @@ -216,7 +236,7 @@ import WordPressShared

private extension Array where Element == URLQueryItem {
func value(of key: String) -> String? {
return self.first(where: { $0.name == key })?.value
self.first(where: { $0.name == key })?.value
}

func intValue(of key: String) -> Int? {
Expand All @@ -231,8 +251,9 @@ private extension URL {
var queryItems: [URLQueryItem]? {
guard let components = URLComponents(url: self, resolvingAgainstBaseURL: false),
let queryItems = components.queryItems,
!queryItems.isEmpty else {
return nil
!queryItems.isEmpty
else {
return nil
}
return queryItems
}
Expand Down
Loading