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

[WIP] Adding support for beatsaver:// links #1

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
35 changes: 26 additions & 9 deletions BeatmapAR/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import UIKit
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?
let backgroundDownloadQueue = DispatchQueue(label: "DownloadQueue", qos: .background)

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let window = UIWindow(frame: UIScreen.main.bounds)
Expand All @@ -18,20 +19,36 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
open url: URL,
options: [UIApplication.OpenURLOptionsKey: Any] = [:]
) -> Bool {

let manager = FileManager.default
guard url.isFileURL,
let documentsURL = manager.urls(for: .documentDirectory, in: .userDomainMask).first
else {
guard let documentsURL = manager.urls(for: .documentDirectory, in: .userDomainMask).first else {
return false
}

try? manager.moveItem(
at: url,
to: documentsURL.appendingPathComponent(url.lastPathComponent)
)
if url.scheme == "beatsaver",
let beatSaverId = url.host,
let downloadURL = URL(string: "https://beatsaver.com/api/download/key/\(beatSaverId)") {

return true
// FIXME: Display a download screen instead...
backgroundDownloadQueue.async {
if let beatmapData = try? Data(contentsOf: downloadURL) {
try? beatmapData.write(
to: documentsURL.appendingPathComponent("\(beatSaverId).zip"),
options: .atomicWrite
)
}
}

return true
} else if url.isFileURL {
try? manager.moveItem(
at: url,
to: documentsURL.appendingPathComponent(url.lastPathComponent)
)

return true
} else {
return false
}
}

func applicationWillResignActive(_ application: UIApplication) {
Expand Down
5 changes: 5 additions & 0 deletions project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ targets:
UTTypeTagSpecification:
public.filename-extension: zip
public.mime-type: application/zip
CFBundleURLTypes:
- CFBundleTypeRole: Editor
CFBundleURLName: beatsaver
CFBundleURLSchemes:
- beatsaver
sources:
- path: README.md
buildPhase: none
Expand Down