Files
SpotiFLAC-Mobile/ios/Runner/ExtensionCallbackParser.swift
T
zarzet 37e21b5712 feat(branding): rename app and native backend to Mornye
Rename the Dart package, Android and iOS identifiers, Rust crates, native libraries, and Discord plugin. Preserve legacy data readers and compatibility aliases.

Update localized branding, documentation, artwork, build tooling, and release artifacts. Route Telegram release notifications to @mornyeupdates and link @mornyecommunity.
2026-10-20 12:00:44 +07:00

54 lines
1.6 KiB
Swift

import Foundation
struct ExtensionCallbackRoute: Equatable {
let code: String
let state: String
let isSessionGrant: Bool
}
enum ExtensionCallbackParser {
static func parse(_ url: URL) -> ExtensionCallbackRoute? {
guard url.scheme?.lowercased() == "mornye" else {
return nil
}
let host = (url.host ?? "").lowercased()
let path = url.path.lowercased()
let isSessionGrant = host == "session-grant"
let isSupportedCallback =
isSessionGrant ||
host == "callback" ||
host == "spotify-callback" ||
path.contains("callback")
guard isSupportedCallback,
let components = URLComponents(
url: url,
resolvingAgainstBaseURL: false
) else {
return nil
}
let queryItems = components.queryItems ?? []
let primaryCodeKey = isSessionGrant ? "grant" : "code"
let code =
queryItems.first { $0.name == primaryCodeKey }?.value?
.trimmingCharacters(in: .whitespacesAndNewlines)
?? queryItems.first { $0.name == "code" }?.value?
.trimmingCharacters(in: .whitespacesAndNewlines)
?? ""
let state =
queryItems.first { $0.name == "state" }?.value?
.trimmingCharacters(in: .whitespacesAndNewlines)
?? ""
guard !code.isEmpty, !state.isEmpty else {
return nil
}
return ExtensionCallbackRoute(
code: code,
state: state,
isSessionGrant: isSessionGrant
)
}
}