Skip to content

Commit

Permalink
Fix #6559: China server switch should not hide when logged-in to FxA (#…
Browse files Browse the repository at this point in the history
…6633)

* Fix #6559: China server switch should not hide when logged-in to FxA

* add telemetry to tapping the switch
  • Loading branch information
garvankeeley committed May 20, 2020
1 parent 4682409 commit 1aff698
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
37 changes: 33 additions & 4 deletions Client/Frontend/Settings/AppSettingsOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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()
Expand All @@ -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)
}
}

Expand Down
1 change: 1 addition & 0 deletions Client/Telemetry/UnifiedTelemetry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 1aff698

Please sign in to comment.