Skip to content

Commit

Permalink
プロキシ設定の実装 (#630)
Browse files Browse the repository at this point in the history
* fix: 寄付画面の名称修正

* fix: 観測点更新

* fix: EEW表示領域調整

* add: dio proxy

* add: headers

* add: proxy settings
  • Loading branch information
YumNumm authored Apr 8, 2024
1 parent 4c8c642 commit dfe7580
Show file tree
Hide file tree
Showing 16 changed files with 141 additions and 33 deletions.
Binary file modified app/assets/kyoshin_observation_point.pb
Binary file not shown.
12 changes: 6 additions & 6 deletions app/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1157;
CURRENT_PROJECT_VERSION = 1158;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = CPL7H8SHVM;
ENABLE_BITCODE = NO;
Expand Down Expand Up @@ -560,7 +560,7 @@
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1157;
CURRENT_PROJECT_VERSION = 1158;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = CPL7H8SHVM;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
Expand Down Expand Up @@ -602,7 +602,7 @@
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1157;
CURRENT_PROJECT_VERSION = 1158;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = CPL7H8SHVM;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
Expand Down Expand Up @@ -643,7 +643,7 @@
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1157;
CURRENT_PROJECT_VERSION = 1158;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = CPL7H8SHVM;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
Expand Down Expand Up @@ -787,7 +787,7 @@
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1157;
CURRENT_PROJECT_VERSION = 1158;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = CPL7H8SHVM;
ENABLE_BITCODE = NO;
Expand Down Expand Up @@ -819,7 +819,7 @@
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1157;
CURRENT_PROJECT_VERSION = 1158;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = CPL7H8SHVM;
ENABLE_BITCODE = NO;
Expand Down
2 changes: 1 addition & 1 deletion app/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1157</string>
<string>1158</string>
<key>LSRequiresIPhoneOS</key>
<true />
<key>UIApplicationSupportsIndirectInputEvents</key>
Expand Down
37 changes: 37 additions & 0 deletions app/lib/core/provider/dio_provider.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'dart:io';

import 'package:dio/dio.dart';
import 'package:dio/io.dart';
import 'package:eqmonitor/core/provider/shared_preferences.dart';
import 'package:eqmonitor/core/provider/telegram_url/provider/telegram_url_provider.dart';
import 'package:flutter/foundation.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
Expand All @@ -22,5 +24,40 @@ Dio dio(DioRef ref) {
baseUrl: ref.watch(telegramUrlProvider).restApiUrl,
),
);
if (ref.watch(isDioProxyEnabledProvider)) {
dio.httpClientAdapter = IOHttpClientAdapter(
createHttpClient: () =>
HttpClient()..findProxy = (url) => 'PROXY macbook-pro:9090',
);
HttpOverrides.global = MyHttpOverrides();
}
return dio;
}

class MyHttpOverrides extends HttpOverrides {
@override
HttpClient createHttpClient(SecurityContext? context) {
return super.createHttpClient(context)
..findProxy = (url) => 'PROXY macbook-pro:9090';
}
}

@Riverpod(keepAlive: true)
class IsDioProxyEnabled extends _$IsDioProxyEnabled {
@override
bool build() {
if (kIsWeb || !kDebugMode) {
return false;
}
final prefs = ref.read(sharedPreferencesProvider);
return prefs.getBool(_key) ?? false;
}

Future<void> set({required bool value}) async {
state = value;
final prefs = ref.read(sharedPreferencesProvider);
await prefs.setBool(_key, value);
}

static const String _key = 'is_dio_proxy_enabled';
}
18 changes: 17 additions & 1 deletion app/lib/core/provider/dio_provider.g.dart

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

Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// ignore_for_file: provider_dependencies
import 'dart:developer';

import 'package:eqapi_types/eqapi_types.dart';
import 'package:eqmonitor/core/provider/eew/eew_alive_telegram.dart';
import 'package:eqmonitor/core/provider/estimated_intensity/data/estimated_intensity_data_source.dart';
Expand All @@ -14,6 +16,7 @@ class EstimatedIntensity extends _$EstimatedIntensity {
@override
List<AnalyzedKmoniObservationPoint> build() {
ref.listen(eewAliveTelegramProvider, (previous, next) {
log('EEW Telegram updated: $next');
state = calc(next ?? []);
});
return calc(ref.read(eewAliveTelegramProvider) ?? []);
Expand Down

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

10 changes: 10 additions & 0 deletions app/lib/core/provider/kmoni/data/kmoni_data_source.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:io';

import 'package:dio/dio.dart';
import 'package:eqmonitor/core/provider/kmoni/model/kmoni_maintenance_message_model.dart';
import 'package:eqmonitor/core/provider/kmoni/util/kmoni_web_api_url_generator.dart';
Expand Down Expand Up @@ -33,6 +35,14 @@ class KmoniDataSource {
responseType: ResponseType.bytes,
receiveTimeout: const Duration(milliseconds: 2000),
sendTimeout: const Duration(milliseconds: 2000),
headers: {
HttpHeaders.userAgentHeader:
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36',
HttpHeaders.refererHeader: 'http://www.kmoni.bosai.go.jp/',
HttpHeaders.hostHeader: 'www.kmoni.bosai.go.jp',
HttpHeaders.cacheControlHeader: 'no-cache',
HttpHeaders.acceptHeader: 'image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8',
},
),
);
return res;
Expand Down
35 changes: 19 additions & 16 deletions app/lib/feature/donation/ui/donation_executed_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,26 @@ class DonationExecutedScreen extends HookConsumerWidget {
);
final body = Stack(
children: [
Column(
children: [
Screenshot(
controller: controller,
child: Material(
child: ColoredBox(
color: const Color.fromARGB(255, 1, 32, 78),
child: _Detail(
productEnum: productEnum,
product: product,
textTheme: textTheme,
customer: customer,
SingleChildScrollView(
child: Column(
children: [
Screenshot(
controller: controller,
child: Material(
child: ColoredBox(
color: const Color.fromARGB(255, 1, 32, 78),
child: _Detail(
productEnum: productEnum,
product: product,
textTheme: textTheme,
customer: customer,
isScreenshot: true,
),
),
),
),
),
],
],
),
),
SetupBackgroundImageWidget(
child: Scaffold(
Expand Down Expand Up @@ -163,7 +166,7 @@ class _ScrollView extends StatelessWidget {
),
),
TextSpan(
text: 'あなたの支援のお陰で、より良いアプリを作ることができます。\n\n',
text: 'あなたのご支援のお陰で、より良いアプリを作ることができます。\n\n',
),
TextSpan(
text: '皆様の声が励みになります!\n',
Expand Down Expand Up @@ -232,7 +235,7 @@ class _Detail extends StatelessWidget {
children: [
const Row(),
Text(
'${productEnum.emoji} ${product.title}',
'${productEnum.emoji} ${productEnum.productName}',
style: textTheme.titleLarge!.copyWith(
color: Colors.white,
fontWeight: FontWeight.bold,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import 'dart:async';
import 'package:collection/collection.dart';
import 'package:eqapi_types/eqapi_types.dart';
import 'package:eqmonitor/core/extension/async_value.dart';
import 'package:eqmonitor/core/provider/app_lifecycle.dart';
import 'package:eqmonitor/core/provider/jma_parameter/jma_parameter.dart';
import 'package:eqmonitor/core/provider/websocket/websocket_provider.dart';
import 'package:eqmonitor/feature/earthquake_history/data/earthquake_history_repository.dart';
import 'package:eqmonitor/feature/earthquake_history/data/model/earthquake_history_parameter.dart';
import 'package:eqmonitor/feature/earthquake_history/data/model/earthquake_v1_extended.dart';
import 'package:eqmonitor/feature/earthquake_history_details/data/earthquake_history_details_notifier.dart';
import 'package:extensions/extensions.dart';
import 'package:flutter/material.dart';
import 'package:jma_parameter_api_client/jma_parameter_api_client.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:web_socket_client/web_socket_client.dart';
Expand Down Expand Up @@ -42,7 +44,18 @@ class EarthquakeHistoryNotifier extends _$EarthquakeHistoryNotifier {
const Duration(seconds: 30),
(_) => _refreshIfWebsocketNotConnected(),
);
ref.onDispose(refetchTimer.cancel);
ref
..onDispose(refetchTimer.cancel)

// アプリがバックグラウンドからフォアグラウンドに戻った際にデータを再取得する
..listen(
appLifeCycleProvider,
(_, next) async {
if (next == AppLifecycleState.resumed) {
await _onResumed();
}
},
);
}
return _fetchInitialData(
param: parameter,
Expand Down Expand Up @@ -141,6 +154,16 @@ class EarthquakeHistoryNotifier extends _$EarthquakeHistoryNotifier {
);
}

Future<void> _onResumed() async {
// パラメータが指定されている場合は何もしない
if (parameter != EarthquakeHistoryParameter.empty()) {
return;
}
final repository = ref.read(earthquakeHistoryRepositoryProvider);
final result = await repository.fetchEarthquakeLists();
await _upsertEarthquakeV1s(result.items);
}

Future<void> _refreshIfWebsocketNotConnected() async {
// AsyncData以外の場合は何もしない
if (state is! AsyncData<EarthquakeHistoryNotifierState>) {
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ class MainMapViewModel extends _$MainMapViewModel {
)
..listen(
estimatedIntensityProvider,
(_, value) => _onEstimatedIntensityChanged(value),
(current, value) => _onEstimatedIntensityChanged(
value,
current?.length != value.length,
),
)
..listen(
kmoniSettingsProvider.select((e) => e.useKmoni),
Expand Down Expand Up @@ -176,11 +179,13 @@ class MainMapViewModel extends _$MainMapViewModel {

Future<void> _onEstimatedIntensityChanged(
List<AnalyzedKmoniObservationPoint> points,
bool isForce,
) async {
final boundary = _getEstimatedIntensityBoundary(points);
try {
await changeHomeBoundaryWithAnimation(
bounds: boundary ?? defaultBoundary,
isForce: isForce,
);
} on Exception catch (e) {
log('error $e');
Expand Down

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

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:eqmonitor/core/provider/dio_provider.dart';
import 'package:eqmonitor/core/provider/telegram_url/provider/telegram_url_provider.dart';
import 'package:eqmonitor/core/router/router.dart';
import 'package:eqmonitor/feature/home/component/kmoni/kmoni_settings_dialog.dart';
Expand Down Expand Up @@ -116,6 +117,14 @@ class _DebugWidget extends ConsumerWidget {
onTap: () async =>
FirebaseMessaging.instance.subscribeToTopic('kevi'),
),
SwitchListTile.adaptive(
value: ref.watch(isDioProxyEnabledProvider),
onChanged: (value) => ref
.read(isDioProxyEnabledProvider.notifier)
.set(value: value),
title: const Text('Dio Proxy'),
subtitle: const Text('mac-mini:9090へのPROXY'),
),
],
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,11 @@ class _OnNotificationPermissionAllowed extends ConsumerWidget {
title: const Text('お知らせ'),
subtitle: const Text('アップデート情報や開発者からのお知らせをお伝えします'),
),
if (ref.watch(debuggerProvider.select(
(value) => value.isDebugger,
))) ...[
if (ref.watch(
debuggerProvider.select(
(value) => value.isDebugger,
),
)) ...[
const SettingsSectionHeader(text: 'FCM DEBUG'),
Consumer(
builder: (context, ref, _) {
Expand Down
2 changes: 1 addition & 1 deletion app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Future<void> main() async {
SystemChrome.setSystemUIOverlayStyle(
const SystemUiOverlayStyle(
systemNavigationBarColor: Colors.transparent,
systemNavigationBarContrastEnforced: true
systemNavigationBarContrastEnforced: true,
),
);
await Firebase.initializeApp(
Expand Down

0 comments on commit dfe7580

Please sign in to comment.