Fix linux build (does not support fcm)
This commit is contained in:
parent
8e0c8e825b
commit
549311535c
@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
@ -17,15 +19,24 @@ import 'firebase_options.dart';
|
|||||||
void main() async {
|
void main() async {
|
||||||
print('[INIT] Application starting...');
|
print('[INIT] Application starting...');
|
||||||
|
|
||||||
|
print('[INIT] Ensure WidgetsFlutterBinding...');
|
||||||
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
await Hive.initFlutter();
|
print('[INIT] Init Globals...');
|
||||||
|
|
||||||
await Globals().init();
|
await Globals().init();
|
||||||
|
|
||||||
|
print('[INIT] Init Hive...');
|
||||||
|
|
||||||
|
await Hive.initFlutter();
|
||||||
|
|
||||||
Hive.registerAdapter(SCNRequestAdapter());
|
Hive.registerAdapter(SCNRequestAdapter());
|
||||||
Hive.registerAdapter(SCNLogAdapter());
|
Hive.registerAdapter(SCNLogAdapter());
|
||||||
Hive.registerAdapter(SCNLogLevelAdapter());
|
Hive.registerAdapter(SCNLogLevelAdapter());
|
||||||
|
|
||||||
|
print('[INIT] Load Hive<scn-requests>...');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await Hive.openBox<SCNRequest>('scn-requests');
|
await Hive.openBox<SCNRequest>('scn-requests');
|
||||||
} catch (exc, trace) {
|
} catch (exc, trace) {
|
||||||
@ -34,6 +45,8 @@ void main() async {
|
|||||||
ApplicationLog.error('Failed to open Hive-Box: scn-requests: ' + exc.toString(), trace: trace);
|
ApplicationLog.error('Failed to open Hive-Box: scn-requests: ' + exc.toString(), trace: trace);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print('[INIT] Load Hive<scn-logs>...');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await Hive.openBox<SCNLog>('scn-logs');
|
await Hive.openBox<SCNLog>('scn-logs');
|
||||||
} catch (exc, trace) {
|
} catch (exc, trace) {
|
||||||
@ -42,45 +55,58 @@ void main() async {
|
|||||||
ApplicationLog.error('Failed to open Hive-Box: scn-logs: ' + exc.toString(), trace: trace);
|
ApplicationLog.error('Failed to open Hive-Box: scn-logs: ' + exc.toString(), trace: trace);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print('[INIT] Load AppAuth...');
|
||||||
|
|
||||||
final appAuth = AppAuth(); // ensure UserAccount is loaded
|
final appAuth = AppAuth(); // ensure UserAccount is loaded
|
||||||
|
|
||||||
if (appAuth.isAuth()) {
|
if (appAuth.isAuth()) {
|
||||||
try {
|
try {
|
||||||
|
print('[INIT] Load User...');
|
||||||
await appAuth.loadUser();
|
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) {
|
} catch (exc, trace) {
|
||||||
ApplicationLog.error('Failed to load user (on startup): ' + exc.toString(), trace: trace);
|
ApplicationLog.error('Failed to load user (on startup): ' + exc.toString(), trace: trace);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
print('[INIT] Load Client...');
|
||||||
await appAuth.loadClient();
|
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) {
|
} catch (exc, trace) {
|
||||||
ApplicationLog.error('Failed to load user (on startup): ' + exc.toString(), trace: 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 {
|
try {
|
||||||
setFirebaseToken(fcmToken);
|
print('[INIT] Query firebase token...');
|
||||||
|
final fcmToken = await FirebaseMessaging.instance.getToken();
|
||||||
|
if (fcmToken != null) {
|
||||||
|
setFirebaseToken(fcmToken);
|
||||||
|
}
|
||||||
} catch (exc, trace) {
|
} 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) {
|
} else {
|
||||||
ApplicationLog.error('Failed to listen to token refresh events: ' + (err?.toString() ?? ''));
|
print('[INIT] Skip Firebase init (Platform == Linux)...');
|
||||||
});
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ApplicationLog.debug('Application started');
|
ApplicationLog.debug('[INIT] Application started');
|
||||||
|
|
||||||
runApp(
|
runApp(
|
||||||
MultiProvider(
|
MultiProvider(
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||||
@ -9,6 +11,7 @@ import 'package:simplecloudnotifier/state/application_log.dart';
|
|||||||
import 'package:simplecloudnotifier/state/globals.dart';
|
import 'package:simplecloudnotifier/state/globals.dart';
|
||||||
import 'package:simplecloudnotifier/state/app_auth.dart';
|
import 'package:simplecloudnotifier/state/app_auth.dart';
|
||||||
import 'package:simplecloudnotifier/utils/toaster.dart';
|
import 'package:simplecloudnotifier/utils/toaster.dart';
|
||||||
|
import 'package:uuid/uuid.dart';
|
||||||
|
|
||||||
class AccountRootPage extends StatefulWidget {
|
class AccountRootPage extends StatefulWidget {
|
||||||
const AccountRootPage({super.key});
|
const AccountRootPage({super.key});
|
||||||
@ -447,15 +450,21 @@ class _AccountRootPageState extends State<AccountRootPage> {
|
|||||||
final acc = Provider.of<AppAuth>(context, listen: false);
|
final acc = Provider.of<AppAuth>(context, listen: false);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final notificationSettings = await FirebaseMessaging.instance.requestPermission(provisional: true);
|
final String? fcmToken;
|
||||||
|
if (Platform.isLinux) {
|
||||||
|
Toaster.warn("Unsupported Platform", 'Your platform is not supported by FCM - notifications will not work');
|
||||||
|
fcmToken = '(linux-' + Uuid().v4() + ')';
|
||||||
|
} else {
|
||||||
|
final notificationSettings = await FirebaseMessaging.instance.requestPermission(provisional: true);
|
||||||
|
|
||||||
if (notificationSettings.authorizationStatus == AuthorizationStatus.denied) {
|
if (notificationSettings.authorizationStatus == AuthorizationStatus.denied) {
|
||||||
Toaster.error("Missing Permission", 'Please allow notifications to create an account');
|
Toaster.error("Missing Permission", 'Please allow notifications to create an account');
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fcmToken = await FirebaseMessaging.instance.getToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
final fcmToken = await FirebaseMessaging.instance.getToken();
|
|
||||||
|
|
||||||
if (fcmToken == null) {
|
if (fcmToken == null) {
|
||||||
Toaster.warn("Missing Token", 'No FCM Token found, please allow notifications, ensure you have a network connection and restart the app');
|
Toaster.warn("Missing Token", 'No FCM Token found, please allow notifications, ensure you have a network connection and restart the app');
|
||||||
return;
|
return;
|
||||||
|
@ -12,6 +12,9 @@ import 'package:simplecloudnotifier/pages/message_list/message_list_item.dart';
|
|||||||
class MessageListPage extends StatefulWidget {
|
class MessageListPage extends StatefulWidget {
|
||||||
const MessageListPage({super.key});
|
const MessageListPage({super.key});
|
||||||
|
|
||||||
|
//TODO reload on switch to tab
|
||||||
|
//TODO reload on app to foreground
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<MessageListPage> createState() => _MessageListPageState();
|
State<MessageListPage> createState() => _MessageListPageState();
|
||||||
}
|
}
|
||||||
|
@ -941,7 +941,7 @@ packages:
|
|||||||
source: hosted
|
source: hosted
|
||||||
version: "3.1.1"
|
version: "3.1.1"
|
||||||
uuid:
|
uuid:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: uuid
|
name: uuid
|
||||||
sha256: "814e9e88f21a176ae1359149021870e87f7cddaf633ab678a5d2b0bff7fd1ba8"
|
sha256: "814e9e88f21a176ae1359149021870e87f7cddaf633ab678a5d2b0bff7fd1ba8"
|
||||||
|
@ -29,6 +29,7 @@ dependencies:
|
|||||||
firebase_messaging: ^14.9.4
|
firebase_messaging: ^14.9.4
|
||||||
device_info_plus: ^10.1.0
|
device_info_plus: ^10.1.0
|
||||||
toastification: ^2.0.0
|
toastification: ^2.0.0
|
||||||
|
uuid: ^4.4.0
|
||||||
|
|
||||||
|
|
||||||
dependency_overrides:
|
dependency_overrides:
|
||||||
|
Loading…
Reference in New Issue
Block a user