2018-09-23 16:01:05 +00:00
|
|
|
//
|
|
|
|
// XCBManager.swift
|
|
|
|
// Tusker
|
|
|
|
//
|
|
|
|
// Created by Shadowfacts on 9/23/18.
|
|
|
|
// Copyright © 2018 Shadowfacts. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
|
|
|
class XCBManager {
|
|
|
|
|
|
|
|
static var specs: [XCallbackURLSpec] = [
|
2018-09-24 01:10:45 +00:00
|
|
|
XCallbackURLSpec(path: "/postStatus", type: .postStatus, arguments: ["mentioning": true, "text": true], canRunSilently: true, action: XCBActions.postStatus)
|
2018-09-23 16:01:05 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
static var currentSession: XCBSession?
|
|
|
|
|
|
|
|
static func handle(url: URL) -> Bool {
|
|
|
|
guard let components = URLComponents(url: url, resolvingAgainstBaseURL: true) else { return false }
|
|
|
|
if let spec = specs.first(where: { $0.matches(components) }) {
|
|
|
|
let xcbURL = XCallbackURL(spec: spec, components: components)
|
2018-09-24 01:10:45 +00:00
|
|
|
return spec.handle(url: xcbURL)
|
2018-09-23 16:01:05 +00:00
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2018-09-23 23:04:39 +00:00
|
|
|
static func createSession(type: XCBSessionType, url: XCallbackURL) -> XCBSession {
|
2018-09-23 16:01:05 +00:00
|
|
|
let session = XCBSession(type: type, success: url.success, error: url.error, cancel: url.cancel)
|
|
|
|
currentSession = session
|
|
|
|
return session
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|