From 1aff698e91d6e675989c1fadcbc7c87db9d48cb3 Mon Sep 17 00:00:00 2001 From: Garvan Keeley Date: Wed, 20 May 2020 09:54:21 -0400 Subject: [PATCH] Fix #6559: China server switch should not hide when logged-in to FxA (#6633) * Fix #6559: China server switch should not hide when logged-in to FxA * add telemetry to tapping the switch --- .../Settings/AppSettingsOptions.swift | 37 +++++++++++++++++-- Client/Telemetry/UnifiedTelemetry.swift | 1 + 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/Client/Frontend/Settings/AppSettingsOptions.swift b/Client/Frontend/Settings/AppSettingsOptions.swift index 4b4c257caf14..2f67bff9c522 100644 --- a/Client/Frontend/Settings/AppSettingsOptions.swift +++ b/Client/Frontend/Settings/AppSettingsOptions.swift @@ -878,10 +878,14 @@ class PrivacyPolicySetting: Setting { } } -class ChinaSyncServiceSetting: WithoutAccountSetting { +class ChinaSyncServiceSetting: Setting { override var accessoryType: UITableViewCell.AccessoryType { return .none } - var prefs: Prefs { return settings.profile.prefs } + var prefs: Prefs { return profile.prefs } let prefKey = "useChinaSyncService" + let profile: Profile + let settings: UIViewController + + override var hidden: Bool { return !AppInfo.isChinaEdition } override var title: NSAttributedString? { return NSAttributedString(string: "本地同步服务", attributes: [NSAttributedString.Key.foregroundColor: UIColor.theme.tableView.rowText]) @@ -891,6 +895,11 @@ class ChinaSyncServiceSetting: WithoutAccountSetting { return NSAttributedString(string: "禁用后使用全球服务同步数据", attributes: [NSAttributedString.Key.foregroundColor: UIColor.theme.tableView.headerTextLight]) } + init(settings: SettingsTableViewController) { + self.profile = settings.profile + self.settings = settings + } + override func onConfigureCell(_ cell: UITableViewCell) { super.onConfigureCell(cell) let control = UISwitchThemed() @@ -902,8 +911,28 @@ class ChinaSyncServiceSetting: WithoutAccountSetting { } @objc func switchValueChanged(_ toggle: UISwitch) { - prefs.setObject(toggle.isOn, forKey: prefKey) - RustFirefoxAccounts.reconfig() + UnifiedTelemetry.recordEvent(category: .action, method: .tap, object: .chinaServerSwitch) + guard profile.rustFxA.hasAccount() else { + prefs.setObject(toggle.isOn, forKey: prefKey) + RustFirefoxAccounts.reconfig() + return + } + + // Show confirmation dialog for the user to sign out of FxA + + let msg = "更改此设置后,再次登录您的帐户" // "Sign-in again to your account after changing this setting" + let alert = UIAlertController(title: "", message: msg, preferredStyle: .alert) + let ok = UIAlertAction(title: Strings.OKString, style: .default) { _ in + self.prefs.setObject(toggle.isOn, forKey: self.prefKey) + self.profile.removeAccount() + RustFirefoxAccounts.reconfig() + } + let cancel = UIAlertAction(title: Strings.CancelString, style: .default) { _ in + toggle.setOn(!toggle.isOn, animated: true) + } + alert.addAction(ok) + alert.addAction(cancel) + settings.present(alert, animated: true) } } diff --git a/Client/Telemetry/UnifiedTelemetry.swift b/Client/Telemetry/UnifiedTelemetry.swift index 4efdd2bad4ff..471fe437c1ad 100644 --- a/Client/Telemetry/UnifiedTelemetry.swift +++ b/Client/Telemetry/UnifiedTelemetry.swift @@ -211,6 +211,7 @@ extension UnifiedTelemetry { case tabSearch = "tab-search" case tabToolbar = "tab-toolbar" case experimentEnrollment = "experiment-enrollment" + case chinaServerSwitch = "china-server-switch" } public enum EventValue: String {