fix(app): read the version from the installed package

The version was a hand-written constant that had to be kept in sync with
`version:` in pubspec.yaml. It was not: the constant still said 1.1.0 while
the shipped build was 1.1.2+22, so every abuse report carried a version that
no build ever had — and reports could not be traced back to a build.

AppInfo reads versionName / CFBundleShortVersionString, which Flutter derives
from the pubspec, so the two cannot drift apart again. Reports now carry the
build number as well; when the version is not known yet the field is omitted
rather than guessed.

Also adds the timestamp regression test that covers MessagingService.wireSentAt,
which shipped in 1.1.2 without its test.
This commit is contained in:
Julius Joska
2026-09-04 10:18:37 +02:00
parent f903e21e3a
commit 79ad411d7e
9 changed files with 193 additions and 5 deletions
+44
View File
@@ -0,0 +1,44 @@
/// Verze aplikace čtená z nainstalovaného balíčku.
///
/// Proč ne konstanta: verze se dřív psala ručně do `AppConstants` a musela se
/// hlídat proti `version:` v pubspec.yaml. Nehlídala se — produkční 1.1.2+22
/// posílala v hlášeních zneužití „1.1.0" a podle hlášení tak nešlo dohledat,
/// ze kterého buildu přišlo. `package_info_plus` čte `versionName` (Android)
/// / `CFBundleShortVersionString` (iOS), které Flutter generuje přímo
/// z pubspecu — rozejít se to už nemůže a ruční editace odpadá.
library;
import 'package:package_info_plus/package_info_plus.dart';
class AppInfo {
AppInfo._();
/// Zástupný text, dokud verzi nezná (nebo když ji nešlo přečíst). Znak, ne
/// slovo — appka běží v pěti jazycích a české „neznámá" by v nich čouhalo.
static const String unknownVersion = '—';
static PackageInfo? _info;
/// Načte verzi z balíčku. Volat jednou při startu, před prvním `runApp`.
static Future<void> init() async {
_info = await PackageInfo.fromPlatform();
}
/// Verze pro uživatele: `1.1.2`.
static String get version => _info?.version ?? unknownVersion;
/// Verze pro diagnostiku: `1.1.2+22`. Build číslo je jediné, čím se hlášení
/// zneužití přiřadí konkrétnímu buildu — do UI nepatří, do hlášení ano.
/// `null`, dokud verzi nezná: hlášení pak pole vynechá, ať server dostane
/// prázdno místo vymyšlené hodnoty.
static String? get versionWithBuild {
final info = _info;
if (info == null) return null;
// iOS bez vyplněného CFBundleVersion vrací v buildNumber rovnou verzi
// (dokumentované chování balíčku) — nelepit „1.1.2+1.1.2".
if (info.buildNumber.isEmpty || info.buildNumber == info.version) {
return info.version;
}
return '${info.version}+${info.buildNumber}';
}
}
@@ -3,8 +3,6 @@ class AppConstants {
AppConstants._();
static const String appName = 'Šepot';
/// Musí sedět s `version:` v pubspec.yaml (bez build čísla).
static const String appVersion = '1.1.0';
static const String appAuthor = 'ajtak.it';
// Relay server (REST + WS na jednom portu). Přepsatelné při buildu:
+6 -1
View File
@@ -21,6 +21,7 @@ import 'dart:convert';
import 'dart:io';
import 'package:http/http.dart' as http;
import 'package:sepot/core/app_info.dart';
import 'package:sepot/core/constants/app_constants.dart';
import 'package:sepot/core/errors.dart';
@@ -67,12 +68,16 @@ class ReportService {
throw const ReportEmptyDescriptionError();
}
// S build číslem, ne jen „1.1.2" — jinak nejde poznat, ze kterého buildu
// hlášení přišlo. Neznámou verzi radši vynechat než poslat vymyšlenou.
final verze = AppInfo.versionWithBuild;
final body = <String, dynamic>{
'kategorie': category.wire,
'popis': popis,
'zdroj': 'app',
'platforma': Platform.operatingSystem,
'verze': AppConstants.appVersion,
'verze': ?verze,
if (reportedFingerprint != null && reportedFingerprint.isNotEmpty)
'nahlasenyOtisk': reportedFingerprint,
if (replyTo != null && replyTo.trim().isNotEmpty)
@@ -8,6 +8,7 @@ import 'package:go_router/go_router.dart';
import 'package:path_provider/path_provider.dart';
import 'package:share_plus/share_plus.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:sepot/core/app_info.dart';
import 'package:sepot/core/constants/app_constants.dart';
import 'package:sepot/core/l10n/error_messages.dart';
import 'package:sepot/core/l10n/l10n.dart';
@@ -181,7 +182,7 @@ class SettingsScreen extends ConsumerWidget {
_buildTile(
icon: Icons.info_outline,
title: l10n.commonAppName,
subtitle: l10n.settingsVersion(AppConstants.appVersion),
subtitle: l10n.settingsVersion(AppInfo.version),
onTap: () => _showAbout(context),
),
// Zdrojový kód je veřejný (AGPL-3.0). Detaily o licenci a odkaz
@@ -614,7 +615,7 @@ class SettingsScreen extends ConsumerWidget {
),
const SizedBox(height: 8),
Text(
ctx.l10n.settingsVersion(AppConstants.appVersion),
ctx.l10n.settingsVersion(AppInfo.version),
style: const TextStyle(color: SepotColors.textSecondary),
),
const SizedBox(height: 16),
+9
View File
@@ -6,6 +6,7 @@ import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:intl/date_symbol_data_local.dart';
import 'package:sepot/app.dart';
import 'package:sepot/core/app_info.dart';
import 'package:sepot/core/constants/app_constants.dart';
import 'package:sepot/core/crypto/sepot_crypto.dart';
import 'package:sepot/core/l10n/l10n.dart';
@@ -56,6 +57,14 @@ void main(List<String> args) {
debugPrint('FlutterError: ${details.exceptionAsString()}');
};
// Verze appky z balíčku — nekritické, bez ní se jen v nastavení a
// v hlášení zneužití místo čísla ukáže AppInfo.unknownVersion.
try {
await AppInfo.init();
} catch (e, s) {
debugPrint('AppInfo.init selhalo (nekritické): $e\n$s');
}
// Formáty dat všech podporovaných jazyků — nekritické, appka poběží i bez nich
for (final lang in const ['cs', 'en', 'de', 'ru', 'it']) {
try {