-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: App version shared and moved to Core, abstracted from UIKit
- Loading branch information
1 parent
4433608
commit 89ed690
Showing
5 changed files
with
172 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
Infomaniak Core - iOS | ||
Copyright (C) 2024 Infomaniak Network SA | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import Foundation | ||
import InfomaniakDI | ||
import OSInfo | ||
|
||
public enum CorePlatform { | ||
|
||
/// Unified version descriptor for IK platform apps | ||
public static var appVersionLabel: String = { | ||
let appName = Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as! String | ||
let release = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String? ?? "x.x" | ||
let build = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as! String? ?? "x" | ||
let betaRelease = Bundle.main.isRunningInTestFlight ? "beta" : "" | ||
|
||
// Returns "macOS" on unmodified iOS and catalyst apps running on macOS | ||
let systemName = OS.current.name | ||
|
||
return "\(appName) \(systemName) version \(release)-\(betaRelease)\(build)" | ||
}() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
Infomaniak Core - iOS | ||
Copyright (C) 2024 Infomaniak Network SA | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import Foundation | ||
|
||
/// Something to help with current running context | ||
public protocol PlatformDetectable { | ||
/// We are running in Mac Catalyst mode | ||
var isMacCatalyst: Bool { get } | ||
|
||
/// We are running an iOS App on Mac | ||
var isiOSAppOnMac: Bool { get } | ||
|
||
/// We are running on Mac | ||
var isMac: Bool { get } | ||
|
||
/// We are running in extension mode | ||
var isInExtension: Bool { get } | ||
|
||
/// We are running a debug build | ||
var isDebug: Bool { get } | ||
} | ||
|
||
@available(macOS 10.16, iOS 14.0, tvOS 14.0, watchOS 7.0, *) | ||
public struct PlatformDetector: PlatformDetectable { | ||
public init() {} | ||
|
||
public var isMacCatalyst: Bool = { | ||
#if targetEnvironment(macCatalyst) | ||
true | ||
#else | ||
false | ||
#endif | ||
}() | ||
|
||
public var isiOSAppOnMac: Bool = ProcessInfo().isiOSAppOnMac | ||
|
||
public var isMac: Bool { | ||
isMacCatalyst || isiOSAppOnMac | ||
} | ||
|
||
public var isInExtension: Bool = { | ||
guard Bundle.main.bundlePath.hasSuffix(".appex") else { | ||
return false | ||
} | ||
|
||
return true | ||
}() | ||
|
||
public var isDebug: Bool = { | ||
#if DEBUG | ||
true | ||
#else | ||
false | ||
#endif | ||
}() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
Infomaniak Core - iOS | ||
Copyright (C) 2024 Infomaniak Network SA | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import InfomaniakCore | ||
import XCTest | ||
|
||
final class UTCorePlatform: XCTestCase { | ||
|
||
func testVersionLabel() { | ||
// GIVEN | ||
let expectedPrefix = "xctest macOS version" | ||
|
||
// WHEN | ||
let versionLabel = CorePlatform.appVersionLabel | ||
|
||
// THEN | ||
XCTAssertTrue(versionLabel.hasPrefix(expectedPrefix)) | ||
} | ||
} |