mirror of
https://github.com/ninxsoft/Mist.git
synced 2025-05-30 06:55:24 -04:00
SwiftFormat wrapArguments
This commit is contained in:
parent
09f132ca78
commit
ab68a45ac5
21 changed files with 84 additions and 42 deletions
|
@ -41,7 +41,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||
content.sound = .default
|
||||
content.categoryIdentifier = success ? UNNotificationCategory.Identifier.success : UNNotificationCategory.Identifier.failure
|
||||
|
||||
if success,
|
||||
if
|
||||
success,
|
||||
let url: URL = url {
|
||||
content.userInfo = ["URL": url.path]
|
||||
}
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
|
||||
extension Dictionary where Key == String {
|
||||
func firmwareCSVString() -> String {
|
||||
guard let signed: Bool = self["signed"] as? Bool,
|
||||
guard
|
||||
let signed: Bool = self["signed"] as? Bool,
|
||||
let name: String = self["name"] as? String,
|
||||
let version: String = self["version"] as? String,
|
||||
let build: String = self["build"] as? String,
|
||||
|
@ -22,7 +23,8 @@ extension Dictionary where Key == String {
|
|||
}
|
||||
|
||||
func installerCSVString() -> String {
|
||||
guard let identifier: String = self["identifier"] as? String,
|
||||
guard
|
||||
let identifier: String = self["identifier"] as? String,
|
||||
let name: String = self["name"] as? String,
|
||||
let version: String = self["version"] as? String,
|
||||
let build: String = self["build"] as? String,
|
||||
|
|
|
@ -17,7 +17,8 @@ extension FileManager {
|
|||
.totalFileAllocatedSizeKey
|
||||
]
|
||||
|
||||
guard let enumerator: FileManager.DirectoryEnumerator = enumerator(at: url, includingPropertiesForKeys: Array(urlResourceKeys), options: [], errorHandler: { _, error -> Bool in
|
||||
guard
|
||||
let enumerator: FileManager.DirectoryEnumerator = enumerator(at: url, includingPropertiesForKeys: Array(urlResourceKeys), options: [], errorHandler: { _, error -> Bool in
|
||||
enumeratorError = error
|
||||
return false
|
||||
}) else {
|
||||
|
|
|
@ -18,7 +18,8 @@ extension URL {
|
|||
|
||||
let resourceValues: URLResourceValues = try resourceValues(forKeys: urlResourceKeys)
|
||||
|
||||
guard let isRegularFile: Bool = resourceValues.isRegularFile,
|
||||
guard
|
||||
let isRegularFile: Bool = resourceValues.isRegularFile,
|
||||
isRegularFile else {
|
||||
return 0
|
||||
}
|
||||
|
@ -38,7 +39,8 @@ extension URL {
|
|||
|
||||
var shasum: Insecure.SHA1 = .init()
|
||||
|
||||
while try autoreleasepool(invoking: {
|
||||
while
|
||||
try autoreleasepool(invoking: {
|
||||
try Task.checkCancellation()
|
||||
let data: Data = fileHandle.readData(ofLength: length)
|
||||
|
||||
|
|
|
@ -273,7 +273,8 @@ class TaskManager: ObservableObject {
|
|||
} else {
|
||||
let attributes: [FileAttributeKey: Any] = try FileManager.default.attributesOfItem(atPath: cacheDirectoryURL.path)
|
||||
|
||||
guard let posixPermissions: NSNumber = attributes[.posixPermissions] as? NSNumber,
|
||||
guard
|
||||
let posixPermissions: NSNumber = attributes[.posixPermissions] as? NSNumber,
|
||||
let ownerAccountName: String = attributes[.ownerAccountName] as? String,
|
||||
let groupOwnerAccountName: String = attributes[.groupOwnerAccountName] as? String else {
|
||||
throw MistError.missingFileAttributes
|
||||
|
@ -324,7 +325,8 @@ class TaskManager: ObservableObject {
|
|||
}
|
||||
]
|
||||
|
||||
if installer.sierraOrOlder,
|
||||
if
|
||||
installer.sierraOrOlder,
|
||||
let package: Package = installer.packages.first {
|
||||
let legacyDiskImageURL: URL = .init(fileURLWithPath: "\(cacheDirectory)/\(installer.id)/\(package.filename)")
|
||||
let legacyDiskImageMountPointURL: URL = .init(fileURLWithPath: "/Volumes/Install \(installer.name)")
|
||||
|
|
|
@ -49,7 +49,8 @@ enum Validator {
|
|||
throw MistError.invalidFileSize(invalid: fileSize, valid: UInt64(package.size))
|
||||
}
|
||||
|
||||
guard let string: String = package.integrityDataURL,
|
||||
guard
|
||||
let string: String = package.integrityDataURL,
|
||||
let url: URL = URL(string: string),
|
||||
let size: Int = package.integrityDataSize else {
|
||||
return
|
||||
|
|
|
@ -117,7 +117,8 @@ struct Firmware: Decodable, Hashable, Identifiable {
|
|||
///
|
||||
/// - Returns: An array of Firmware build strings.
|
||||
static func supportedBuilds() throws -> [String] {
|
||||
guard let architecture: Architecture = Hardware.architecture,
|
||||
guard
|
||||
let architecture: Architecture = Hardware.architecture,
|
||||
architecture == .appleSilicon,
|
||||
let modelIdentifier: String = Hardware.modelIdentifier,
|
||||
let url: URL = URL(string: Firmware.deviceURLTemplate.replacingOccurrences(of: "MODELIDENTIFIER", with: modelIdentifier)) else {
|
||||
|
@ -126,7 +127,8 @@ struct Firmware: Decodable, Hashable, Identifiable {
|
|||
|
||||
let string: String = try String(contentsOf: url)
|
||||
|
||||
guard let data: Data = string.data(using: .utf8),
|
||||
guard
|
||||
let data: Data = string.data(using: .utf8),
|
||||
let dictionary: [String: Any] = try JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [String: Any],
|
||||
let array: [[String: Any]] = dictionary["firmwares"] as? [[String: Any]] else {
|
||||
return []
|
||||
|
|
|
@ -57,14 +57,16 @@ enum Hardware {
|
|||
|
||||
var properties: Unmanaged<CFMutableDictionary>?
|
||||
|
||||
guard IORegistryEntryCreateCFProperties(entry, &properties, kCFAllocatorDefault, 0) == KERN_SUCCESS,
|
||||
guard
|
||||
IORegistryEntryCreateCFProperties(entry, &properties, kCFAllocatorDefault, 0) == KERN_SUCCESS,
|
||||
let properties: Unmanaged<CFMutableDictionary> = properties else {
|
||||
return nil
|
||||
}
|
||||
|
||||
let nsDictionary: NSDictionary = properties.takeRetainedValue() as NSDictionary
|
||||
|
||||
guard let dictionary: [String: Any] = nsDictionary as? [String: Any],
|
||||
guard
|
||||
let dictionary: [String: Any] = nsDictionary as? [String: Any],
|
||||
dictionary.keys.contains(key),
|
||||
let data: Data = IORegistryEntryCreateCFProperty(entry, key as CFString, kCFAllocatorDefault, 0).takeRetainedValue() as? Data,
|
||||
let string: String = String(data: data, encoding: .utf8) else {
|
||||
|
|
|
@ -691,7 +691,8 @@ struct Installer: Decodable, Hashable, Identifiable {
|
|||
|
||||
var compatible: Bool {
|
||||
// Board ID (Intel)
|
||||
if let boardID: String = Hardware.boardID,
|
||||
if
|
||||
let boardID: String = Hardware.boardID,
|
||||
!boardIDs.isEmpty,
|
||||
!boardIDs.contains(boardID) {
|
||||
return false
|
||||
|
@ -699,7 +700,8 @@ struct Installer: Decodable, Hashable, Identifiable {
|
|||
|
||||
// Device ID (Apple Silicon or Intel T2)
|
||||
// macOS Big Sur 11 or newer
|
||||
if version.range(of: "^1[1-9]\\.", options: .regularExpression) != nil,
|
||||
if
|
||||
version.range(of: "^1[1-9]\\.", options: .regularExpression) != nil,
|
||||
let deviceID: String = Hardware.deviceID,
|
||||
!deviceIDs.isEmpty,
|
||||
!deviceIDs.contains(deviceID) {
|
||||
|
@ -709,12 +711,14 @@ struct Installer: Decodable, Hashable, Identifiable {
|
|||
// Model Identifier (Apple Silicon or Intel)
|
||||
// macOS Catalina 10.15 or older
|
||||
if version.range(of: "^10\\.", options: .regularExpression) != nil {
|
||||
if let architecture: Architecture = Hardware.architecture,
|
||||
if
|
||||
let architecture: Architecture = Hardware.architecture,
|
||||
architecture == .appleSilicon {
|
||||
return false
|
||||
}
|
||||
|
||||
if let modelIdentifier: String = Hardware.modelIdentifier,
|
||||
if
|
||||
let modelIdentifier: String = Hardware.modelIdentifier,
|
||||
!unsupportedModelIdentifiers.isEmpty,
|
||||
unsupportedModelIdentifiers.contains(modelIdentifier) {
|
||||
return false
|
||||
|
|
|
@ -46,12 +46,14 @@ enum MistError: Error, Equatable {
|
|||
case .invalidTerminationStatus(let status, let output, let error):
|
||||
var string: String = "Invalid Termination Status: \(status)"
|
||||
|
||||
if let output: String = output,
|
||||
if
|
||||
let output: String = output,
|
||||
!output.isEmpty {
|
||||
string += "\n\n\(output)"
|
||||
}
|
||||
|
||||
if let error: String = error,
|
||||
if
|
||||
let error: String = error,
|
||||
!error.isEmpty {
|
||||
string += "\n\n\(error)"
|
||||
}
|
||||
|
|
|
@ -10,7 +10,8 @@ import UserNotifications
|
|||
|
||||
class UserNotificationCenterDelegate: NSObject, UNUserNotificationCenterDelegate {
|
||||
func userNotificationCenter(_: UNUserNotificationCenter, didReceive response: UNNotificationResponse) async {
|
||||
guard response.actionIdentifier == UNNotificationAction.Identifier.show,
|
||||
guard
|
||||
response.actionIdentifier == UNNotificationAction.Identifier.show,
|
||||
let string: String = response.notification.request.content.userInfo["URL"] as? String else {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -64,7 +64,8 @@ struct ActivityView: View {
|
|||
ForEach(taskGroup.tasks.indices, id: \.self) { index in
|
||||
VStack {
|
||||
ActivityRowView(state: taskGroup.tasks[index].state, description: taskGroup.tasks[index].currentDescription, degrees: degrees)
|
||||
if taskGroup.tasks[index].type == .download, taskGroup.tasks[index].state != .pending,
|
||||
if
|
||||
taskGroup.tasks[index].type == .download, taskGroup.tasks[index].state != .pending,
|
||||
let size: UInt64 = taskGroup.tasks[index].downloadSize {
|
||||
ActivityProgressView(state: taskGroup.tasks[index].state, value: value, size: size)
|
||||
}
|
||||
|
|
|
@ -47,7 +47,8 @@ struct FooterView: View {
|
|||
|
||||
let response: NSApplication.ModalResponse = savePanel.runModal()
|
||||
|
||||
guard response == .OK,
|
||||
guard
|
||||
response == .OK,
|
||||
let url: URL = savePanel.url else {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -73,7 +73,8 @@ struct InstallerVolumeSelectionView: View {
|
|||
do {
|
||||
let resourceValues: URLResourceValues = try url.resourceValues(forKeys: Set(keys))
|
||||
|
||||
guard let volumeName: String = resourceValues.volumeName,
|
||||
guard
|
||||
let volumeName: String = resourceValues.volumeName,
|
||||
let volumeLocalizedFormatDescription: String = resourceValues.volumeLocalizedFormatDescription,
|
||||
let volumeIsReadOnly: Bool = resourceValues.volumeIsReadOnly,
|
||||
let volumeTotalCapacity: Int = resourceValues.volumeTotalCapacity,
|
||||
|
|
|
@ -91,7 +91,8 @@ struct ListRowInstaller: View {
|
|||
}
|
||||
.help("Download and export macOS Installer")
|
||||
.buttonStyle(.mistAction)
|
||||
if let architecture: Architecture = Hardware.architecture,
|
||||
if
|
||||
let architecture: Architecture = Hardware.architecture,
|
||||
(architecture == .appleSilicon && installer.bigSurOrNewer) || (architecture == .intel && installer.mavericksOrNewer) {
|
||||
Button {
|
||||
pressButton(.volumeSelection)
|
||||
|
@ -259,7 +260,8 @@ struct ListRowInstaller: View {
|
|||
|
||||
let filePermissions: FilePermissions = .init(rawValue: CModeT(posixPermissions.int16Value))
|
||||
|
||||
guard filePermissions == [.ownerReadWriteExecute, .groupReadExecute, .otherReadExecute],
|
||||
guard
|
||||
filePermissions == [.ownerReadWriteExecute, .groupReadExecute, .otherReadExecute],
|
||||
let ownerAccountName: String = attributes[.ownerAccountName] as? String,
|
||||
ownerAccountName == NSUserName(),
|
||||
let groupOwnerAccountName: String = attributes[.groupOwnerAccountName] as? String,
|
||||
|
|
|
@ -70,7 +70,8 @@ struct RefreshView: View {
|
|||
successful = false
|
||||
try? await Task.sleep(nanoseconds: nanoseconds)
|
||||
|
||||
if let error = error as? MistError,
|
||||
if
|
||||
let error = error as? MistError,
|
||||
error == .missingDevicesKey {
|
||||
withAnimation {
|
||||
firmwaresState = .warning
|
||||
|
@ -107,7 +108,8 @@ struct RefreshView: View {
|
|||
|
||||
let string: String = try String(contentsOf: firmwaresURL, encoding: .utf8)
|
||||
|
||||
guard let data: Data = string.data(using: .utf8),
|
||||
guard
|
||||
let data: Data = string.data(using: .utf8),
|
||||
let dictionary: [String: Any] = try JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [String: Any] else {
|
||||
throw MistError.invalidData
|
||||
}
|
||||
|
@ -119,14 +121,16 @@ struct RefreshView: View {
|
|||
let supportedBuilds: [String] = try Firmware.supportedBuilds()
|
||||
|
||||
for (identifier, device) in devices {
|
||||
guard identifier.contains("Mac"),
|
||||
guard
|
||||
identifier.contains("Mac"),
|
||||
let device: [String: Any] = device as? [String: Any],
|
||||
let firmwaresArray: [[String: Any]] = device["firmwares"] as? [[String: Any]] else {
|
||||
continue
|
||||
}
|
||||
|
||||
for var firmwareDictionary in firmwaresArray {
|
||||
if let url: String = firmwareDictionary["url"] as? String,
|
||||
if
|
||||
let url: String = firmwareDictionary["url"] as? String,
|
||||
url.contains("http://updates-http.cdn-apple.com") {
|
||||
firmwareDictionary["url"] = url.replacingOccurrences(of: "http://updates-http.cdn-apple.com", with: "https://updates.cdn-apple.com")
|
||||
}
|
||||
|
@ -167,7 +171,8 @@ struct RefreshView: View {
|
|||
|
||||
var format: PropertyListSerialization.PropertyListFormat = .xml
|
||||
|
||||
guard let catalog: [String: Any] = try PropertyListSerialization.propertyList(from: data, options: [.mutableContainers], format: &format) as? [String: Any],
|
||||
guard
|
||||
let catalog: [String: Any] = try PropertyListSerialization.propertyList(from: data, options: [.mutableContainers], format: &format) as? [String: Any],
|
||||
let productsDictionary: [String: Any] = catalog["Products"] as? [String: Any] else {
|
||||
continue
|
||||
}
|
||||
|
@ -240,7 +245,8 @@ struct RefreshView: View {
|
|||
dateFormatter.dateFormat = "yyyy-MM-dd"
|
||||
|
||||
for (key, value) in dictionary {
|
||||
guard var value: [String: Any] = value as? [String: Any],
|
||||
guard
|
||||
var value: [String: Any] = value as? [String: Any],
|
||||
let date: Date = value["PostDate"] as? Date,
|
||||
let extendedMetaInfo: [String: Any] = value["ExtendedMetaInfo"] as? [String: Any],
|
||||
extendedMetaInfo["InstallAssistantPackageIdentifiers"] as? [String: Any] != nil,
|
||||
|
@ -253,7 +259,8 @@ struct RefreshView: View {
|
|||
do {
|
||||
let string: String = try String(contentsOf: url, encoding: .utf8)
|
||||
|
||||
guard let name: String = nameFromDistribution(string),
|
||||
guard
|
||||
let name: String = nameFromDistribution(string),
|
||||
let version: String = versionFromDistribution(string),
|
||||
let build: String = buildFromDistribution(string),
|
||||
!name.isEmpty, !version.isEmpty, !build.isEmpty else {
|
||||
|
|
|
@ -57,7 +57,8 @@ struct SettingsDiskImagesView: View {
|
|||
var items: CFTypeRef?
|
||||
let status: OSStatus = SecItemCopyMatching(query as CFDictionary, &items)
|
||||
|
||||
guard status == noErr,
|
||||
guard
|
||||
status == noErr,
|
||||
let identities: [SecIdentity] = items as? [SecIdentity] else {
|
||||
self.codesigningIdentities = []
|
||||
return
|
||||
|
@ -67,7 +68,8 @@ struct SettingsDiskImagesView: View {
|
|||
var certificate: SecCertificate?
|
||||
let status: OSStatus = SecIdentityCopyCertificate(identity, &certificate)
|
||||
|
||||
guard status == noErr,
|
||||
guard
|
||||
status == noErr,
|
||||
let certificate: SecCertificate = certificate,
|
||||
let subject: String = SecCertificateCopySubjectSummary(certificate) as? String,
|
||||
subject.hasPrefix("Developer ID Application") else {
|
||||
|
|
|
@ -19,7 +19,8 @@ struct SettingsGeneralHelperView: View {
|
|||
@State private var error: Error?
|
||||
private let length: CGFloat = 16
|
||||
private var status: String {
|
||||
guard installed,
|
||||
guard
|
||||
installed,
|
||||
let installed: HelperToolInfoPropertyList = installedInfoPropertyList else {
|
||||
return "Not Installed"
|
||||
}
|
||||
|
@ -80,7 +81,8 @@ struct SettingsGeneralHelperView: View {
|
|||
processing = false
|
||||
self.error = error
|
||||
|
||||
if let error: AuthorizationError = error as? AuthorizationError,
|
||||
if
|
||||
let error: AuthorizationError = error as? AuthorizationError,
|
||||
error == .canceled {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -97,7 +97,8 @@ struct SettingsInstallersCacheView: View {
|
|||
|
||||
let response: NSApplication.ModalResponse = openPanel.runModal()
|
||||
|
||||
guard response == .OK,
|
||||
guard
|
||||
response == .OK,
|
||||
let url: URL = openPanel.url else {
|
||||
return
|
||||
}
|
||||
|
@ -121,7 +122,8 @@ struct SettingsInstallersCacheView: View {
|
|||
for id in ids {
|
||||
let url: URL = url.appendingPathComponent(id)
|
||||
|
||||
guard FileManager.default.fileExists(atPath: url.path, isDirectory: &isDirectory),
|
||||
guard
|
||||
FileManager.default.fileExists(atPath: url.path, isDirectory: &isDirectory),
|
||||
isDirectory.boolValue,
|
||||
let installer: Installer = installer(for: url) else {
|
||||
continue
|
||||
|
@ -151,7 +153,8 @@ struct SettingsInstallersCacheView: View {
|
|||
let distributionURL: URL = url.appendingPathComponent("\(id).English.dist")
|
||||
let string: String = try String(contentsOf: distributionURL)
|
||||
|
||||
if let version: String = versionFromDistribution(string),
|
||||
if
|
||||
let version: String = versionFromDistribution(string),
|
||||
let build: String = buildFromDistribution(string) {
|
||||
let size: UInt64 = try FileManager.default.sizeOfDirectory(at: url)
|
||||
return Installer(
|
||||
|
|
|
@ -70,7 +70,8 @@ struct SettingsPackagesView: View {
|
|||
var items: CFTypeRef?
|
||||
let status: OSStatus = SecItemCopyMatching(query as CFDictionary, &items)
|
||||
|
||||
guard status == noErr,
|
||||
guard
|
||||
status == noErr,
|
||||
let identities: [SecIdentity] = items as? [SecIdentity] else {
|
||||
self.codesigningIdentities = []
|
||||
return
|
||||
|
@ -80,7 +81,8 @@ struct SettingsPackagesView: View {
|
|||
var certificate: SecCertificate?
|
||||
let status: OSStatus = SecIdentityCopyCertificate(identity, &certificate)
|
||||
|
||||
guard status == noErr,
|
||||
guard
|
||||
status == noErr,
|
||||
let certificate: SecCertificate = certificate,
|
||||
let subject: String = SecCertificateCopySubjectSummary(certificate) as? String,
|
||||
subject.hasPrefix("Developer ID Installer") else {
|
||||
|
|
|
@ -38,7 +38,8 @@ enum HelperToolCommandRunner {
|
|||
}
|
||||
case .fileAttributes:
|
||||
|
||||
guard let path: String = request.arguments.first,
|
||||
guard
|
||||
let path: String = request.arguments.first,
|
||||
let ownerAccountName: String = request.arguments.last else {
|
||||
return HelperToolCommandResponse(terminationStatus: 1, standardOutput: nil, standardError: "Invalid attributes: \(request.arguments)")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue