Skip to content

Commit

Permalink
fix: Changed onLink behavior.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathrunet committed Oct 31, 2023
1 parent d44a4f9 commit d76467f
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 83 deletions.
16 changes: 8 additions & 8 deletions packages/masamune_notification/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -460,14 +460,14 @@ packages:
path: "../../katana_model"
relative: true
source: path
version: "2.13.4"
version: "2.13.5"
katana_model_local:
dependency: "direct overridden"
description:
path: "../../katana_model_local"
relative: true
source: path
version: "2.8.9"
version: "2.8.10"
katana_prefs:
dependency: "direct overridden"
description:
Expand Down Expand Up @@ -523,7 +523,7 @@ packages:
path: "../../katana_theme"
relative: true
source: path
version: "2.0.29"
version: "2.1.0"
katana_theme_annotation:
dependency: "direct overridden"
description:
Expand Down Expand Up @@ -560,7 +560,7 @@ packages:
path: "../../masamune"
relative: true
source: path
version: "2.4.77"
version: "2.4.78"
masamune_annotation:
dependency: "direct overridden"
description:
Expand All @@ -574,14 +574,14 @@ packages:
path: ".."
relative: true
source: path
version: "2.2.18"
version: "2.2.19"
masamune_scheduler:
dependency: "direct overridden"
description:
path: "../../masamune_scheduler"
relative: true
source: path
version: "2.1.16"
version: "2.1.17"
matcher:
dependency: transitive
description:
Expand Down Expand Up @@ -943,10 +943,10 @@ packages:
dependency: transitive
description:
name: uuid
sha256: "648e103079f7c64a36dc7d39369cabb358d377078a051d6ae2ad3aa539519313"
sha256: b715b8d3858b6fa9f68f87d20d98830283628014750c2b09b6f516c1da4af2a7
url: "https://pub.dev"
source: hosted
version: "3.0.7"
version: "4.1.0"
vector_math:
dependency: transitive
description:
Expand Down
25 changes: 20 additions & 5 deletions packages/masamune_notification/lib/src/push_notification.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ class PushNotification extends MasamuneControllerBase<PushNotificationValue,
bool get listening => _listening;
bool _listening = false;

/// Callback when the URL is launched.
///
/// URLが起動されたときのコールバック。
FutureOr<void> Function(Uri link)? get onLink => _onLink;
FutureOr<void> Function(Uri link)? _onLink;

/// Obtain the FCM token for this terminal.
///
/// この端末のFCMトークンを取得します。
Expand All @@ -124,12 +130,18 @@ class PushNotification extends MasamuneControllerBase<PushNotificationValue,
///
/// By monitoring the status with [addListener], it is possible to do something when a notification comes in.
///
/// You can specify a callback when the URL is launched with [onLink].
///
/// 通知の受け取りを開始します。
///
/// 通知を取得した場合、[value]が更新され、[notifyListeners]が呼ばれます。
///
/// [addListener]で状態を監視することで通知が来たときになにかしらの処理を行うことが可能です。
Future<void> listen() async {
///
/// [onLink]でURLが起動されたときのコールバックを指定することができます。
Future<void> listen({
FutureOr<void> Function(Uri link)? onLink,
}) async {
if (_completer != null) {
return _completer?.future;
}
Expand All @@ -138,6 +150,7 @@ class PushNotification extends MasamuneControllerBase<PushNotificationValue,
}
_completer = Completer();
try {
_onLink = onLink;
_listenResponse = await adapter.listen(
onMessage: _onMessage,
onMessageOpenedApp: _onMessageOpenedApp,
Expand Down Expand Up @@ -294,10 +307,11 @@ class PushNotification extends MasamuneControllerBase<PushNotificationValue,

Future<void> _onMessage(PushNotificationValue value) async {
_value = value;
if (adapter.onLink != null && value.data.containsKey(_linkKey)) {
final onLink = this.onLink ?? adapter.onLink;
if (onLink != null && value.data.containsKey(_linkKey)) {
final uri = value.data.get(_linkKey, "").toUri();
if (uri != null) {
await adapter.onLink?.call(uri);
await onLink.call(uri);
}
}
_sendLog(PushNotificationLoggerEvent.receive, parameters: {
Expand All @@ -310,10 +324,11 @@ class PushNotification extends MasamuneControllerBase<PushNotificationValue,

Future<void> _onMessageOpenedApp(PushNotificationValue value) async {
_value = value;
if (adapter.onLink != null && value.data.containsKey(_linkKey)) {
final onLink = this.onLink ?? adapter.onLink;
if (onLink != null && value.data.containsKey(_linkKey)) {
final uri = value.data.get(_linkKey, "").toUri();
if (uri != null) {
await adapter.onLink?.call(uri);
await onLink.call(uri);
}
}
_sendLog(PushNotificationLoggerEvent.receive, parameters: {
Expand Down
66 changes: 33 additions & 33 deletions packages/masamune_notification/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -377,189 +377,189 @@ packages:
path: "../katana"
relative: true
source: path
version: "2.4.3"
version: "2.5.0"
katana_auth:
dependency: "direct overridden"
description:
path: "../katana_auth"
relative: true
source: path
version: "2.2.4"
version: "2.2.5"
katana_form:
dependency: "direct overridden"
description:
path: "../katana_form"
relative: true
source: path
version: "2.7.16"
version: "2.7.17"
katana_functions:
dependency: "direct overridden"
description:
path: "../katana_functions"
relative: true
source: path
version: "2.4.10"
version: "2.4.11"
katana_indicator:
dependency: "direct overridden"
description:
path: "../katana_indicator"
relative: true
source: path
version: "2.0.15"
version: "2.0.16"
katana_listenables:
dependency: "direct overridden"
description:
path: "../katana_listenables"
relative: true
source: path
version: "2.0.18"
version: "2.0.19"
katana_listenables_annotation:
dependency: "direct overridden"
description:
path: "../katana_listenables_annotation"
relative: true
source: path
version: "2.0.17"
version: "2.0.18"
katana_listenables_builder:
dependency: "direct overridden"
description:
path: "../katana_listenables_builder"
relative: true
source: path
version: "2.0.21"
version: "2.0.22"
katana_localization:
dependency: "direct overridden"
description:
path: "../katana_localization"
relative: true
source: path
version: "2.0.22"
version: "2.0.23"
katana_localization_annotation:
dependency: "direct overridden"
description:
path: "../katana_localization_annotation"
relative: true
source: path
version: "2.0.18"
version: "2.0.19"
katana_localization_builder:
dependency: "direct overridden"
description:
path: "../katana_localization_builder"
relative: true
source: path
version: "2.0.23"
version: "2.0.24"
katana_logger:
dependency: "direct overridden"
description:
path: "../katana_logger"
relative: true
source: path
version: "2.0.15"
version: "2.0.16"
katana_model:
dependency: "direct overridden"
description:
path: "../katana_model"
relative: true
source: path
version: "2.13.5"
version: "2.13.6"
katana_model_local:
dependency: "direct overridden"
description:
path: "../katana_model_local"
relative: true
source: path
version: "2.8.10"
version: "2.8.11"
katana_prefs:
dependency: "direct overridden"
description:
path: "../katana_prefs"
relative: true
source: path
version: "2.0.20"
version: "2.0.21"
katana_prefs_annotation:
dependency: "direct overridden"
description:
path: "../katana_prefs_annotation"
relative: true
source: path
version: "2.0.17"
version: "2.0.18"
katana_prefs_builder:
dependency: "direct overridden"
description:
path: "../katana_prefs_builder"
relative: true
source: path
version: "2.0.21"
version: "2.0.22"
katana_router:
dependency: "direct overridden"
description:
path: "../katana_router"
relative: true
source: path
version: "2.0.43"
version: "2.0.44"
katana_router_annotation:
dependency: "direct overridden"
description:
path: "../katana_router_annotation"
relative: true
source: path
version: "2.0.22"
version: "2.0.23"
katana_router_builder:
dependency: "direct overridden"
description:
path: "../katana_router_builder"
relative: true
source: path
version: "2.0.30"
version: "2.0.31"
katana_scoped:
dependency: "direct overridden"
description:
path: "../katana_scoped"
relative: true
source: path
version: "2.0.29"
version: "2.0.30"
katana_shorten:
dependency: "direct overridden"
description:
path: "../katana_shorten"
relative: true
source: path
version: "2.0.15"
version: "2.0.16"
katana_storage:
dependency: "direct overridden"
description:
path: "../katana_storage"
relative: true
source: path
version: "2.0.17"
version: "2.0.18"
katana_theme:
dependency: "direct overridden"
description:
path: "../katana_theme"
relative: true
source: path
version: "2.1.0"
version: "2.1.1"
katana_theme_annotation:
dependency: "direct overridden"
description:
path: "../katana_theme_annotation"
relative: true
source: path
version: "2.0.20"
version: "2.0.21"
katana_theme_builder:
dependency: "direct overridden"
description:
path: "../katana_theme_builder"
relative: true
source: path
version: "2.1.0"
version: "2.1.1"
katana_ui:
dependency: "direct overridden"
description:
path: "../katana_ui"
relative: true
source: path
version: "2.5.4"
version: "2.5.5"
lints:
dependency: transitive
description:
Expand All @@ -582,28 +582,28 @@ packages:
path: "../masamune"
relative: true
source: path
version: "2.4.78"
version: "2.4.79"
masamune_annotation:
dependency: "direct overridden"
description:
path: "../masamune_annotation"
relative: true
source: path
version: "2.3.10"
version: "2.3.11"
masamune_builder:
dependency: "direct dev"
description:
path: "../masamune_builder"
relative: true
source: path
version: "2.8.17"
version: "2.8.18"
masamune_scheduler:
dependency: "direct main"
description:
path: "../masamune_scheduler"
relative: true
source: path
version: "2.1.17"
version: "2.1.18"
matcher:
dependency: transitive
description:
Expand Down Expand Up @@ -1021,10 +1021,10 @@ packages:
dependency: transitive
description:
name: uuid
sha256: "648e103079f7c64a36dc7d39369cabb358d377078a051d6ae2ad3aa539519313"
sha256: b715b8d3858b6fa9f68f87d20d98830283628014750c2b09b6f516c1da4af2a7
url: "https://pub.dev"
source: hosted
version: "3.0.7"
version: "4.1.0"
vector_math:
dependency: transitive
description:
Expand Down

0 comments on commit d76467f

Please sign in to comment.