Fix linux build (does not support fcm)
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
@@ -17,15 +19,24 @@ import 'firebase_options.dart';
|
||||
void main() async {
|
||||
print('[INIT] Application starting...');
|
||||
|
||||
print('[INIT] Ensure WidgetsFlutterBinding...');
|
||||
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
await Hive.initFlutter();
|
||||
print('[INIT] Init Globals...');
|
||||
|
||||
await Globals().init();
|
||||
|
||||
print('[INIT] Init Hive...');
|
||||
|
||||
await Hive.initFlutter();
|
||||
|
||||
Hive.registerAdapter(SCNRequestAdapter());
|
||||
Hive.registerAdapter(SCNLogAdapter());
|
||||
Hive.registerAdapter(SCNLogLevelAdapter());
|
||||
|
||||
print('[INIT] Load Hive<scn-requests>...');
|
||||
|
||||
try {
|
||||
await Hive.openBox<SCNRequest>('scn-requests');
|
||||
} catch (exc, trace) {
|
||||
@@ -34,6 +45,8 @@ void main() async {
|
||||
ApplicationLog.error('Failed to open Hive-Box: scn-requests: ' + exc.toString(), trace: trace);
|
||||
}
|
||||
|
||||
print('[INIT] Load Hive<scn-logs>...');
|
||||
|
||||
try {
|
||||
await Hive.openBox<SCNLog>('scn-logs');
|
||||
} catch (exc, trace) {
|
||||
@@ -42,45 +55,58 @@ void main() async {
|
||||
ApplicationLog.error('Failed to open Hive-Box: scn-logs: ' + exc.toString(), trace: trace);
|
||||
}
|
||||
|
||||
print('[INIT] Load AppAuth...');
|
||||
|
||||
final appAuth = AppAuth(); // ensure UserAccount is loaded
|
||||
|
||||
if (appAuth.isAuth()) {
|
||||
try {
|
||||
print('[INIT] Load User...');
|
||||
await appAuth.loadUser();
|
||||
//TODO fallback to cached user (perhaps event use cached client (if exists) directly and only update/load in background)
|
||||
} catch (exc, trace) {
|
||||
ApplicationLog.error('Failed to load user (on startup): ' + exc.toString(), trace: trace);
|
||||
}
|
||||
try {
|
||||
print('[INIT] Load Client...');
|
||||
await appAuth.loadClient();
|
||||
//TODO fallback to cached client (perhaps event use cached client (if exists) directly and only update/load in background)
|
||||
} catch (exc, trace) {
|
||||
ApplicationLog.error('Failed to load user (on startup): ' + exc.toString(), trace: trace);
|
||||
}
|
||||
}
|
||||
|
||||
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
|
||||
if (!Platform.isLinux) {
|
||||
print('[INIT] Init Firebase...');
|
||||
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
|
||||
|
||||
await FirebaseMessaging.instance.requestPermission(provisional: true);
|
||||
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);
|
||||
print('[INIT] Query firebase token...');
|
||||
final fcmToken = await FirebaseMessaging.instance.getToken();
|
||||
if (fcmToken != null) {
|
||||
setFirebaseToken(fcmToken);
|
||||
}
|
||||
} catch (exc, trace) {
|
||||
ApplicationLog.error('Failed to set firebase token: ' + exc.toString(), trace: trace);
|
||||
ApplicationLog.error('Failed to get+set firebase token: ' + exc.toString(), trace: trace);
|
||||
}
|
||||
}).onError((dynamic err) {
|
||||
ApplicationLog.error('Failed to listen to token refresh events: ' + (err?.toString() ?? ''));
|
||||
});
|
||||
|
||||
try {
|
||||
final fcmToken = await FirebaseMessaging.instance.getToken();
|
||||
if (fcmToken != null) {
|
||||
setFirebaseToken(fcmToken);
|
||||
}
|
||||
} catch (exc, trace) {
|
||||
ApplicationLog.error('Failed to get+set firebase token: ' + exc.toString(), trace: trace);
|
||||
} else {
|
||||
print('[INIT] Skip Firebase init (Platform == Linux)...');
|
||||
}
|
||||
|
||||
ApplicationLog.debug('Application started');
|
||||
ApplicationLog.debug('[INIT] Application started');
|
||||
|
||||
runApp(
|
||||
MultiProvider(
|
||||
|
||||
Reference in New Issue
Block a user