Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Universal Links #1184

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Simplenote.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:app.simplenote.com</string>
</array>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.application-groups</key>
Expand Down
9 changes: 7 additions & 2 deletions Simplenote/MagicLinkAuthenticator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion Simplenote/PreferencesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions Simplenote/SimplenoteAppDelegate+Swift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,25 @@ extension SimplenoteAppDelegate {

@objc
func handleUserActivity(_ userActivity: NSUserActivity) -> Bool {
if handleMagicLinkActivity(userActivity) {
return true
}

if handleSpotlightSearchActivity(userActivity) {
return true
}

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 {
Expand Down
15 changes: 8 additions & 7 deletions Simplenote/SimplenoteConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,19 @@ 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
///
static let simplenotePlatformName = "macOS"

/// 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/")
}
4 changes: 4 additions & 0 deletions Simplenote/SimplenoteDebug.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:app.simplenote.com</string>
</array>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.application-groups</key>
Expand Down