Skip to content

Commit

Permalink
Break out isShieldActive
Browse files Browse the repository at this point in the history
  • Loading branch information
robertherber committed Dec 10, 2024
1 parent 2781606 commit c11e530
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
19 changes: 3 additions & 16 deletions ios/ReactNativeDeviceActivityModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -470,25 +470,12 @@ public class ReactNativeDeviceActivityModule: Module {
}

Function("isShieldActive") {
let areAnyApplicationsShielded =
store.shield.applications != nil && store.shield.applications!.count > 0
let areAnyWebDomainsShielded =
store.shield.webDomains != nil && store.shield.webDomains!.count > 0
let areAnyApplicationCategoriesShielded =
store.shield.applicationCategories != nil
&& store.shield.applicationCategories
!= ShieldSettings.ActivityCategoryPolicy<Application>.none
let areAnyWebDomainCategoriesShielded =
store.shield.webDomainCategories != nil
&& store.shield.webDomainCategories != ShieldSettings.ActivityCategoryPolicy<WebDomain>.none

return areAnyApplicationsShielded || areAnyWebDomainsShielded
|| areAnyApplicationCategoriesShielded || areAnyWebDomainCategoriesShielded
return isShieldActive()
}

Function("isShieldActiveWithSelection") { (familyActivitySelectionStr: String) -> Bool in
let isShieldActive = isShieldActive()
if !isShieldActive {
let _isShieldActive = isShieldActive()
if !_isShieldActive {
return false
}

Expand Down
18 changes: 18 additions & 0 deletions ios/Shared.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,24 @@ func executeAction(action: [String: Any], placeholders: [String: String?]) {
}
}

@available(iOS 15.0, *)
func isShieldActive() -> Bool {
let areAnyApplicationsShielded =
store.shield.applications != nil && store.shield.applications!.count > 0
let areAnyWebDomainsShielded =
store.shield.webDomains != nil && store.shield.webDomains!.count > 0
let areAnyApplicationCategoriesShielded =
store.shield.applicationCategories != nil
&& store.shield.applicationCategories
!= ShieldSettings.ActivityCategoryPolicy<Application>.none
let areAnyWebDomainCategoriesShielded =
store.shield.webDomainCategories != nil
&& store.shield.webDomainCategories != ShieldSettings.ActivityCategoryPolicy<WebDomain>.none

return areAnyApplicationsShielded || areAnyWebDomainsShielded
|| areAnyApplicationCategoriesShielded || areAnyWebDomainCategoriesShielded
}

func openUrl(urlString: String) {
guard let url = URL(string: urlString) else {
return // be safe
Expand Down

0 comments on commit c11e530

Please sign in to comment.