mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-26 00:29:20 +08:00
Use flutter_runtime_env
Now almost all of the custom Java/iOS code has been moved to plugins.
This commit is contained in:
@ -40,35 +40,9 @@ public class MainActivity extends FlutterActivity implements MethodCallHandler {
|
||||
Context context = getApplicationContext();
|
||||
final String filesDir = PathUtils.getFilesDir(context);
|
||||
|
||||
Log.d("GitJournalAndroid", "Called method " + call.method);
|
||||
if (call.arguments instanceof Map) {
|
||||
Map<String, Object> map = (Map<String, Object>) call.arguments;
|
||||
for (Map.Entry<String, Object> entry : map.entrySet()) {
|
||||
Object val = entry.getValue();
|
||||
String objVal = "";
|
||||
if (val != null) {
|
||||
objVal = val.toString();
|
||||
}
|
||||
Log.d("GitJournalAndroid", ". " + entry.getKey() + ": " + val);
|
||||
}
|
||||
}
|
||||
|
||||
if (call.method.equals("getBaseDirectory")) {
|
||||
result.success(filesDir);
|
||||
return;
|
||||
} else if (call.method.equals("shouldEnableAnalytics")) {
|
||||
boolean shouldBe = true;
|
||||
String testLabSetting = Settings.System.getString(context.getContentResolver(), "firebase.test.lab");
|
||||
if ("true".equals(testLabSetting)) {
|
||||
shouldBe = false;
|
||||
}
|
||||
|
||||
if (BuildConfig.DEBUG) {
|
||||
shouldBe = false;
|
||||
}
|
||||
|
||||
result.success(shouldBe);
|
||||
return;
|
||||
}
|
||||
|
||||
result.notImplemented();
|
||||
|
10
lib/app.dart
10
lib/app.dart
@ -7,13 +7,13 @@ import 'package:firebase_analytics/observer.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:flutter_runtime_env/flutter_runtime_env.dart' as runtime_env;
|
||||
|
||||
import 'package:git_bindings/git_bindings.dart';
|
||||
|
||||
import 'package:gitjournal/apis/git.dart';
|
||||
import 'package:gitjournal/settings.dart';
|
||||
import 'package:gitjournal/state_container.dart';
|
||||
import 'package:gitjournal/utils.dart';
|
||||
import 'package:gitjournal/appstate.dart';
|
||||
import 'package:gitjournal/themes.dart';
|
||||
|
||||
@ -62,10 +62,7 @@ class JournalApp extends StatelessWidget {
|
||||
}
|
||||
|
||||
static void _enableAnalyticsIfPossible() async {
|
||||
//
|
||||
// Check if in debugMode or not a real device
|
||||
//
|
||||
assert(JournalApp.isInDebugMode = true);
|
||||
JournalApp.isInDebugMode = runtime_env.isInDebugMode();
|
||||
|
||||
var isPhysicalDevice = true;
|
||||
try {
|
||||
@ -82,12 +79,11 @@ class JournalApp extends StatelessWidget {
|
||||
}
|
||||
|
||||
if (isPhysicalDevice == false) {
|
||||
Fimber.d("Not running in a physcial device");
|
||||
JournalApp.isInDebugMode = true;
|
||||
}
|
||||
|
||||
bool should = (JournalApp.isInDebugMode == false);
|
||||
should = should && (await shouldEnableAnalytics());
|
||||
should = should && (await runtime_env.inFirebaseTestLab());
|
||||
|
||||
Fimber.d("Analytics Collection: $should");
|
||||
JournalApp.analytics.setAnalyticsCollectionEnabled(should);
|
||||
|
@ -1,6 +1,5 @@
|
||||
import 'package:fimber/fimber.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:package_info/package_info.dart';
|
||||
|
||||
import 'package:flushbar/flushbar.dart';
|
||||
@ -23,17 +22,6 @@ Future<String> getVersionString() async {
|
||||
return versionText;
|
||||
}
|
||||
|
||||
Future<bool> shouldEnableAnalytics() async {
|
||||
try {
|
||||
const _platform = MethodChannel('gitjournal.io/git');
|
||||
final bool result = await _platform.invokeMethod('shouldEnableAnalytics');
|
||||
return result;
|
||||
} on MissingPluginException catch (e) {
|
||||
Fimber.d("shouldEnableAnalytics: $e");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void showUndoDeleteSnackbar(
|
||||
BuildContext context,
|
||||
StateContainerState stateContainer,
|
||||
|
@ -193,6 +193,13 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.3.2"
|
||||
flutter_runtime_env:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_runtime_env
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.0.1"
|
||||
flutter_staggered_grid_view:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -32,6 +32,7 @@ dependencies:
|
||||
provider: ^3.2.0
|
||||
git_bindings: ^0.0.6
|
||||
fetch_app_logs: ^0.0.2
|
||||
flutter_runtime_env: ^0.0.1
|
||||
|
||||
dev_dependencies:
|
||||
flutter_launcher_icons: "^0.7.2"
|
||||
|
Reference in New Issue
Block a user