Skip to content
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

[MOB-3028] Ecosia Framework #816

Open
wants to merge 59 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
6ae09d2
Temporarily using ios-core feature branch
lucaschifino Nov 4, 2024
32ba5ce
Add Braze package and BrazeService integration
lucaschifino Nov 5, 2024
f84ddde
Create Newsletter Card and refactor nudge card superclass to simplify…
lucaschifino Nov 6, 2024
6205cc7
Create experiment and link to card
lucaschifino Nov 6, 2024
b910304
Fix trailing whitespaces
lucaschifino Nov 11, 2024
466bcfe
[MOB-2959] Use ios-core main again
lucaschifino Nov 13, 2024
dbcdf5c
[MOB-3028] Create Ecosia Framework and move Braze there
lucaschifino Nov 15, 2024
11dfbf9
[MOB-3028] Move Analytics and dependencies to Ecosia framework
lucaschifino Nov 15, 2024
c4e1211
[MOB-3028] Lint fix
lucaschifino Nov 15, 2024
7c1ad1c
[MOB-3028] Including correct Info.plist
lucaschifino Nov 20, 2024
35fd5df
[MOB-3028] Build succeeded - to check install
d4r1091 Dec 3, 2024
4abc85f
[MOB-3028] Add Bundle+Ecosia, move LaunchScreen to Client/Ecosia/UI
d4r1091 Dec 4, 2024
6b0ffa7
[MOB-3028] Update Info.plist to specify variables like other targets
d4r1091 Dec 4, 2024
43d0467
[MOB-3028] Add comments to Info.plist
d4r1091 Dec 4, 2024
f64e7ee
[MOB-3028] Build succeed with Core as part of the main project
d4r1091 Dec 5, 2024
3f05fd8
[MOB-3028] Add Core's ADRs
d4r1091 Dec 5, 2024
d264aa5
[MOB-3028] Remove SeedCounter's CoreData ref
d4r1091 Dec 5, 2024
aef2abb
[MOB-3028] Adapt Ecosia Snapshots and Units Tests
d4r1091 Dec 5, 2024
ce9e09a
[MOB-3028] Snowplow's SPM Update
d4r1091 Dec 11, 2024
5389ff9
[MOB-3028] Update proj and swift files to make it a build successful …
d4r1091 Dec 11, 2024
fa133e7
[MOB-3028] Add explicit `CFBundleDisplayName`
d4r1091 Dec 11, 2024
275cde1
[MOB-3028] Update Snapshot Testing resource files
d4r1091 Dec 11, 2024
2f24f60
[MOB-3028] Update reference for Bookmark test resources
d4r1091 Dec 11, 2024
a975f07
[MOB-3028] Fix comment typo
d4r1091 Dec 11, 2024
901cac6
[MOB-3028] Update tests scheme
d4r1091 Dec 11, 2024
e6bdfdc
[MOB-3028] Add `Ecosia` framework as part of the `Shared` one
d4r1091 Dec 11, 2024
19248a5
[MOB-3028] Temporarily remove the `file_header` check from Swiftlint
d4r1091 Dec 11, 2024
90ff208
[MOB-3028] Run tests forcely
d4r1091 Dec 11, 2024
1e75443
[MOB-3028] Fix after SwiftLint run
d4r1091 Dec 11, 2024
24a6d4e
[MOB-3028] SPM Update
d4r1091 Dec 12, 2024
69d933e
[MOB-3028] Remove `Ecosia` framework dependency.
d4r1091 Dec 12, 2024
270f5e5
[MOB-3028] Review Ecosia-based favicon bundle domain matcher
d4r1091 Dec 12, 2024
6d30eda
[MOB-3028] Update transifex integration to match new folder
d4r1091 Dec 12, 2024
7ce016a
[MOB-3028] Remove meaningless Ecosia comment
d4r1091 Dec 12, 2024
5b619c4
[MOB-3028] Project fixes after rebase
d4r1091 Dec 12, 2024
d0dfb8b
[MOB-3028] Remove old APNConsent reference
d4r1091 Dec 12, 2024
a46c95c
[MOB-3028] Update EcosiaFramework test plan
d4r1091 Dec 12, 2024
67a4fce
[MOB-3028] Update Ecosia Scheme removing EcosiaFramework tests
d4r1091 Dec 12, 2024
a4f55d5
[MOB-3028] Forcely perform snapshot tests
d4r1091 Dec 12, 2024
a7614b6
[MOB-3028] Aligned EcosiaTests deployment target as other tests
d4r1091 Dec 12, 2024
6d578c6
[MOB-3028] Fix Ecosia's Unit Tests
d4r1091 Dec 12, 2024
37dbe10
[MOB-3028] Disable `ns_number_init_as_function_reference`
d4r1091 Dec 12, 2024
8890698
[MOB-3028] Update Snapshot Tests files
d4r1091 Dec 12, 2024
221cee3
[MOB-3028] Update snapshot tests script to continue running after fai…
d4r1091 Dec 16, 2024
e038d7b
[MOB-3028] Upload test results as artifact
d4r1091 Dec 16, 2024
2c3bf1d
[MOB-3028] Import correct Lproj bundle
d4r1091 Dec 16, 2024
6caf049
[MOB-3028] Revert "[MOB-3028] Forcely perform snapshot tests"
d4r1091 Dec 16, 2024
eb823e9
[MOB-3028] Revert "[MOB-3028] Run tests forcely"
d4r1091 Dec 16, 2024
2cb6dbe
[MOB-3028] Re-add Swiftlint's `file_header`
d4r1091 Dec 17, 2024
1bcc995
[MOB-3028] Remove useless Tests folder
d4r1091 Dec 17, 2024
2076816
[MOB-3028] Add thorough Ecosia comment
d4r1091 Dec 18, 2024
a9ce0d1
[MOB-3028] Add new line
d4r1091 Dec 18, 2024
023ec30
[MOB-3028] Update Environment check with `MOZ_CHANNEL_RELEASE`
d4r1091 Dec 18, 2024
13f816d
[MOB-3028] Add specific tests for URLProvider interim solution
d4r1091 Dec 18, 2024
b81aa87
[MOB-3028] Remove whitespaces
d4r1091 Dec 18, 2024
9578dd9
[MOB-3028] Remove `// Ecosia: Import Ecosia Framework` comment
d4r1091 Dec 18, 2024
731b515
[MOB-3028] Swiftlint fix
d4r1091 Dec 18, 2024
fd76165
[MOB-3028] Remove Ecosia framework comments
d4r1091 Dec 18, 2024
16d3d4f
[MOB-3028] Update tests and made the Language.make function thread-safe
d4r1091 Dec 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 6 additions & 0 deletions .github/actions/perform_snapshot_tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ runs:
mkdir -p EcosiaTests/Results/
./perform_snapshot_tests.sh "EcosiaTests/SnapshotTests/snapshot_configuration.json" "EcosiaTests/SnapshotTests/environment.json" "EcosiaTests/Results" "EcosiaSnapshotTests"

- name: Upload test result as artifact
uses: actions/upload-artifact@v3
with:
name: test-result
path: 'EcosiaTests/Results/all_tests.xcresult'

- name: Process xcresult files
uses: kishikawakatsumi/xcresulttool@v1
with:
Expand Down
1 change: 1 addition & 0 deletions .github/actions/perform_unit_tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ runs:
shell: bash
run: |
bundle exec fastlane run run_tests prelaunch_simulator:true testplan:"UnitTest"
bundle exec fastlane run run_tests prelaunch_simulator:true scheme:"EcosiaFramework" testplan:"UnitTest"

- name: Publish Test Report
uses: mikepenz/[email protected]
Expand Down
5 changes: 4 additions & 1 deletion .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ only_rules: # Only enforce these rules, ignore all others
- legacy_nsgeometry_functions
- mark
- no_space_in_method_call
- ns_number_init_as_function_reference
# Ecosia: disabled
# - ns_number_init_as_function_reference
- operator_whitespace
- orphaned_doc_comment
- private_over_fileprivate
Expand Down Expand Up @@ -151,6 +152,8 @@ excluded: # paths to ignore during linting. Takes precedence over `included`.
- BrowserKit/.build/
# Ecosia: Exclude Swift Packages
- SourcePackages
# Ecosia; Excluding Core's EcosiaTests as we have some force unwraps
- EcosiaTests/Core

included:
- /Users/vagrant/git
Expand Down
8 changes: 4 additions & 4 deletions .tx/integration_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ filters:

- filter_type: file
source_language: en
source_file: Client/Ecosia/L10N/en.lproj/Ecosia.strings
source_file: Ecosia/L10N/en.lproj/Ecosia.strings
file_format: STRINGS
translation_files_expression: 'Client/Ecosia/L10N/<lang>.lproj/Ecosia.strings'
translation_files_expression: 'Ecosia/L10N/<lang>.lproj/Ecosia.strings'

- filter_type: file
source_language: en
source_file: Client/Ecosia/L10N/en.lproj/Plurals.stringsdict
source_file: Ecosia/L10N/en.lproj/Plurals.stringsdict
file_format: STRINGSDICT
translation_files_expression: 'Client/Ecosia/L10N/<lang>.lproj/Plurals.stringsdict'
translation_files_expression: 'Ecosia/L10N/<lang>.lproj/Plurals.stringsdict'
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

import UIKit
import Common
// Ecosia: Import Core
import Core

protocol BundleImageFetcher {
/// Fetches from the bundle
Expand Down Expand Up @@ -66,7 +64,7 @@ class DefaultBundleImageFetcher: BundleImageFetcher {
// MARK: - Private

private func getBundleDomain(domain: ImageDomain) -> String? {
/* Ecosia: Allor Favicon to import the correct financial one
/* Ecosia: Allow Favicon to import the correct financial one
OLD Implementation:
return domain.bundleDomains.first(where: { bundledImages[$0] != nil })

Expand All @@ -82,17 +80,11 @@ class DefaultBundleImageFetcher: BundleImageFetcher {
However, as per this class and all other dependencies being wrapped
into the BrowserKit package, this would have resulted into macking a lot of changes into accessors to be able to make our own file outside of the BrowserKit context.
*/

let financialReportsURL = Environment.current.urlProvider.financialReports.absoluteString.replacingOccurrences(of: "https://", with: "")
let privacyURL = Environment.current.urlProvider.privacy.absoluteString.replacingOccurrences(of: "https://", with: "")
let urlMap = [
financialReportsURL: "blog.ecosia.finance",
privacyURL: "privacy.ecosia"
]
if let matchingKey = urlMap.keys.first(where: { domain.bundleDomains.contains($0) }) {
return urlMap[matchingKey]
if let ecosiaBundleDomain = EcosiaURLProvider.getBundleDomain(for: domain) {
return ecosiaBundleDomain
} else {
return domain.bundleDomains.first(where: { bundledImages[$0] != nil })
}
return domain.bundleDomains.first(where: { bundledImages[$0] != nil })
}

private func retrieveBundledImages() -> [String: FormattedBundledImage] {
Expand Down Expand Up @@ -163,3 +155,86 @@ class DefaultBundleImageFetcher: BundleImageFetcher {
return UIGraphicsGetImageFromCurrentImageContext() ?? image
}
}
/* Ecosia
There was an annoying dependency on Core in BrowserKit as part of the BundleImageFetcher.swift that would lead to a flaky build step.
This is noticeable especially when checking out between branches without cleaning up your DerivedData.
With the advent of our EcosiaFramework, this flakiness became even more noticeable. To get a Build Successful, you had to first // comment out the Ecosia-related code as part of that file, let it build, uncomment, and build again.
This process is far from being ideal and we want as less dependencies/code changes in BrowserKit as possible.

After spending a considerable amount of time looking for a robust solution, I realized that the best approach in this very niche scenario would be to directly implement a part of our Ecosia.Environment.swift directly in the file.
I'm conscious this is not ideal, but that's the only approach so far that guarantees the expected Favicon's workaround to work solidly.
*/
struct EcosiaURLProvider {

// Static variables for privacy and financial reports URLs
static let privacyURL = URL(string: "https://www.ecosia.org/privacy")!

static var financialReportsURL: URL {
let blog: URL!

switch Language.current {
case .de:
blog = URL(string: "https://de.blog.ecosia.org/")!
case .fr:
blog = URL(string: "https://fr.blog.ecosia.org/")!
default:
blog = URL(string: "https://blog.ecosia.org/")!
}

switch Language.current {
case .de:
return blog.appendingPathComponent("ecosia-finanzberichte-baumplanzbelege/")
case .fr:
return blog.appendingPathComponent("rapports-financiers-recus-de-plantations-arbres/")
default:
return blog.appendingPathComponent("ecosia-financial-reports-tree-planting-receipts/")
}
}

// Utility function to create a domain part from URL (removes "https://")
private static func getURLDomain(_ url: URL) -> String {
return url.absoluteString.replacingOccurrences(of: "https://", with: "")
}

// Static method to get the appropriate bundle domain
static func getBundleDomain(for domain: ImageDomain) -> String? {
let financialReportsDomain = getURLDomain(financialReportsURL)
let privacyDomain = getURLDomain(privacyURL)

let urlMap: [String: String] = [
financialReportsDomain: "blog.ecosia.finance",
privacyDomain: "privacy.ecosia"
]

// Check for the first matching domain
if let matchingKey = urlMap.keys.first(where: { domain.bundleDomains.contains($0) }) {
return urlMap[matchingKey]
}

return nil
}

public enum Language: String, Codable, CaseIterable {
case
de,
en,
fr

public internal(set) static var current = make(for: .current)

private static let queue = DispatchQueue(label: "\(Bundle.main.bundleIdentifier!).LanguageQueue")
static func make(for locale: Locale) -> Self {
return queue.sync {
locale.withLanguage ?? .en
}
}
}
}

private extension Locale {
var withLanguage: EcosiaURLProvider.Language? {
languageCode.flatMap {
EcosiaURLProvider.Language(rawValue: $0.lowercased())
}
}
}
Loading
Loading