Skip to content

Commit

Permalink
Temporary Support to Web (#472)
Browse files Browse the repository at this point in the history
* add
  • Loading branch information
YumNumm authored Dec 26, 2023
1 parent 583f455 commit cc033e5
Show file tree
Hide file tree
Showing 14 changed files with 119 additions and 20 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ app.*.symbols


# Web related
lib/generated_plugin_registrant.dart

# Obfuscation related
app.*.map.json
Expand Down Expand Up @@ -172,4 +171,4 @@ ios/*.p8


*.pem
*_old
*_old
12 changes: 6 additions & 6 deletions .metadata
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# This file should be version controlled and should not be manually edited.

version:
revision: "9e1c857886f07d342cf106f2cd588bcd5e031bb2"
revision: "78666c8dc57e9f7548ca9f8dd0740fbf0c658dc9"
channel: "stable"

project_type: app
Expand All @@ -13,11 +13,11 @@ project_type: app
migration:
platforms:
- platform: root
create_revision: 9e1c857886f07d342cf106f2cd588bcd5e031bb2
base_revision: 9e1c857886f07d342cf106f2cd588bcd5e031bb2
- platform: ios
create_revision: 9e1c857886f07d342cf106f2cd588bcd5e031bb2
base_revision: 9e1c857886f07d342cf106f2cd588bcd5e031bb2
create_revision: 78666c8dc57e9f7548ca9f8dd0740fbf0c658dc9
base_revision: 78666c8dc57e9f7548ca9f8dd0740fbf0c658dc9
- platform: web
create_revision: 78666c8dc57e9f7548ca9f8dd0740fbf0c658dc9
base_revision: 78666c8dc57e9f7548ca9f8dd0740fbf0c658dc9

# User provided section

Expand Down
5 changes: 3 additions & 2 deletions lib/core/provider/app_information/app_information_model.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:io';

import 'package:eqapi_types/eqapi_types.dart';
import 'package:flutter/foundation.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:version/version.dart';

Expand Down Expand Up @@ -42,7 +43,7 @@ extension AppInformationEx on AppInformation {
AppInformationModel toModel({
required Version currentVersion,
}) {
if (Platform.isIOS) {
if (!kIsWeb && Platform.isIOS) {
final latestVersion = Version.parse(iosLatestVersion);
final minimumVersion =
iosMinimumVersion == null ? null : Version.parse(iosMinimumVersion!);
Expand All @@ -57,7 +58,7 @@ extension AppInformationEx on AppInformation {
latestVersion > currentVersion,
);
}
if (Platform.isAndroid) {
if (!kIsWeb && Platform.isAndroid) {
final latestVersion = Version.parse(androidLatestVersion);
final minimumVersion = androidMinimumVersion == null
? null
Expand Down
5 changes: 3 additions & 2 deletions lib/core/provider/dio_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ Dio dio(DioRef ref) {
final dio = Dio(
BaseOptions(
headers: {
'user-agent': 'eqmonitor-${Platform.version}',
'x-operation-system-version': Platform.operatingSystemVersion,
'user-agent': 'eqmonitor-${kIsWeb ? "web" : Platform.version}',
'x-operation-system-version':
kIsWeb ? 'web' : Platform.operatingSystemVersion,
if (authorization != null) 'authorization': authorization,
},
baseUrl: ref.watch(telegramUrlProvider).restApiUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ part 'earthquake_history_view_model.g.dart';
class EarthquakeHistoryViewModel extends _$EarthquakeHistoryViewModel {
@override
AsyncValue<List<EarthquakeHistoryItem>> build() {
_useCase = ref.watch(earthquakeHistoryUseCaseProvider);
// start listen telegram ws
ref
..listen(telegramWsProvider, (previous, next) {
Expand All @@ -42,7 +41,6 @@ class EarthquakeHistoryViewModel extends _$EarthquakeHistoryViewModel {
return const AsyncData([]);
}

late EarthquakeHistoryUseCase _useCase;
// state
final bool _includeTestTelegrams = false;

Expand Down Expand Up @@ -80,7 +78,8 @@ class EarthquakeHistoryViewModel extends _$EarthquakeHistoryViewModel {
// 処理開始
state = await state.guardPlus(() async {
final offset = isRefresh ? 0 : state.asData?.value.length ?? 0;
final result = await _useCase.getEarthquakeHistory(
final useCase = ref.read(earthquakeHistoryUseCaseProvider);
final result = await useCase.getEarthquakeHistory(
limit: limit,
offset: offset,
includeEew: true,
Expand Down
9 changes: 6 additions & 3 deletions lib/feature/settings/settings_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:eqmonitor/feature/home/component/sheet/debug_widget.dart';
import 'package:eqmonitor/feature/home/features/debugger/debugger_provider.dart';
import 'package:eqmonitor/feature/settings/component/settings_section_header.dart';
import 'package:eqmonitor/gen/assets.gen.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:go_router/go_router.dart';
Expand Down Expand Up @@ -186,9 +187,11 @@ Future<void> _onInquiryTap(BuildContext context, WidgetRef ref) async {
),
);
final packageInfo = ref.read(packageInfoProvider);
final androidDeviceInfo =
Platform.isAndroid ? ref.read(androidDeviceInfoProvider) : null;
final iosDeviceInfo = Platform.isIOS ? ref.read(iosDeviceInfoProvider) : null;
final androidDeviceInfo = !kIsWeb && Platform.isAndroid
? ref.read(androidDeviceInfoProvider)
: null;
final iosDeviceInfo =
!kIsWeb && Platform.isIOS ? ref.read(iosDeviceInfoProvider) : null;

final notificationSetting =
await ref.read(firebaseMessagingProvider).getNotificationSettings();
Expand Down
6 changes: 4 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ Future<void> main() async {
),
PackageInfo.fromPlatform(),
// ignore: prefer_void_to_null
(Platform.isAndroid ? deviceInfo.androidInfo : Future<Null>.value()),
(!kIsWeb && Platform.isAndroid
? deviceInfo.androidInfo
: Future<Null>.value()),
// ignore: prefer_void_to_null
(Platform.isIOS ? deviceInfo.iosInfo : Future<Null>.value()),
(!kIsWeb && Platform.isIOS ? deviceInfo.iosInfo : Future<Null>.value()),
FlutterLocalNotificationsPlugin().initialize(
const InitializationSettings(
iOS: DarwinInitializationSettings(
Expand Down
Binary file added web/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added web/icons/Icon-192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added web/icons/Icon-512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added web/icons/Icon-maskable-192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added web/icons/Icon-maskable-512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 59 additions & 0 deletions web/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!DOCTYPE html>
<html>
<head>
<!--
If you are serving your web app in a path other than the root, change the
href value below to reflect the base path you are serving from.
The path provided below has to start and end with a slash "/" in order for
it to work correctly.
For more details:
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
This is a placeholder for base href that will be replaced by the value of
the `--base-href` argument provided to `flutter build`.
-->
<base href="$FLUTTER_BASE_HREF">

<meta charset="UTF-8">
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
<meta name="description" content="A new Flutter project.">

<!-- iOS meta tags & icons -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="eqmonitor">
<link rel="apple-touch-icon" href="icons/Icon-192.png">

<!-- Favicon -->
<link rel="icon" type="image/png" href="favicon.png"/>

<title>eqmonitor</title>
<link rel="manifest" href="manifest.json">

<script>
// The value below is injected by flutter build, do not touch.
const serviceWorkerVersion = null;
</script>
<!-- This script adds the flutter initialization JS code -->
<script src="flutter.js" defer></script>
</head>
<body>
<script>
window.addEventListener('load', function(ev) {
// Download main.dart.js
_flutter.loader.loadEntrypoint({
serviceWorker: {
serviceWorkerVersion: serviceWorkerVersion,
},
onEntrypointLoaded: function(engineInitializer) {
engineInitializer.initializeEngine().then(function(appRunner) {
appRunner.runApp();
});
}
});
});
</script>
</body>
</html>
35 changes: 35 additions & 0 deletions web/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "eqmonitor",
"short_name": "eqmonitor",
"start_url": ".",
"display": "standalone",
"background_color": "#0175C2",
"theme_color": "#0175C2",
"description": "A new Flutter project.",
"orientation": "portrait-primary",
"prefer_related_applications": false,
"icons": [
{
"src": "icons/Icon-192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "icons/Icon-512.png",
"sizes": "512x512",
"type": "image/png"
},
{
"src": "icons/Icon-maskable-192.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "maskable"
},
{
"src": "icons/Icon-maskable-512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "maskable"
}
]
}

0 comments on commit cc033e5

Please sign in to comment.