From d3bce8fb42bba134f2a938eea32203507d3dca52 Mon Sep 17 00:00:00 2001 From: Jorge Leandro Perez Date: Fri, 28 Jun 2024 18:53:20 -0300 Subject: [PATCH 1/3] Entitlements: App Links --- Simplenote.entitlements | 4 ++++ Simplenote/SimplenoteDebug.entitlements | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/Simplenote.entitlements b/Simplenote.entitlements index e0cb4bdea..6e83cc7f1 100644 --- a/Simplenote.entitlements +++ b/Simplenote.entitlements @@ -2,6 +2,10 @@ + com.apple.developer.associated-domains + + applinks:app.simplenote.com + com.apple.security.app-sandbox com.apple.security.application-groups diff --git a/Simplenote/SimplenoteDebug.entitlements b/Simplenote/SimplenoteDebug.entitlements index 66b8b4480..74121b747 100644 --- a/Simplenote/SimplenoteDebug.entitlements +++ b/Simplenote/SimplenoteDebug.entitlements @@ -2,6 +2,10 @@ + com.apple.developer.associated-domains + + applinks:app.simplenote.com + com.apple.security.app-sandbox com.apple.security.application-groups From 12582b8d0d862cb311d944f8f9244aac28fd92c9 Mon Sep 17 00:00:00 2001 From: Jorge Leandro Perez Date: Mon, 1 Jul 2024 10:50:46 -0300 Subject: [PATCH 2/3] SimplenoteAppDelegate: Wiring Authentication Activity --- Simplenote/SimplenoteAppDelegate+Swift.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Simplenote/SimplenoteAppDelegate+Swift.swift b/Simplenote/SimplenoteAppDelegate+Swift.swift index dba25346b..cf8cd5f6d 100644 --- a/Simplenote/SimplenoteAppDelegate+Swift.swift +++ b/Simplenote/SimplenoteAppDelegate+Swift.swift @@ -280,6 +280,14 @@ extension SimplenoteAppDelegate { return handleShortcutActivity(userActivity) } + private func handleMagicLinkActivity(_ userActivity: NSUserActivity) -> Bool { + guard let url = userActivity.webpageURL else { + return false + } + + return handleMagicAuth(url: url) + } + private func handleSpotlightSearchActivity(_ userActivity: NSUserActivity) -> Bool { guard userActivity.activityType == CSSearchableItemActionType, let simperiumKey = userActivity.userInfo?[CSSearchableItemActivityIdentifier] as? String else { From 265360a28e59d77d43a01371bc05945a6a389a29 Mon Sep 17 00:00:00 2001 From: Jorge Leandro Perez Date: Tue, 2 Jul 2024 13:42:06 -0300 Subject: [PATCH 3/3] MagicLinkAuthenticator: Supporting AppEngine URL --- Simplenote/MagicLinkAuthenticator.swift | 9 +++++++-- Simplenote/PreferencesViewController.swift | 2 +- Simplenote/SimplenoteAppDelegate+Swift.swift | 4 ++++ Simplenote/SimplenoteConstants.swift | 15 ++++++++------- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/Simplenote/MagicLinkAuthenticator.swift b/Simplenote/MagicLinkAuthenticator.swift index 1f80c1d49..a56407ffc 100644 --- a/Simplenote/MagicLinkAuthenticator.swift +++ b/Simplenote/MagicLinkAuthenticator.swift @@ -22,7 +22,7 @@ struct MagicLinkAuthenticator { } func handle(url: URL) -> Bool { - guard url.host == Constants.host else { + guard let host = url.host, AllowedHosts.all.contains(host) else { return false } @@ -105,8 +105,13 @@ private extension Array where Element == URLQueryItem { // MARK: - Constants // +private struct AllowedHosts { + static let hostForSimplenoteSchema = "login" + static let hostForUniversalLinks = SimplenoteConstants.googleAppEngineHost + static let all = [hostForSimplenoteSchema, hostForUniversalLinks] +} + private struct Constants { - static let host = "login" static let emailField = "email" static let tokenField = "token" static let authKeyField = "auth_key" diff --git a/Simplenote/PreferencesViewController.swift b/Simplenote/PreferencesViewController.swift index 12013673a..e13ec278f 100644 --- a/Simplenote/PreferencesViewController.swift +++ b/Simplenote/PreferencesViewController.swift @@ -208,7 +208,7 @@ class PreferencesViewController: NSViewController { case .alertFirstButtonReturn: appDelegate.signOut() case .alertThirdButtonReturn: - let url = URL(string: SimplenoteConstants.currentEngineBaseURL as String)! + let url = URL(string: SimplenoteConstants.googleAppEngineBaseURL as String)! NSWorkspace.shared.open(url) default: break diff --git a/Simplenote/SimplenoteAppDelegate+Swift.swift b/Simplenote/SimplenoteAppDelegate+Swift.swift index cf8cd5f6d..90f75f821 100644 --- a/Simplenote/SimplenoteAppDelegate+Swift.swift +++ b/Simplenote/SimplenoteAppDelegate+Swift.swift @@ -273,6 +273,10 @@ extension SimplenoteAppDelegate { @objc func handleUserActivity(_ userActivity: NSUserActivity) -> Bool { + if handleMagicLinkActivity(userActivity) { + return true + } + if handleSpotlightSearchActivity(userActivity) { return true } diff --git a/Simplenote/SimplenoteConstants.swift b/Simplenote/SimplenoteConstants.swift index ea068ae24..f18cff193 100644 --- a/Simplenote/SimplenoteConstants.swift +++ b/Simplenote/SimplenoteConstants.swift @@ -22,7 +22,8 @@ class SimplenoteConstants: NSObject { static let simplenoteInterlinkHost = "note" static let simplenoteInterlinkMaxTitleLength = 150 - static let currentEngineBaseURL = "https://app.simplenote.com" as NSString + static let googleAppEngineBaseURL = "https://app.simplenote.com" as NSString + static let googleAppEngineHost = "app.simplenote.com" /// Simplenote: Current Platform /// @@ -30,10 +31,10 @@ class SimplenoteConstants: NSObject { /// URL(s) /// - static let loginRequestURL = currentEngineBaseURL.appendingPathComponent("/account/request-login") - static let loginCompletionURL = currentEngineBaseURL.appendingPathComponent("/account/complete-login") - static let simplenoteSettingsURL = currentEngineBaseURL.appendingPathComponent("/settings") - static let simplenoteVerificationURL = currentEngineBaseURL.appendingPathComponent("/account/verify-email/") - static let simplenoteRequestSignupURL = currentEngineBaseURL.appendingPathComponent("/account/request-signup") - static let accountDeletionURL = currentEngineBaseURL.appendingPathComponent("/account/request-delete/") + static let loginRequestURL = googleAppEngineBaseURL.appendingPathComponent("/account/request-login") + static let loginCompletionURL = googleAppEngineBaseURL.appendingPathComponent("/account/complete-login") + static let simplenoteSettingsURL = googleAppEngineBaseURL.appendingPathComponent("/settings") + static let simplenoteVerificationURL = googleAppEngineBaseURL.appendingPathComponent("/account/verify-email/") + static let simplenoteRequestSignupURL = googleAppEngineBaseURL.appendingPathComponent("/account/request-signup") + static let accountDeletionURL = googleAppEngineBaseURL.appendingPathComponent("/account/request-delete/") }