[AltStoreCore] Adds StoreApp.category + StoreCategory enum

This commit is contained in:
Riley Testut
2023-12-07 18:04:48 -06:00
committed by Magesh K
parent 71eb77cfda
commit 1b8daa59c0
4 changed files with 84 additions and 3 deletions

View File

@@ -239,6 +239,7 @@
</entity>
<entity name="StoreApp" representedClassName="StoreApp" syncable="YES">
<attribute name="bundleIdentifier" attributeType="String"/>
<attribute name="category" optional="YES" attributeType="String"/>
<attribute name="developerName" attributeType="String"/>
<attribute name="downloadURL" attributeType="URI"/>
<attribute name="iconURL" attributeType="URI"/>

View File

@@ -115,6 +115,14 @@ public class StoreApp: NSManagedObject, Decodable, Fetchable
@NSManaged public private(set) var localizedDescription: String
@NSManaged @objc(size) internal var _size: Int32
@nonobjc public var category: StoreCategory? {
guard let _category else { return nil }
let category = StoreCategory(rawValue: _category)
return category
}
@NSManaged @objc(category) public private(set) var _category: String?
@NSManaged public private(set) var iconURL: URL
@NSManaged public private(set) var screenshotURLs: [URL]
@@ -259,6 +267,7 @@ public class StoreApp: NSManagedObject, Decodable, Fetchable
case isBeta = "beta"
case versions
case patreon
case category
// Legacy
case version
@@ -282,10 +291,10 @@ public class StoreApp: NSManagedObject, Decodable, Fetchable
self.bundleIdentifier = try container.decode(String.self, forKey: .bundleIdentifier)
self.developerName = try container.decode(String.self, forKey: .developerName)
self.localizedDescription = try container.decode(String.self, forKey: .localizedDescription)
self.iconURL = try container.decode(URL.self, forKey: .iconURL)
self.subtitle = try container.decodeIfPresent(String.self, forKey: .subtitle)
self.iconURL = try container.decode(URL.self, forKey: .iconURL)
self.isBeta = try container.decodeIfPresent(Bool.self, forKey: .isBeta) ?? false
var downloadURL = try container.decodeIfPresent(URL.self, forKey: .downloadURL)
let platformURLs = try container.decodeIfPresent(PlatformURLs.self.self, forKey: .platformURLs)
@@ -329,7 +338,10 @@ public class StoreApp: NSManagedObject, Decodable, Fetchable
self.tintColor = tintColor
}
self.isBeta = try container.decodeIfPresent(Bool.self, forKey: .isBeta) ?? false
if let rawCategory = try container.decodeIfPresent(String.self, forKey: .category)
{
self._category = rawCategory.lowercased() // Store raw (lowercased) category value.
}
let appScreenshots: [AppScreenshot]

View File

@@ -0,0 +1,64 @@
//
// StoreCategory.swift
// AltStoreCore
//
// Created by Riley Testut on 11/8/23.
// Copyright © 2023 Riley Testut. All rights reserved.
//
import Foundation
import UIKit
public enum StoreCategory: String, CaseIterable
{
case developer
case entertainment
case games
case lifestyle
case photoAndVideo = "photo"
case social
case utilities
case other
public var localizedName: String {
switch self
{
case .developer: NSLocalizedString("Developer", comment: "")
case .entertainment: NSLocalizedString("Entertainment", comment: "")
case .games: NSLocalizedString("Games", comment: "")
case .lifestyle: NSLocalizedString("Lifestyle", comment: "")
case .photoAndVideo: NSLocalizedString("Photo & Video", comment: "")
case .social: NSLocalizedString("Social", comment: "")
case .utilities: NSLocalizedString("Utilities", comment: "")
case .other: NSLocalizedString("Other", comment: "")
}
}
public var symbolName: String {
switch self
{
case .developer: "terminal"
case .entertainment: "popcorn"
case .games: "gamecontroller"
case .lifestyle: "tree"
case .photoAndVideo: "camera"
case .social: "hand.wave"
case .utilities: "paperclip"
case .other: "square.stack.3d.up"
}
}
public var tintColor: UIColor {
switch self
{
case .developer: UIColor.systemPurple
case .entertainment: UIColor.systemPink
case .games: UIColor.systemGreen
case .lifestyle: UIColor.systemYellow
case .photoAndVideo: UIColor.systemGray
case .social: UIColor.systemRed
case .utilities: UIColor.systemBlue
case .other: UIColor.black
}
}
}