File tree Expand file tree Collapse file tree 2 files changed +22
-14
lines changed
templates/swift/Sources/PackageInfo Expand file tree Collapse file tree 2 files changed +22
-14
lines changed Original file line number Diff line number Diff line change @@ -6,19 +6,18 @@ extension PackageInfo {
6
6
let version = getVersionJson ( )
7
7
8
8
return PackageInfo (
9
- appName: version [ " app_name " ] as! String ,
10
- version: version [ " version " ] as! String ,
11
- buildNumber: version [ " build_number " ] as! String ,
12
- packageName: " " ,
13
- buildSignature: " "
9
+ appName: version ? [ " appName " ] as? String ?? " " ,
10
+ version: version ? [ " version " ] as? String ?? " " ,
11
+ buildNumber: version ? [ " buildNumber " ] as? String ?? " " ,
12
+ packageName: version ? [ " packageName " ] as? String ?? " " ,
13
+ buildSignature: version ? [ " buildSignature " ] as? String ?? " "
14
14
)
15
15
}
16
16
17
- private static func getVersionJson( ) -> [ String : Any ] {
17
+ private static func getVersionJson( ) -> [ String : Any ] ? {
18
18
let exePath = URL ( fileURLWithPath: " /proc/self/exe " ) . resolvingSymlinksInPath ( )
19
19
let appPath = exePath. deletingLastPathComponent ( )
20
20
let jsonPath = appPath. appendingPathComponent ( " version.json " )
21
- return try ! JSONSerialization
22
- . jsonObject ( with: Data ( contentsOf: jsonPath) ) as! [ String : Any ]
21
+ return try ? JSONSerialization . jsonObject ( with: Data ( contentsOf: jsonPath) ) as? [ String : Any ]
23
22
}
24
23
}
Original file line number Diff line number Diff line change 1
1
import Foundation
2
2
3
- class WindowsPackageInfo : PackageInfo {
3
+ extension PackageInfo {
4
4
5
5
public static func getWindowsPackage( ) -> PackageInfo {
6
- return WindowsPackageInfo (
7
- appName: " " ,
8
- version: " " ,
9
- buildNumber: " " ,
10
- packageName: " "
6
+ let version = getVersionJson ( )
7
+ return PackageInfo (
8
+ appName: version ? [ " appName " ] as? String ?? " " ,
9
+ version: version ? [ " version " ] as? String ?? " " ,
10
+ buildNumber: version ? [ " buildNumber " ] as? String ?? " " ,
11
+ packageName: version ? [ " packageName " ] as? String ?? " " ,
12
+ buildSignature: version ? [ " buildSignature " ] as? String ?? " "
11
13
)
12
14
}
15
+
16
+ private static func getVersionJson( ) -> [ String : Any ] ? {
17
+ let exePath = URL ( fileURLWithPath: " /proc/self/exe " ) . resolvingSymlinksInPath ( )
18
+ let appPath = exePath. deletingLastPathComponent ( )
19
+ let jsonPath = appPath. appendingPathComponent ( " version.json " )
20
+ return try ? JSONSerialization . jsonObject ( with: Data ( contentsOf: jsonPath) ) as? [ String : Any ]
21
+ }
13
22
}
You can’t perform that action at this time.
0 commit comments