mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-09 06:43:25 +01:00
[AltStoreCore] Adds Date, FileManager, and UIColor extensions
This commit is contained in:
34
AltStoreCore/Extensions/Date+RelativeDate.swift
Normal file
34
AltStoreCore/Extensions/Date+RelativeDate.swift
Normal file
@@ -0,0 +1,34 @@
|
||||
//
|
||||
// Date+RelativeDate.swift
|
||||
// AltStore
|
||||
//
|
||||
// Created by Riley Testut on 7/28/19.
|
||||
// Copyright © 2019 Riley Testut. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public extension Date
|
||||
{
|
||||
func numberOfCalendarDays(since date: Date) -> Int
|
||||
{
|
||||
let today = Calendar.current.startOfDay(for: self)
|
||||
let previousDay = Calendar.current.startOfDay(for: date)
|
||||
|
||||
let components = Calendar.current.dateComponents([.day], from: previousDay, to: today)
|
||||
return components.day!
|
||||
}
|
||||
|
||||
func relativeDateString(since date: Date, dateFormatter: DateFormatter) -> String
|
||||
{
|
||||
let numberOfDays = self.numberOfCalendarDays(since: date)
|
||||
|
||||
switch numberOfDays
|
||||
{
|
||||
case 0: return NSLocalizedString("Today", comment: "")
|
||||
case 1: return NSLocalizedString("Yesterday", comment: "")
|
||||
case 2...7: return String(format: NSLocalizedString("%@ days ago", comment: ""), NSNumber(value: numberOfDays))
|
||||
default: return dateFormatter.string(from: date)
|
||||
}
|
||||
}
|
||||
}
|
||||
30
AltStoreCore/Extensions/FileManager+SharedDirectories.swift
Normal file
30
AltStoreCore/Extensions/FileManager+SharedDirectories.swift
Normal file
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// FileManager+SharedDirectories.swift
|
||||
// AltStore
|
||||
//
|
||||
// Created by Riley Testut on 5/14/20.
|
||||
// Copyright © 2020 Riley Testut. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public extension FileManager
|
||||
{
|
||||
var altstoreSharedDirectory: URL? {
|
||||
guard let appGroup = Bundle.main.appGroups.first else { return nil }
|
||||
|
||||
let sharedDirectoryURL = self.containerURL(forSecurityApplicationGroupIdentifier: appGroup)
|
||||
return sharedDirectoryURL
|
||||
}
|
||||
|
||||
var appBackupsDirectory: URL? {
|
||||
let appBackupsDirectory = self.altstoreSharedDirectory?.appendingPathComponent("Backups", isDirectory: true)
|
||||
return appBackupsDirectory
|
||||
}
|
||||
|
||||
func backupDirectoryURL(for app: InstalledApp) -> URL?
|
||||
{
|
||||
let backupDirectoryURL = self.appBackupsDirectory?.appendingPathComponent(app.bundleIdentifier, isDirectory: true)
|
||||
return backupDirectoryURL
|
||||
}
|
||||
}
|
||||
24
AltStoreCore/Extensions/UIColor+AltStore.swift
Normal file
24
AltStoreCore/Extensions/UIColor+AltStore.swift
Normal file
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// UIColor+AltStore.swift
|
||||
// AltStore
|
||||
//
|
||||
// Created by Riley Testut on 5/9/19.
|
||||
// Copyright © 2019 Riley Testut. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
public extension UIColor
|
||||
{
|
||||
private static let colorBundle = Bundle(for: DatabaseManager.self)
|
||||
|
||||
static let altPrimary = UIColor(named: "Primary", in: colorBundle, compatibleWith: nil)!
|
||||
static let deltaPrimary = UIColor(named: "DeltaPrimary", in: colorBundle, compatibleWith: nil)
|
||||
|
||||
static let altPink = UIColor(named: "Pink", in: colorBundle, compatibleWith: nil)!
|
||||
|
||||
static let refreshRed = UIColor(named: "RefreshRed", in: colorBundle, compatibleWith: nil)!
|
||||
static let refreshOrange = UIColor(named: "RefreshOrange", in: colorBundle, compatibleWith: nil)!
|
||||
static let refreshYellow = UIColor(named: "RefreshYellow", in: colorBundle, compatibleWith: nil)!
|
||||
static let refreshGreen = UIColor(named: "RefreshGreen", in: colorBundle, compatibleWith: nil)!
|
||||
}
|
||||
Reference in New Issue
Block a user