From a75ca179ce7d6ef74b6f3b2d2ca1df03686c42c8 Mon Sep 17 00:00:00 2001 From: cranci1 <100066266+cranci1@users.noreply.github.com> Date: Mon, 27 Jan 2025 14:38:04 +0100 Subject: [PATCH] added url scheme --- Sora/Info.plist | 13 +++++++++++++ Sora/SoraApp.swift | 21 +++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/Sora/Info.plist b/Sora/Info.plist index 6a6654d..d3ac246 100644 --- a/Sora/Info.plist +++ b/Sora/Info.plist @@ -2,6 +2,19 @@ + CFBundleURLTypes + + + CFBundleTypeRole + Editor + CFBundleURLName + me.cranci.scheme + CFBundleURLSchemes + + sora + + + NSAppTransportSecurity NSAllowsArbitraryLoads diff --git a/Sora/SoraApp.swift b/Sora/SoraApp.swift index 15267b9..4a41c27 100644 --- a/Sora/SoraApp.swift +++ b/Sora/SoraApp.swift @@ -23,6 +23,27 @@ struct SoraApp: App { .onAppear { settings.updateAppearance() } + .onOpenURL { url in + handleURL(url) + } + } + } + + private func handleURL(_ url: URL) { + guard url.scheme == "sora", + url.host == "module", + let components = URLComponents(url: url, resolvingAgainstBaseURL: true), + let moduleURL = components.queryItems?.first(where: { $0.name == "url" })?.value else { + return + } + + Task { + do { + let module = try await moduleManager.addModule(metadataUrl: moduleURL) + DropManager.shared.showDrop(title: "Module Added!", subtitle: "Check settings to select it", duration: 2.0, icon: UIImage(systemName: "app.badge.checkmark")) + } catch { + Logger.shared.log("Failed to add module from URL scheme: \(error.localizedDescription)", type: "Error") + } } } }