-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add desktop specific RMF attributes #883
Changes from 7 commits
fefe3d2
3db9c9d
f77c20b
4237c2f
0ee0ec7
e4f80ed
148f0bb
d1090e9
ebaad95
2850a8a
70ffc2d
08f23d2
4024e97
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,59 @@ import Foundation | |
import Common | ||
import BrowserServicesKit | ||
|
||
public struct AppAttributeMatcher: AttributeMatching { | ||
#if os(iOS) | ||
public typealias AppAttributeMatcher = MobileAppAttributeMatcher | ||
#elseif os(macOS) | ||
public typealias AppAttributeMatcher = DesktopAppAttributeMatcher | ||
#endif | ||
|
||
public typealias MobileAppAttributeMatcher = CommonAppAttributeMatcher | ||
|
||
public struct DesktopAppAttributeMatcher: AttributeMatching { | ||
private let isInstalledMacAppStore: Bool | ||
|
||
private let commonAppAttributeMatcher: CommonAppAttributeMatcher | ||
|
||
public init(statisticsStore: StatisticsStore, variantManager: VariantManager, isInternalUser: Bool = true, isInstalledMacAppStore: Bool) { | ||
self.isInstalledMacAppStore = isInstalledMacAppStore | ||
|
||
commonAppAttributeMatcher = .init(statisticsStore: statisticsStore, variantManager: variantManager, isInternalUser: isInternalUser) | ||
} | ||
|
||
public init( | ||
bundleId: String, | ||
appVersion: String, | ||
isInternalUser: Bool, | ||
statisticsStore: StatisticsStore, | ||
variantManager: VariantManager, | ||
isInstalledMacAppStore: Bool | ||
) { | ||
self.isInstalledMacAppStore = isInternalUser | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. self can be skipped There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lol it's a bug 😮 should be |
||
|
||
commonAppAttributeMatcher = .init( | ||
bundleId: bundleId, | ||
appVersion: appVersion, | ||
isInternalUser: isInternalUser, | ||
statisticsStore: statisticsStore, | ||
variantManager: variantManager | ||
) | ||
} | ||
|
||
public func evaluate(matchingAttribute: MatchingAttribute) -> EvaluationResult? { | ||
switch matchingAttribute { | ||
case let matchingAttribute as IsInstalledMacAppStoreMatchingAttribute: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle |
||
guard let value = matchingAttribute.value else { | ||
return .fail | ||
} | ||
|
||
return BooleanMatchingAttribute(value).matches(value: isInstalledMacAppStore) | ||
default: | ||
return commonAppAttributeMatcher.evaluate(matchingAttribute: matchingAttribute) | ||
} | ||
} | ||
} | ||
|
||
public struct CommonAppAttributeMatcher: AttributeMatching { | ||
|
||
private let bundleId: String | ||
private let appVersion: String | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,8 +26,6 @@ public typealias UserAttributeMatcher = MobileUserAttributeMatcher | |
public typealias UserAttributeMatcher = DesktopUserAttributeMatcher | ||
#endif | ||
|
||
public typealias DesktopUserAttributeMatcher = CommonUserAttributeMatcher | ||
|
||
public struct MobileUserAttributeMatcher: AttributeMatching { | ||
|
||
private enum PrivacyProSubscriptionStatus: String { | ||
|
@@ -95,6 +93,73 @@ public struct MobileUserAttributeMatcher: AttributeMatching { | |
|
||
} | ||
|
||
public struct DesktopUserAttributeMatcher: AttributeMatching { | ||
private let pinnedTabsCount: Int | ||
private let hasCustomHomePage: Bool | ||
|
||
private let commonUserAttributeMatcher: CommonUserAttributeMatcher | ||
|
||
public init(statisticsStore: StatisticsStore, | ||
variantManager: VariantManager, | ||
emailManager: EmailManager = EmailManager(), | ||
bookmarksCount: Int, | ||
favoritesCount: Int, | ||
appTheme: String, | ||
daysSinceNetPEnabled: Int, | ||
isPrivacyProEligibleUser: Bool, | ||
isPrivacyProSubscriber: Bool, | ||
privacyProDaysSinceSubscribed: Int, | ||
privacyProDaysUntilExpiry: Int, | ||
privacyProPurchasePlatform: String?, | ||
isPrivacyProSubscriptionActive: Bool, | ||
isPrivacyProSubscriptionExpiring: Bool, | ||
isPrivacyProSubscriptionExpired: Bool, | ||
dismissedMessageIds: [String], | ||
pinnedTabsCount: Int, | ||
hasCustomHomePage: Bool | ||
) { | ||
self.pinnedTabsCount = pinnedTabsCount | ||
self.hasCustomHomePage = hasCustomHomePage | ||
|
||
commonUserAttributeMatcher = .init( | ||
statisticsStore: statisticsStore, | ||
variantManager: variantManager, | ||
emailManager: emailManager, | ||
bookmarksCount: bookmarksCount, | ||
favoritesCount: favoritesCount, | ||
appTheme: appTheme, | ||
daysSinceNetPEnabled: daysSinceNetPEnabled, | ||
isPrivacyProEligibleUser: isPrivacyProEligibleUser, | ||
isPrivacyProSubscriber: isPrivacyProSubscriber, | ||
privacyProDaysSinceSubscribed: privacyProDaysSinceSubscribed, | ||
privacyProDaysUntilExpiry: privacyProDaysUntilExpiry, | ||
privacyProPurchasePlatform: privacyProPurchasePlatform, | ||
isPrivacyProSubscriptionActive: isPrivacyProSubscriptionActive, | ||
isPrivacyProSubscriptionExpiring: isPrivacyProSubscriptionExpiring, | ||
isPrivacyProSubscriptionExpired: isPrivacyProSubscriptionExpired, | ||
dismissedMessageIds: dismissedMessageIds | ||
) | ||
} | ||
|
||
public func evaluate(matchingAttribute: MatchingAttribute) -> EvaluationResult? { | ||
switch matchingAttribute { | ||
case let matchingAttribute as PinnedTabsMatchingAttribute: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to app attributes matcher, handle pinned tab, custom home page and duck player here and use common matcher for the rest. |
||
if matchingAttribute.value != MatchingAttributeDefaults.intDefaultValue { | ||
return IntMatchingAttribute(matchingAttribute.value).matches(value: pinnedTabsCount) | ||
} else { | ||
return RangeIntMatchingAttribute(min: matchingAttribute.min, max: matchingAttribute.max).matches(value: pinnedTabsCount) | ||
} | ||
case let matchingAttribute as CustomHomePageMatchingAttribute: | ||
guard let value = matchingAttribute.value else { | ||
return .fail | ||
} | ||
return BooleanMatchingAttribute(value).matches(value: hasCustomHomePage) | ||
default: | ||
return commonUserAttributeMatcher.evaluate(matchingAttribute: matchingAttribute) | ||
} | ||
} | ||
} | ||
|
||
public struct CommonUserAttributeMatcher: AttributeMatching { | ||
|
||
private enum PrivacyProSubscriptionStatus: String { | ||
|
@@ -226,7 +291,7 @@ public struct CommonUserAttributeMatcher: AttributeMatching { | |
case let matchingAttribute as PrivacyProPurchasePlatformMatchingAttribute: | ||
return StringArrayMatchingAttribute(matchingAttribute.value).matches(value: privacyProPurchasePlatform ?? "") | ||
case let matchingAttribute as PrivacyProSubscriptionStatusMatchingAttribute: | ||
let mappedStatuses = matchingAttribute.value.compactMap { status in | ||
let mappedStatuses = (matchingAttribute.value ?? []).compactMap { status in | ||
return PrivacyProSubscriptionStatus(rawValue: status) | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
installedMacAppStore
is an "app" attribute, so we're adding platform-specific structs for app attribute matching.