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

Refactor FXIOS-9331 [Theming] Fix ThemeManager issues #20667

Merged
merged 11 commits into from
Jun 17, 2024

Conversation

adudenamedruby
Copy link
Contributor

@adudenamedruby adudenamedruby commented Jun 14, 2024

📜 Tickets

Jira ticket
Github issue

💡 Description

OK. So, I was fixing a bug, and then another bug would pop up. I got tired of it, and decided to fix everything in one go by fixing the underlying logic of the theming system.

Changes of note:

  • If you want to do something theming related, now you use the appropriate, clearly-named function, instead of the confusing chain of oddly-named function calls from before
  • Standardized function naming re: get & set
  • determineThemeType(for... is now the heart of the theming system when it comes to deciding what theme needs to be shown instead of managing that in a bunch of different places
  • Removed windowThemeState 🎉
  • Removed the use of window throughout the theming system as much as possible. window is really only needed for private mode stuff, but it started getting introduced in a bunch of places because of the chain calls. I've just simplified this to only the stuff needed 🥳
  • Refactored the theme settings middleware to 1) adapt to the new changes, and b) make it easier to read 🤓

For review:
The bulk of the meaningful changes are in DefaultThemeManager and in ThemeMiddleware. Everything else is mostly updates from naming and such.

📝 Checklist

You have to check all boxes before merging

  • Filled in the above information (tickets numbers and description of your work)
  • Updated the PR name to follow our PR naming guidelines
  • Wrote unit tests and/or ensured the tests suite is passing
  • When working on UI, I checked and implemented accessibility (minimum Dynamic Text and VoiceOver)
  • If needed, I updated documentation / comments for complex code and public methods
  • If needed, added a backport comment (example @Mergifyio backport release/v120)

@mobiletest-ci-bot
Copy link

mobiletest-ci-bot commented Jun 14, 2024

Warnings
⚠️ Pull Request size seems relatively large. If this Pull Request contains multiple changes, please split each into separate PR will helps faster, easier review. Consider using epic branches for work that would affect main.
Messages
📖 Project coverage: 32.1%
📖 Edited 127 files
📖 Created 0 files

Client.app: Coverage: 30.74

File Coverage
SiriSettingsViewController.swift 11.54% ⚠️
ThemedTableViewController.swift 58.02%
AddressAutofillSettingsViewController.swift 26.23% ⚠️
LegacyTabTrayViewController.swift 16.26% ⚠️
CustomSearchViewController.swift 16.83% ⚠️
SearchBarSetting.swift 0.0% ⚠️
FirefoxAccountSignInViewController.swift 32.89% ⚠️
AdvancedAccountSettingViewController.swift 0.0% ⚠️
ThemedDefaultNavigationController.swift 0.0% ⚠️
BrowserViewController.swift 4.16% ⚠️
ShareExtensionCoordinator.swift 30.77% ⚠️
EnhancedTrackingProtectionVC.swift 28.78% ⚠️
PasswordManagerOnboardingViewController.swift 12.21% ⚠️
AddCredentialViewController.swift 2.58% ⚠️
SearchGroupedItemsViewController.swift 4.95% ⚠️
AddressAutoFillBottomSheetView.swift 0.0% ⚠️
SearchEnginePicker.swift 0.0% ⚠️
UpdateViewController.swift 3.85% ⚠️
ReaderPanel.swift 45.2% ⚠️
SettingsTableViewController.swift 25.95% ⚠️
HistoryPanel.swift 37.66% ⚠️
OnboardingInstructionPopupViewController.swift 0.0% ⚠️
TopTabsViewController.swift 0.0% ⚠️
SettingsContentViewController.swift 4.97% ⚠️
LegacyRemoteTabsPanel.swift 64.0%
HomepageViewController.swift 36.75% ⚠️
AutofillCreditCardSettings.swift 0.0% ⚠️
LoginListView.swift 71.95%
MicrosurveyViewController.swift 74.37%
OnboardingMultipleChoiceButtonView.swift 0.0% ⚠️
PhotonActionSheet.swift 27.0% ⚠️
HomePageSettingViewController.swift 5.88% ⚠️
TabDisplayPanel.swift 16.06% ⚠️
RemoveCardButton.swift 0.0% ⚠️
LibraryViewController.swift 44.63% ⚠️
AppSettingsTableViewController.swift 23.82% ⚠️
BackForwardListViewController.swift 12.97% ⚠️
ClearPrivateDataSetting.swift 0.0% ⚠️
MainMenuActionHelper.swift 41.54% ⚠️
EnhancedTrackingProtectionDetailsVC.swift 0.0% ⚠️
AddressCellView.swift 0.0% ⚠️
AutofillHeaderView.swift 100.0%
AddressScrollView.swift 0.0% ⚠️
BookmarksPanel.swift 39.47% ⚠️
SurveySurfaceViewController.swift 3.72% ⚠️
WebsiteDataManagementViewController.swift 0.0% ⚠️
WebsiteDataSearchResultsViewController.swift 0.0% ⚠️
SearchViewController.swift 23.98% ⚠️
SiriPageSetting.swift 0.0% ⚠️
CredentialAutofillCoordinator.swift 76.82%
ReaderModeStyleViewController.swift 0.0% ⚠️
SettingsViewController.swift 36.36% ⚠️
LegacyGridTabViewController.swift 11.97% ⚠️
ShowIntroductionSetting.swift 0.0% ⚠️
RemoteTabsTableViewController.swift 54.32%
CreditCardSettingsEmptyView.swift 1.73% ⚠️
AddressListViewModel.swift 76.81%
CircularProgressView.swift 0.0% ⚠️
FakespotViewController.swift 4.44% ⚠️
ReaderMode.swift 38.35% ⚠️
AccessoryViewProvider.swift 72.52%
LoginCellView.swift 0.0% ⚠️
WallpaperSelectorViewController.swift 0.0% ⚠️
OpenWithSettingsViewController.swift 4.29% ⚠️
PasswordManagerSetting.swift 0.0% ⚠️
SettingsNavigationController.swift 76.6%
PasswordManagerListViewController.swift 31.46% ⚠️
DevicePasscodeRequiredViewController.swift 18.84% ⚠️
DownloadsPanel.swift 37.88% ⚠️
SearchSetting.swift 0.0% ⚠️
SyncContentSettingsViewController.swift 50.87%
BrowserViewController+ReaderMode.swift 0.0% ⚠️
PhotonActionSheetProtocol.swift 2.11% ⚠️
AddressAutofillToggle.swift 0.0% ⚠️
SceneSetupHelper.swift 72.5%
AutofillFooterView.swift 100.0%
TabLocationView.swift 41.45% ⚠️
OnboardingCardDelegate.swift 15.0% ⚠️
TPAccessoryInfo.swift 0.0% ⚠️
TabTrayViewController.swift 66.51%
CreditCardInputField.swift 30.05% ⚠️
ThemeSettingsController.swift 36.51% ⚠️
LoginAutofillView.swift 98.04%
RemoteTabsPanel.swift 28.33% ⚠️
OpenWithSetting.swift 0.0% ⚠️
DefaultBrowserOnboardingViewController.swift 3.4% ⚠️
PrivacyPolicyViewController.swift 0.0% ⚠️
OnboardingCardViewController.swift 94.87%
CreditCardSectionHeader.swift 0.0% ⚠️
SiteTableViewController.swift 57.45%
CreditCardTableViewController.swift 6.67% ⚠️
BrowserViewController+ZoomPage.swift 9.89% ⚠️
ClearPrivateDataTableViewController.swift 5.15% ⚠️
NewTabPageSetting.swift 0.0% ⚠️
CreditCardAutofillToggle.swift 8.42% ⚠️
AddressListView.swift 0.0% ⚠️
ThemeMiddleware.swift 72.53%
AddressAutofillSettingsView.swift 0.0% ⚠️
IntroViewController.swift 41.09% ⚠️
SettingsCoordinator.swift 93.85%
HomeSetting.swift 0.0% ⚠️
CreditCardBottomSheetViewController.swift 58.99%
WallpaperSettingsViewController.swift 2.65% ⚠️
EditAddressViewController.swift 0.0% ⚠️
HistoryActionables.swift 43.75% ⚠️
RecentlyClosedTabsPanel.swift 6.52% ⚠️
TopSitesSettingsViewController.swift 10.14% ⚠️
PrivateHomepageViewController.swift 5.88% ⚠️
SearchSettingsTableViewController.swift 1.72% ⚠️
CreditCardInputView.swift 0.0% ⚠️
CreditCardSettingsViewController.swift 9.96% ⚠️
PasswordDetailViewController.swift 2.57% ⚠️
LegacyRemoteTabsTableViewController.swift 71.94%
ContextualHintViewController.swift 7.43% ⚠️
FirefoxSuggestSettingsViewController.swift 0.0% ⚠️
BookmarkDetailPanel.swift 22.59% ⚠️
CreditCardItemRow.swift 0.0% ⚠️

Generated by 🚫 Danger Swift against e366b5f

Comment on lines 178 to 179
private func migrateSingleWindowPrivateDefaultsToMultiWindow(for window: WindowUUID) {
// Migrate old private setting to our window-based settings
Copy link
Collaborator

@mattreaganmozilla mattreaganmozilla Jun 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we may be able to remove this migration code and persisted state entirely? IIRC this persisted state was to keep track of private mode between app launches, but now I think we've updated the iOS client to always clear private tabs on launch. And I believe the related setting for that has also been removed. (Though we should double-check, maybe all of this is still behind an experiment. I also have seen several user reviews already complaining about that change so we'd want to confirm with Product whether it's permanent or not.)

But if we have decided 100% to remove all of that, then I think we can also remove this migration and persisted state, since the app will never launch with any windows in Private mode.

I'd definitely like to get confirmation on that from someone who is a bit more in-the-loop on that however. (cc @OrlaM)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I can make a note to fully look into this afterward, but I feel like this shouldn't be a blocker for merging this PR. It's easily removed later.

Copy link
Contributor

mergify bot commented Jun 14, 2024

This pull request has conflicts when rebasing. Could you fix it @adudenamedruby? 🙏

@adudenamedruby
Copy link
Contributor Author

When this is approved., could you also merge it, please, as I'm gone for the wknd now.

Copy link
Collaborator

@mattreaganmozilla mattreaganmozilla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adudenamedruby I did a quick smoke test and only saw one issue which is the flash of Private theme during launch, but that's already happening on main also AFAICS. Removing the use of user defaults might be a nice follow-up if we can confirm it's no longer needed.

Probably wouldn't hurt to get additional eyes on this just as a sanity check, but otherwise LGTM. :shipit:


var settings: KeyedPrivateModeFlags
= userDefaults.object(forKey: ThemeKeys.PrivateMode.byWindowUUID) as? KeyedPrivateModeFlags ?? [:]

settings[window.uuidString] = NSNumber(value: isOn)
userDefaults.set(settings, forKey: ThemeKeys.PrivateMode.byWindowUUID)

updateCurrentTheme(to: fetchSavedThemeType(for: window), for: window)
applyThemeChanges(for: window, using: determineThemeType(for: window))
}

public func getPrivateThemeIsOn(for window: WindowUUID) -> Bool {
let settings = userDefaults.object(forKey: ThemeKeys.PrivateMode.byWindowUUID) as? KeyedPrivateModeFlags
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't need to block the PR but we probably don't need to store this in UserDefaults any longer, and changing it might also fix this issue where the windows are rendering briefly in Private theme incorrectly during launch:

launch_flash.mov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants