Add constants.dart

This commit is contained in:
Calcitem 2021-06-26 21:18:10 +08:00
parent 8511f1891b
commit f2bdf24e15
11 changed files with 116 additions and 39 deletions

View File

@ -16,6 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
import 'package:sanmill/common/constants.dart';
import 'package:sanmill/mill/rule.dart'; import 'package:sanmill/mill/rule.dart';
import 'package:sanmill/style/app_theme.dart'; import 'package:sanmill/style/app_theme.dart';
@ -45,7 +46,7 @@ class Config {
static bool experimentsEnabled = false; static bool experimentsEnabled = false;
// Display // Display
static String languageCode = "Default"; static String languageCode = Constants.defaultLanguageCodeName;
static bool standardNotationEnabled = true; static bool standardNotationEnabled = true;
static bool isPieceCountInHandShown = false; static bool isPieceCountInHandShown = false;
static bool isNotationsShown = false; static bool isNotationsShown = false;
@ -106,7 +107,7 @@ class Config {
Config.experimentsEnabled = settings['ExperimentsEnabled'] ?? false; Config.experimentsEnabled = settings['ExperimentsEnabled'] ?? false;
// Display // Display
Config.languageCode = settings['LanguageCode'] ?? "Default"; Config.languageCode = settings['LanguageCode'] ?? Constants.defaultLanguageCodeName;
Config.standardNotationEnabled = Config.standardNotationEnabled =
settings['StandardNotationEnabled'] ?? true; settings['StandardNotationEnabled'] ?? true;
Config.isPieceCountInHandShown = Config.isPieceCountInHandShown =

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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";
}

View File

@ -20,9 +20,10 @@ import 'dart:convert';
import 'dart:io'; import 'dart:io';
import 'package:path_provider/path_provider.dart'; import 'package:path_provider/path_provider.dart';
import 'package:sanmill/common/constants.dart';
class Settings { class Settings {
static const settingsFileName = 'sanmill_settings.json'; static final settingsFileName = Constants.settingsFilename;
static Settings? _instance; static Settings? _instance;
late File _file; late File _file;

View File

@ -20,6 +20,7 @@ import 'dart:io';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:sanmill/common/config.dart'; import 'package:sanmill/common/config.dart';
import 'package:sanmill/common/constants.dart';
final supportedLocales = [ final supportedLocales = [
const Locale('en', ''), const Locale('en', ''),
@ -193,7 +194,7 @@ class Resources {
Resources(); Resources();
String get languageCode { String get languageCode {
if (Config.languageCode == "Default") { if (Config.languageCode == Constants.defaultLanguageCodeName) {
return Platform.localeName.substring(0, 2); return Platform.localeName.substring(0, 2);
} }

View File

@ -26,6 +26,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:path_provider/path_provider.dart'; import 'package:path_provider/path_provider.dart';
import 'package:sanmill/common/constants.dart';
import 'package:sanmill/generated/l10n.dart'; import 'package:sanmill/generated/l10n.dart';
import 'package:sanmill/l10n/resources.dart'; import 'package:sanmill/l10n/resources.dart';
import 'package:sanmill/services/audios.dart'; import 'package:sanmill/services/audios.dart';
@ -53,9 +54,9 @@ Future<void> main() async {
print(e); print(e);
externalDirStr = "."; externalDirStr = ".";
} }
String path = externalDirStr + "/sanmill-crash-logs.txt"; String path = externalDirStr + "/" + Constants.crashLogsFileName;
print("[env] ExternalStorageDirectory: " + externalDirStr); print("[env] ExternalStorageDirectory: " + externalDirStr);
String recipients = "calcitem@outlook.com"; String recipients = Constants.recipients;
CatcherOptions debugOptions = CatcherOptions debugOptions =
CatcherOptions(PageReportMode(showStackTrace: true), [ CatcherOptions(PageReportMode(showStackTrace: true), [

View File

@ -26,6 +26,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_email_sender/flutter_email_sender.dart'; import 'package:flutter_email_sender/flutter_email_sender.dart';
import 'package:package_info_plus/package_info_plus.dart'; import 'package:package_info_plus/package_info_plus.dart';
import 'package:path_provider/path_provider.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/flutter_version.dart';
import 'package:sanmill/generated/l10n.dart'; import 'package:sanmill/generated/l10n.dart';
import 'package:sanmill/style/app_theme.dart'; import 'package:sanmill/style/app_theme.dart';
@ -97,7 +98,7 @@ class _AboutPageState extends State<AboutPage> {
SettingsListTile( SettingsListTile(
context: context, context: context,
titleString: S.of(context).versionInfo, titleString: S.of(context).versionInfo,
subtitleString: "Sanmill " + "$_version" + " " + mode, subtitleString: Constants.projectName + " $_version" + " " + mode,
onTap: _showVersionInfo, onTap: _showVersionInfo,
), ),
ListItemDivider(), ListItemDivider(),
@ -116,8 +117,10 @@ class _AboutPageState extends State<AboutPage> {
final Email email = Email( final Email email = Email(
body: feedback.text, body: feedback.text,
subject: "[Mill] Sanmill " + "$_version" + " Feedback", subject: Constants.feedbackSubjectPrefix +
recipients: ['calcitem@outlook.com'], "$_version" +
Constants.feedbackSubjectSuffix,
recipients: [Constants.recipients],
attachmentPaths: [screenshotFilePath], attachmentPaths: [screenshotFilePath],
isHTML: false, isHTML: false,
); );
@ -209,9 +212,9 @@ class _AboutPageState extends State<AboutPage> {
print("$tag local = $locale"); print("$tag local = $locale");
if (locale != null && locale.startsWith("zh_")) { if (locale != null && locale.startsWith("zh_")) {
_launchURL('https://gitee.com/calcitem/Sanmill/issues'); _launchURL(Constants.giteeIssuesURL);
} else { } else {
_launchURL('https://github.com/calcitem/Sanmill/issues'); _launchURL(Constants.githubIssuesURL);
} }
} }
@ -224,9 +227,9 @@ class _AboutPageState extends State<AboutPage> {
print("$tag local = $locale"); print("$tag local = $locale");
if (locale != null && locale.startsWith("zh_")) { if (locale != null && locale.startsWith("zh_")) {
_launchURL('https://gitee.com/calcitem/Sanmill/wikis/EULA_zh'); _launchURL(Constants.giteeEulaURL);
} else { } else {
_launchURL('https://github.com/calcitem/Sanmill/wiki/EULA'); _launchURL(Constants.githubEulaURL);
} }
} }
@ -239,9 +242,9 @@ class _AboutPageState extends State<AboutPage> {
print("$tag local = $locale"); print("$tag local = $locale");
if (locale != null && locale.startsWith("zh_")) { if (locale != null && locale.startsWith("zh_")) {
_launchURL('https://gitee.com/calcitem/Sanmill'); _launchURL(Constants.giteeSourceCodeURL);
} else { } else {
_launchURL('https://github.com/calcitem/Sanmill'); _launchURL(Constants.githubSourceCodeURL);
} }
} }
@ -260,11 +263,9 @@ class _AboutPageState extends State<AboutPage> {
print("$tag local = $locale"); print("$tag local = $locale");
if (locale != null && locale.startsWith("zh_")) { if (locale != null && locale.startsWith("zh_")) {
_launchURL( _launchURL(Constants.giteeThirdPartyNoticesURL);
'https://gitee.com/calcitem/Sanmill/wikis/third-party_notices');
} else { } else {
_launchURL( _launchURL(Constants.githubThirdPartyNoticesURL);
'https://github.com/calcitem/Sanmill/wiki/third-party_notices');
} }
*/ */
} }
@ -278,9 +279,9 @@ class _AboutPageState extends State<AboutPage> {
print("$tag local = $locale"); print("$tag local = $locale");
if (locale != null && locale.startsWith("zh_")) { if (locale != null && locale.startsWith("zh_")) {
_launchURL('https://gitee.com/calcitem/Sanmill/wikis/privacy_policy_zh'); _launchURL(Constants.giteePrivacyPolicyURL);
} else { } else {
_launchURL('https://github.com/calcitem/Sanmill/wiki/privacy_policy'); _launchURL(Constants.githubPrivacyPolicyURL);
} }
} }
@ -293,9 +294,9 @@ class _AboutPageState extends State<AboutPage> {
print("$tag local = $locale"); print("$tag local = $locale");
if (locale != null && locale.startsWith("zh_")) { if (locale != null && locale.startsWith("zh_")) {
_launchURL('https://gitee.com/calcitem/Sanmill/wikis/thanks'); _launchURL(Constants.giteeThanksURL);
} else { } else {
_launchURL('https://github.com/calcitem/Sanmill/wiki/thanks'); _launchURL(Constants.githubThanksURL);
} }
} }

View File

@ -24,6 +24,7 @@ import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:sanmill/common/config.dart'; import 'package:sanmill/common/config.dart';
import 'package:sanmill/common/constants.dart';
import 'package:sanmill/generated/l10n.dart'; import 'package:sanmill/generated/l10n.dart';
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
@ -123,13 +124,11 @@ showPrivacyDialog(
print("[about] local = $locale"); print("[about] local = $locale");
if (locale != null && locale.startsWith("zh_")) { if (locale != null && locale.startsWith("zh_")) {
eulaURL = 'https://gitee.com/calcitem/Sanmill/wikis/EULA_zh'; eulaURL = Constants.giteeEulaURL;
privacyPolicyURL = privacyPolicyURL = Constants.giteePrivacyPolicyURL;
'https://gitee.com/calcitem/Sanmill/wikis/privacy_policy_zh';
} else { } else {
eulaURL = 'https://github.com/calcitem/Sanmill/wiki/EULA'; eulaURL = Constants.githubEulaURL;
privacyPolicyURL = privacyPolicyURL = Constants.githubPrivacyPolicyURL;
'https://github.com/calcitem/Sanmill/wiki/privacy_policy';
} }
final ThemeData themeData = Theme.of(context); final ThemeData themeData = Theme.of(context);

View File

@ -18,11 +18,13 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart' show rootBundle; import 'package:flutter/services.dart' show rootBundle;
import 'package:sanmill/common/constants.dart';
import 'package:sanmill/generated/l10n.dart'; import 'package:sanmill/generated/l10n.dart';
class EnvironmentVariablesPage extends StatefulWidget { class EnvironmentVariablesPage extends StatefulWidget {
@override @override
_EnvironmentVariablesPageState createState() => _EnvironmentVariablesPageState(); _EnvironmentVariablesPageState createState() =>
_EnvironmentVariablesPageState();
} }
class _EnvironmentVariablesPageState extends State<EnvironmentVariablesPage> { class _EnvironmentVariablesPageState extends State<EnvironmentVariablesPage> {
@ -30,7 +32,7 @@ class _EnvironmentVariablesPageState extends State<EnvironmentVariablesPage> {
Future<void> _loadData() async { Future<void> _loadData() async {
final _loadedData = final _loadedData =
await rootBundle.loadString('assets/files/environment_variables.txt'); await rootBundle.loadString(Constants.environmentVariablesFilename);
setState(() { setState(() {
_data = _loadedData; _data = _loadedData;
}); });
@ -41,7 +43,8 @@ class _EnvironmentVariablesPageState extends State<EnvironmentVariablesPage> {
_loadData(); _loadData();
return Scaffold( return Scaffold(
appBar: AppBar(title: Text(S.of(context).environmentVariables), centerTitle: true), appBar: AppBar(
title: Text(S.of(context).environmentVariables), centerTitle: true),
body: ListView( body: ListView(
children: <Widget>[ children: <Widget>[
Container( Container(

View File

@ -23,6 +23,7 @@ import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:sanmill/common/config.dart'; import 'package:sanmill/common/config.dart';
import 'package:sanmill/common/constants.dart';
import 'package:sanmill/engine/engine.dart'; import 'package:sanmill/engine/engine.dart';
import 'package:sanmill/engine/native_engine.dart'; import 'package:sanmill/engine/native_engine.dart';
import 'package:sanmill/generated/l10n.dart'; import 'package:sanmill/generated/l10n.dart';
@ -1651,7 +1652,7 @@ class _GamePageState extends State<GamePage>
final route = ModalRoute.of(context)!.settings.name; final route = ModalRoute.of(context)!.settings.name;
print('$tag Game Page didPush route: $route'); print('$tag Game Page didPush route: $route');
await widget.engine.setOptions(); await widget.engine.setOptions();
if (Config.languageCode != "Default") { if (Config.languageCode != Constants.defaultLanguageCodeName) {
S.load(Locale(Config.languageCode)); S.load(Locale(Config.languageCode));
setState(() {}); setState(() {});
} }
@ -1662,7 +1663,7 @@ class _GamePageState extends State<GamePage>
final route = ModalRoute.of(context)!.settings.name; final route = ModalRoute.of(context)!.settings.name;
print('$tag Game Page didPopNext route: $route'); print('$tag Game Page didPopNext route: $route');
await widget.engine.setOptions(); await widget.engine.setOptions();
if (Config.languageCode != "Default") { if (Config.languageCode != Constants.defaultLanguageCodeName) {
S.load(Locale(Config.languageCode)); S.load(Locale(Config.languageCode));
} }
} }
@ -1672,7 +1673,7 @@ class _GamePageState extends State<GamePage>
final route = ModalRoute.of(context)!.settings.name; final route = ModalRoute.of(context)!.settings.name;
print('$tag Game Page didPushNext route: $route'); print('$tag Game Page didPushNext route: $route');
await widget.engine.setOptions(); await widget.engine.setOptions();
if (Config.languageCode != "Default") { if (Config.languageCode != Constants.defaultLanguageCodeName) {
S.load(Locale(Config.languageCode)); S.load(Locale(Config.languageCode));
} }
} }

View File

@ -18,6 +18,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart' show rootBundle; import 'package:flutter/services.dart' show rootBundle;
import 'package:sanmill/common/constants.dart';
import 'package:sanmill/generated/l10n.dart'; import 'package:sanmill/generated/l10n.dart';
class LicenseAgreementPage extends StatefulWidget { class LicenseAgreementPage extends StatefulWidget {
@ -30,7 +31,7 @@ class _LicenseAgreementPageState extends State<LicenseAgreementPage> {
Future<void> _loadData() async { Future<void> _loadData() async {
final _loadedData = final _loadedData =
await rootBundle.loadString('assets/licenses/GPL-3.0.txt'); await rootBundle.loadString(Constants.gplLicenseFilename);
setState(() { setState(() {
_data = _loadedData; _data = _loadedData;
}); });

View File

@ -19,6 +19,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_colorpicker/flutter_colorpicker.dart'; import 'package:flutter_colorpicker/flutter_colorpicker.dart';
import 'package:sanmill/common/config.dart'; import 'package:sanmill/common/config.dart';
import 'package:sanmill/common/constants.dart';
import 'package:sanmill/generated/l10n.dart'; import 'package:sanmill/generated/l10n.dart';
import 'package:sanmill/l10n/resources.dart'; import 'package:sanmill/l10n/resources.dart';
import 'package:sanmill/style/app_theme.dart'; import 'package:sanmill/style/app_theme.dart';
@ -341,7 +342,7 @@ class _PersonalizationSettingsPageState
SettingsListTile( SettingsListTile(
context: context, context: context,
titleString: S.of(context).language, titleString: S.of(context).language,
trailingString: Config.languageCode == "Default" trailingString: Config.languageCode == Constants.defaultLanguageCodeName
? "" ? ""
: Config.languageCode.toString(), : Config.languageCode.toString(),
onTap: setLanguage, onTap: setLanguage,
@ -471,7 +472,7 @@ class _PersonalizationSettingsPageState
Navigator.of(context).pop(); Navigator.of(context).pop();
setState(() { setState(() {
Config.languageCode = langCode ?? "Default"; Config.languageCode = langCode ?? Constants.defaultLanguageCodeName;
S.load(Locale(Resources.of().languageCode)); S.load(Locale(Resources.of().languageCode));
}); });
@ -494,7 +495,7 @@ class _PersonalizationSettingsPageState
activeColor: AppTheme.switchListTileActiveColor, activeColor: AppTheme.switchListTileActiveColor,
title: Text(S.of(context).defaultLanguage), title: Text(S.of(context).defaultLanguage),
groupValue: Config.languageCode, groupValue: Config.languageCode,
value: "Default", value: Constants.defaultLanguageCodeName,
onChanged: callback, onChanged: callback,
), ),
ListItemDivider(), ListItemDivider(),