[Flutter] Use deviceName instead of hostName for clients
This commit is contained in:
@@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
import 'package:in_app_purchase/in_app_purchase.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:simplecloudnotifier/api/api_client.dart';
|
||||
import 'package:simplecloudnotifier/main_messaging.dart';
|
||||
import 'package:simplecloudnotifier/main_utils.dart';
|
||||
import 'package:simplecloudnotifier/components/layout/nav_layout.dart';
|
||||
@@ -68,15 +69,17 @@ void main() async {
|
||||
print('[INIT] Request Notification permissions...');
|
||||
await FirebaseMessaging.instance.requestPermission(provisional: true);
|
||||
|
||||
FirebaseMessaging.instance.onTokenRefresh.listen((fcmToken) {
|
||||
try {
|
||||
setFirebaseToken(fcmToken);
|
||||
} catch (exc, trace) {
|
||||
ApplicationLog.error('Failed to set firebase token: ' + exc.toString(), trace: trace);
|
||||
}
|
||||
}).onError((dynamic err) {
|
||||
ApplicationLog.error('Failed to listen to token refresh events: ' + (err?.toString() ?? ''));
|
||||
});
|
||||
FirebaseMessaging.instance.onTokenRefresh
|
||||
.listen((fcmToken) {
|
||||
try {
|
||||
setFirebaseToken(fcmToken);
|
||||
} catch (exc, trace) {
|
||||
ApplicationLog.error('Failed to set firebase token: ' + exc.toString(), trace: trace);
|
||||
}
|
||||
})
|
||||
.onError((dynamic err) {
|
||||
ApplicationLog.error('Failed to listen to token refresh events: ' + (err?.toString() ?? ''));
|
||||
});
|
||||
|
||||
try {
|
||||
print('[INIT] Query firebase token...');
|
||||
@@ -96,6 +99,25 @@ void main() async {
|
||||
|
||||
await appAuth.tryMigrateFromV1();
|
||||
|
||||
if (appAuth.isAuth()) {
|
||||
print('[INIT] Load Client and potentially update...');
|
||||
|
||||
try {
|
||||
var client = await appAuth.loadClient(onlyCached: true);
|
||||
if (client != null) {
|
||||
if (client.agentModel != Globals().deviceModel || client.name != Globals().nameForClient() || client.agentVersion != Globals().version) {
|
||||
print('[INIT] Update Client info...');
|
||||
|
||||
final newClient = await APIClient.updateClient(appAuth, client.clientID, agentModel: Globals().deviceModel, name: Globals().nameForClient(), agentVersion: Globals().version);
|
||||
appAuth.setClientAndClientID(newClient);
|
||||
await appAuth.save();
|
||||
}
|
||||
}
|
||||
} catch (exc, trace) {
|
||||
ApplicationLog.error('Failed to get client (on init): ' + exc.toString(), trace: trace);
|
||||
}
|
||||
}
|
||||
|
||||
print('[INIT] Load Notifications...');
|
||||
|
||||
final flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
|
||||
|
||||
Reference in New Issue
Block a user