From 21bc816e9beccc014925653b0756017761c63a77 Mon Sep 17 00:00:00 2001 From: Elena Willen Date: Wed, 8 May 2024 13:11:09 +0200 Subject: [PATCH 1/9] fix: Do not present aiDiscovery for macOS --- Mail/Views/New Message/ComposeMessageView.swift | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Mail/Views/New Message/ComposeMessageView.swift b/Mail/Views/New Message/ComposeMessageView.swift index 8e2c8310a..d37478303 100644 --- a/Mail/Views/New Message/ComposeMessageView.swift +++ b/Mail/Views/New Message/ComposeMessageView.swift @@ -272,10 +272,12 @@ struct ComposeMessageView: View { } } .discoveryPresenter(isPresented: $aiModel.isShowingDiscovery) { - DiscoveryView(item: .aiDiscovery) { - UserDefaults.shared.shouldPresentAIFeature = false - } completionHandler: { willShowAIPrompt in - aiModel.isShowingPrompt = willShowAIPrompt + if !platformDetector.isMac { + DiscoveryView(item: .aiDiscovery) { + UserDefaults.shared.shouldPresentAIFeature = false + } completionHandler: { willShowAIPrompt in + aiModel.isShowingPrompt = willShowAIPrompt + } } } .aiPromptPresenter(isPresented: $aiModel.isShowingPrompt) { From 426fbd2a54e0d7502f5d61bc8642681a6da2691b Mon Sep 17 00:00:00 2001 From: Elena Willen Date: Wed, 8 May 2024 13:11:37 +0200 Subject: [PATCH 2/9] fix: Remove AI settings for macOS --- Mail/Views/Settings/SettingsView.swift | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Mail/Views/Settings/SettingsView.swift b/Mail/Views/Settings/SettingsView.swift index 232b135b8..9fed4498d 100644 --- a/Mail/Views/Settings/SettingsView.swift +++ b/Mail/Views/Settings/SettingsView.swift @@ -103,9 +103,11 @@ struct SettingsView: View { // MARK: AI Writer - if featureFlagsManageable.isEnabled(.aiMailComposer) { - SettingsSubMenuCell(title: MailResourcesStrings.Localizable.aiPromptTitle, subtitle: aiEngine.title) { - SettingsAIEngineOptionView() + if !platformDetector.isMac { + if featureFlagsManageable.isEnabled(.aiMailComposer) { + SettingsSubMenuCell(title: MailResourcesStrings.Localizable.aiPromptTitle, subtitle: aiEngine.title) { + SettingsAIEngineOptionView() + } } } From bfe1157bf9346e86b78aab223ff9ef6d10010a99 Mon Sep 17 00:00:00 2001 From: Elena Willen Date: Wed, 8 May 2024 13:39:59 +0200 Subject: [PATCH 3/9] fix: Do not present syncDiscovery for macOS --- Mail/Views/SplitView.swift | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Mail/Views/SplitView.swift b/Mail/Views/SplitView.swift index 9ece5f388..68cdb1575 100644 --- a/Mail/Views/SplitView.swift +++ b/Mail/Views/SplitView.swift @@ -124,11 +124,13 @@ struct SplitView: View { } } .discoveryPresenter(isPresented: $mainViewState.isShowingSyncDiscovery) { - DiscoveryView(item: .syncDiscovery) { - UserDefaults.shared.shouldPresentSyncDiscovery = false - } completionHandler: { willSync in - guard willSync else { return } - mainViewState.isShowingSyncProfile = true + if !platformDetector.isMac { + DiscoveryView(item: .syncDiscovery) { + UserDefaults.shared.shouldPresentSyncDiscovery = false + } completionHandler: { willSync in + guard willSync else { return } + mainViewState.isShowingSyncProfile = true + } } } .discoveryPresenter(isPresented: $mainViewState.isShowingSetAppAsDefaultDiscovery) { From 4829f6c1313ed2e2163dc47fc5ab8e5fbbcdca30 Mon Sep 17 00:00:00 2001 From: Elena Willen Date: Wed, 8 May 2024 13:40:35 +0200 Subject: [PATCH 4/9] fix: Remove sync from settings for macOS --- Mail/Views/Settings/SettingsView.swift | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Mail/Views/Settings/SettingsView.swift b/Mail/Views/Settings/SettingsView.swift index 9fed4498d..d605345d8 100644 --- a/Mail/Views/Settings/SettingsView.swift +++ b/Mail/Views/Settings/SettingsView.swift @@ -89,17 +89,19 @@ struct SettingsView: View { // MARK: Sync Calendar/Contacts - Button { - matomo.track(eventWithCategory: .syncAutoConfig, name: "openFromSettings") - if platformDetector.isMac { - isShowingSyncProfile = true - } else { - mainViewState.isShowingSyncProfile = true + if !platformDetector.isMac { + Button { + matomo.track(eventWithCategory: .syncAutoConfig, name: "openFromSettings") + if platformDetector.isMac { + isShowingSyncProfile = true + } else { + mainViewState.isShowingSyncProfile = true + } + } label: { + SettingsSubMenuLabel(title: MailResourcesStrings.Localizable.syncCalendarsAndContactsTitle) } - } label: { - SettingsSubMenuLabel(title: MailResourcesStrings.Localizable.syncCalendarsAndContactsTitle) + .buttonStyle(.plain) } - .buttonStyle(.plain) // MARK: AI Writer From 4935959e62f339daad4b436b8710ce7729e65e7f Mon Sep 17 00:00:00 2001 From: Elena Willen Date: Tue, 21 May 2024 13:10:36 +0200 Subject: [PATCH 5/9] fix: Set isShowingDiscovery to false instead of hiding the view --- Mail/Views/New Message/ComposeMessageView.swift | 12 +++++------- Mail/Views/SplitView.swift | 14 ++++++-------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/Mail/Views/New Message/ComposeMessageView.swift b/Mail/Views/New Message/ComposeMessageView.swift index d37478303..cc96822bd 100644 --- a/Mail/Views/New Message/ComposeMessageView.swift +++ b/Mail/Views/New Message/ComposeMessageView.swift @@ -231,7 +231,7 @@ struct ComposeMessageView: View { initialAttachments = [] if featureFlagsManager.isEnabled(.aiMailComposer) && UserDefaults.shared.shouldPresentAIFeature { - aiModel.isShowingDiscovery = true + aiModel.isShowingDiscovery = platformDetector.isMac ? false : true return } @@ -272,12 +272,10 @@ struct ComposeMessageView: View { } } .discoveryPresenter(isPresented: $aiModel.isShowingDiscovery) { - if !platformDetector.isMac { - DiscoveryView(item: .aiDiscovery) { - UserDefaults.shared.shouldPresentAIFeature = false - } completionHandler: { willShowAIPrompt in - aiModel.isShowingPrompt = willShowAIPrompt - } + DiscoveryView(item: .aiDiscovery) { + UserDefaults.shared.shouldPresentAIFeature = false + } completionHandler: { willShowAIPrompt in + aiModel.isShowingPrompt = willShowAIPrompt } } .aiPromptPresenter(isPresented: $aiModel.isShowingPrompt) { diff --git a/Mail/Views/SplitView.swift b/Mail/Views/SplitView.swift index 68cdb1575..617fdaf74 100644 --- a/Mail/Views/SplitView.swift +++ b/Mail/Views/SplitView.swift @@ -124,13 +124,11 @@ struct SplitView: View { } } .discoveryPresenter(isPresented: $mainViewState.isShowingSyncDiscovery) { - if !platformDetector.isMac { - DiscoveryView(item: .syncDiscovery) { - UserDefaults.shared.shouldPresentSyncDiscovery = false - } completionHandler: { willSync in - guard willSync else { return } - mainViewState.isShowingSyncProfile = true - } + DiscoveryView(item: .syncDiscovery) { + UserDefaults.shared.shouldPresentSyncDiscovery = false + } completionHandler: { willSync in + guard willSync else { return } + mainViewState.isShowingSyncProfile = true } } .discoveryPresenter(isPresented: $mainViewState.isShowingSetAppAsDefaultDiscovery) { @@ -167,7 +165,7 @@ struct SplitView: View { try await mailboxManager.refreshAllSignatures() } guard !platformDetector.isDebug else { return } - mainViewState.isShowingSyncDiscovery = shouldShowSync() + mainViewState.isShowingSyncDiscovery = platformDetector.isMac ? false : shouldShowSync() } } .onOpenURL { url in From 0ef2957b216d0a7e898c2c9da12d3c2530a9b8ef Mon Sep 17 00:00:00 2001 From: Elena Willen Date: Wed, 22 May 2024 10:36:44 +0200 Subject: [PATCH 6/9] fix: Use FeatureFlagsManager to check if isEnabledLocally --- Mail/Views/New Message/ComposeMessageView.swift | 2 +- Mail/Views/Settings/SettingsView.swift | 17 +++++------------ Mail/Views/SplitView.swift | 3 ++- MailCore/Utils/FeatureFlagsManageable.swift | 3 +++ MailCore/Utils/FeatureFlagsManager.swift | 11 +++++++++++ 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/Mail/Views/New Message/ComposeMessageView.swift b/Mail/Views/New Message/ComposeMessageView.swift index cc96822bd..8136cd143 100644 --- a/Mail/Views/New Message/ComposeMessageView.swift +++ b/Mail/Views/New Message/ComposeMessageView.swift @@ -231,7 +231,7 @@ struct ComposeMessageView: View { initialAttachments = [] if featureFlagsManager.isEnabled(.aiMailComposer) && UserDefaults.shared.shouldPresentAIFeature { - aiModel.isShowingDiscovery = platformDetector.isMac ? false : true + aiModel.isShowingDiscovery = featureFlagsManager.isEnabledLocally(.aiMailComposer) ? true : false return } diff --git a/Mail/Views/Settings/SettingsView.swift b/Mail/Views/Settings/SettingsView.swift index d605345d8..6f7d6ad3f 100644 --- a/Mail/Views/Settings/SettingsView.swift +++ b/Mail/Views/Settings/SettingsView.swift @@ -30,7 +30,6 @@ struct SettingsView: View { @LazyInjectService private var appLockHelper: AppLockHelper @LazyInjectService private var featureFlagsManageable: FeatureFlagsManageable @LazyInjectService private var matomo: MatomoUtils - @LazyInjectService private var platformDetector: PlatformDetectable @EnvironmentObject private var mailboxManager: MailboxManager @EnvironmentObject private var mainViewState: MainViewState @@ -89,14 +88,10 @@ struct SettingsView: View { // MARK: Sync Calendar/Contacts - if !platformDetector.isMac { + if featureFlagsManageable.isEnabledLocally(.syncCalendarAndContacts) { Button { matomo.track(eventWithCategory: .syncAutoConfig, name: "openFromSettings") - if platformDetector.isMac { - isShowingSyncProfile = true - } else { - mainViewState.isShowingSyncProfile = true - } + mainViewState.isShowingSyncProfile = true } label: { SettingsSubMenuLabel(title: MailResourcesStrings.Localizable.syncCalendarsAndContactsTitle) } @@ -105,11 +100,9 @@ struct SettingsView: View { // MARK: AI Writer - if !platformDetector.isMac { - if featureFlagsManageable.isEnabled(.aiMailComposer) { - SettingsSubMenuCell(title: MailResourcesStrings.Localizable.aiPromptTitle, subtitle: aiEngine.title) { - SettingsAIEngineOptionView() - } + if featureFlagsManageable.isEnabled(.aiMailComposer) && featureFlagsManageable.isEnabledLocally(.aiMailComposer) { + SettingsSubMenuCell(title: MailResourcesStrings.Localizable.aiPromptTitle, subtitle: aiEngine.title) { + SettingsAIEngineOptionView() } } diff --git a/Mail/Views/SplitView.swift b/Mail/Views/SplitView.swift index 617fdaf74..5d61ef6c5 100644 --- a/Mail/Views/SplitView.swift +++ b/Mail/Views/SplitView.swift @@ -63,6 +63,7 @@ struct SplitView: View { @LazyInjectService private var snackbarPresenter: SnackBarPresentable @LazyInjectService private var platformDetector: PlatformDetectable @LazyInjectService private var appLaunchCounter: AppLaunchCounter + @LazyInjectService private var featureFlagsManageable: FeatureFlagsManageable let mailboxManager: MailboxManager @@ -165,7 +166,7 @@ struct SplitView: View { try await mailboxManager.refreshAllSignatures() } guard !platformDetector.isDebug else { return } - mainViewState.isShowingSyncDiscovery = platformDetector.isMac ? false : shouldShowSync() + mainViewState.isShowingSyncDiscovery = featureFlagsManageable.isEnabledLocally(.syncCalendarAndContacts) ? shouldShowSync() : false } } .onOpenURL { url in diff --git a/MailCore/Utils/FeatureFlagsManageable.swift b/MailCore/Utils/FeatureFlagsManageable.swift index 82d8e1c98..079c1b185 100644 --- a/MailCore/Utils/FeatureFlagsManageable.swift +++ b/MailCore/Utils/FeatureFlagsManageable.swift @@ -27,6 +27,9 @@ public protocol FeatureFlagsManageable { /// Check if a given feature is enabled for the current mailbox func isEnabled(_ feature: FeatureFlag) -> Bool + /// Check if a given feature has locals constraints + func isEnabledLocally(_ feature: FeatureFlag) -> Bool + /// Execute the correct closure depending if a given feature is enabled or not for the current mailbox func feature(_ feature: FeatureFlag, on: () -> Void, off: (() -> Void)?) diff --git a/MailCore/Utils/FeatureFlagsManager.swift b/MailCore/Utils/FeatureFlagsManager.swift index c9271c26f..f7ec27dc5 100644 --- a/MailCore/Utils/FeatureFlagsManager.swift +++ b/MailCore/Utils/FeatureFlagsManager.swift @@ -26,6 +26,7 @@ import SwiftUI public enum FeatureFlag: String, Codable { case aiMailComposer = "ai-mail-composer" case bimi + case syncCalendarAndContacts case unknown public init(from decoder: Decoder) throws { @@ -46,6 +47,7 @@ public enum FeatureFlag: String, Codable { public final class FeatureFlagsManager: FeatureFlagsManageable { @LazyInjectService private var accountManager: AccountManager + @LazyInjectService private var platformDetector: PlatformDetectable private var enabledFeatures: SendableDictionary @@ -59,6 +61,15 @@ public final class FeatureFlagsManager: FeatureFlagsManageable { return userFeatures.contains(feature) } + public func isEnabledLocally(_ feature: FeatureFlag) -> Bool { + switch feature { + case .aiMailComposer, .syncCalendarAndContacts: + return platformDetector.isMac ? false : true + default: + return true + } + } + public func feature(_ feature: FeatureFlag, on: () -> Void, off: (() -> Void)?) { if isEnabled(feature) { on() From 1d40a3a38a3a59aea128a7fefbc10cfcd3d8c17c Mon Sep 17 00:00:00 2001 From: Elena Willen Date: Wed, 22 May 2024 11:19:16 +0200 Subject: [PATCH 7/9] fix: Feedbacks --- Mail/Views/New Message/ComposeMessageView.swift | 2 +- Mail/Views/Settings/SettingsView.swift | 5 +++-- Mail/Views/SplitView.swift | 2 +- MailCore/Utils/FeatureFlagsManageable.swift | 3 --- MailCore/Utils/FeatureFlagsManager.swift | 8 +++++--- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Mail/Views/New Message/ComposeMessageView.swift b/Mail/Views/New Message/ComposeMessageView.swift index 8136cd143..8e2c8310a 100644 --- a/Mail/Views/New Message/ComposeMessageView.swift +++ b/Mail/Views/New Message/ComposeMessageView.swift @@ -231,7 +231,7 @@ struct ComposeMessageView: View { initialAttachments = [] if featureFlagsManager.isEnabled(.aiMailComposer) && UserDefaults.shared.shouldPresentAIFeature { - aiModel.isShowingDiscovery = featureFlagsManager.isEnabledLocally(.aiMailComposer) ? true : false + aiModel.isShowingDiscovery = true return } diff --git a/Mail/Views/Settings/SettingsView.swift b/Mail/Views/Settings/SettingsView.swift index 6f7d6ad3f..dd5323b4c 100644 --- a/Mail/Views/Settings/SettingsView.swift +++ b/Mail/Views/Settings/SettingsView.swift @@ -30,6 +30,7 @@ struct SettingsView: View { @LazyInjectService private var appLockHelper: AppLockHelper @LazyInjectService private var featureFlagsManageable: FeatureFlagsManageable @LazyInjectService private var matomo: MatomoUtils + @LazyInjectService private var platformDetector: PlatformDetectable @EnvironmentObject private var mailboxManager: MailboxManager @EnvironmentObject private var mainViewState: MainViewState @@ -88,7 +89,7 @@ struct SettingsView: View { // MARK: Sync Calendar/Contacts - if featureFlagsManageable.isEnabledLocally(.syncCalendarAndContacts) { + if !platformDetector.isMac { Button { matomo.track(eventWithCategory: .syncAutoConfig, name: "openFromSettings") mainViewState.isShowingSyncProfile = true @@ -100,7 +101,7 @@ struct SettingsView: View { // MARK: AI Writer - if featureFlagsManageable.isEnabled(.aiMailComposer) && featureFlagsManageable.isEnabledLocally(.aiMailComposer) { + if featureFlagsManageable.isEnabled(.aiMailComposer) { SettingsSubMenuCell(title: MailResourcesStrings.Localizable.aiPromptTitle, subtitle: aiEngine.title) { SettingsAIEngineOptionView() } diff --git a/Mail/Views/SplitView.swift b/Mail/Views/SplitView.swift index 5d61ef6c5..c3fb72682 100644 --- a/Mail/Views/SplitView.swift +++ b/Mail/Views/SplitView.swift @@ -166,7 +166,7 @@ struct SplitView: View { try await mailboxManager.refreshAllSignatures() } guard !platformDetector.isDebug else { return } - mainViewState.isShowingSyncDiscovery = featureFlagsManageable.isEnabledLocally(.syncCalendarAndContacts) ? shouldShowSync() : false + mainViewState.isShowingSyncDiscovery = platformDetector.isMac ? false : shouldShowSync() } } .onOpenURL { url in diff --git a/MailCore/Utils/FeatureFlagsManageable.swift b/MailCore/Utils/FeatureFlagsManageable.swift index 079c1b185..82d8e1c98 100644 --- a/MailCore/Utils/FeatureFlagsManageable.swift +++ b/MailCore/Utils/FeatureFlagsManageable.swift @@ -27,9 +27,6 @@ public protocol FeatureFlagsManageable { /// Check if a given feature is enabled for the current mailbox func isEnabled(_ feature: FeatureFlag) -> Bool - /// Check if a given feature has locals constraints - func isEnabledLocally(_ feature: FeatureFlag) -> Bool - /// Execute the correct closure depending if a given feature is enabled or not for the current mailbox func feature(_ feature: FeatureFlag, on: () -> Void, off: (() -> Void)?) diff --git a/MailCore/Utils/FeatureFlagsManager.swift b/MailCore/Utils/FeatureFlagsManager.swift index f7ec27dc5..f752c5677 100644 --- a/MailCore/Utils/FeatureFlagsManager.swift +++ b/MailCore/Utils/FeatureFlagsManager.swift @@ -26,7 +26,6 @@ import SwiftUI public enum FeatureFlag: String, Codable { case aiMailComposer = "ai-mail-composer" case bimi - case syncCalendarAndContacts case unknown public init(from decoder: Decoder) throws { @@ -56,14 +55,17 @@ public final class FeatureFlagsManager: FeatureFlagsManageable { } public func isEnabled(_ feature: FeatureFlag) -> Bool { + guard isEnabledLocally(feature) else { return false } + guard let mailboxUUID = accountManager.currentMailboxManager?.mailbox.uuid, let userFeatures = enabledFeatures.value(for: mailboxUUID) else { return false } + return userFeatures.contains(feature) } - public func isEnabledLocally(_ feature: FeatureFlag) -> Bool { + private func isEnabledLocally(_ feature: FeatureFlag) -> Bool { switch feature { - case .aiMailComposer, .syncCalendarAndContacts: + case .aiMailComposer: return platformDetector.isMac ? false : true default: return true From dcf692d3d29493c3fba55d4a6f34ba6662acc554 Mon Sep 17 00:00:00 2001 From: Elena Willen Date: Wed, 22 May 2024 11:27:05 +0200 Subject: [PATCH 8/9] fix: Remove syncCalendar from MenuDrawer if isMac --- .../Items/MenuDrawerItemsListView.swift | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Mail/Views/Menu Drawer/Items/MenuDrawerItemsListView.swift b/Mail/Views/Menu Drawer/Items/MenuDrawerItemsListView.swift index 9671fe483..0e78a9bc6 100644 --- a/Mail/Views/Menu Drawer/Items/MenuDrawerItemsListView.swift +++ b/Mail/Views/Menu Drawer/Items/MenuDrawerItemsListView.swift @@ -30,6 +30,7 @@ struct MenuDrawerItemsAdvancedListView: View { @EnvironmentObject private var mainViewState: MainViewState @LazyInjectService private var matomo: MatomoUtils + @LazyInjectService private var platformDetector: PlatformDetectable @Environment(\.openURL) private var openURL @@ -40,11 +41,13 @@ struct MenuDrawerItemsAdvancedListView: View { var body: some View { MenuDrawerItemsListView(title: MailResourcesStrings.Localizable.menuDrawerAdvancedActions, matomoName: "advancedActions") { - MenuDrawerItemCell(icon: MailResourcesAsset.doubleArrowsSynchronize, - label: MailResourcesStrings.Localizable.syncCalendarsAndContactsTitle, - matomoName: "syncProfile") { - matomo.track(eventWithCategory: .syncAutoConfig, name: "openFromMenuDrawer") - mainViewState.isShowingSyncProfile = true + if !platformDetector.isMac { + MenuDrawerItemCell(icon: MailResourcesAsset.doubleArrowsSynchronize, + label: MailResourcesStrings.Localizable.syncCalendarsAndContactsTitle, + matomoName: "syncProfile") { + matomo.track(eventWithCategory: .syncAutoConfig, name: "openFromMenuDrawer") + mainViewState.isShowingSyncProfile = true + } } MenuDrawerItemCell(icon: MailResourcesAsset.drawerDownload, @@ -52,6 +55,7 @@ struct MenuDrawerItemsAdvancedListView: View { matomoName: "importEmails") { openURL(URLConstants.importMails.url) } + if mailboxCanRestoreEmails { MenuDrawerItemCell( icon: MailResourcesAsset.restoreArrow, From cf1ecf11410bb48b1cca5c37adc473ba81734ab9 Mon Sep 17 00:00:00 2001 From: Elena Willen Date: Wed, 22 May 2024 11:46:46 +0200 Subject: [PATCH 9/9] fix: Feedbacks --- MailCore/Utils/FeatureFlagsManager.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MailCore/Utils/FeatureFlagsManager.swift b/MailCore/Utils/FeatureFlagsManager.swift index f752c5677..24936600b 100644 --- a/MailCore/Utils/FeatureFlagsManager.swift +++ b/MailCore/Utils/FeatureFlagsManager.swift @@ -66,7 +66,7 @@ public final class FeatureFlagsManager: FeatureFlagsManageable { private func isEnabledLocally(_ feature: FeatureFlag) -> Bool { switch feature { case .aiMailComposer: - return platformDetector.isMac ? false : true + return !platformDetector.isMac default: return true }