add compile time enviornment options

## Why?
- in the future we could enable the developer options in dev builds only. This would result in better performance and smaller downloadsize.
- Ability to disable catcher. Catcher limits the ability of debuging as it catches everything thrown. Also catcher won't even display the crash when the system is in dark mode (white text on white background. Probably a bug on theier side)

## How to use this?
just add a `--dart-define` followed by your config after the flutter command. Further info can be found in [Readme.md](/Readme.md)
This commit is contained in:
Leptopoda 2021-10-22 14:47:06 +02:00
parent 4d53769dca
commit a0f234bf47
No known key found for this signature in database
GPG Key ID: 661B059EDE309F11
15 changed files with 236 additions and 50 deletions

7
.run/Sanmill-dev.run.xml Normal file
View File

@ -0,0 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Sanmill-dev" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="additionalArgs" value="--dart-define dev_mode=true --dart-define catcher=false" />
<option name="filePath" value="$PROJECT_DIR$/src/ui/flutter_app/lib/main.dart" />
<method v="2" />
</configuration>
</component>

View File

@ -0,0 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Sanmill-monkey" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="additionalArgs" value="--dart-define monkey_test=true" />
<option name="filePath" value="$PROJECT_DIR$/src/ui/flutter_app/lib/main.dart" />
<method v="2" />
</configuration>
</component>

View File

@ -0,0 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Sanmill-profile" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="additionalArgs" value="--profile" />
<option name="filePath" value="$PROJECT_DIR$/src/ui/flutter_app/lib/main.dart" />
<method v="2" />
</configuration>
</component>

View File

@ -0,0 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Sanmill-release" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="additionalArgs" value="--release" />
<option name="filePath" value="$PROJECT_DIR$/src/ui/flutter_app/lib/main.dart" />
<method v="2" />
</configuration>
</component>

6
.run/Sanmill.run.xml Normal file
View File

@ -0,0 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Sanmill" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="filePath" value="$PROJECT_DIR$/src/ui/flutter_app/lib/main.dart" />
<method v="2" />
</configuration>
</component>

View File

@ -0,0 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="true" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="filePath" value="$PROJECT_DIR$/src/ui/flutter_app/lib/main.dart" />
<method v="2" />
</configuration>
</component>

60
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,60 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Sanmill",
"type": "dart",
"request": "launch",
"cwd": "src/ui/flutter_app",
"program": "lib/main.dart"
},
{
"name": "Sanmill: Attach to Device",
"type": "dart",
"request": "attach"
},
{
"name": "Sanmill-dev",
"type": "dart",
"request": "launch",
"cwd": "src/ui/flutter_app",
"program": "lib/main.dart",
"args": [
"--dart-define",
"dev_mode=true",
"--dart-define",
"catcher=false"
]
},
{
"name": "Sanmill-monkey",
"type": "dart",
"request": "launch",
"cwd": "src/ui/flutter_app",
"program": "lib/main.dart",
"args": [
"--dart-define",
"monkey_test=true"
]
},
{
"name": "Sanmill-profile",
"type": "dart",
"request": "launch",
"cwd": "src/ui/flutter_app",
"program": "lib/main.dart",
"flutterMode": "profile"
},
{
"name": "Sanmill-release",
"type": "dart",
"request": "launch",
"cwd": "src/ui/flutter_app",
"program": "lib/main.dart",
"flutterMode": "release"
}
]
}

View File

@ -71,6 +71,21 @@ Use Qt Creator to open `millgame.pro` , or use Visual Studio to open `millgame.s
Run `./flutter-init.sh` , copy `src/ui/flutter_app/android/key.properties.example` to `src/ui/flutter_app/android/key.properties`, modify it, and then use Android Studio or Visual Studio Code to open `src/ui/flutter_app` to build Flutter App.
We use compile time enviornmet configs to enable specific parts of the code:
* `monkey_test` to prepare the app for monkey tests (references to external sites are going to be disabled)
* `dev_mode` to show the developer mode without needing to enable it first
* `catcher` to controll the use of catcher (this is on by default and needs to be disabled when needed)
all enviornment configs can be combined and take a value of bool like:
```shell
flutter run --dart-define catcher=false dev_mode=true
```
For ease of use some launch configs vor VS-Code and IntelliJ IDEA are available. Just select the
needed one in the `Run and Debug` or `Run/Debug Configurations` tab.
## Understanding the code base and participating in the project
Sanmill's improvement over the last couple of years has been a great community effort. There are a few ways to help contribute to its growth.

View File

@ -30,6 +30,7 @@ import 'package:sanmill/generated/intl/l10n.dart';
import 'package:sanmill/models/display.dart';
import 'package:sanmill/screens/navigation_home_screen.dart';
import 'package:sanmill/services/audios.dart';
import 'package:sanmill/services/enviornment_config.dart';
import 'package:sanmill/services/language_info.dart';
import 'package:sanmill/services/storage/storage.dart';
import 'package:sanmill/services/storage/storage_v1.dart';
@ -37,39 +38,30 @@ import 'package:sanmill/shared/constants.dart';
import 'package:sanmill/shared/theme/app_theme.dart';
part 'package:sanmill/services/catcher.dart';
part 'package:sanmill/services/init_system_ui.dart';
Future<void> main() async {
debugPrint('Enviornment [catcher]: ${EnvironmentConfig.catcher}');
debugPrint('Enviornment [dev_mode]: ${EnvironmentConfig.devMode}');
debugPrint('Enviornment [monkey_test]: ${EnvironmentConfig.monkeyTest}');
await LocalDatabaseService.initStorage();
await DatabaseV1.migrateDB();
final catcher = Catcher(
rootWidget: const BetterFeedback(
child: SanmillApp(),
//localeOverride: Locale(Resources.of().languageCode),
),
ensureInitialized: true,
);
await _initCatcher(catcher);
_initUI();
debugPrint(window.physicalSize.toString());
debugPrint(Constants.windowAspectRatio.toString());
SystemChrome.setPreferredOrientations(
[DeviceOrientation.portraitUp, DeviceOrientation.portraitDown],
);
if (Platform.isAndroid && isLargeScreen) {
SystemChrome.setSystemUIOverlayStyle(
const SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
statusBarBrightness: Brightness.light,
statusBarIconBrightness: Brightness.dark,
systemNavigationBarColor: Colors.black,
systemNavigationBarIconBrightness: Brightness.dark,
if (EnvironmentConfig.catcher) {
final catcher = Catcher(
rootWidget: const BetterFeedback(
child: SanmillApp(),
//localeOverride: Locale(Resources.of().languageCode),
),
ensureInitialized: true,
);
} else if (isSmallScreen) {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []);
await _initCatcher(catcher);
} else {
runApp(const SanmillApp());
}
}
@ -83,8 +75,6 @@ class SanmillApp extends StatelessWidget {
final globalScaffoldKey = GlobalKey<ScaffoldState>();
Audios.loadSounds();
setSpecialCountryAndRegion(context);
return ValueListenableBuilder(
valueListenable: LocalDatabaseService.listenDisplay,
builder: (BuildContext context, Box<Display> displayBox, _) {
@ -95,7 +85,7 @@ class SanmillApp extends StatelessWidget {
return MaterialApp(
/// Add navigator key from Catcher.
/// It will be used to navigate user to report page or to show dialog.
navigatorKey: Catcher.navigatorKey,
navigatorKey: EnvironmentConfig.catcher ? Catcher.navigatorKey : null,
key: globalScaffoldKey,
navigatorObservers: [routeObserver],
localizationsDelegates: S.localizationsDelegates,
@ -104,25 +94,22 @@ class SanmillApp extends StatelessWidget {
theme: AppTheme.lightThemeData,
darkTheme: AppTheme.darkThemeData,
debugShowCheckedModeBanner: false,
home: const _Home(),
home: Builder(
builder: (context) {
setSpecialCountryAndRegion(context);
return Scaffold(
body: DoubleBackToCloseApp(
snackBar: SnackBar(
content: Text(S.of(context).tapBackAgainToLeave),
),
child: const NavigationHomeScreen(),
),
);
},
),
);
},
);
}
}
class _Home extends StatelessWidget {
const _Home({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: DoubleBackToCloseApp(
snackBar: SnackBar(
content: Text(S.of(context).tapBackAgainToLeave),
),
child: const NavigationHomeScreen(),
),
);
}
}

View File

@ -16,6 +16,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:sanmill/services/enviornment_config.dart';
/// Temporary data model
///
/// holds temporary runtime data that isn't yet or shouldn't be saved to the LocalDatabase
@ -23,5 +25,5 @@ class Temp {
const Temp._();
/// represents a temporary value for Preferences.developerMode
static bool developerMode = false;
static bool developerMode = EnvironmentConfig.devMode;
}

View File

@ -25,6 +25,7 @@ import 'package:sanmill/generated/intl/l10n.dart';
import 'package:sanmill/models/preferences.dart';
import 'package:sanmill/models/temporary.dart';
import 'package:sanmill/screens/env_page.dart';
import 'package:sanmill/services/enviornment_config.dart';
import 'package:sanmill/services/storage/storage.dart';
import 'package:sanmill/shared/settings/settings_card.dart';
import 'package:sanmill/shared/settings/settings_list_tile.dart';

View File

@ -25,7 +25,10 @@ class _ResetSettingsAlert extends StatelessWidget {
Future<void> _restore(BuildContext context) async {
Navigator.pop(context);
if (!LocalDatabaseService.preferences.developerMode) {
// TODO: we should probably enable database deletion in monkey tests
//as the new storage backend supports deletion without needing an app restart
if (!EnvironmentConfig.monkeyTest) {
await LocalDatabaseService.resetStorage();
}
}

View File

@ -36,6 +36,7 @@ import 'package:sanmill/screens/help_screen.dart';
import 'package:sanmill/screens/personalization_settings/personalization_settings_page.dart';
import 'package:sanmill/screens/rule_settings/rule_settings_page.dart';
import 'package:sanmill/services/engine/engine.dart';
import 'package:sanmill/services/enviornment_config.dart';
import 'package:sanmill/services/storage/storage.dart';
import 'package:sanmill/shared/constants.dart';
import 'package:sanmill/shared/theme/app_theme.dart';
@ -103,7 +104,7 @@ class _NavigationHomeScreenState extends State<NavigationHomeScreen> {
} else if (drawerIndex == DrawerIndex.personalization) {
screenView = PersonalizationSettingsPage();
} else if (drawerIndex == DrawerIndex.feedback &&
!LocalDatabaseService.preferences.developerMode) {
!EnvironmentConfig.monkeyTest) {
if (Platform.isWindows) {
debugPrint("flutter_email_sender does not support Windows.");
//_launchFeedback();
@ -128,10 +129,10 @@ class _NavigationHomeScreenState extends State<NavigationHomeScreen> {
});
}
} else if (drawerIndex == DrawerIndex.Help &&
!LocalDatabaseService.preferences.developerMode) {
!EnvironmentConfig.monkeyTest) {
screenView = HelpScreen();
} else if (drawerIndex == DrawerIndex.About &&
!LocalDatabaseService.preferences.developerMode) {
!EnvironmentConfig.monkeyTest) {
screenView = AboutPage();
} else {
//do in your way......

View File

@ -0,0 +1,34 @@
/*
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/>.
*/
/// Enviornment configutation
///
/// Enables devs to start the app with compile time options
class EnvironmentConfig {
const EnvironmentConfig._();
/// gets weather we build for a monkey test
static const monkeyTest = bool.fromEnvironment('monkey_test');
/// gets weather we build for devMode
static const devMode = bool.fromEnvironment('dev_mode');
/// gets weather we want catcher to be enabled
/// defaults to true
static const catcher = bool.fromEnvironment('catcher', defaultValue: true);
}

View File

@ -0,0 +1,43 @@
/*
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/>.
*/
part of 'package:sanmill/main.dart';
/// initializes the given [SystemChrome] ui
void _initUI() {
debugPrint(window.physicalSize.toString());
debugPrint(Constants.windowAspectRatio.toString());
SystemChrome.setPreferredOrientations(
[DeviceOrientation.portraitUp, DeviceOrientation.portraitDown],
);
if (Platform.isAndroid && isLargeScreen) {
SystemChrome.setSystemUIOverlayStyle(
const SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
statusBarBrightness: Brightness.light,
statusBarIconBrightness: Brightness.dark,
systemNavigationBarColor: Colors.black,
systemNavigationBarIconBrightness: Brightness.dark,
),
);
} else if (isSmallScreen) {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []);
}
}