Compare commits
2 Commits
b37e5fffbf
...
c94e60d49b
Author | SHA1 | Date |
---|---|---|
Shadowfacts | c94e60d49b | |
Shadowfacts | b00170c3f9 |
|
@ -88,7 +88,7 @@ public class InstanceFeatures: ObservableObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
public var needsWideColorGamutHack: Bool {
|
public var needsWideColorGamutHack: Bool {
|
||||||
if case .mastodon(_, .some(let version)) = instanceType {
|
if case .mastodon(_, let version) = instanceType {
|
||||||
return version < Version(4, 0, 0)
|
return version < Version(4, 0, 0)
|
||||||
} else {
|
} else {
|
||||||
return true
|
return true
|
||||||
|
@ -116,8 +116,16 @@ public class InstanceFeatures: ObservableObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
public var editStatuses: Bool {
|
public var editStatuses: Bool {
|
||||||
// todo: does this require a particular akkoma version?
|
switch instanceType {
|
||||||
hasMastodonVersion(3, 5, 0) || instanceType.isPleroma(.akkoma(nil))
|
case .mastodon(_, let v) where v >= Version(3, 5, 0):
|
||||||
|
return true
|
||||||
|
case .pleroma(.vanilla(let v)) where v >= Version(2, 5, 0):
|
||||||
|
return true
|
||||||
|
case .pleroma(.akkoma(nil)):
|
||||||
|
return true
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public var needsEditAttachmentsInSeparateRequest: Bool {
|
public var needsEditAttachmentsInSeparateRequest: Bool {
|
||||||
|
@ -188,7 +196,7 @@ public class InstanceFeatures: ObservableObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
public func hasMastodonVersion(_ major: Int, _ minor: Int, _ patch: Int) -> Bool {
|
public func hasMastodonVersion(_ major: Int, _ minor: Int, _ patch: Int) -> Bool {
|
||||||
if case .mastodon(_, .some(let version)) = instanceType {
|
if case .mastodon(_, let version) = instanceType {
|
||||||
return version >= Version(major, minor, patch)
|
return version >= Version(major, minor, patch)
|
||||||
} else {
|
} else {
|
||||||
return false
|
return false
|
||||||
|
@ -197,7 +205,7 @@ public class InstanceFeatures: ObservableObject {
|
||||||
|
|
||||||
func hasPleromaVersion(_ major: Int, _ minor: Int, _ patch: Int) -> Bool {
|
func hasPleromaVersion(_ major: Int, _ minor: Int, _ patch: Int) -> Bool {
|
||||||
switch instanceType {
|
switch instanceType {
|
||||||
case .pleroma(.vanilla(.some(let version))), .pleroma(.akkoma(.some(let version))):
|
case .pleroma(.vanilla(let version)), .pleroma(.akkoma(let version)):
|
||||||
return version >= Version(major, minor, patch)
|
return version >= Version(major, minor, patch)
|
||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
|
@ -283,61 +291,3 @@ extension InstanceFeatures {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension InstanceFeatures {
|
|
||||||
@_spi(InstanceType) public struct Version: Equatable, Comparable, CustomStringConvertible {
|
|
||||||
private static let regex = try! NSRegularExpression(pattern: "^(\\d+)\\.(\\d+)\\.(\\d+).*$")
|
|
||||||
|
|
||||||
let major: Int
|
|
||||||
let minor: Int
|
|
||||||
let patch: Int
|
|
||||||
|
|
||||||
init(_ major: Int, _ minor: Int, _ patch: Int) {
|
|
||||||
self.major = major
|
|
||||||
self.minor = minor
|
|
||||||
self.patch = patch
|
|
||||||
}
|
|
||||||
|
|
||||||
init?(string: String) {
|
|
||||||
guard let match = Version.regex.firstMatch(in: string, range: NSRange(location: 0, length: string.utf16.count)),
|
|
||||||
match.numberOfRanges == 4 else {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
let majorStr = (string as NSString).substring(with: match.range(at: 1))
|
|
||||||
let minorStr = (string as NSString).substring(with: match.range(at: 2))
|
|
||||||
let patchStr = (string as NSString).substring(with: match.range(at: 3))
|
|
||||||
guard let major = Int(majorStr),
|
|
||||||
let minor = Int(minorStr),
|
|
||||||
let patch = Int(patchStr) else {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
self.major = major
|
|
||||||
self.minor = minor
|
|
||||||
self.patch = patch
|
|
||||||
}
|
|
||||||
|
|
||||||
public var description: String {
|
|
||||||
"\(major).\(minor).\(patch)"
|
|
||||||
}
|
|
||||||
|
|
||||||
public static func ==(lhs: Version, rhs: Version) -> Bool {
|
|
||||||
return lhs.major == rhs.major && lhs.minor == rhs.minor && lhs.patch == rhs.patch
|
|
||||||
}
|
|
||||||
|
|
||||||
public static func < (lhs: InstanceFeatures.Version, rhs: InstanceFeatures.Version) -> Bool {
|
|
||||||
if lhs.major < rhs.major {
|
|
||||||
return true
|
|
||||||
} else if lhs.major > rhs.major {
|
|
||||||
return false
|
|
||||||
} else if lhs.minor < rhs.minor {
|
|
||||||
return true
|
|
||||||
} else if lhs.minor > rhs.minor {
|
|
||||||
return false
|
|
||||||
} else if lhs.patch < rhs.patch {
|
|
||||||
return true
|
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,80 @@
|
||||||
|
//
|
||||||
|
// Version.swift
|
||||||
|
// InstanceFeatures
|
||||||
|
//
|
||||||
|
// Created by Shadowfacts on 5/14/23.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
@_spi(InstanceType) public struct Version: Equatable, Comparable, CustomStringConvertible {
|
||||||
|
private static let regex = try! NSRegularExpression(pattern: "^(\\d+)\\.(\\d+)\\.(\\d+).*$")
|
||||||
|
|
||||||
|
let major: Int
|
||||||
|
let minor: Int
|
||||||
|
let patch: Int
|
||||||
|
|
||||||
|
init(_ major: Int, _ minor: Int, _ patch: Int) {
|
||||||
|
self.major = major
|
||||||
|
self.minor = minor
|
||||||
|
self.patch = patch
|
||||||
|
}
|
||||||
|
|
||||||
|
init?(string: String) {
|
||||||
|
guard let match = Version.regex.firstMatch(in: string, range: NSRange(location: 0, length: string.utf16.count)),
|
||||||
|
match.numberOfRanges == 4 else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
let majorStr = (string as NSString).substring(with: match.range(at: 1))
|
||||||
|
let minorStr = (string as NSString).substring(with: match.range(at: 2))
|
||||||
|
let patchStr = (string as NSString).substring(with: match.range(at: 3))
|
||||||
|
guard let major = Int(majorStr),
|
||||||
|
let minor = Int(minorStr),
|
||||||
|
let patch = Int(patchStr) else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
self.major = major
|
||||||
|
self.minor = minor
|
||||||
|
self.patch = patch
|
||||||
|
}
|
||||||
|
|
||||||
|
public var description: String {
|
||||||
|
"\(major).\(minor).\(patch)"
|
||||||
|
}
|
||||||
|
|
||||||
|
public static func ==(lhs: Version, rhs: Version) -> Bool {
|
||||||
|
return lhs.major == rhs.major && lhs.minor == rhs.minor && lhs.patch == rhs.patch
|
||||||
|
}
|
||||||
|
|
||||||
|
public static func <(lhs: Version, rhs: Version) -> Bool {
|
||||||
|
if lhs.major < rhs.major {
|
||||||
|
return true
|
||||||
|
} else if lhs.major > rhs.major {
|
||||||
|
return false
|
||||||
|
} else if lhs.minor < rhs.minor {
|
||||||
|
return true
|
||||||
|
} else if lhs.minor > rhs.minor {
|
||||||
|
return false
|
||||||
|
} else if lhs.patch < rhs.patch {
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func <(lhs: Version?, rhs: Version) -> Bool {
|
||||||
|
guard let lhs else {
|
||||||
|
// nil is less than or equal to everything
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return lhs < rhs
|
||||||
|
}
|
||||||
|
|
||||||
|
func >=(lhs: Version?, rhs: Version) -> Bool {
|
||||||
|
guard let lhs else {
|
||||||
|
// nil is less than or equal to everything
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return lhs >= rhs
|
||||||
|
}
|
Loading…
Reference in New Issue