Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Shorebirdの導入・いくつかバグ修正 #743

Merged
merged 3 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/lib/core/provider/ntp/ntp_config_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ class NtpConfig extends _$NtpConfig {
NtpConfigModel _load() {
final prefs = ref.read(sharedPreferencesProvider);
final json = prefs.getString(_prefsKey);
if (json == null) {
return const NtpConfigModel();
}
try {
return NtpConfigModel.fromJson(jsonDecode(json!) as Map<String, dynamic>);
return NtpConfigModel.fromJson(jsonDecode(json) as Map<String, dynamic>);
// ignore: avoid_catches_without_on_clauses
} catch (e) {
return const NtpConfigModel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class EarthquakeHistoryNotifier extends _$EarthquakeHistoryNotifier {
ref.watch(jmaParameterProvider).valueOrNull?.earthquake;

if (earthquakeParameter == null) {
ref.invalidate(jmaParameterProvider);
throw EarthquakeParameterHasNotInitializedException();
}
// 検索条件を指定していないNotifierでのみ、30秒ごとにデータ再取得するタイマーを設定
Expand Down Expand Up @@ -112,6 +113,9 @@ class EarthquakeHistoryNotifier extends _$EarthquakeHistoryNotifier {
await AsyncValue.guard<(List<EarthquakeV1Extended>, int totalCount)>(
() async {
// ensure earthquakeParameter has been initialized.
if (ref.read(jmaParameterProvider).hasError) {
ref.invalidate(jmaParameterProvider);
}
await ref.read(jmaParameterProvider.future);
final earthquakeParameter =
ref.watch(jmaParameterProvider).valueOrNull!.earthquake;
Expand Down
65 changes: 42 additions & 23 deletions app/lib/feature/home/view/home_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import 'package:eqmonitor/feature/settings/features/notification_remote_settings
import 'package:eqmonitor/feature/settings/features/notification_remote_settings/data/service/notification_remote_settings_migrate_service.dart';
import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
Expand Down Expand Up @@ -96,30 +97,48 @@ class _HomeBodyWidget extends HookConsumerWidget {
ref.read(permissionProvider.notifier).initialize(),
ref.read(ntpProvider.notifier).sync(),
() async {
final token = await ref.read(notificationTokenProvider.future);
final fcmToken = token.fcmToken;
if (fcmToken == null) {
return;
final talker = ref.read(talkerProvider);
try {
talker.log('Start Initialize');
final token = await ref.read(notificationTokenProvider.future);
talker.log('Token: ${token.toJson()}');
final fcmToken = token.fcmToken;
if (fcmToken == null) {
throw Exception('fcmToken is null');
}
talker.log('updateToken...');
await ref
.read(notificationRemoteAuthenticateServiceProvider)
.updateToken(fcmToken: fcmToken);
talker.log('updateToken... Done');
await ref
.read(fcmTokenChangeDetectorProvider.notifier)
.save(fcmToken);
talker.log('fcmTokenChangeDetectorProvider... Done');
final authenticationService =
ref.read(apiAuthenticationServiceProvider.notifier);
final (
id: id,
role: role,
) = await authenticationService.extractPayload();
talker.log(
'Authentication: id=$id, role=$role',
);
await FirebaseCrashlytics.instance.setUserIdentifier(id);
await FirebaseAnalytics.instance.setUserId(
id: id,
);
// ignore: avoid_catches_without_on_clauses
} catch (e) {
ref.read(talkerProvider).log(
'Authentication Error: $e',
);
await FirebaseCrashlytics.instance.recordError(
e,
StackTrace.current,
);
rethrow;
}
await ref
.read(notificationRemoteAuthenticateServiceProvider)
.updateToken(fcmToken: fcmToken);
await ref
.read(fcmTokenChangeDetectorProvider.notifier)
.save(fcmToken);
final authenticationService =
ref.read(apiAuthenticationServiceProvider.notifier);
final (
id: id,
role: role,
) = await authenticationService.extractPayload();
ref.read(talkerProvider).log(
'Authentication: id=$id, role=$role',
);
await FirebaseCrashlytics.instance.setUserIdentifier(id);
await FirebaseAnalytics.instance.setUserId(
id: id,
);
}(),
Future.doWhile(() async {
try {
Expand Down
59 changes: 49 additions & 10 deletions app/lib/feature/settings/settings_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import 'package:feedback/feedback.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_email_sender/flutter_email_sender.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:go_router/go_router.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:path_provider/path_provider.dart';
import 'package:shorebird_code_push/shorebird_code_push.dart';
import 'package:url_launcher/url_launcher_string.dart';

class SettingsScreen extends ConsumerWidget {
Expand Down Expand Up @@ -52,16 +54,7 @@ class SettingsScreen extends ConsumerWidget {
),
),
),
Center(
child: Padding(
padding: const EdgeInsets.only(bottom: 16),
child: Text(
'EQMonitor v${packageInfo.version} '
'(${packageInfo.buildNumber})',
style: textTheme.bodyMedium,
),
),
),
const _AppVersionInformation(),
BorderedContainer(
accentColor: Theme.of(context).colorScheme.secondaryContainer,
padding: EdgeInsets.zero,
Expand Down Expand Up @@ -149,6 +142,52 @@ class SettingsScreen extends ConsumerWidget {
}
}

class _AppVersionInformation extends HookConsumerWidget {
const _AppVersionInformation();

@override
Widget build(BuildContext context, WidgetRef ref) {
final packageInfo = ref.watch(packageInfoProvider);
final theme = Theme.of(context);
final textTheme = theme.textTheme;

final patchInfoFuture = useMemoized(
() => (
ShorebirdCodePush().currentPatchNumber(),
ShorebirdCodePush().nextPatchNumber(),
).wait,
);
final patchInfo = useFuture(patchInfoFuture);

var text = 'EQMonitor v${packageInfo.version} '
'(${packageInfo.buildNumber}';
if (patchInfo.hasData) {
final currentPatch = patchInfo.data!.$1;
final nextPatch = patchInfo.data!.$2;
text += switch ((currentPatch, nextPatch)) {
(null, null) => ')',
(null, final int next) => '+$next)\n&'
'新しいパッチが利用可能です。2回アプリケーションを再起動して適用できます。',
(final int current, null) => '+$current)',
(final int current, final int next) => '+$current->$next)\n'
'新しいパッチが利用可能です。2回アプリケーションを再起動して適用できます。',
};
} else {
text += ')';
}

return Center(
child: Padding(
padding: const EdgeInsets.only(bottom: 16),
child: Text(
text,
style: textTheme.bodyMedium,
),
),
);
}
}

Future<void> _onInquiryTap(BuildContext context, WidgetRef ref) async {
BetterFeedback.of(context).show(
(feedback) async {
Expand Down
8 changes: 8 additions & 0 deletions app/pubspec.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: eqmonitor
description: An earthquake monitoring Application
publish_to: "none"

version: 2.5.1+1190
version: 2.5.1+1200

environment:
sdk: ^3.4.0
Expand Down Expand Up @@ -96,6 +96,7 @@ dependencies:
url: https:/YumNumm/modal_bottom_sheet.git
branch: main
path: sheet
shorebird_code_push: ^1.1.3
talker_dio_logger: ^4.2.4
talker_flutter: 4.2.4
url_launcher: ^6.3.0
Expand Down Expand Up @@ -129,6 +130,7 @@ flutter:
- assets/images/theme/
- assets/fonts/
- assets/docs/
- shorebird.yaml

shaders:
- shaders/introduction.glsl
Expand Down
14 changes: 14 additions & 0 deletions app/shorebird.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# This file is used to configure the Shorebird updater used by your app.
# Learn more at https://docs.shorebird.dev
# This file should be checked into version control.

# This is the unique identifier assigned to your app.
# Your app_id is not a secret and is just used to identify your app
# when requesting patches from Shorebird's servers.
app_id: 674ef9fa-cd89-41c7-b2f2-e99662c5823c

# auto_update controls if Shorebird should automatically update in the background on launch.
# If auto_update: false, you will need to use package:shorebird_code_push to trigger updates.
# https://pub.dev/packages/shorebird_code_push
# Uncomment the following line to disable automatic updates.
# auto_update: false
Loading