Skip to content

Commit

Permalink
fix(neon_framework): Migrate to notifications_push_repository
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <kate@provokateurin.de>
  • Loading branch information
provokateurin committed Oct 19, 2024
1 parent 2b95461 commit a01e746
Show file tree
Hide file tree
Showing 28 changed files with 880 additions and 576 deletions.
16 changes: 12 additions & 4 deletions packages/neon_framework/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -513,10 +513,11 @@ packages:
flutter_local_notifications:
dependency: transitive
description:
name: flutter_local_notifications
sha256: "49eeef364fddb71515bc78d5a8c51435a68bccd6e4d68e25a942c5e47761ae71"
url: "https://pub.dev"
source: hosted
path: flutter_local_notifications
ref: d9789d8496545ca2c5a42b78b9f49dc8efe2929b
resolved-ref: d9789d8496545ca2c5a42b78b9f49dc8efe2929b
url: "https://github.com/MaikuB/flutter_local_notifications"
source: git
version: "17.2.3"
flutter_local_notifications_linux:
dependency: transitive
Expand Down Expand Up @@ -917,6 +918,13 @@ packages:
relative: true
source: path
version: "1.0.0"
notifications_push_repository:
dependency: "direct overridden"
description:
path: "../packages/notifications_push_repository"
relative: true
source: path
version: "0.1.0"
open_filex:
dependency: transitive
description:
Expand Down
4 changes: 3 additions & 1 deletion packages/neon_framework/example/pubspec_overrides.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# melos_managed_dependency_overrides: account_repository,cookie_store,dashboard_app,dynamite_runtime,files_app,interceptor_http_client,neon_framework,neon_http_client,neon_lints,news_app,nextcloud,notes_app,notifications_app,sort_box,talk_app
# melos_managed_dependency_overrides: account_repository,cookie_store,dashboard_app,dynamite_runtime,files_app,interceptor_http_client,neon_framework,neon_http_client,neon_lints,news_app,nextcloud,notes_app,notifications_app,notifications_push_repository,sort_box,talk_app
dependency_overrides:
account_repository:
path: ../packages/account_repository
Expand Down Expand Up @@ -26,6 +26,8 @@ dependency_overrides:
path: ../packages/notes_app
notifications_app:
path: ../packages/notifications_app
notifications_push_repository:
path: ../packages/notifications_push_repository
sort_box:
path: ../packages/sort_box
talk_app:
Expand Down
6 changes: 3 additions & 3 deletions packages/neon_framework/lib/l10n/en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
"actionContinue": "Continue",
"actionCancel": "Cancel",
"actionDone": "Done",
"actionOpen": "Open",
"firstLaunchGoToSettingsToEnablePushNotifications": "Go to the settings to enable push notifications",
"nextPushSupported": "NextPush is supported!",
"nextPushSupportedText": "NextPush is a FOSS way of receiving push notifications using the UnifiedPush protocol via a Nextcloud instance.\nYou can install NextPush from the F-Droid app store.",
Expand Down Expand Up @@ -162,9 +163,8 @@
"globalOptionsThemeOLEDAsDark": "OLED theme as dark theme",
"globalOptionsThemeUseNextcloudTheme": "Use Nextcloud theme",
"globalOptionsThemeCustomBackground": "Custom background",
"globalOptionsPushNotificationsEnabled": "Enabled",
"globalOptionsPushNotificationsEnabledDisabledNotice": "No UnifiedPush distributor could be found or you denied the permission for showing notifications. Please go to the app settings and allow notifications and go to https://unifiedpush.org/users/distributors and setup any of the listed distributors. Then re-open this app and you should be able to enable notifications",
"globalOptionsPushNotificationsDistributor": "UnifiedPush Distributor",
"globalOptionsPushNotifications": "UnifiedPush",
"globalOptionsPushNotificationsDisabled": "Disabled",
"globalOptionsPushNotificationsDistributorGotifyUP": "Gotify-UP (FOSS)",
"globalOptionsPushNotificationsDistributorFirebaseEmbedded": "Firebase (proprietary)",
"globalOptionsPushNotificationsDistributorNtfy": "ntfy (FOSS)",
Expand Down
24 changes: 12 additions & 12 deletions packages/neon_framework/lib/l10n/localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,12 @@ abstract class NeonLocalizations {
/// **'Done'**
String get actionDone;

/// No description provided for @actionOpen.
///
/// In en, this message translates to:
/// **'Open'**
String get actionOpen;

/// No description provided for @firstLaunchGoToSettingsToEnablePushNotifications.
///
/// In en, this message translates to:
Expand Down Expand Up @@ -559,23 +565,17 @@ abstract class NeonLocalizations {
/// **'Custom background'**
String get globalOptionsThemeCustomBackground;

/// No description provided for @globalOptionsPushNotificationsEnabled.
///
/// In en, this message translates to:
/// **'Enabled'**
String get globalOptionsPushNotificationsEnabled;

/// No description provided for @globalOptionsPushNotificationsEnabledDisabledNotice.
/// No description provided for @globalOptionsPushNotifications.
///
/// In en, this message translates to:
/// **'No UnifiedPush distributor could be found or you denied the permission for showing notifications. Please go to the app settings and allow notifications and go to https://unifiedpush.org/users/distributors and setup any of the listed distributors. Then re-open this app and you should be able to enable notifications'**
String get globalOptionsPushNotificationsEnabledDisabledNotice;
/// **'UnifiedPush'**
String get globalOptionsPushNotifications;

/// No description provided for @globalOptionsPushNotificationsDistributor.
/// No description provided for @globalOptionsPushNotificationsDisabled.
///
/// In en, this message translates to:
/// **'UnifiedPush Distributor'**
String get globalOptionsPushNotificationsDistributor;
/// **'Disabled'**
String get globalOptionsPushNotificationsDisabled;

/// No description provided for @globalOptionsPushNotificationsDistributorGotifyUP.
///
Expand Down
11 changes: 5 additions & 6 deletions packages/neon_framework/lib/l10n/localizations_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ class NeonLocalizationsEn extends NeonLocalizations {
@override
String get actionDone => 'Done';

@override
String get actionOpen => 'Open';

@override
String get firstLaunchGoToSettingsToEnablePushNotifications => 'Go to the settings to enable push notifications';

Expand Down Expand Up @@ -283,14 +286,10 @@ class NeonLocalizationsEn extends NeonLocalizations {
String get globalOptionsThemeCustomBackground => 'Custom background';

@override
String get globalOptionsPushNotificationsEnabled => 'Enabled';

@override
String get globalOptionsPushNotificationsEnabledDisabledNotice =>
'No UnifiedPush distributor could be found or you denied the permission for showing notifications. Please go to the app settings and allow notifications and go to https://unifiedpush.org/users/distributors and setup any of the listed distributors. Then re-open this app and you should be able to enable notifications';
String get globalOptionsPushNotifications => 'UnifiedPush';

@override
String get globalOptionsPushNotificationsDistributor => 'UnifiedPush Distributor';
String get globalOptionsPushNotificationsDisabled => 'Disabled';

@override
String get globalOptionsPushNotificationsDistributorGotifyUP => 'Gotify-UP (FOSS)';
Expand Down
46 changes: 37 additions & 9 deletions packages/neon_framework/lib/neon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,24 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_native_splash/flutter_native_splash.dart';
import 'package:http/http.dart' as http;
import 'package:logging/logging.dart';
import 'package:neon_framework/models.dart';
import 'package:neon_framework/src/app.dart';
import 'package:neon_framework/src/blocs/accounts.dart';
import 'package:neon_framework/src/blocs/first_launch.dart';
import 'package:neon_framework/src/blocs/next_push.dart';
import 'package:neon_framework/src/blocs/push_notifications.dart';
import 'package:neon_framework/src/models/app_implementation.dart';
import 'package:neon_framework/src/models/disposable.dart';
import 'package:neon_framework/src/platform/platform.dart';
import 'package:neon_framework/src/storage/keys.dart';
import 'package:neon_framework/src/storage/sqlite_persistence.dart';
import 'package:neon_framework/src/theme/neon.dart';
import 'package:neon_framework/src/utils/global_options.dart';
import 'package:neon_framework/src/utils/provider.dart';
import 'package:neon_framework/src/utils/push_utils.dart';
import 'package:neon_framework/src/utils/timezone.dart';
import 'package:neon_framework/src/utils/user_agent.dart';
import 'package:neon_framework/storage.dart';
import 'package:notifications_push_repository/notifications_push_repository.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:provider/provider.dart';
import 'package:timezone/data/latest.dart' as tzdata;
Expand Down Expand Up @@ -57,10 +60,6 @@ Future<void> runNeon({

final packageInfo = await PackageInfo.fromPlatform();

final globalOptions = GlobalOptions(
packageInfo,
);

final accountStorage = AccountStorage(
accountsPersistence: NeonStorage().singleValueStore(StorageKeys.accounts),
lastAccountPersistence: NeonStorage().singleValueStore(StorageKeys.lastUsedAccount),
Expand All @@ -72,20 +71,49 @@ Future<void> runNeon({
storage: accountStorage,
);

NotificationsPushRepository? notificationsPushRepository;
var distributors = BuiltList<String>();
if (NeonPlatform.instance.canUsePushNotifications) {
final notificationsPushStorage = NotificationsPushStorage(
devicePrivateKeyPersistence: NeonStorage().singleValueStore(StorageKeys.notificationsDevicePrivateKey),
pushSubscriptionsPersistence: SQLiteCachedPersistence(
prefix: 'notifications-push-subscriptions',
),
);

notificationsPushRepository = NotificationsPushRepository(
accountRepository: accountRepository,
storage: notificationsPushStorage,
onMessage: PushUtils.onMessage,
);

distributors = await notificationsPushRepository.distributors;
}

final globalOptions = GlobalOptions(
packageInfo,
distributors,
);

await accountRepository.loadAccounts(
initialAccount: globalOptions.initialAccount.value,
rememberLastUsedAccount: globalOptions.rememberLastUsedAccount.value,
);

if (notificationsPushRepository != null) {
await notificationsPushRepository.initialize();

PushNotificationsBloc(
globalOptions: globalOptions,
notificationsPushRepository: notificationsPushRepository,
);
}

final accountsBloc = AccountsBloc(
allAppImplementations: appImplementations,
accountRepository: accountRepository,
);

PushNotificationsBloc(
globalOptions: globalOptions,
accountRepository: accountRepository,
);
final firstLaunchBloc = FirstLaunchBloc();
final nextPushBloc = NextPushBloc(
accountsSubject: accountsBloc.accounts,
Expand Down
10 changes: 8 additions & 2 deletions packages/neon_framework/lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import 'package:neon_framework/models.dart';
import 'package:neon_framework/src/blocs/accounts.dart';
import 'package:neon_framework/src/blocs/maintenance_mode.dart';
import 'package:neon_framework/src/blocs/unified_search.dart';
import 'package:neon_framework/src/models/push_notification.dart';
import 'package:neon_framework/src/platform/platform.dart';
import 'package:neon_framework/src/router.dart';
import 'package:neon_framework/src/theme/neon.dart';
Expand All @@ -27,6 +26,7 @@ import 'package:neon_framework/src/utils/provider.dart';
import 'package:neon_framework/src/utils/push_utils.dart';
import 'package:neon_framework/src/widgets/options_collection_builder.dart';
import 'package:nextcloud/notifications.dart' as notifications;
import 'package:notifications_push_repository/notifications_push_repository.dart';
import 'package:provider/provider.dart';
import 'package:quick_actions/quick_actions.dart';
import 'package:universal_io/io.dart';
Expand Down Expand Up @@ -108,7 +108,6 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, WindowLi
}

if (NeonPlatform.instance.canUsePushNotifications) {
final localNotificationsPlugin = await PushUtils.initLocalNotifications();
PushUtils.onPushNotificationReceived = (accountID) async {
final account = _accountsBloc.accountByID(accountID);
if (account == null) {
Expand Down Expand Up @@ -149,6 +148,13 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, WindowLi
await _openAppFromExternal(account, app.id);
};

if (!mounted) {
return;
}

final localNotificationsPlugin = await PushUtils.initLocalNotifications(
localizations: localizations,
);
final details = await localNotificationsPlugin.getNotificationAppLaunchDetails();
if (details != null && details.didNotificationLaunchApp && details.notificationResponse?.payload != null) {
await PushUtils.onLocalNotificationClicked!(
Expand Down
10 changes: 3 additions & 7 deletions packages/neon_framework/lib/src/blocs/next_push.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,11 @@ class _NextPushBloc extends Bloc implements NextPushBloc {
if (disabled) {
return;
}
changesSubscription = Rx.merge([
globalOptions.pushNotificationsEnabled.stream,
changesSubscription = Rx.merge<dynamic>([
globalOptions.pushNotificationsDistributor.stream,
accountsSubject,
]).debounceTime(const Duration(milliseconds: 100)).listen((_) async {
if (!globalOptions.pushNotificationsEnabled.enabled || !globalOptions.pushNotificationsEnabled.value) {
return;
}
if (globalOptions.pushNotificationsDistributor.value != null) {
]).listen((_) async {
if (globalOptions.pushNotificationsDistributor.value == null) {
return;
}
if (globalOptions.pushNotificationsDistributor.values.containsKey(unifiedPushNextPushID)) {
Expand Down
Loading

0 comments on commit a01e746

Please sign in to comment.