diff --git a/lib/app.dart b/lib/app.dart index ba33175f..0c8392a4 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -12,6 +12,7 @@ import 'package:flutter/services.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:mimir/agreements/entity/agreements.dart'; import 'package:mimir/agreements/page/privacy_policy.dart'; +import 'package:mimir/backend/stats/utils/stats.dart'; import 'package:mimir/credentials/init.dart'; import 'package:mimir/files.dart'; import 'package:mimir/intent/file_type/handle.dart'; @@ -97,8 +98,7 @@ class _MimirAppState extends ConsumerState { void onRouteChanged() { final info = router.routeInformationProvider.value; - final route = info.uri; - print(info.uri); + Stats.onRoute(info.uri); } @override diff --git a/lib/backend/stats/init.dart b/lib/backend/stats/init.dart new file mode 100644 index 00000000..c2e2edf9 --- /dev/null +++ b/lib/backend/stats/init.dart @@ -0,0 +1,15 @@ +import 'service/stats.dart'; +import 'storage/stats.dart'; + +class StatsInit { + static late final StatsStorage storage; + static late final StatsService service; + + static void init() { + service = StatsService(); + } + + static void initStorage() { + storage = StatsStorage(); + } +} diff --git a/lib/backend/stats/service/stats.dart b/lib/backend/stats/service/stats.dart new file mode 100644 index 00000000..598b652d --- /dev/null +++ b/lib/backend/stats/service/stats.dart @@ -0,0 +1 @@ +class StatsService {} diff --git a/lib/backend/stats/storage/stats.dart b/lib/backend/stats/storage/stats.dart new file mode 100644 index 00000000..091dbdac --- /dev/null +++ b/lib/backend/stats/storage/stats.dart @@ -0,0 +1,10 @@ +import 'package:objectbox/objectbox.dart'; +import 'package:mimir/storage/objectbox/init.dart'; + +import '../entity/feature.dart'; +import '../entity/route.dart'; + +class StatsStorage { + late final Box feature = ObjectBoxInit.store.box(); + late final Box route = ObjectBoxInit.store.box(); +} diff --git a/lib/backend/stats/utils/stats.dart b/lib/backend/stats/utils/stats.dart new file mode 100644 index 00000000..01c9d1ec --- /dev/null +++ b/lib/backend/stats/utils/stats.dart @@ -0,0 +1,35 @@ +import 'package:flutter/foundation.dart'; +import 'package:mimir/backend/stats/entity/route.dart'; + +import '../entity/feature.dart'; +import '../init.dart'; + +class Stats { + static String? lastRoute; + + static void onRoute(Uri uri) { + final route = uri.toString(); + if (route == lastRoute) { + return; + } + lastRoute = route; + final time = DateTime.now(); + final row = StatsRoute( + route: route.toString(), + time: time, + ); + final id = StatsInit.storage.route.put(row); + debugPrint('[${time.toString()}] On route #$id: "$route"'); + } + + static void onFeature(String feature, [String? result]) { + final time = DateTime.now(); + final row = StatsFeatureUsage( + feature: feature, + result: result ?? "", + time: time, + ); + final id = StatsInit.storage.feature.put(row); + debugPrint('[${time.toString()}] On feature #$id: "$feature"'); + } +} diff --git a/lib/init.dart b/lib/init.dart index 22ebe27b..07636554 100644 --- a/lib/init.dart +++ b/lib/init.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:mimir/backend/init.dart'; import 'package:mimir/backend/network/ua.dart'; +import 'package:mimir/backend/stats/init.dart'; import 'package:mimir/credentials/entity/credential.dart'; import 'package:mimir/credentials/entity/login_status.dart'; import 'package:mimir/credentials/entity/user_type.dart'; @@ -129,6 +130,7 @@ class Init { YwbInit.init(); Class2ndInit.init(); ElectricityBalanceInit.init(); + StatsInit.init(); } YellowPagesInit.init(); EduEmailInit.init(); @@ -149,6 +151,7 @@ class Init { YwbInit.initStorage(); Class2ndInit.initStorage(); ElectricityBalanceInit.initStorage(); + StatsInit.initStorage(); } YellowPagesInit.initStorage(); EduEmailInit.initStorage(); diff --git a/lib/main.dart b/lib/main.dart index 0d0a087f..2207bae9 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -8,6 +8,7 @@ import 'package:flutter/services.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; +import 'package:mimir/storage/objectbox/init.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:mimir/files.dart'; import 'package:mimir/network/proxy.dart'; @@ -102,13 +103,11 @@ void main() async { // iOS will clear the cache under [getApplicationCacheDirectory()] when device has no enough storage. cacheDir: Files.internal.subDir("hive-cache", R.hiveStorageVersionCache), ); - // if (kDebugMode) { - // final objectBoxDir = Files.internal.subDir("obx", R.objectBoxStorageVersion); - // await objectBoxDir.create(recursive: true); - // await ObjectBoxInit.init( - // dir: objectBoxDir, - // ); - // } + final objectBoxDir = Files.internal.subDir("obx", R.objectBoxStorageVersion); + await objectBoxDir.create(recursive: true); + await ObjectBoxInit.init( + dir: objectBoxDir, + ); } HiveInit.initAdapters(); await HiveInit.initBox(); diff --git a/lib/r.dart b/lib/r.dart index e3361b50..3b087163 100644 --- a/lib/r.dart +++ b/lib/r.dart @@ -14,7 +14,7 @@ class R { static const scheme = "sitlife"; static const hiveStorageVersionCache = "2.3.0"; static const hiveStorageVersionCore = "2.1.1"; - static const objectBoxStorageVersion = "2.6.0"; + static const objectBoxStorageVersion = "2.7.0"; static const appId = "life.mysit.SITLife"; static const appName = "SIT Life"; static const icpLicense = "沪ICP备2024077945号-6A";