Skip to content

Commit

Permalink
feat(firebase): conditionally load Firebase depending on the platform
Browse files Browse the repository at this point in the history
  • Loading branch information
JagandeepBrar committed Mar 26, 2022
1 parent b792ea6 commit 91f556d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 21 deletions.
14 changes: 14 additions & 0 deletions lib/core/firebase/core.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
import 'package:firebase_core/firebase_core.dart';
import '../../firebase_options.dart';
import '../system/platform.dart';

class LunaFirebase {
static bool get isSupported {
final platform = LunaPlatform();
if (platform.isMobile || platform.isMacOS || platform.isWeb) {
// Validate that the firebase config exists by trying to load it
try {
DefaultFirebaseOptions.currentPlatform;
return true;
// ignore: empty_catches
} catch (_) {}
}
return false;
}

/// Initialize Firebase and configuration.
///
/// This must be called before anything accesses Firebase services, or an exception will be thrown.
Expand Down
4 changes: 2 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Future<void> main() async {
() async {
//LunaSea initialization
await Database().initialize();
await LunaFirebase().initialize();
if (LunaFirebase.isSupported) await LunaFirebase().initialize();
LunaLogger().initialize();
LunaTheme().initialize();
if (LunaWindowManager.isSupported) await LunaWindowManager().initialize();
Expand Down Expand Up @@ -113,7 +113,7 @@ class _State extends State<LunaOS> {
}

Future<void> _boot() async {
_initNotifications();
if (LunaFirebase.isSupported) _initNotifications();

String? tag = LunaLanguage.ENGLISH.fromLocale(context.locale)?.languageTag;
tag ??= LunaLanguage.ENGLISH.languageTag;
Expand Down
17 changes: 11 additions & 6 deletions lib/modules/settings/core/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@ class SettingsRouter extends LunaModuleRouter {
void defineAllRoutes(FluroRouter router) {
SettingsHomeRouter().defineRoute(router);
// Account
SettingsAccountRouter().defineRoute(router);
SettingsAccountPasswordResetRouter().defineRoute(router);
SettingsAccountSettingsRouter().defineRoute(router);
if (LunaFirebase.isSupported) {
SettingsAccountRouter().defineRoute(router);
SettingsAccountPasswordResetRouter().defineRoute(router);
SettingsAccountSettingsRouter().defineRoute(router);
SettingsNotificationsRouter().defineRoute(router);
}
// Donations
if (LunaInAppPurchases.isSupported) {
SettingsDonationsRouter().defineRoute(router);
SettingsDonationsThankYouRouter().defineRoute(router);
}
// Configuration
SettingsConfigurationRouter().defineRoute(router);
SettingsConfigurationAppearanceRouter().defineRoute(router);
Expand Down Expand Up @@ -73,9 +81,6 @@ class SettingsRouter extends LunaModuleRouter {
SettingsDebugMenuRouter().defineRoute(router);
SettingsSystemDebugMenuUIRouter().defineRoute(router);
// Other
SettingsDonationsRouter().defineRoute(router);
SettingsDonationsThankYouRouter().defineRoute(router);
SettingsNotificationsRouter().defineRoute(router);
SettingsProfilesRouter().defineRoute(router);
SettingsResourcesRouter().defineRoute(router);
SettingsSystemRouter().defineRoute(router);
Expand Down
27 changes: 15 additions & 12 deletions lib/modules/settings/routes/settings/route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,27 @@ class _State extends State<_Widget> with LunaScrollControllerMixin {
return LunaListView(
controller: scrollController,
children: [
LunaBlock(
title: 'settings.Account'.tr(),
body: [TextSpan(text: 'settings.AccountDescription'.tr())],
trailing: const LunaIconButton(icon: Icons.person_rounded),
onTap: () async => SettingsAccountRouter().navigateTo(context),
),
if (LunaFirebase.isSupported)
LunaBlock(
title: 'settings.Account'.tr(),
body: [TextSpan(text: 'settings.AccountDescription'.tr())],
trailing: const LunaIconButton(icon: Icons.person_rounded),
onTap: () async => SettingsAccountRouter().navigateTo(context),
),
LunaBlock(
title: 'settings.Configuration'.tr(),
body: [TextSpan(text: 'settings.ConfigurationDescription'.tr())],
trailing: const LunaIconButton(icon: Icons.device_hub_rounded),
onTap: () async => SettingsConfigurationRouter().navigateTo(context),
),
LunaBlock(
title: 'settings.Notifications'.tr(),
body: [TextSpan(text: 'settings.NotificationsDescription'.tr())],
trailing: const LunaIconButton(icon: Icons.notifications_rounded),
onTap: () async => SettingsNotificationsRouter().navigateTo(context),
),
if (LunaFirebase.isSupported)
LunaBlock(
title: 'settings.Notifications'.tr(),
body: [TextSpan(text: 'settings.NotificationsDescription'.tr())],
trailing: const LunaIconButton(icon: Icons.notifications_rounded),
onTap: () async =>
SettingsNotificationsRouter().navigateTo(context),
),
LunaBlock(
title: 'settings.Profiles'.tr(),
body: [TextSpan(text: 'settings.ProfilesDescription'.tr())],
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/settings/routes/system/route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class _State extends State<_Widget> with LunaScrollControllerMixin {
bool result = await SettingsDialogs().clearConfiguration(context);
if (result) {
Database().bootstrap();
LunaFirebaseAuth().signOut();
if (LunaFirebase.isSupported) LunaFirebaseAuth().signOut();
LunaState.reset(context);
showLunaSuccessSnackBar(
title: 'Configuration Cleared',
Expand Down

0 comments on commit 91f556d

Please sign in to comment.