2019-07-24 12:23:54 -07:00
|
|
|
//
|
|
|
|
|
// AppPermission.swift
|
|
|
|
|
// AltStore
|
|
|
|
|
//
|
|
|
|
|
// Created by Riley Testut on 7/23/19.
|
|
|
|
|
// Copyright © 2019 Riley Testut. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import CoreData
|
|
|
|
|
import UIKit
|
|
|
|
|
|
2020-09-03 16:39:08 -07:00
|
|
|
public extension ALTAppPermissionType
|
2019-07-24 12:23:54 -07:00
|
|
|
{
|
|
|
|
|
var localizedShortName: String? {
|
|
|
|
|
switch self
|
|
|
|
|
{
|
|
|
|
|
case .photos: return NSLocalizedString("Photos", comment: "")
|
|
|
|
|
case .backgroundAudio: return NSLocalizedString("Audio (BG)", comment: "")
|
|
|
|
|
case .backgroundFetch: return NSLocalizedString("Fetch (BG)", comment: "")
|
|
|
|
|
default: return nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var localizedName: String? {
|
|
|
|
|
switch self
|
|
|
|
|
{
|
|
|
|
|
case .photos: return NSLocalizedString("Photos", comment: "")
|
|
|
|
|
case .backgroundAudio: return NSLocalizedString("Background Audio", comment: "")
|
|
|
|
|
case .backgroundFetch: return NSLocalizedString("Background Fetch", comment: "")
|
|
|
|
|
default: return nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var icon: UIImage? {
|
|
|
|
|
switch self
|
|
|
|
|
{
|
|
|
|
|
case .photos: return UIImage(named: "PhotosPermission")
|
|
|
|
|
case .backgroundAudio: return UIImage(named: "BackgroundAudioPermission")
|
|
|
|
|
case .backgroundFetch: return UIImage(named: "BackgroundFetchPermission")
|
|
|
|
|
default: return nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@objc(AppPermission)
|
2020-09-03 16:39:08 -07:00
|
|
|
public class AppPermission: NSManagedObject, Decodable, Fetchable
|
2019-07-24 12:23:54 -07:00
|
|
|
{
|
|
|
|
|
/* Properties */
|
2020-09-03 16:39:08 -07:00
|
|
|
@NSManaged public var type: ALTAppPermissionType
|
|
|
|
|
@NSManaged public var usageDescription: String
|
2019-07-24 12:23:54 -07:00
|
|
|
|
|
|
|
|
/* Relationships */
|
2020-09-03 16:39:08 -07:00
|
|
|
@NSManaged public private(set) var app: StoreApp!
|
2019-07-24 12:23:54 -07:00
|
|
|
|
|
|
|
|
private override init(entity: NSEntityDescription, insertInto context: NSManagedObjectContext?)
|
|
|
|
|
{
|
|
|
|
|
super.init(entity: entity, insertInto: context)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private enum CodingKeys: String, CodingKey
|
|
|
|
|
{
|
|
|
|
|
case type
|
|
|
|
|
case usageDescription
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-03 16:39:08 -07:00
|
|
|
public required init(from decoder: Decoder) throws
|
2019-07-24 12:23:54 -07:00
|
|
|
{
|
|
|
|
|
guard let context = decoder.managedObjectContext else { preconditionFailure("Decoder must have non-nil NSManagedObjectContext.") }
|
|
|
|
|
|
2020-08-27 16:23:50 -07:00
|
|
|
super.init(entity: AppPermission.entity(), insertInto: context)
|
2019-07-24 12:23:54 -07:00
|
|
|
|
2020-08-27 16:23:50 -07:00
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
|
|
|
|
self.usageDescription = try container.decode(String.self, forKey: .usageDescription)
|
|
|
|
|
|
|
|
|
|
let rawType = try container.decode(String.self, forKey: .type)
|
|
|
|
|
self.type = ALTAppPermissionType(rawValue: rawType)
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
if let context = self.managedObjectContext
|
|
|
|
|
{
|
|
|
|
|
context.delete(self)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw error
|
|
|
|
|
}
|
2019-07-24 12:23:54 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-03 16:39:08 -07:00
|
|
|
public extension AppPermission
|
2019-07-24 12:23:54 -07:00
|
|
|
{
|
|
|
|
|
@nonobjc class func fetchRequest() -> NSFetchRequest<AppPermission>
|
|
|
|
|
{
|
|
|
|
|
return NSFetchRequest<AppPermission>(entityName: "AppPermission")
|
|
|
|
|
}
|
|
|
|
|
}
|