Skip to content

Commit 6f813d2

Browse files
github-actions[bot]Firefox Sync Engineering
andauthored
Auto update with latest AS Release v93.0.0 (#47)
* Updates Package.swift with v93.0.0 release * Version 93.0.0 Co-authored-by: Firefox Sync Engineering <[email protected]>
1 parent 603262d commit 6f813d2

File tree

5 files changed

+110
-66
lines changed

5 files changed

+110
-66
lines changed

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// swift-tools-version:5.4
22
import PackageDescription
33

4-
let checksum = "a315d0dba54895526935316ecc66aa6c9a522194d02225119e6b35378c7ba914"
5-
let version = "v92.0.1"
4+
let checksum = "b0bfb2bf91bf52978b8f0450456a4e9b2f7d346d635b0ac7f743709e6eaa98cb"
5+
let version = "v93.0.0"
66
let url = "https://github.com/mozilla/application-services/releases/download/\(version)/MozillaRustComponents.xcframework.zip"
77

88
let package = Package(

swift-source/Generated/Metrics/Metrics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ extension GleanMetrics {
2222
// Intentionally left private, no external user can instantiate a new global object.
2323
}
2424

25-
public static let info = BuildInfo(buildDate: DateComponents(calendar: Calendar.current, timeZone: TimeZone(abbreviation: "UTC"), year: 2022, month: 3, day: 25, hour: 15, minute: 6, second: 26))
25+
public static let info = BuildInfo(buildDate: DateComponents(calendar: Calendar.current, timeZone: TimeZone(abbreviation: "UTC"), year: 2022, month: 4, day: 14, hour: 15, minute: 6, second: 43))
2626
}
2727

2828
enum NimbusEvents {

swift-source/Nimbus/Collections+.swift

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
import Foundation
66

7+
#if canImport(UIKit)
8+
import UIKit
9+
#endif
10+
711
public extension Dictionary {
812
func mapKeysNotNull<K1>(_ transform: (Key) -> K1?) -> [K1: Value] {
913
let transformed: [(K1, Value)] = compactMap { k, v in
@@ -36,3 +40,59 @@ public extension Dictionary {
3640
return merging(defaults, uniquingKeysWith: valueMerger)
3741
}
3842
}
43+
44+
public extension Array where Element == Bundle {
45+
/// Search through the resource bundles looking for an image of the given name.
46+
///
47+
/// If no image is found in any of the `resourceBundles`, then the `nil` is returned.
48+
func getImage(named name: String) -> UIImage? {
49+
for bundle in self {
50+
if let image = UIImage(named: name, in: bundle, compatibleWith: nil) {
51+
return image
52+
}
53+
}
54+
return nil
55+
}
56+
57+
/// Search through the resource bundles looking for an image of the given name.
58+
///
59+
/// If no image is found in any of the `resourceBundles`, then a fatal error is
60+
/// thrown. This method is only intended for use with hard coded default images
61+
/// when other images have been omitted or are missing.
62+
///
63+
/// The two ways of fixing this would be to provide the image as its named in the `.fml.yaml`
64+
/// file or to change the name of the image in the FML file.
65+
func getImageNotNull(named name: String) -> UIImage {
66+
guard let image = getImage(named: name) else {
67+
fatalError(
68+
"An image named \"\(name)\" has been named in a `.fml.yaml` file, but is missing from the asset bundle")
69+
}
70+
return image
71+
}
72+
73+
/// Search through the resource bundles looking for localized strings with the given name.
74+
/// If the `name` contains exactly one slash, it is split up and the first part of the string is used
75+
/// as the `tableName` and the second the `key` in localized string lookup.
76+
/// If no string is found in any of the `resourceBundles`, then the `name` is passed back unmodified.
77+
func getString(named name: String) -> String? {
78+
let parts = name.split(separator: "/", maxSplits: 1, omittingEmptySubsequences: true).map { String($0) }
79+
let key: String
80+
let tableName: String?
81+
switch parts.count {
82+
case 2:
83+
tableName = parts[0]
84+
key = parts[1]
85+
default:
86+
tableName = nil
87+
key = name
88+
}
89+
90+
for bundle in self {
91+
let value = bundle.localizedString(forKey: key, value: nil, table: tableName)
92+
if value != key {
93+
return value
94+
}
95+
}
96+
return nil
97+
}
98+
}

swift-source/Nimbus/FeatureVariables.swift

Lines changed: 46 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import Foundation
2626
///
2727
/// This may become the basis of a generated-from-manifest solution.
2828
public protocol Variables {
29+
var resourceBundles: [Bundle] { get }
30+
2931
/// Finds a string typed value for this key. If none exists, `nil` is returned.
3032
///
3133
/// N.B. the `key` and type `String` should be listed in the experiment manifest.
@@ -241,9 +243,7 @@ private func asEnum<T: RawRepresentable>(_ string: String) -> T? where T.RawValu
241243
return T(rawValue: string)
242244
}
243245

244-
protocol VariablesWithBundle: Variables {
245-
var resourceBundles: [Bundle] { get }
246-
}
246+
protocol VariablesWithBundle: Variables {}
247247

248248
extension VariablesWithBundle {
249249
func getImage(_ key: String) -> UIImage? {
@@ -289,65 +289,21 @@ extension VariablesWithBundle {
289289
///
290290
/// If no image is found in any of the `resourceBundles`, then the `nil` is returned.
291291
func asImage(name: String) -> UIImage? {
292-
for bundle in resourceBundles {
293-
if let image = UIImage(named: name, in: bundle, compatibleWith: nil) {
294-
return image
295-
}
296-
}
297-
return nil
292+
return resourceBundles.getImage(named: name)
298293
}
299294

300295
/// Search through the resource bundles looking for localized strings with the given name.
301296
/// If the `name` contains exactly one slash, it is split up and the first part of the string is used
302297
/// as the `tableName` and the second the `key` in localized string lookup.
303298
/// If no string is found in any of the `resourceBundles`, then the `name` is passed back unmodified.
304299
func asLocalizedString(name: String) -> String? {
305-
let parts = name.split(separator: "/", maxSplits: 1, omittingEmptySubsequences: true).map { String($0) }
306-
let key: String
307-
let tableName: String?
308-
switch parts.count {
309-
case 2:
310-
tableName = parts[0]
311-
key = parts[1]
312-
default:
313-
tableName = nil
314-
key = name
315-
}
316-
317-
for bundle in resourceBundles {
318-
let value = bundle.localizedString(forKey: key, value: nil, table: tableName)
319-
if value != key {
320-
return value
321-
}
322-
}
323-
return name
300+
return resourceBundles.getString(named: name) ?? name
324301
}
325302
}
326303

327304
/// A thin wrapper around the JSON produced by the `get_feature_variables_json(feature_id)` call, useful
328305
/// for configuring a feature, but without needing the developer to know about experiment specifics.
329306
internal class JSONVariables: VariablesWithBundle {
330-
func asStringMap() -> [String: String]? {
331-
return nil
332-
}
333-
334-
func asIntMap() -> [String: Int]? {
335-
return nil
336-
}
337-
338-
func asBoolMap() -> [String: Bool]? {
339-
return nil
340-
}
341-
342-
func asVariablesMap() -> [String: Variables]? {
343-
return json.compactMapValues { value in
344-
if let jsonMap = value as? [String: Any] {
345-
return JSONVariables(with: jsonMap)
346-
}
347-
return nil
348-
}
349-
}
350-
351307
private let json: [String: Any]
352308
internal let resourceBundles: [Bundle]
353309

@@ -370,6 +326,10 @@ internal class JSONVariables: VariablesWithBundle {
370326
return valueMap(key)
371327
}
372328

329+
func asStringMap() -> [String: String]? {
330+
return nil
331+
}
332+
373333
func getInt(_ key: String) -> Int? {
374334
return value(key)
375335
}
@@ -382,6 +342,10 @@ internal class JSONVariables: VariablesWithBundle {
382342
return valueMap(key)
383343
}
384344

345+
func asIntMap() -> [String: Int]? {
346+
return nil
347+
}
348+
385349
func getBool(_ key: String) -> Bool? {
386350
return value(key)
387351
}
@@ -394,6 +358,10 @@ internal class JSONVariables: VariablesWithBundle {
394358
return valueMap(key)
395359
}
396360

361+
func asBoolMap() -> [String: Bool]? {
362+
return nil
363+
}
364+
397365
// Methods used to get sub-objects. We immediately re-wrap an JSON object if it exists.
398366
func getVariables(_ key: String) -> Variables? {
399367
if let dictionary: [String: Any] = value(key) {
@@ -415,6 +383,15 @@ internal class JSONVariables: VariablesWithBundle {
415383
}
416384
}
417385

386+
func asVariablesMap() -> [String: Variables]? {
387+
return json.compactMapValues { value in
388+
if let jsonMap = value as? [String: Any] {
389+
return JSONVariables(with: jsonMap)
390+
}
391+
return nil
392+
}
393+
}
394+
418395
private func value<T>(_ key: String) -> T? {
419396
return json[key] as? T
420397
}
@@ -438,24 +415,14 @@ internal class JSONVariables: VariablesWithBundle {
438415

439416
// Another implementation of `Variables` may just return nil for everything.
440417
public class NilVariables: Variables {
441-
public func asStringMap() -> [String: String]? {
442-
return nil
443-
}
444-
445-
public func asIntMap() -> [String: Int]? {
446-
return nil
447-
}
418+
public static let instance = NilVariables()
448419

449-
public func asBoolMap() -> [String: Bool]? {
450-
return nil
451-
}
420+
public private(set) var resourceBundles: [Bundle] = [Bundle.main]
452421

453-
public func asVariablesMap() -> [String: Variables]? {
454-
return nil
422+
public func set(bundles: [Bundle]) {
423+
resourceBundles = bundles
455424
}
456425

457-
public static let instance: Variables = NilVariables()
458-
459426
public func getString(_: String) -> String? {
460427
return nil
461428
}
@@ -468,6 +435,10 @@ public class NilVariables: Variables {
468435
return nil
469436
}
470437

438+
public func asStringMap() -> [String: String]? {
439+
return nil
440+
}
441+
471442
public func getInt(_: String) -> Int? {
472443
return nil
473444
}
@@ -480,6 +451,10 @@ public class NilVariables: Variables {
480451
return nil
481452
}
482453

454+
public func asIntMap() -> [String: Int]? {
455+
return nil
456+
}
457+
483458
public func getBool(_: String) -> Bool? {
484459
return nil
485460
}
@@ -492,6 +467,10 @@ public class NilVariables: Variables {
492467
return nil
493468
}
494469

470+
public func asBoolMap() -> [String: Bool]? {
471+
return nil
472+
}
473+
495474
public func getImage(_: String) -> UIImage? {
496475
return nil
497476
}
@@ -527,4 +506,8 @@ public class NilVariables: Variables {
527506
public func getVariablesMap(_: String) -> [String: Variables]? {
528507
return nil
529508
}
509+
510+
public func asVariablesMap() -> [String: Variables]? {
511+
return nil
512+
}
530513
}

swift-source/Nimbus/Nimbus.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class Nimbus: NimbusApi {
3333
self.errorReporter = errorReporter
3434
self.nimbusClient = nimbusClient
3535
self.resourceBundles = resourceBundles
36+
NilVariables.instance.set(bundles: resourceBundles)
3637
}
3738
}
3839

0 commit comments

Comments
 (0)