Skip to content

Commit

Permalink
Adds the feature to show data source info.
Browse files Browse the repository at this point in the history
  • Loading branch information
mntone committed Feb 3, 2024
1 parent 6c2b4f5 commit f045410
Show file tree
Hide file tree
Showing 6 changed files with 298 additions and 1 deletion.
264 changes: 264 additions & 0 deletions src/App/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -3971,6 +3971,88 @@
}
}
},
"Copyright" : {
"localizations" : {
"ar" : {
"stringUnit" : {
"state" : "translated",
"value" : "حقوق النشر"
}
},
"de" : {
"stringUnit" : {
"state" : "translated",
"value" : "Urheberrechte"
}
},
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "Derechos de autor"
}
},
"es-419" : {
"stringUnit" : {
"state" : "translated",
"value" : "Derechos de autor"
}
},
"fr" : {
"stringUnit" : {
"state" : "translated",
"value" : "Droits d'auteur"
}
},
"it" : {
"stringUnit" : {
"state" : "translated",
"value" : "Diritto d'autore"
}
},
"ja" : {
"stringUnit" : {
"state" : "translated",
"value" : "著作権"
}
},
"ko" : {
"stringUnit" : {
"state" : "translated",
"value" : "저작권"
}
},
"pl" : {
"stringUnit" : {
"state" : "translated",
"value" : "Prawo autorskie"
}
},
"pt-BR" : {
"stringUnit" : {
"state" : "translated",
"value" : "Direito autoral"
}
},
"ru" : {
"stringUnit" : {
"state" : "translated",
"value" : "Авторские права"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "版权"
}
},
"zh-Hant" : {
"stringUnit" : {
"state" : "translated",
"value" : "版權"
}
}
}
},
"Data" : {
"localizations" : {
"ar" : {
Expand Down Expand Up @@ -4135,6 +4217,88 @@
}
}
},
"Data Source Info" : {
"localizations" : {
"ar" : {
"stringUnit" : {
"state" : "translated",
"value" : "معلومات مصدر البيانات"
}
},
"de" : {
"stringUnit" : {
"state" : "translated",
"value" : "Informationen zur Datenquelle"
}
},
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "Información de origen de datos"
}
},
"es-419" : {
"stringUnit" : {
"state" : "translated",
"value" : "Información de origen de datos"
}
},
"fr" : {
"stringUnit" : {
"state" : "translated",
"value" : "Informations sur la source de données"
}
},
"it" : {
"stringUnit" : {
"state" : "translated",
"value" : "Informazioni sull'origine dati"
}
},
"ja" : {
"stringUnit" : {
"state" : "translated",
"value" : "データソース情報"
}
},
"ko" : {
"stringUnit" : {
"state" : "translated",
"value" : "데이터 소스 정보"
}
},
"pl" : {
"stringUnit" : {
"state" : "translated",
"value" : "Informacje o źródle danych"
}
},
"pt-BR" : {
"stringUnit" : {
"state" : "translated",
"value" : "Informações da Fonte de Dados"
}
},
"ru" : {
"stringUnit" : {
"state" : "translated",
"value" : "Информация источника данных"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "数据源信息"
}
},
"zh-Hant" : {
"stringUnit" : {
"state" : "translated",
"value" : "資料來源資訊"
}
}
}
},
"Delete Favorite" : {
"localizations" : {
"ar" : {
Expand Down Expand Up @@ -6743,6 +6907,12 @@
},
"GPLv3 License" : {
"localizations" : {
"ar" : {
"stringUnit" : {
"state" : "translated",
"value" : "رخصة GPLv3"
}
},
"de" : {
"stringUnit" : {
"state" : "translated",
Expand Down Expand Up @@ -8371,8 +8541,102 @@
}
}
},
"License" : {
"localizations" : {
"ar" : {
"stringUnit" : {
"state" : "translated",
"value" : "رخصة"
}
},
"de" : {
"stringUnit" : {
"state" : "translated",
"value" : "Lizenz"
}
},
"en-GB" : {
"stringUnit" : {
"state" : "translated",
"value" : "Licence"
}
},
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "Licencia"
}
},
"es-419" : {
"stringUnit" : {
"state" : "translated",
"value" : "Licencia"
}
},
"fr" : {
"stringUnit" : {
"state" : "translated",
"value" : "Licence"
}
},
"it" : {
"stringUnit" : {
"state" : "translated",
"value" : "Licenza"
}
},
"ja" : {
"stringUnit" : {
"state" : "translated",
"value" : "ライセンス"
}
},
"ko" : {
"stringUnit" : {
"state" : "translated",
"value" : "사용권"
}
},
"pl" : {
"stringUnit" : {
"state" : "translated",
"value" : "Licencja"
}
},
"pt-BR" : {
"stringUnit" : {
"state" : "translated",
"value" : "Licença"
}
},
"ru" : {
"stringUnit" : {
"state" : "translated",
"value" : "Лицензия"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "许可证"
}
},
"zh-Hant" : {
"stringUnit" : {
"state" : "translated",
"value" : "許可證"
}
}
}
},
"LICENSES" : {
"localizations" : {
"ar" : {
"stringUnit" : {
"state" : "translated",
"value" : "تراخيص"
}
},
"de" : {
"stringUnit" : {
"state" : "translated",
Expand Down
7 changes: 7 additions & 0 deletions src/App/ViewModels/Settings/DataSettingsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ final class DataSettingsViewModel: ObservableObject {
app.sourceURL.absoluteString
}

@Published
private(set) var currentDataSourceInformation: MHDataSourceInformation?

#if os(watchOS)
@Published
var isSourceURLChanged: Bool = false
Expand Down Expand Up @@ -48,6 +51,10 @@ final class DataSettingsViewModel: ObservableObject {
}
self.app = app
self.sourceURLString = Self.getSourceURLString(app)

app.$dataSourceInformation
.receive(on: DispatchQueue.main)
.assign(to: &$currentDataSourceInformation)
}

// MARK: - Data Source
Expand Down
11 changes: 11 additions & 0 deletions src/App/Views/Settings/Data/DataSettingsPane.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ struct DataSettingsPane: View {
}

if !isEditMode {
if let dataSourceInfo = viewModel.currentDataSourceInformation {
SettingsSection("Data Source Info") {
SettingsLabeledContent(LocalizedStringKey("Name"), value: dataSourceInfo.name)
SettingsLabeledContent(LocalizedStringKey("Copyright"), value: dataSourceInfo.copyright)
SettingsLabeledContent(LocalizedStringKey("License"), value: dataSourceInfo.license)
}
#if os(watchOS)
.listRowBackground(EmptyView())
#endif
}

SettingsSection {
ResetSettingsButton(viewModel: viewModel)
ResetCacheButton(viewModel: viewModel)
Expand Down
2 changes: 1 addition & 1 deletion src/Core/DataSources/MockDataSource.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

public struct MockDataSource {
static let config = MHConfig(version: 3, games: ["mockgame"], languages: ["en", "ja"])
static let config = MHConfig(version: 3, games: ["mockgame"], languages: ["en", "ja"], source: nil)

static let localizationEnglish = MHLocalization(
games: [
Expand Down
7 changes: 7 additions & 0 deletions src/Core/DataSources/Objects/MHConfig.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import Foundation

public struct MHDataSourceInformation: Codable, Sendable {
public let name: String
public let copyright: String
public let license: String
}

struct MHConfig: Codable, Sendable {
let version: UInt8
let games: [String]
let languages: [String]
let source: MHDataSourceInformation?

static let currentVersion: UInt8 = 3
}
8 changes: 8 additions & 0 deletions src/Core/StarSwings/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public final class App: FetchableEntity<[Game]>, Entity {

private var requireReinitApp: Bool = false

@Published
public private(set) var dataSourceInformation: MHDataSourceInformation?

public init(container: Container,
requestBehavior: RepeatBehavior,
pad: Bool) {
Expand Down Expand Up @@ -135,6 +138,11 @@ public final class App: FetchableEntity<[Game]>, Entity {
throw StarSwingsError.notSupported
}

// Set data source information.
if let source = config.source {
self.dataSourceInformation = source
}

// Get localization.
let preferredLocaleKey = LanguageUtil.getPreferredLanguageKey(config.languages)
let localization = try await _dataSource.getLocalization(of: preferredLocaleKey)
Expand Down

0 comments on commit f045410

Please sign in to comment.