Skip to content

Commit 93ef96d

Browse files
Merge pull request appwrite#612 from appwrite/fix-tvos-watchos
2 parents a5decbf + cc82a02 commit 93ef96d

24 files changed

+1171
-189
lines changed

src/SDK/Language/Apple.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,31 @@ public function getFiles(): array
136136
'destination' => '/example-swiftui/Example.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist',
137137
'template' => '/swift/example-swiftui/Example.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist',
138138
],
139+
[
140+
'scope' => 'default',
141+
'destination' => '/example-uikit/UIKitExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved',
142+
'template' => '/swift/example-uikit/UIKitExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved',
143+
],
144+
[
145+
'scope' => 'default',
146+
'destination' => '/example-swiftui/Example.xcodeproj/xcshareddata/xcschemes/test (iOS).xcscheme',
147+
'template' => '/swift/example-swiftui/Example.xcodeproj/xcshareddata/xcschemes/test (iOS).xcscheme',
148+
],
149+
[
150+
'scope' => 'default',
151+
'destination' => '/example-swiftui/Example.xcodeproj/xcshareddata/xcschemes/test (macOS).xcscheme',
152+
'template' => '/swift/example-swiftui/Example.xcodeproj/xcshareddata/xcschemes/test (macOS).xcscheme',
153+
],
154+
[
155+
'scope' => 'default',
156+
'destination' => '/example-swiftui/Example.xcodeproj/xcshareddata/xcschemes/test (tvOS).xcscheme',
157+
'template' => '/swift/example-swiftui/Example.xcodeproj/xcshareddata/xcschemes/test (tvOS).xcscheme',
158+
],
159+
[
160+
'scope' => 'default',
161+
'destination' => '/example-swiftui/Example.xcodeproj/xcshareddata/xcschemes/test (watchOS).xcscheme',
162+
'template' => '/swift/example-swiftui/Example.xcodeproj/xcshareddata/xcschemes/test (watchOS).xcscheme',
163+
],
139164
[
140165
'scope' => 'default',
141166
'destination' => '/example-swiftui/Example.xcodeproj/project.pbxproj',

src/SDK/Language/Swift.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ public function getFiles(): array
206206
],
207207
[
208208
'scope' => 'default',
209-
'destination' => '/Sources/{{ spec.title | caseUcfirst}}/DeviceInfo/iOS/iOSDeviceInfo.swift',
210-
'template' => 'swift/Sources/DeviceInfo/iOS/iOSDeviceInfo.swift',
209+
'destination' => '/Sources/{{ spec.title | caseUcfirst}}/DeviceInfo/iOS/IOSDeviceInfo.swift',
210+
'template' => 'swift/Sources/DeviceInfo/iOS/IOSDeviceInfo.swift',
211211
],
212212
[
213213
'scope' => 'default',
@@ -221,13 +221,23 @@ public function getFiles(): array
221221
],
222222
[
223223
'scope' => 'default',
224-
'destination' => '/Sources/{{ spec.title | caseUcfirst}}/DeviceInfo/MacOS/MacOSDeviceInfo.swift',
225-
'template' => 'swift/Sources/DeviceInfo/MacOS/MacOSDeviceInfo.swift',
224+
'destination' => '/Sources/{{ spec.title | caseUcfirst}}/DeviceInfo/macOS/MacOSDeviceInfo.swift',
225+
'template' => 'swift/Sources/DeviceInfo/macOS/MacOSDeviceInfo.swift',
226226
],
227227
[
228228
'scope' => 'default',
229-
'destination' => '/Sources/{{ spec.title | caseUcfirst}}/DeviceInfo/MacOS/CwlSysCtl.swift',
230-
'template' => 'swift/Sources/DeviceInfo/MacOS/CwlSysCtl.swift',
229+
'destination' => '/Sources/{{ spec.title | caseUcfirst}}/DeviceInfo/watchOS/WatchOSDeviceInfo.swift',
230+
'template' => 'swift/Sources/DeviceInfo/watchOS/WatchOSDeviceInfo.swift',
231+
],
232+
[
233+
'scope' => 'default',
234+
'destination' => '/Sources/{{ spec.title | caseUcfirst}}/DeviceInfo/watchOS/WKInterfaceDevice+ModelName.swift',
235+
'template' => 'swift/Sources/DeviceInfo/watchOS/WKInterfaceDevice+ModelName.swift',
236+
],
237+
[
238+
'scope' => 'default',
239+
'destination' => '/Sources/{{ spec.title | caseUcfirst}}/DeviceInfo/macOS/CwlSysCtl.swift',
240+
'template' => 'swift/Sources/DeviceInfo/macOS/CwlSysCtl.swift',
231241
],
232242
[
233243
'scope' => 'default',

templates/swift/Package.swift.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let package = Package(
77
platforms: [
88
.iOS("15.0"),
99
.macOS("11.0"),
10-
.watchOS("6.0"),
10+
.watchOS("7.0"),
1111
.tvOS("13.0"),
1212
],
1313
products: [

templates/swift/Sources/Client.swift.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -562,10 +562,10 @@ extension Client {
562562
device = "\(info!.modelIdentifier) iOS/\(info!.systemVersion)"
563563
#elseif os(watchOS)
564564
let info = deviceInfo.watchOSInfo
565-
device = "\(info!.systemInfo.machine) watchOS/\(info!.systemVersion)"
565+
device = "\(info!.modelIdentifier) watchOS/\(info!.systemVersion)"
566566
#elseif os(tvOS)
567-
let info = deviceInfo.tvOSInfo
568-
device = "\(info!.systemInfo.machine) tvOS/\(info!.systemVersion)"
567+
let info = deviceInfo.iOSInfo
568+
device = "\(info!.modelIdentifier) tvOS/\(info!.systemVersion)"
569569
#elseif os(macOS)
570570
let info = deviceInfo.macOSInfo
571571
device = "(Macintosh; \(info!.model))"
Lines changed: 22 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#if os(Linux)
22
import Foundation
33

4-
class LinuxDeviceInfo : DeviceInfo {
4+
class LinuxDeviceInfo {
55

66
let name: String
77
let version: String
@@ -14,53 +14,24 @@ class LinuxDeviceInfo : DeviceInfo {
1414
let variant: String
1515
let variantId: String
1616
let machineId: String
17-
18-
internal init(
19-
name: String,
20-
version: String,
21-
id: String,
22-
idLike: [String],
23-
versionCodename: String,
24-
versionId: String,
25-
prettyName: String,
26-
buildId: String,
27-
variant: String,
28-
variantId: String,
29-
machineId: String
30-
) {
31-
self.name = name
32-
self.version = version
33-
self.id = id
34-
self.idLike = idLike
35-
self.versionCodename = versionCodename
36-
self.versionId = versionId
37-
self.prettyName = prettyName
38-
self.buildId = buildId
39-
self.variant = variant
40-
self.variantId = variantId
41-
self.machineId = machineId
42-
}
43-
44-
public static func get() -> LinuxDeviceInfo {
45-
let os = getOsRelease()
46-
let lsb = getLsbRelease()
47-
let machineId = getMachineId()
48-
49-
return LinuxDeviceInfo(
50-
name: os["NAME"] ?? "Linux",
51-
version: os["VERSION"] ?? lsb["LSB_VERSION"] ?? "",
52-
id: os["ID"] ?? lsb["DISTRIB_ID"] ?? "linux",
53-
idLike: os["ID_LIKE"]?.split(separator: " ").map { String($0) } ?? [],
54-
versionCodename: os["VERSION_CODENAME"] ?? lsb["DISTRIB_CODENAME"] ?? "",
55-
versionId: os["VERSION_ID"] ?? lsb["DISTRIB_RELEASE"] ?? "",
56-
prettyName: os["PRETTY_NAME"] ?? lsb["DISTRIB_DESCRIPTION"] ?? "Linux",
57-
buildId: os["BUILD_ID"] ?? "",
58-
variant: os["VARIANT"] ?? "",
59-
variantId: os["VARIANT_ID"] ?? "",
60-
machineId: machineId
61-
)
17+
18+
public init() {
19+
let os = LinuxDeviceInfo.getOsRelease()
20+
let lsb = LinuxDeviceInfo.getLsbRelease()
21+
22+
name = os["NAME"] ?? "Linux"
23+
version = os["VERSION"] ?? lsb["LSB_VERSION"] ?? ""
24+
id = os["ID"] ?? lsb["DISTRIB_ID"] ?? "linux"
25+
idLike = os["ID_LIKE"]?.split(separator: " ").map { String($0) } ?? []
26+
versionCodename = os["VERSION_CODENAME"] ?? lsb["DISTRIB_CODENAME"] ?? ""
27+
versionId = os["VERSION_ID"] ?? lsb["DISTRIB_RELEASE"] ?? ""
28+
prettyName = os["PRETTY_NAME"] ?? lsb["DISTRIB_DESCRIPTION"] ?? "Linux"
29+
buildId = os["BUILD_ID"] ?? ""
30+
variant = os["VARIANT"] ?? ""
31+
variantId = os["VARIANT_ID"] ?? ""
32+
machineId = LinuxDeviceInfo.getMachineId()
6233
}
63-
34+
6435
private static func getOsRelease() -> [String: String] {
6536
return tryReadKeyValues(path: "/etc/os-release")
6637
}
@@ -82,19 +53,19 @@ class LinuxDeviceInfo : DeviceInfo {
8253
let url = URL(fileURLWithPath: path)
8354
let string = try! String(contentsOf: url, encoding: .utf8)
8455
let lines = string.components(separatedBy: .newlines)
85-
56+
8657
var dict = [String: String]()
8758
for line in lines {
8859
let splits = line.split(separator: "=")
8960
if splits.count > 1 {
9061
let key = String(splits[0])
9162
let value = String(splits[1])
92-
63+
9364
dict[key] = value
9465
}
9566
}
96-
67+
9768
return dict
9869
}
9970
}
100-
#endif
71+
#endif

templates/swift/Sources/DeviceInfo/MacOS/MacOSDeviceInfo.swift

Lines changed: 0 additions & 17 deletions
This file was deleted.

templates/swift/Sources/DeviceInfo/OSDeviceInfo.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import Foundation
22

3-
protocol DeviceInfo {}
4-
53
class OSDeviceInfo {
64

7-
#if os(iOS) || os(watchOS) || os(tvOS)
8-
var iOSInfo: iOSDeviceInfo?
5+
#if os(iOS) || os(tvOS)
6+
var iOSInfo: IOSDeviceInfo?
7+
#elseif os(watchOS)
8+
var watchOSInfo: WatchOSDeviceInfo?
99
#elseif os(macOS)
1010
var macOSInfo: MacOSDeviceInfo?
1111
#elseif os(Linux)
@@ -15,14 +15,16 @@ class OSDeviceInfo {
1515
#endif
1616

1717
init() {
18-
#if os(iOS) || os(watchOS) || os(tvOS)
19-
self.iOSInfo = iOSDeviceInfo.get()
18+
#if os(iOS) || os(tvOS)
19+
self.iOSInfo = IOSDeviceInfo()
20+
#elseif os(watchOS)
21+
self.watchOSInfo = WatchOSDeviceInfo()
2022
#elseif os(macOS)
21-
self.macOSInfo = MacOSDeviceInfo.get()
23+
self.macOSInfo = MacOSDeviceInfo()
2224
#elseif os(Linux)
23-
self.linuxInfo = LinuxDeviceInfo.get()
25+
self.linuxInfo = LinuxDeviceInfo()
2426
#elseif os(Windows)
25-
self.windowsInfo = LinuxDeviceInfo.get()
27+
self.windowsInfo = LinuxDeviceInfo()
2628
#endif
2729
}
2830
}
Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,16 @@
11
#if os(Windows)
22
import Foundation
33

4-
class WindowsDeviceInfo : DeviceInfo {
5-
4+
class WindowsDeviceInfo {
5+
66
let numberOfCores: String
77
let computerName: String
88
let systemMemoryInMegabytes: UInt64
9-
10-
public init(
11-
numberOfCores: String,
12-
computerName: String,
13-
systemMemoryInMegabytes: UInt64
14-
) {
15-
self.numberOfCores = numberOfCores
16-
self.computerName = computerName
17-
self.systemMemoryInMegabytes = systemMemoryInMegabytes
18-
}
199

20-
public static func get() -> WindowsDeviceInfo {
21-
let memory = ProcessInfo.processInfo.physicalMemory / 1000 / 1000 // Bytes to MB
22-
23-
return WindowsDeviceInfo(
24-
numberOfCores: ProcessInfo.processInfo.processorCount.description,
25-
computerName: Host.current().localizedName ?? "",
26-
systemMemoryInMegabytes: memory
27-
)
10+
public init() {
11+
numberOfCores = ProcessInfo.processInfo.processorCount.description
12+
computerName = Host.current().localizedName ?? ""
13+
systemMemoryInMegabytes = ProcessInfo.processInfo.physicalMemory / 1000 / 1000 // Bytes to MB
2814
}
2915
}
30-
#endif
31-
16+
#endif
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#if os(iOS) || os(tvOS)
2+
import Foundation
3+
import UIKit
4+
5+
class IOSDeviceInfo {
6+
7+
let name: String
8+
let systemName: String
9+
let systemVersion: String
10+
let model: String
11+
let localizedModel: String
12+
let identifierForVendor: String
13+
let modelIdentifier: String
14+
15+
public init() {
16+
let device = UIDevice.current
17+
18+
name = device.name
19+
systemName = device.systemName
20+
systemVersion = device.systemVersion
21+
model = device.model
22+
localizedModel = device.localizedModel
23+
identifierForVendor = device.identifierForVendor?.uuidString ?? ""
24+
modelIdentifier = UIDevice.modelName
25+
}
26+
}
27+
#endif

templates/swift/Sources/DeviceInfo/iOS/UIDevice+ModelName.swift

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if os(iOS) || os(tvOS) || os(watchOS)
1+
#if os(iOS) || os(tvOS)
22
import Foundation
33
import UIKit
44

@@ -14,8 +14,8 @@ public extension UIDevice {
1414
}
1515

1616
func mapToDevice(identifier: String) -> String { // swiftlint:disable:this cyclomatic_complexity
17-
#if os(iOS)
1817
switch identifier {
18+
#if os(iOS)
1919
case "iPod5,1": return "iPod touch (5th generation)"
2020
case "iPod7,1": return "iPod touch (6th generation)"
2121
case "iPod9,1": return "iPod touch (7th generation)"
@@ -49,6 +49,11 @@ public extension UIDevice {
4949
case "iPhone14,5": return "iPhone 13"
5050
case "iPhone14,2": return "iPhone 13 Pro"
5151
case "iPhone14,3": return "iPhone 13 Pro Max"
52+
case "iPhone14,6": return "iPhone SE (3rd generation)"
53+
case "iPhone14,7": return "iPhone 14"
54+
case "iPhone14,8": return "iPhone 14 Plus"
55+
case "iPhone15,2": return "iPhone 14 Pro"
56+
case "iPhone15,3": return "iPhone 14 Pro Max"
5257
case "iPad2,1", "iPad2,2", "iPad2,3", "iPad2,4": return "iPad 2"
5358
case "iPad3,1", "iPad3,2", "iPad3,3": return "iPad (3rd generation)"
5459
case "iPad3,4", "iPad3,5", "iPad3,6": return "iPad (4th generation)"
@@ -77,21 +82,19 @@ public extension UIDevice {
7782
case "iPad8,5", "iPad8,6", "iPad8,7", "iPad8,8": return "iPad Pro (12.9-inch) (3rd generation)"
7883
case "iPad8,11", "iPad8,12": return "iPad Pro (12.9-inch) (4th generation)"
7984
case "iPad13,8", "iPad13,9", "iPad13,10", "iPad13,11":return "iPad Pro (12.9-inch) (5th generation)"
80-
case "AppleTV5,3": return "Apple TV"
81-
case "AppleTV6,2": return "Apple TV 4K"
82-
case "AudioAccessory1,1": return "HomePod"
83-
case "AudioAccessory5,1": return "HomePod mini"
8485
case "i386", "x86_64": return "Simulator \(mapToDevice(identifier: ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "iOS"))"
8586
default: return identifier
86-
}
8787
#elseif os(tvOS)
88-
switch identifier {
89-
case "AppleTV5,3": return "Apple TV 4"
90-
case "AppleTV6,2": return "Apple TV 4K"
88+
case "AppleTV1,1": return "Apple TV (1st generation)"
89+
case "AppleTV2,1": return "Apple TV (2nd generation)"
90+
case "AppleTV3,1", "AppleTV3,2": return "Apple TV (3rd generation)"
91+
case "AppleTV5,3": return "Apple TV (4th generation)"
92+
case "AppleTV6,2": return "Apple TV 4K (1st generation)"
93+
case "AppleTV11,1": return "Apple TV 4K (2nd generation)"
9194
case "i386", "x86_64": return "Simulator \(mapToDevice(identifier: ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "tvOS"))"
9295
default: return identifier
93-
}
9496
#endif
97+
}
9598
}
9699

97100
return mapToDevice(identifier: identifier)

0 commit comments

Comments
 (0)