fix: hard code instance version tag issue. resolve #203

This commit is contained in:
CMK 2021-07-06 15:20:32 +08:00
parent fea3638669
commit 1214180c55
6 changed files with 53 additions and 9 deletions

View File

@ -523,6 +523,9 @@
"signout": "Sign Out"
}
},
"footer": {
"mastodon_description": "Mastodon is open source software. You can contribute or report issues on GitHub at %s (%s)"
},
"keyboard": {
"close_settings_window": "Close Settings Window"
}

View File

@ -910,6 +910,12 @@ internal enum L10n {
internal enum Settings {
/// Settings
internal static let title = L10n.tr("Localizable", "Scene.Settings.Title")
internal enum Footer {
/// Mastodon is open source software. You can contribute or report issues on GitHub at %@ (%@)
internal static func mastodonDescription(_ p1: Any, _ p2: Any) -> String {
return L10n.tr("Localizable", "Scene.Settings.Footer.MastodonDescription", String(describing: p1), String(describing: p2))
}
}
internal enum Keyboard {
/// Close Settings Window
internal static let closeSettingsWindow = L10n.tr("Localizable", "Scene.Settings.Keyboard.CloseSettingsWindow")

View File

@ -310,6 +310,7 @@ any server.";
"Scene.ServerRules.Subtitle" = "These rules are set by the admins of %@.";
"Scene.ServerRules.TermsOfService" = "terms of service";
"Scene.ServerRules.Title" = "Some ground rules.";
"Scene.Settings.Footer.MastodonDescription" = "Mastodon is open source software. You can contribute or report issues on GitHub at %@ (%@)";
"Scene.Settings.Keyboard.CloseSettingsWindow" = "Close Settings Window";
"Scene.Settings.Section.Appearance.Automatic" = "Automatic";
"Scene.Settings.Section.Appearance.Dark" = "Always Dark";

View File

@ -310,6 +310,7 @@ any server.";
"Scene.ServerRules.Subtitle" = "These rules are set by the admins of %@.";
"Scene.ServerRules.TermsOfService" = "terms of service";
"Scene.ServerRules.Title" = "Some ground rules.";
"Scene.Settings.Footer.MastodonDescription" = "Mastodon is open source software. You can contribute or report issues on GitHub at %@ (%@)";
"Scene.Settings.Keyboard.CloseSettingsWindow" = "Close Settings Window";
"Scene.Settings.Section.Appearance.Automatic" = "Automatic";
"Scene.Settings.Section.Appearance.Dark" = "Always Dark";

View File

@ -102,7 +102,13 @@ class SettingsViewController: UIViewController, NeedsDependency {
tableView.register(SettingsLinkTableViewCell.self, forCellReuseIdentifier: String(describing: SettingsLinkTableViewCell.self))
return tableView
}()
let tableFooterActiveLabel: ActiveLabel = {
let label = ActiveLabel(style: .default)
label.adjustsFontForContentSizeCategory = true
label.textAlignment = .center
return label
}()
lazy var tableFooterView: UIView = {
// init with a frame to fix a conflict ('UIView-Encapsulated-Layout-Height' UIStackView:0x7ffe41e47da0.height == 0)
let view = UIStackView(frame: CGRect(x: 0, y: 0, width: 320, height: 320))
@ -110,14 +116,9 @@ class SettingsViewController: UIViewController, NeedsDependency {
view.layoutMargins = UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20)
view.axis = .vertical
view.alignment = .center
let label = ActiveLabel(style: .default)
label.adjustsFontForContentSizeCategory = true
label.textAlignment = .center
label.configure(content: "Mastodon is open source software. You can contribute or report issues on GitHub at <a href=\"https://github.com/tootsuite/mastodon\">tootsuite/mastodon</a> (v3.3.0).", emojiDict: [:])
label.delegate = self
view.addArrangedSubview(label)
tableFooterActiveLabel.delegate = self
view.addArrangedSubview(tableFooterActiveLabel)
return view
}()
@ -190,6 +191,17 @@ class SettingsViewController: UIViewController, NeedsDependency {
}
}
.store(in: &disposeBag)
viewModel.currentInstance
.receive(on: RunLoop.main)
.sink { [weak self] instance in
guard let self = self else { return }
let version = instance?.version ?? "-"
let link = #"<a href="https://github.com/tootsuite/mastodon">tootsuite/mastodon</a>"#
let content = L10n.Scene.Settings.Footer.mastodonDescription(link, version)
self.tableFooterActiveLabel.configure(content: content, emojiDict: [:])
}
.store(in: &disposeBag)
}
private func setupView() {

View File

@ -32,6 +32,7 @@ class SettingsViewModel {
/// - does not has one
/// - does not find subscription for selected trigger when change trigger
let createSubscriptionSubject = PassthroughSubject<(triggerBy: String, values: [Bool?]), Never>()
let currentInstance = CurrentValueSubject<Mastodon.Entity.Instance?, Never>(nil)
/// update a subscription when:
/// - change switch for specified alerts
@ -55,6 +56,26 @@ class SettingsViewModel {
self.processDataSource(setting)
})
.store(in: &disposeBag)
context.authenticationService.activeMastodonAuthenticationBox
.compactMap { $0?.domain }
.map { context.apiService.instance(domain: $0) }
.switchToLatest()
.sink { [weak self] completion in
guard let self = self else { return }
switch completion {
case .failure(let error):
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: fetch instance fail: %s", ((#file as NSString).lastPathComponent), #line, #function, error.localizedDescription)
self.currentInstance.value = nil
case .finished:
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: fetch instance success", ((#file as NSString).lastPathComponent), #line, #function)
}
} receiveValue: { [weak self] response in
guard let self = self else { return }
self.currentInstance.value = response.value
}
.store(in: &disposeBag)
}
deinit {