Implement sending version string of app
This commit is contained in:
parent
4f2ff2d95b
commit
efcc5831c2
5 changed files with 39 additions and 8 deletions
|
@ -5,6 +5,7 @@ import 'package:contacts_plus_plus/models/friend.dart';
|
|||
import 'package:contacts_plus_plus/models/personal_profile.dart';
|
||||
import 'package:contacts_plus_plus/models/user.dart';
|
||||
import 'package:contacts_plus_plus/models/user_profile.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
|
||||
class UserApi {
|
||||
static Future<Iterable<User>> searchUsers(ApiClient client, {required String needle}) async {
|
||||
|
@ -29,6 +30,10 @@ class UserApi {
|
|||
}
|
||||
|
||||
static Future<void> setStatus(ApiClient client, {required UserStatus status}) async {
|
||||
final pkginfo = await PackageInfo.fromPlatform();
|
||||
status = status.copyWith(
|
||||
neosVersion: "${pkginfo.version} of ${pkginfo.appName}",
|
||||
);
|
||||
final body = jsonEncode(status.toMap(shallow: true));
|
||||
final response = await client.put("/users/${client.userId}/status", body: body);
|
||||
ApiClient.checkResponse(response);
|
||||
|
|
|
@ -98,13 +98,17 @@ class UserStatus {
|
|||
final OnlineStatus onlineStatus;
|
||||
final DateTime lastStatusChange;
|
||||
final List<Session> activeSessions;
|
||||
final String neosVersion;
|
||||
|
||||
UserStatus({required this.onlineStatus, required this.lastStatusChange, required this.activeSessions});
|
||||
UserStatus({required this.onlineStatus, required this.lastStatusChange, required this.activeSessions,
|
||||
required this.neosVersion,
|
||||
});
|
||||
|
||||
factory UserStatus.empty() => UserStatus(
|
||||
onlineStatus: OnlineStatus.offline,
|
||||
lastStatusChange: DateTime.now(),
|
||||
activeSessions: [],
|
||||
neosVersion: "",
|
||||
);
|
||||
|
||||
factory UserStatus.fromMap(Map map) {
|
||||
|
@ -114,6 +118,7 @@ class UserStatus {
|
|||
onlineStatus: status,
|
||||
lastStatusChange: DateTime.parse(map["lastStatusChange"]),
|
||||
activeSessions: (map["activeSessions"] as List? ?? []).map((e) => Session.fromMap(e)).toList(),
|
||||
neosVersion: map["neosVersion"] ?? "",
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -121,14 +126,18 @@ class UserStatus {
|
|||
return {
|
||||
"onlineStatus": onlineStatus.index,
|
||||
"lastStatusChange": lastStatusChange.toIso8601String(),
|
||||
"activeSessions": shallow ? [] : activeSessions.map((e) => e.toMap(),)
|
||||
"activeSessions": shallow ? [] : activeSessions.map((e) => e.toMap(),),
|
||||
"neosVersion": neosVersion,
|
||||
};
|
||||
}
|
||||
|
||||
UserStatus copyWith({OnlineStatus? onlineStatus, DateTime? lastStatusChange, List<Session>? activeSessions})
|
||||
UserStatus copyWith({OnlineStatus? onlineStatus, DateTime? lastStatusChange, List<Session>? activeSessions,
|
||||
String? neosVersion
|
||||
})
|
||||
=> UserStatus(
|
||||
onlineStatus: onlineStatus ?? this.onlineStatus,
|
||||
lastStatusChange: lastStatusChange ?? this.lastStatusChange,
|
||||
activeSessions: activeSessions ?? this.activeSessions,
|
||||
neosVersion: neosVersion ?? this.neosVersion,
|
||||
);
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
import 'package:contacts_plus_plus/client_holder.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import 'package:workmanager/workmanager.dart';
|
||||
|
||||
class SettingsPage extends StatelessWidget {
|
||||
const SettingsPage({super.key});
|
||||
|
@ -81,10 +81,10 @@ class SettingsPage extends StatelessWidget {
|
|||
ListTile(
|
||||
trailing: const Icon(Icons.info_outline),
|
||||
title: const Text("About Contacts++"),
|
||||
onTap: () {
|
||||
onTap: () async {
|
||||
showAboutDialog(
|
||||
context: context,
|
||||
applicationVersion: "1.0.0",
|
||||
applicationVersion: (await PackageInfo.fromPlatform()).version,
|
||||
applicationIcon: InkWell(
|
||||
onTap: () async {
|
||||
if (!await launchUrl(Uri.parse("https://github.com/Nutcake/contacts-plus-plus"), mode: LaunchMode.externalApplication)) {
|
||||
|
|
16
pubspec.lock
16
pubspec.lock
|
@ -376,6 +376,22 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.2"
|
||||
package_info_plus:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: package_info_plus
|
||||
sha256: "10259b111176fba5c505b102e3a5b022b51dd97e30522e906d6922c745584745"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.1.2"
|
||||
package_info_plus_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: package_info_plus_platform_interface
|
||||
sha256: "9bc8ba46813a4cc42c66ab781470711781940780fd8beddd0c3da62506d3a6c6"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.1"
|
||||
path:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
|
|
@ -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: 1.0.1+1
|
||||
|
||||
environment:
|
||||
sdk: '>=2.19.6 <3.0.0'
|
||||
|
@ -50,7 +50,8 @@ dependencies:
|
|||
url_launcher: ^6.1.10
|
||||
workmanager: ^0.5.1
|
||||
flutter_local_notifications: ^14.0.0+1
|
||||
collection: any
|
||||
collection: ^1.17.0
|
||||
package_info_plus: ^3.1.2
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
Loading…
Reference in a new issue