diff --git a/src/ui/flutter_app/lib/common/config.dart b/src/ui/flutter_app/lib/common/config.dart index c70018df..472616d3 100644 --- a/src/ui/flutter_app/lib/common/config.dart +++ b/src/ui/flutter_app/lib/common/config.dart @@ -16,6 +16,7 @@ along with this program. If not, see . */ +import 'package:sanmill/common/constants.dart'; import 'package:sanmill/mill/rule.dart'; import 'package:sanmill/style/app_theme.dart'; @@ -45,7 +46,7 @@ class Config { static bool experimentsEnabled = false; // Display - static String languageCode = "Default"; + static String languageCode = Constants.defaultLanguageCodeName; static bool standardNotationEnabled = true; static bool isPieceCountInHandShown = false; static bool isNotationsShown = false; @@ -106,7 +107,7 @@ class Config { Config.experimentsEnabled = settings['ExperimentsEnabled'] ?? false; // Display - Config.languageCode = settings['LanguageCode'] ?? "Default"; + Config.languageCode = settings['LanguageCode'] ?? Constants.defaultLanguageCodeName; Config.standardNotationEnabled = settings['StandardNotationEnabled'] ?? true; Config.isPieceCountInHandShown = diff --git a/src/ui/flutter_app/lib/common/constants.dart b/src/ui/flutter_app/lib/common/constants.dart new file mode 100644 index 00000000..69147f17 --- /dev/null +++ b/src/ui/flutter_app/lib/common/constants.dart @@ -0,0 +1,67 @@ +/* + This file is part of Sanmill. + Copyright (C) 2019-2021 The Sanmill developers (see AUTHORS file) + + Sanmill is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Sanmill is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +class Constants { + static String appName = "Mill"; + static String authorAccount = "calcitem"; + static String projectName = "Sanmill"; + static String projectNameLower = projectName.toLowerCase(); + static String recipients = "$authorAccount@outlook.com"; + + static String settingsFilename = "${projectNameLower}_settings.json"; + static String crashLogsFileName = "$projectName-crash-logs.txt"; + static String environmentVariablesFilename = + "assets/files/environment_variables.txt"; + static String gplLicenseFilename = "assets/licenses/GPL-3.0.txt"; + + static String defaultLanguageCodeName = "Default"; + + static String feedbackSubjectPrefix = "[$appName] $projectName "; + static String feedbackSubjectSuffix = " Feedback"; + + static String githubURL = "https://github.com"; + static String giteeURL = "https://gitee.com"; + + static String fullRepoName = "$authorAccount/$projectName"; + + static String githubRepoURL = "$githubURL/$fullRepoName"; + static String giteeRepoURL = "$giteeURL/$fullRepoName"; + + static String githubRepoWiKiURL = "$githubURL/$fullRepoName/wiki"; + static String giteeRepoWiKiURL = "$giteeURL/$fullRepoName/wikis"; + + static String githubIssuesURL = "$githubRepoURL/issues"; + static String giteeIssuesURL = "$giteeRepoURL/issues"; + + static String githubEulaURL = "$githubRepoWiKiURL/EULA"; + static String giteeEulaURL = "$giteeRepoWiKiURL/EULA_zh"; + + static String githubSourceCodeURL = "$githubRepoURL"; + static String giteeSourceCodeURL = "$giteeRepoURL"; + + static String githubThirdPartyNoticesURL = + "$githubRepoURL/wiki/third-party_notices"; + static String giteeThirdPartyNoticesURL = + "$giteeRepoURL/wikis/third-party_notices"; + + static String githubPrivacyPolicyURL = "$githubRepoWiKiURL/privacy_policy"; + static String giteePrivacyPolicyURL = "$giteeRepoWiKiURL/privacy_policy_zh"; + + static String githubThanksURL = "$githubRepoWiKiURL/thanks"; + static String giteeThanksURL = "$giteeRepoWiKiURL/thanks"; +} diff --git a/src/ui/flutter_app/lib/common/settings.dart b/src/ui/flutter_app/lib/common/settings.dart index be1acc07..f41c3754 100644 --- a/src/ui/flutter_app/lib/common/settings.dart +++ b/src/ui/flutter_app/lib/common/settings.dart @@ -20,9 +20,10 @@ import 'dart:convert'; import 'dart:io'; import 'package:path_provider/path_provider.dart'; +import 'package:sanmill/common/constants.dart'; class Settings { - static const settingsFileName = 'sanmill_settings.json'; + static final settingsFileName = Constants.settingsFilename; static Settings? _instance; late File _file; diff --git a/src/ui/flutter_app/lib/l10n/resources.dart b/src/ui/flutter_app/lib/l10n/resources.dart index 34cc2410..54530b94 100644 --- a/src/ui/flutter_app/lib/l10n/resources.dart +++ b/src/ui/flutter_app/lib/l10n/resources.dart @@ -20,6 +20,7 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:sanmill/common/config.dart'; +import 'package:sanmill/common/constants.dart'; final supportedLocales = [ const Locale('en', ''), @@ -193,7 +194,7 @@ class Resources { Resources(); String get languageCode { - if (Config.languageCode == "Default") { + if (Config.languageCode == Constants.defaultLanguageCodeName) { return Platform.localeName.substring(0, 2); } diff --git a/src/ui/flutter_app/lib/main.dart b/src/ui/flutter_app/lib/main.dart index 8da5c161..c3f813ba 100644 --- a/src/ui/flutter_app/lib/main.dart +++ b/src/ui/flutter_app/lib/main.dart @@ -26,6 +26,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:path_provider/path_provider.dart'; +import 'package:sanmill/common/constants.dart'; import 'package:sanmill/generated/l10n.dart'; import 'package:sanmill/l10n/resources.dart'; import 'package:sanmill/services/audios.dart'; @@ -53,9 +54,9 @@ Future main() async { print(e); externalDirStr = "."; } - String path = externalDirStr + "/sanmill-crash-logs.txt"; + String path = externalDirStr + "/" + Constants.crashLogsFileName; print("[env] ExternalStorageDirectory: " + externalDirStr); - String recipients = "calcitem@outlook.com"; + String recipients = Constants.recipients; CatcherOptions debugOptions = CatcherOptions(PageReportMode(showStackTrace: true), [ diff --git a/src/ui/flutter_app/lib/widgets/about_page.dart b/src/ui/flutter_app/lib/widgets/about_page.dart index 5a2429b7..3994b3d7 100644 --- a/src/ui/flutter_app/lib/widgets/about_page.dart +++ b/src/ui/flutter_app/lib/widgets/about_page.dart @@ -26,6 +26,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_email_sender/flutter_email_sender.dart'; import 'package:package_info_plus/package_info_plus.dart'; import 'package:path_provider/path_provider.dart'; +import 'package:sanmill/common/constants.dart'; import 'package:sanmill/generated/flutter_version.dart'; import 'package:sanmill/generated/l10n.dart'; import 'package:sanmill/style/app_theme.dart'; @@ -97,7 +98,7 @@ class _AboutPageState extends State { SettingsListTile( context: context, titleString: S.of(context).versionInfo, - subtitleString: "Sanmill " + "$_version" + " " + mode, + subtitleString: Constants.projectName + " $_version" + " " + mode, onTap: _showVersionInfo, ), ListItemDivider(), @@ -116,8 +117,10 @@ class _AboutPageState extends State { final Email email = Email( body: feedback.text, - subject: "[Mill] Sanmill " + "$_version" + " Feedback", - recipients: ['calcitem@outlook.com'], + subject: Constants.feedbackSubjectPrefix + + "$_version" + + Constants.feedbackSubjectSuffix, + recipients: [Constants.recipients], attachmentPaths: [screenshotFilePath], isHTML: false, ); @@ -209,9 +212,9 @@ class _AboutPageState extends State { print("$tag local = $locale"); if (locale != null && locale.startsWith("zh_")) { - _launchURL('https://gitee.com/calcitem/Sanmill/issues'); + _launchURL(Constants.giteeIssuesURL); } else { - _launchURL('https://github.com/calcitem/Sanmill/issues'); + _launchURL(Constants.githubIssuesURL); } } @@ -224,9 +227,9 @@ class _AboutPageState extends State { print("$tag local = $locale"); if (locale != null && locale.startsWith("zh_")) { - _launchURL('https://gitee.com/calcitem/Sanmill/wikis/EULA_zh'); + _launchURL(Constants.giteeEulaURL); } else { - _launchURL('https://github.com/calcitem/Sanmill/wiki/EULA'); + _launchURL(Constants.githubEulaURL); } } @@ -239,9 +242,9 @@ class _AboutPageState extends State { print("$tag local = $locale"); if (locale != null && locale.startsWith("zh_")) { - _launchURL('https://gitee.com/calcitem/Sanmill'); + _launchURL(Constants.giteeSourceCodeURL); } else { - _launchURL('https://github.com/calcitem/Sanmill'); + _launchURL(Constants.githubSourceCodeURL); } } @@ -260,11 +263,9 @@ class _AboutPageState extends State { print("$tag local = $locale"); if (locale != null && locale.startsWith("zh_")) { - _launchURL( - 'https://gitee.com/calcitem/Sanmill/wikis/third-party_notices'); + _launchURL(Constants.giteeThirdPartyNoticesURL); } else { - _launchURL( - 'https://github.com/calcitem/Sanmill/wiki/third-party_notices'); + _launchURL(Constants.githubThirdPartyNoticesURL); } */ } @@ -278,9 +279,9 @@ class _AboutPageState extends State { print("$tag local = $locale"); if (locale != null && locale.startsWith("zh_")) { - _launchURL('https://gitee.com/calcitem/Sanmill/wikis/privacy_policy_zh'); + _launchURL(Constants.giteePrivacyPolicyURL); } else { - _launchURL('https://github.com/calcitem/Sanmill/wiki/privacy_policy'); + _launchURL(Constants.githubPrivacyPolicyURL); } } @@ -293,9 +294,9 @@ class _AboutPageState extends State { print("$tag local = $locale"); if (locale != null && locale.startsWith("zh_")) { - _launchURL('https://gitee.com/calcitem/Sanmill/wikis/thanks'); + _launchURL(Constants.giteeThanksURL); } else { - _launchURL('https://github.com/calcitem/Sanmill/wiki/thanks'); + _launchURL(Constants.githubThanksURL); } } diff --git a/src/ui/flutter_app/lib/widgets/dialog.dart b/src/ui/flutter_app/lib/widgets/dialog.dart index f921ec09..5d6e02c6 100644 --- a/src/ui/flutter_app/lib/widgets/dialog.dart +++ b/src/ui/flutter_app/lib/widgets/dialog.dart @@ -24,6 +24,7 @@ import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:sanmill/common/config.dart'; +import 'package:sanmill/common/constants.dart'; import 'package:sanmill/generated/l10n.dart'; import 'package:url_launcher/url_launcher.dart'; @@ -123,13 +124,11 @@ showPrivacyDialog( print("[about] local = $locale"); if (locale != null && locale.startsWith("zh_")) { - eulaURL = 'https://gitee.com/calcitem/Sanmill/wikis/EULA_zh'; - privacyPolicyURL = - 'https://gitee.com/calcitem/Sanmill/wikis/privacy_policy_zh'; + eulaURL = Constants.giteeEulaURL; + privacyPolicyURL = Constants.giteePrivacyPolicyURL; } else { - eulaURL = 'https://github.com/calcitem/Sanmill/wiki/EULA'; - privacyPolicyURL = - 'https://github.com/calcitem/Sanmill/wiki/privacy_policy'; + eulaURL = Constants.githubEulaURL; + privacyPolicyURL = Constants.githubPrivacyPolicyURL; } final ThemeData themeData = Theme.of(context); diff --git a/src/ui/flutter_app/lib/widgets/env_page.dart b/src/ui/flutter_app/lib/widgets/env_page.dart index 5267c4d1..84356511 100644 --- a/src/ui/flutter_app/lib/widgets/env_page.dart +++ b/src/ui/flutter_app/lib/widgets/env_page.dart @@ -18,11 +18,13 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart' show rootBundle; +import 'package:sanmill/common/constants.dart'; import 'package:sanmill/generated/l10n.dart'; class EnvironmentVariablesPage extends StatefulWidget { @override - _EnvironmentVariablesPageState createState() => _EnvironmentVariablesPageState(); + _EnvironmentVariablesPageState createState() => + _EnvironmentVariablesPageState(); } class _EnvironmentVariablesPageState extends State { @@ -30,7 +32,7 @@ class _EnvironmentVariablesPageState extends State { Future _loadData() async { final _loadedData = - await rootBundle.loadString('assets/files/environment_variables.txt'); + await rootBundle.loadString(Constants.environmentVariablesFilename); setState(() { _data = _loadedData; }); @@ -41,7 +43,8 @@ class _EnvironmentVariablesPageState extends State { _loadData(); return Scaffold( - appBar: AppBar(title: Text(S.of(context).environmentVariables), centerTitle: true), + appBar: AppBar( + title: Text(S.of(context).environmentVariables), centerTitle: true), body: ListView( children: [ Container( diff --git a/src/ui/flutter_app/lib/widgets/game_page.dart b/src/ui/flutter_app/lib/widgets/game_page.dart index 8aeaf95b..dd5bfd1f 100644 --- a/src/ui/flutter_app/lib/widgets/game_page.dart +++ b/src/ui/flutter_app/lib/widgets/game_page.dart @@ -23,6 +23,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:sanmill/common/config.dart'; +import 'package:sanmill/common/constants.dart'; import 'package:sanmill/engine/engine.dart'; import 'package:sanmill/engine/native_engine.dart'; import 'package:sanmill/generated/l10n.dart'; @@ -1651,7 +1652,7 @@ class _GamePageState extends State final route = ModalRoute.of(context)!.settings.name; print('$tag Game Page didPush route: $route'); await widget.engine.setOptions(); - if (Config.languageCode != "Default") { + if (Config.languageCode != Constants.defaultLanguageCodeName) { S.load(Locale(Config.languageCode)); setState(() {}); } @@ -1662,7 +1663,7 @@ class _GamePageState extends State final route = ModalRoute.of(context)!.settings.name; print('$tag Game Page didPopNext route: $route'); await widget.engine.setOptions(); - if (Config.languageCode != "Default") { + if (Config.languageCode != Constants.defaultLanguageCodeName) { S.load(Locale(Config.languageCode)); } } @@ -1672,7 +1673,7 @@ class _GamePageState extends State final route = ModalRoute.of(context)!.settings.name; print('$tag Game Page didPushNext route: $route'); await widget.engine.setOptions(); - if (Config.languageCode != "Default") { + if (Config.languageCode != Constants.defaultLanguageCodeName) { S.load(Locale(Config.languageCode)); } } diff --git a/src/ui/flutter_app/lib/widgets/license_page.dart b/src/ui/flutter_app/lib/widgets/license_page.dart index 9dea6464..c6117898 100644 --- a/src/ui/flutter_app/lib/widgets/license_page.dart +++ b/src/ui/flutter_app/lib/widgets/license_page.dart @@ -18,6 +18,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart' show rootBundle; +import 'package:sanmill/common/constants.dart'; import 'package:sanmill/generated/l10n.dart'; class LicenseAgreementPage extends StatefulWidget { @@ -30,7 +31,7 @@ class _LicenseAgreementPageState extends State { Future _loadData() async { final _loadedData = - await rootBundle.loadString('assets/licenses/GPL-3.0.txt'); + await rootBundle.loadString(Constants.gplLicenseFilename); setState(() { _data = _loadedData; }); diff --git a/src/ui/flutter_app/lib/widgets/personalization_settings_page.dart b/src/ui/flutter_app/lib/widgets/personalization_settings_page.dart index 4cc803d3..e49eec96 100644 --- a/src/ui/flutter_app/lib/widgets/personalization_settings_page.dart +++ b/src/ui/flutter_app/lib/widgets/personalization_settings_page.dart @@ -19,6 +19,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_colorpicker/flutter_colorpicker.dart'; import 'package:sanmill/common/config.dart'; +import 'package:sanmill/common/constants.dart'; import 'package:sanmill/generated/l10n.dart'; import 'package:sanmill/l10n/resources.dart'; import 'package:sanmill/style/app_theme.dart'; @@ -341,7 +342,7 @@ class _PersonalizationSettingsPageState SettingsListTile( context: context, titleString: S.of(context).language, - trailingString: Config.languageCode == "Default" + trailingString: Config.languageCode == Constants.defaultLanguageCodeName ? "" : Config.languageCode.toString(), onTap: setLanguage, @@ -471,7 +472,7 @@ class _PersonalizationSettingsPageState Navigator.of(context).pop(); setState(() { - Config.languageCode = langCode ?? "Default"; + Config.languageCode = langCode ?? Constants.defaultLanguageCodeName; S.load(Locale(Resources.of().languageCode)); }); @@ -494,7 +495,7 @@ class _PersonalizationSettingsPageState activeColor: AppTheme.switchListTileActiveColor, title: Text(S.of(context).defaultLanguage), groupValue: Config.languageCode, - value: "Default", + value: Constants.defaultLanguageCodeName, onChanged: callback, ), ListItemDivider(),