mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-09 06:43:25 +01:00
[AltKit] Replaces dedicated AltKit module with shared files across targets
Treating AltKit as a full module resulted in more complexity than necessary, when we really just wanted to share some files between different targets. Now we can share individual files across modules as-needed without AltKit overhead.
This commit is contained in:
36
Shared/Extensions/ALTServerError+Conveniences.swift
Normal file
36
Shared/Extensions/ALTServerError+Conveniences.swift
Normal file
@@ -0,0 +1,36 @@
|
||||
//
|
||||
// ALTServerError+Conveniences.swift
|
||||
// AltKit
|
||||
//
|
||||
// Created by Riley Testut on 6/4/20.
|
||||
// Copyright © 2020 Riley Testut. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public extension ALTServerError
|
||||
{
|
||||
init<E: Error>(_ error: E)
|
||||
{
|
||||
switch error
|
||||
{
|
||||
case let error as ALTServerError: self = error
|
||||
case is DecodingError: self = ALTServerError(.invalidRequest, underlyingError: error)
|
||||
case is EncodingError: self = ALTServerError(.invalidResponse, underlyingError: error)
|
||||
case let error as NSError:
|
||||
var userInfo = error.userInfo
|
||||
if !userInfo.keys.contains(NSUnderlyingErrorKey)
|
||||
{
|
||||
// Assign underlying error (if there isn't already one).
|
||||
userInfo[NSUnderlyingErrorKey] = error
|
||||
}
|
||||
|
||||
self = ALTServerError(.underlyingError, userInfo: userInfo)
|
||||
}
|
||||
}
|
||||
|
||||
init<E: Error>(_ code: ALTServerError.Code, underlyingError: E)
|
||||
{
|
||||
self = ALTServerError(code, userInfo: [NSUnderlyingErrorKey: underlyingError])
|
||||
}
|
||||
}
|
||||
58
Shared/Extensions/Bundle+AltStore.swift
Normal file
58
Shared/Extensions/Bundle+AltStore.swift
Normal file
@@ -0,0 +1,58 @@
|
||||
//
|
||||
// Bundle+AltStore.swift
|
||||
// AltStore
|
||||
//
|
||||
// Created by Riley Testut on 5/30/19.
|
||||
// Copyright © 2019 Riley Testut. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public extension Bundle
|
||||
{
|
||||
struct Info
|
||||
{
|
||||
public static let deviceID = "ALTDeviceID"
|
||||
public static let serverID = "ALTServerID"
|
||||
public static let certificateID = "ALTCertificateID"
|
||||
public static let appGroups = "ALTAppGroups"
|
||||
public static let altBundleID = "ALTBundleIdentifier"
|
||||
|
||||
public static let urlTypes = "CFBundleURLTypes"
|
||||
public static let exportedUTIs = "UTExportedTypeDeclarations"
|
||||
}
|
||||
}
|
||||
|
||||
public extension Bundle
|
||||
{
|
||||
static var baseAltStoreAppGroupID = "group.com.rileytestut.AltStore"
|
||||
|
||||
var infoPlistURL: URL {
|
||||
let infoPlistURL = self.bundleURL.appendingPathComponent("Info.plist")
|
||||
return infoPlistURL
|
||||
}
|
||||
|
||||
var provisioningProfileURL: URL {
|
||||
let infoPlistURL = self.bundleURL.appendingPathComponent("embedded.mobileprovision")
|
||||
return infoPlistURL
|
||||
}
|
||||
|
||||
var certificateURL: URL {
|
||||
let infoPlistURL = self.bundleURL.appendingPathComponent("ALTCertificate.p12")
|
||||
return infoPlistURL
|
||||
}
|
||||
|
||||
var appGroups: [String] {
|
||||
return self.infoDictionary?[Bundle.Info.appGroups] as? [String] ?? []
|
||||
}
|
||||
|
||||
var altstoreAppGroup: String? {
|
||||
let appGroup = self.appGroups.first { $0.contains(Bundle.baseAltStoreAppGroupID) }
|
||||
return appGroup
|
||||
}
|
||||
|
||||
var completeInfoDictionary: [String : Any]? {
|
||||
let infoPlistURL = self.infoPlistURL
|
||||
return NSDictionary(contentsOf: infoPlistURL) as? [String : Any]
|
||||
}
|
||||
}
|
||||
76
Shared/Extensions/Result+Conveniences.swift
Normal file
76
Shared/Extensions/Result+Conveniences.swift
Normal file
@@ -0,0 +1,76 @@
|
||||
//
|
||||
// Result+Conveniences.swift
|
||||
// AltStore
|
||||
//
|
||||
// Created by Riley Testut on 5/22/19.
|
||||
// Copyright © 2019 Riley Testut. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public extension Result
|
||||
{
|
||||
var value: Success? {
|
||||
switch self
|
||||
{
|
||||
case .success(let value): return value
|
||||
case .failure: return nil
|
||||
}
|
||||
}
|
||||
|
||||
var error: Failure? {
|
||||
switch self
|
||||
{
|
||||
case .success: return nil
|
||||
case .failure(let error): return error
|
||||
}
|
||||
}
|
||||
|
||||
init(_ value: Success?, _ error: Failure?)
|
||||
{
|
||||
switch (value, error)
|
||||
{
|
||||
case (let value?, _): self = .success(value)
|
||||
case (_, let error?): self = .failure(error)
|
||||
case (nil, nil): preconditionFailure("Either value or error must be non-nil")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public extension Result where Success == Void
|
||||
{
|
||||
init(_ success: Bool, _ error: Failure?)
|
||||
{
|
||||
if success
|
||||
{
|
||||
self = .success(())
|
||||
}
|
||||
else if let error = error
|
||||
{
|
||||
self = .failure(error)
|
||||
}
|
||||
else
|
||||
{
|
||||
preconditionFailure("Error must be non-nil if success is false")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public extension Result
|
||||
{
|
||||
init<T, U>(_ values: (T?, U?), _ error: Failure?) where Success == (T, U)
|
||||
{
|
||||
if let value1 = values.0, let value2 = values.1
|
||||
{
|
||||
self = .success((value1, value2))
|
||||
}
|
||||
else if let error = error
|
||||
{
|
||||
self = .failure(error)
|
||||
}
|
||||
else
|
||||
{
|
||||
preconditionFailure("Error must be non-nil if either provided values are nil")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user