Add constants.dart
This commit is contained in:
parent
8511f1891b
commit
f2bdf24e15
|
@ -16,6 +16,7 @@
|
|||
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/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 =
|
||||
|
|
|
@ -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";
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<void> 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), [
|
||||
|
|
|
@ -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<AboutPage> {
|
|||
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<AboutPage> {
|
|||
|
||||
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<AboutPage> {
|
|||
|
||||
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<AboutPage> {
|
|||
|
||||
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<AboutPage> {
|
|||
|
||||
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<AboutPage> {
|
|||
|
||||
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<AboutPage> {
|
|||
|
||||
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<AboutPage> {
|
|||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<EnvironmentVariablesPage> {
|
||||
|
@ -30,7 +32,7 @@ class _EnvironmentVariablesPageState extends State<EnvironmentVariablesPage> {
|
|||
|
||||
Future<void> _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<EnvironmentVariablesPage> {
|
|||
_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: <Widget>[
|
||||
Container(
|
||||
|
|
|
@ -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<GamePage>
|
|||
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<GamePage>
|
|||
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<GamePage>
|
|||
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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<LicenseAgreementPage> {
|
|||
|
||||
Future<void> _loadData() async {
|
||||
final _loadedData =
|
||||
await rootBundle.loadString('assets/licenses/GPL-3.0.txt');
|
||||
await rootBundle.loadString(Constants.gplLicenseFilename);
|
||||
setState(() {
|
||||
_data = _loadedData;
|
||||
});
|
||||
|
|
|
@ -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(),
|
||||
|
|
Loading…
Reference in New Issue