From 1a6d00730ed9b4499b5ba419efe8f966a976a2ce Mon Sep 17 00:00:00 2001 From: Sven Carstensen Date: Sun, 10 Mar 2024 12:03:09 +0100 Subject: [PATCH] Versionnummer (halb) automatisiert --- android/app/build.gradle | 7 +++++-- lib/popups/infos_popup.dart | 4 +++- lib/tools/mqtt_core.dart | 17 ++++++++++++----- lib/tools/util.dart | 7 +++++++ pubspec.lock | 32 ++++++++++++++++++++++++++++++++ pubspec.yaml | 4 +++- 6 files changed, 62 insertions(+), 9 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 39e0624..208f653 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -49,11 +49,14 @@ android { } defaultConfig { + // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "de.assecutor.stadtbote" + // You can update the following values to match your application needs. + // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. minSdkVersion flutter.minSdkVersion targetSdkVersion flutter.targetSdkVersion - versionCode 3 - versionName 'A213' + versionCode flutterVersionCode.toInteger() + versionName flutterVersionName minSdkVersion 28 } diff --git a/lib/popups/infos_popup.dart b/lib/popups/infos_popup.dart index b76f335..ec7c200 100644 --- a/lib/popups/infos_popup.dart +++ b/lib/popups/infos_popup.dart @@ -5,7 +5,9 @@ import 'package:stadtbote/tools/mqtt_core.dart'; import 'package:stadtbote/tools/util.dart'; void showInfosPopup(BuildContext context, SessionStatus? status) async { - var text = "Versionsnummer: a213\n"; + var version = await Util.getAppVersion(); + + var text = "Versionsnummer: a$version\n"; text += "Verbindungsstatus: ${MqttCore.instance.connectionState == ConnectionStateEnum.connected ? "Verbunden" : "NICHT verbunden"}\n"; text += "GPS-Status: ${MyApp.currentPosition != null ? MyApp.currentPosition!.timestamp.toString() : "Unbekannt"}\n"; text += "\n"; diff --git a/lib/tools/mqtt_core.dart b/lib/tools/mqtt_core.dart index 5ca4039..c48de7d 100644 --- a/lib/tools/mqtt_core.dart +++ b/lib/tools/mqtt_core.dart @@ -2,10 +2,12 @@ import 'dart:async'; import 'dart:convert'; import 'dart:math'; +import 'package:device_info_plus/device_info_plus.dart'; import 'package:flutter/foundation.dart'; import 'package:isar/isar.dart'; import 'package:mqtt_client/mqtt_client.dart'; import 'package:mqtt_client/mqtt_server_client.dart'; +import 'package:package_info/package_info.dart'; import 'package:stadtbote/model/enqueued_message.dart'; import 'package:stadtbote/model/ranking.dart'; import 'package:stadtbote/model/status.dart'; @@ -357,17 +359,22 @@ class MqttCore { void _processBootstrap() async { try { + var deviceInfoPlugin = DeviceInfoPlugin(); + + AndroidDeviceInfo androidInfo = await deviceInfoPlugin.androidInfo; + BaseDeviceInfo deviceInfo = await deviceInfoPlugin.deviceInfo; + var deviceObject = DeviceObject(); - deviceObject.manufacturer = "sven"; - deviceObject.model = "emulator"; - deviceObject.os = "hat es"; - deviceObject.osVer = "0.0"; + deviceObject.manufacturer = deviceInfo.data['manufacturer']; + deviceObject.model = deviceInfo.data['model']; + deviceObject.os = androidInfo.version.release; + deviceObject.osVer = androidInfo.version.sdkInt.toString(); var handshakeMessage = BootstrapRequest(); handshakeMessage.app = "sb"; handshakeMessage.mqttClientId = await Util.getAppUuid(); handshakeMessage.deviceObject = deviceObject; - handshakeMessage.ver = 213; + handshakeMessage.ver = await Util.getAppVersion(); var jsonMap = handshakeMessage.toJson(); var json = jsonEncode(jsonMap); diff --git a/lib/tools/util.dart b/lib/tools/util.dart index c74abc7..cf6205a 100644 --- a/lib/tools/util.dart +++ b/lib/tools/util.dart @@ -4,6 +4,7 @@ import 'package:audioplayers/audioplayers.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:image_picker/image_picker.dart'; +import 'package:package_info/package_info.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:stadtbote/model/job.dart'; import 'package:stadtbote/tools/constants.dart'; @@ -72,6 +73,12 @@ class Util { return currentUuid; } + static Future getAppVersion() async { + PackageInfo packageInfo = await PackageInfo.fromPlatform(); + + return int.parse(packageInfo.version.replaceAll(".0.0", "")); + } + static _printLongText(String text) { final pattern = RegExp('.{1,800}'); // 800 is the size of each chunk pattern.allMatches(text).forEach((match) => debugPrint(match.group(0))); diff --git a/pubspec.lock b/pubspec.lock index 58a8382..d6ea1b7 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -297,6 +297,22 @@ packages: url: "https://pub.dev" source: hosted version: "1.2.0" + device_info_plus: + dependency: "direct main" + description: + name: device_info_plus + sha256: "77f757b789ff68e4eaf9c56d1752309bd9f7ad557cb105b938a7f8eb89e59110" + url: "https://pub.dev" + source: hosted + version: "9.1.2" + device_info_plus_platform_interface: + dependency: transitive + description: + name: device_info_plus_platform_interface + sha256: d3b01d5868b50ae571cd1dc6e502fc94d956b665756180f7b16ead09e836fd64 + url: "https://pub.dev" + source: hosted + version: "7.0.0" diffutil_dart: dependency: transitive description: @@ -896,6 +912,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.0" + package_info: + dependency: "direct main" + description: + name: package_info + sha256: "6c07d9d82c69e16afeeeeb6866fe43985a20b3b50df243091bfc4a4ad2b03b75" + url: "https://pub.dev" + source: hosted + version: "2.0.2" path: dependency: transitive description: @@ -1453,6 +1477,14 @@ packages: url: "https://pub.dev" source: hosted version: "5.1.0" + win32_registry: + dependency: transitive + description: + name: win32_registry + sha256: "41fd8a189940d8696b1b810efb9abcf60827b6cbfab90b0c43e8439e3a39d85a" + url: "https://pub.dev" + source: hosted + version: "1.1.2" wkt_parser: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index b090875..d49f5cc 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.0.0+1 +version: 214.0.0+5 environment: sdk: '>=2.19.6 <3.0.0' @@ -68,6 +68,8 @@ dependencies: url_launcher: ^6.2.4 audioplayers: ^5.2.1 image: ^4.1.7 + device_info_plus: ^9.1.2 + package_info: ^2.0.2 dev_dependencies: flutter_test: