Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚠️ Add a temporary warning about macOS Monterey #427

Merged
merged 4 commits into from
Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/MasKit/AppStore/Downloader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private func downloadWithRetries(

let attempts = attempts - 1
printWarning((downloadError ?? error).localizedDescription)
print("Trying again up to \(attempts) more \(attempts == 1 ? "time" : "times").")
printWarning("Trying again up to \(attempts) more \(attempts == 1 ? "time" : "times").")
return downloadWithRetries(appID, purchase: purchase, attempts: attempts)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/MasKit/Commands/Open.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public struct OpenCommand: CommandProtocol {

guard let appId = Int(options.appId)
else {
print("Invalid app ID")
printError("Invalid app ID")
return .failure(.noSearchResultsFound)
}

Expand Down
55 changes: 47 additions & 8 deletions Sources/MasKit/Formatters/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ let csi = "\u{001B}["

// Override global print for testability.
// See MasKitTests/OutputListener.swift.
func print(_ items: Any..., separator: String = " ", terminator: String = "\n") {
func print(
_ items: Any...,
separator: String = " ",
terminator: String = "\n"
) {
if let observer = printObserver {
let output =
items
Expand All @@ -39,8 +43,42 @@ let csi = "\u{001B}["
Swift.print(terminator, terminator: "")
}

func print<Target>(
_ items: Any...,
separator: String = " ",
terminator: String = "\n",
to output: inout Target
) where Target: TextOutputStream {
if let observer = printObserver {
let output =
items
.map { "\($0)" }
.joined(separator: separator)
.appending(terminator)
observer(output)
}

var prefix = ""
for item in items {
Swift.print(prefix, terminator: "", to: &output)
Swift.print(item, terminator: "", to: &output)
prefix = separator
}

Swift.print(terminator, terminator: "", to: &output)
}

#endif

private var standardError = FileHandle.standardError

extension FileHandle: TextOutputStream {
public func write(_ string: String) {
guard let data = string.data(using: .utf8) else { return }
write(data)
}
}

func printInfo(_ message: String) {
guard isatty(fileno(stdout)) != 0 else {
print("==> \(message)")
Expand All @@ -51,30 +89,31 @@ func printInfo(_ message: String) {
print("\(csi)1;34m==>\(csi)0m \(csi)1m\(message)\(csi)0m")
}

func printWarning(_ message: String) {
guard isatty(fileno(stdout)) != 0 else {
print("Warning: \(message)")
public func printWarning(_ message: String) {
guard isatty(fileno(stderr)) != 0 else {
print("Warning: \(message)", to: &standardError)
return
}

// Yellow, underlined "Warning:" prefix
print("\(csi)4;33mWarning:\(csi)0m \(message)")
print("\(csi)4;33mWarning:\(csi)0m \(message)", to: &standardError)
}

public func printError(_ message: String) {
guard isatty(fileno(stdout)) != 0 else {
print("Error: \(message)")
guard isatty(fileno(stderr)) != 0 else {
print("Error: \(message)", to: &standardError)
return
}

// Red, underlined "Error:" prefix
print("\(csi)4;31mError:\(csi)0m \(message)")
print("\(csi)4;31mError:\(csi)0m \(message)", to: &standardError)
}

func clearLine() {
guard isatty(fileno(stdout)) != 0 else {
return
}

print("\(csi)2K\(csi)0G", terminator: "")
fflush(stdout)
}
7 changes: 5 additions & 2 deletions Sources/MasKit/Models/SoftwareProduct.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ extension SoftwareProduct {
// Only look at min OS version if we have one, also only consider macOS apps
// Replace string literal with MasStoreSearch.Entity once `search` branch is merged.
if let osVersion = Version(tolerant: storeApp.minimumOsVersion), storeApp.kind == "mac-software" {
let requiredVersion = OperatingSystemVersion(majorVersion: osVersion.major, minorVersion: osVersion.minor,
patchVersion: osVersion.patch)
let requiredVersion = OperatingSystemVersion(
majorVersion: osVersion.major,
minorVersion: osVersion.minor,
patchVersion: osVersion.patch
)
// Don't consider an app outdated if the version in the app store requires a higher OS version.
guard ProcessInfo.processInfo.isOperatingSystemAtLeast(requiredVersion) else {
return false
Expand Down
9 changes: 9 additions & 0 deletions Sources/mas/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@
//

import Commandant
import Foundation
import MasKit

MasKit.initialize()

let monterey = OperatingSystemVersion(majorVersion: 12, minorVersion: 0, patchVersion: 0)
if ProcessInfo.processInfo.isOperatingSystemAtLeast(monterey) {
printWarning(
"mas is not yet functional on macOS Monterey (12) due to changes in macOS frameworks. "
+ "To track progress or to *contribute* to fixing this issue, please see: "
+ "https://github.com/mas-cli/mas/issues/417")
}

let registry = CommandRegistry<MASError>()
let helpCommand = HelpCommand(registry: registry)

Expand Down
9 changes: 7 additions & 2 deletions Tests/MasKitTests/Models/SoftwareProductSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ public class SoftwareProductSpec: QuickSpec {
MasKit.initialize()
}
describe("software product") {
let app = SoftwareProductMock(appName: "App", bundleIdentifier: "", bundlePath: "", bundleVersion: "1.0.0",
itemIdentifier: 111)
let app = SoftwareProductMock(
appName: "App",
bundleIdentifier: "",
bundlePath: "",
bundleVersion: "1.0.0",
itemIdentifier: 111
)

let currentApp = SearchResult(kind: "mac-software", version: "1.0.0")
let appUpdate = SearchResult(kind: "mac-software", version: "2.0.0")
Expand Down