mirror of
https://github.com/ninxsoft/Mist.git
synced 2025-05-20 02:05:39 -04:00
Add missing docstrings
This commit is contained in:
parent
791612ff85
commit
bafffe5df1
15 changed files with 108 additions and 0 deletions
|
@ -8,6 +8,7 @@
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
extension ButtonStyle where Self == MistActionButtonStyle {
|
extension ButtonStyle where Self == MistActionButtonStyle {
|
||||||
|
/// Action button style
|
||||||
static var mistAction: Self {
|
static var mistAction: Self {
|
||||||
.init()
|
.init()
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,9 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
extension Dictionary where Key == String {
|
extension Dictionary where Key == String {
|
||||||
|
/// Provides a firmware CSV string representation.
|
||||||
|
///
|
||||||
|
/// - Returns: A firmware CSV string representation.
|
||||||
func firmwareCSVString() -> String {
|
func firmwareCSVString() -> String {
|
||||||
guard
|
guard
|
||||||
let name: String = self["name"] as? String,
|
let name: String = self["name"] as? String,
|
||||||
|
@ -44,6 +47,9 @@ extension Dictionary where Key == String {
|
||||||
return string
|
return string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Provides an installer CSV string representation.
|
||||||
|
///
|
||||||
|
/// - Returns: An installer CSV string representation.
|
||||||
func installerCSVString() -> String {
|
func installerCSVString() -> String {
|
||||||
guard
|
guard
|
||||||
let identifier: String = self["identifier"] as? String,
|
let identifier: String = self["identifier"] as? String,
|
||||||
|
|
|
@ -15,6 +15,9 @@ extension Double {
|
||||||
/// gigabytes constant
|
/// gigabytes constant
|
||||||
static let gigabyte: Double = .megabyte * 1_000
|
static let gigabyte: Double = .megabyte * 1_000
|
||||||
|
|
||||||
|
/// Pretty formatted string representation of the double, as bytes.
|
||||||
|
///
|
||||||
|
/// - Returns: A pretty formatted bytes string.
|
||||||
func bytesString() -> String {
|
func bytesString() -> String {
|
||||||
if self < .kilobyte {
|
if self < .kilobyte {
|
||||||
"\(Int(self)) bytes"
|
"\(Int(self)) bytes"
|
||||||
|
|
|
@ -8,6 +8,14 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
extension FileManager {
|
extension FileManager {
|
||||||
|
/// Provides the size of a specified directory, in bytes.
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - url: The URL of the directory to query.
|
||||||
|
///
|
||||||
|
/// - Throws: An `Error` if the directory size is unable to be determined.
|
||||||
|
///
|
||||||
|
/// - Returns: The size of the directory in bytes.
|
||||||
func sizeOfDirectory(at url: URL) throws -> UInt64 {
|
func sizeOfDirectory(at url: URL) throws -> UInt64 {
|
||||||
var enumeratorError: Error?
|
var enumeratorError: Error?
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,9 @@
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
extension Scene {
|
extension Scene {
|
||||||
|
/// Fixes the window size across all macOS versions.
|
||||||
|
///
|
||||||
|
/// - Returns: A modified window for macOS 13.0 Ventura and later otherwise an unmodified window.
|
||||||
func fixedWindow() -> some Scene {
|
func fixedWindow() -> some Scene {
|
||||||
if #available(macOS 13.0, *) {
|
if #available(macOS 13.0, *) {
|
||||||
// swiftformat:disable:next redundantReturn
|
// swiftformat:disable:next redundantReturn
|
||||||
|
|
|
@ -9,24 +9,45 @@ import Foundation
|
||||||
import Yams
|
import Yams
|
||||||
|
|
||||||
extension Sequence where Iterator.Element == [String: Any] {
|
extension Sequence where Iterator.Element == [String: Any] {
|
||||||
|
/// Provides a firmware CSV string representation.
|
||||||
|
///
|
||||||
|
/// - Returns: A firmware CSV string representation.
|
||||||
func firmwaresCSVString() -> String {
|
func firmwaresCSVString() -> String {
|
||||||
"Name,Version,Build,Size,URL,Date,Compatible,Signed,Beta\n" + map { $0.firmwareCSVString() }.joined()
|
"Name,Version,Build,Size,URL,Date,Compatible,Signed,Beta\n" + map { $0.firmwareCSVString() }.joined()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Provides an installer CSV string representation.
|
||||||
|
///
|
||||||
|
/// - Returns: An installer CSV string representation.
|
||||||
func installersCSVString() -> String {
|
func installersCSVString() -> String {
|
||||||
"Identifier,Name,Version,Build,Size,Date,Compatible,Beta\n" + map { $0.installerCSVString() }.joined()
|
"Identifier,Name,Version,Build,Size,Date,Compatible,Beta\n" + map { $0.installerCSVString() }.joined()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Provides a JSON string representation.
|
||||||
|
///
|
||||||
|
/// - Throws: An `Error` if a JSON string representation cannot be created.
|
||||||
|
///
|
||||||
|
/// - Returns: A JSON string representation.
|
||||||
func jsonString() throws -> String {
|
func jsonString() throws -> String {
|
||||||
let data: Data = try JSONSerialization.data(withJSONObject: self, options: [.prettyPrinted, .sortedKeys])
|
let data: Data = try JSONSerialization.data(withJSONObject: self, options: [.prettyPrinted, .sortedKeys])
|
||||||
return String(decoding: data, as: UTF8.self)
|
return String(decoding: data, as: UTF8.self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Provides a Property List string representation.
|
||||||
|
///
|
||||||
|
/// - Throws: An `Error` if a Property List string representation cannot be created.
|
||||||
|
///
|
||||||
|
/// - Returns: A Property List string representation.
|
||||||
func propertyListString() throws -> String {
|
func propertyListString() throws -> String {
|
||||||
let data: Data = try PropertyListSerialization.data(fromPropertyList: self, format: .xml, options: .bitWidth)
|
let data: Data = try PropertyListSerialization.data(fromPropertyList: self, format: .xml, options: .bitWidth)
|
||||||
return String(decoding: data, as: UTF8.self)
|
return String(decoding: data, as: UTF8.self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Provides a YAML string representation.
|
||||||
|
///
|
||||||
|
/// - Throws: An `Error` if a YAML string representation cannot be created.
|
||||||
|
///
|
||||||
|
/// - Returns: A YAML string representation.
|
||||||
func yamlString() throws -> String {
|
func yamlString() throws -> String {
|
||||||
try Yams.dump(object: self)
|
try Yams.dump(object: self)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,24 +8,49 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
extension String {
|
extension String {
|
||||||
|
/// App name
|
||||||
static let appName: String = "mist"
|
static let appName: String = "mist"
|
||||||
|
/// App identifier
|
||||||
static let appIdentifier: String = "com.ninxsoft.\(appName)"
|
static let appIdentifier: String = "com.ninxsoft.\(appName)"
|
||||||
|
/// Helper identifier
|
||||||
static let helperIdentifier: String = "\(appIdentifier).helper"
|
static let helperIdentifier: String = "\(appIdentifier).helper"
|
||||||
|
/// Helper LaunchDaemon URL
|
||||||
static let helperLaunchDaemonURL: String = "/Library/LaunchDaemons/\(helperIdentifier).plist"
|
static let helperLaunchDaemonURL: String = "/Library/LaunchDaemons/\(helperIdentifier).plist"
|
||||||
|
/// Helper URL
|
||||||
static let helperURL: String = "/Library/PrivilegedHelperTools/\(helperIdentifier)"
|
static let helperURL: String = "/Library/PrivilegedHelperTools/\(helperIdentifier)"
|
||||||
|
/// Repository URL
|
||||||
static let repositoryURL: String = "https://github.com/ninxsoft/Mist"
|
static let repositoryURL: String = "https://github.com/ninxsoft/Mist"
|
||||||
|
/// Filename template
|
||||||
static let filenameTemplate: String = "Install %NAME% %VERSION%_%BUILD%"
|
static let filenameTemplate: String = "Install %NAME% %VERSION%_%BUILD%"
|
||||||
|
/// Firmware filename template
|
||||||
static let firmwareFilenameTemplate: String = "\(filenameTemplate).ipsw"
|
static let firmwareFilenameTemplate: String = "\(filenameTemplate).ipsw"
|
||||||
|
/// Application filename template
|
||||||
static let applicationFilenameTemplate: String = "\(filenameTemplate).app"
|
static let applicationFilenameTemplate: String = "\(filenameTemplate).app"
|
||||||
|
/// Disk Image filename template
|
||||||
static let diskImageFilenameTemplate: String = "\(filenameTemplate).dmg"
|
static let diskImageFilenameTemplate: String = "\(filenameTemplate).dmg"
|
||||||
|
/// ISO filename template
|
||||||
static let isoFilenameTemplate: String = "\(filenameTemplate).iso"
|
static let isoFilenameTemplate: String = "\(filenameTemplate).iso"
|
||||||
|
/// Package filename template
|
||||||
static let packageFilenameTemplate: String = "\(filenameTemplate).pkg"
|
static let packageFilenameTemplate: String = "\(filenameTemplate).pkg"
|
||||||
|
/// Package identifier template
|
||||||
static let packageIdentifierTemplate: String = "com.company.pkg.%NAME%.%VERSION%.%BUILD%"
|
static let packageIdentifierTemplate: String = "com.company.pkg.%NAME%.%VERSION%.%BUILD%"
|
||||||
|
/// Tempoarary directory
|
||||||
static let temporaryDirectory: String = "/private/tmp/\(appIdentifier)"
|
static let temporaryDirectory: String = "/private/tmp/\(appIdentifier)"
|
||||||
|
/// Cache directory
|
||||||
static let cacheDirectory: String = "/Users/Shared/Mist/Cache"
|
static let cacheDirectory: String = "/Users/Shared/Mist/Cache"
|
||||||
|
/// TCC database path
|
||||||
static let tccDatabasePath: String = "/Library/Application Support/com.apple.TCC/TCC.db"
|
static let tccDatabasePath: String = "/Library/Application Support/com.apple.TCC/TCC.db"
|
||||||
|
/// Log URL
|
||||||
static let logURL: String = "\(appName)://log"
|
static let logURL: String = "\(appName)://log"
|
||||||
|
|
||||||
|
/// Provides a string replacing placeholder `name`, `version` and `build` values.
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - name: A firmware / installer name.
|
||||||
|
/// - version: A firmware / installer version.
|
||||||
|
/// - build: A firmware / installer build.
|
||||||
|
///
|
||||||
|
/// - Returns: A string with name, version and build placeholders substituted.
|
||||||
func stringWithSubstitutions(name: String, version: String, build: String) -> String {
|
func stringWithSubstitutions(name: String, version: String, build: String) -> String {
|
||||||
replacingOccurrences(of: "%NAME%", with: name)
|
replacingOccurrences(of: "%NAME%", with: name)
|
||||||
.replacingOccurrences(of: "%VERSION%", with: version)
|
.replacingOccurrences(of: "%VERSION%", with: version)
|
||||||
|
|
|
@ -8,6 +8,9 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
extension UInt32 {
|
extension UInt32 {
|
||||||
|
/// Hexadecimal representation of the 32-bit unsigned integer.
|
||||||
|
///
|
||||||
|
/// - Returns: A hexademical string.
|
||||||
func hexString() -> String {
|
func hexString() -> String {
|
||||||
String(format: "0x%08X", self)
|
String(format: "0x%08X", self)
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,9 @@ extension UInt64 {
|
||||||
/// gigabytes constant
|
/// gigabytes constant
|
||||||
static let gigabyte: UInt64 = .megabyte * 1_000
|
static let gigabyte: UInt64 = .megabyte * 1_000
|
||||||
|
|
||||||
|
/// Pretty formatted string representation of the 64-bit unsigned integer, as bytes.
|
||||||
|
///
|
||||||
|
/// - Returns: A pretty formatted bytes string.
|
||||||
func bytesString() -> String {
|
func bytesString() -> String {
|
||||||
if self < .kilobyte {
|
if self < .kilobyte {
|
||||||
"\(self) bytes"
|
"\(self) bytes"
|
||||||
|
@ -27,6 +30,9 @@ extension UInt64 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Hexadecimal representation of the 64-bit unsigned integer.
|
||||||
|
///
|
||||||
|
/// - Returns: A hexademical string.
|
||||||
func hexString() -> String {
|
func hexString() -> String {
|
||||||
String(format: "0x%016X", self)
|
String(format: "0x%016X", self)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,9 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
extension UInt8 {
|
extension UInt8 {
|
||||||
|
/// Hexadecimal representation of the 8-bit unsigned integer.
|
||||||
|
///
|
||||||
|
/// - Returns: A hexademical string.
|
||||||
func hexString() -> String {
|
func hexString() -> String {
|
||||||
String(format: "0x%02X", self)
|
String(format: "0x%02X", self)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
import UserNotifications
|
import UserNotifications
|
||||||
|
|
||||||
extension UNNotificationAction {
|
extension UNNotificationAction {
|
||||||
|
/// Mist Notification Action identifiers
|
||||||
enum Identifier {
|
enum Identifier {
|
||||||
/// Show Identifier
|
/// Show Identifier
|
||||||
static let show: String = "Show"
|
static let show: String = "Show"
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
import UserNotifications
|
import UserNotifications
|
||||||
|
|
||||||
extension UNNotificationCategory {
|
extension UNNotificationCategory {
|
||||||
|
/// Mist Notification identifiers
|
||||||
enum Identifier {
|
enum Identifier {
|
||||||
/// Success Identifier
|
/// Success Identifier
|
||||||
static let success: String = "Success"
|
static let success: String = "Success"
|
||||||
|
|
|
@ -9,6 +9,11 @@ import CryptoKit
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
extension URL {
|
extension URL {
|
||||||
|
/// Provides the size of the file at the URL, in bytes.
|
||||||
|
///
|
||||||
|
/// - Throws: An `Error` if the file size is unable to be determined.
|
||||||
|
///
|
||||||
|
/// - Returns: The file size of the provided URL, in bytes.
|
||||||
func fileSize() throws -> UInt64 {
|
func fileSize() throws -> UInt64 {
|
||||||
let urlResourceKeys: Set<URLResourceKey> = [
|
let urlResourceKeys: Set<URLResourceKey> = [
|
||||||
.isRegularFileKey,
|
.isRegularFileKey,
|
||||||
|
@ -27,6 +32,9 @@ extension URL {
|
||||||
return UInt64(resourceValues.totalFileAllocatedSize ?? resourceValues.fileAllocatedSize ?? 0)
|
return UInt64(resourceValues.totalFileAllocatedSize ?? resourceValues.fileAllocatedSize ?? 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Provides the SHA1 hash of the file at the URL.
|
||||||
|
///
|
||||||
|
/// - Returns: The SHA1 hash of the file at the provided URL, or `nil` if a has is unable to be determined.
|
||||||
func shasum() -> String? {
|
func shasum() -> String? {
|
||||||
let length: Int = 1_024 * 1_024 * 50 // 50 MB
|
let length: Int = 1_024 * 1_024 * 50 // 50 MB
|
||||||
|
|
||||||
|
|
|
@ -6,16 +6,34 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
extension [UInt8] {
|
extension [UInt8] {
|
||||||
|
/// Provides an 8-bit unsigned integer based of the provided offset in the 8-bit unsigned integer array.
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - offset: The offset in the array of unsigned 8-bit integers.
|
||||||
|
///
|
||||||
|
/// - Returns: The 8-bit unsigned integer in the array at the provided offset.
|
||||||
func uInt8(at offset: Int) -> UInt8 {
|
func uInt8(at offset: Int) -> UInt8 {
|
||||||
self[offset]
|
self[offset]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Provides a 32-bit unsigned integer based of the provided offset in the 8-bit unsigned integer array.
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - offset: The offset in the array of unsigned 8-bit integers.
|
||||||
|
///
|
||||||
|
/// - Returns: The 32-bit unsigned integer in the array at the provided offset.
|
||||||
func uInt32(at offset: Int) -> UInt32 {
|
func uInt32(at offset: Int) -> UInt32 {
|
||||||
self[offset ... offset + 0x03].reversed().reduce(0) {
|
self[offset ... offset + 0x03].reversed().reduce(0) {
|
||||||
$0 << 0x08 + UInt32($1)
|
$0 << 0x08 + UInt32($1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Provides a 64-bit unsigned integer based of the provided offset in the 8-bit unsigned integer array.
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - offset: The offset in the array of unsigned 8-bit integers.
|
||||||
|
///
|
||||||
|
/// - Returns: The 64-bit unsigned integer in the array at the provided offset.
|
||||||
func uInt64(at offset: Int) -> UInt64 {
|
func uInt64(at offset: Int) -> UInt64 {
|
||||||
self[offset ... offset + 0x07].reversed().reduce(0) {
|
self[offset ... offset + 0x07].reversed().reduce(0) {
|
||||||
$0 << 0x08 + UInt64($1)
|
$0 << 0x08 + UInt64($1)
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
import SecureXPC
|
import SecureXPC
|
||||||
|
|
||||||
extension XPCRoute {
|
extension XPCRoute {
|
||||||
|
/// Default XPC Route
|
||||||
static let commandRoute: XPCRouteWithMessageWithReply<HelperToolCommandRequest, HelperToolCommandResponse> = XPCRoute.named("com.ninxsoft.mist.helper")
|
static let commandRoute: XPCRouteWithMessageWithReply<HelperToolCommandRequest, HelperToolCommandResponse> = XPCRoute.named("com.ninxsoft.mist.helper")
|
||||||
.withMessageType(HelperToolCommandRequest.self)
|
.withMessageType(HelperToolCommandRequest.self)
|
||||||
.withReplyType(HelperToolCommandResponse.self)
|
.withReplyType(HelperToolCommandResponse.self)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue