added check for new update feature
This commit is contained in:
parent
7085417410
commit
7b94186732
12 changed files with 263 additions and 26 deletions
|
|
@ -193,6 +193,12 @@
|
|||
"library_no_category_exist":"You don't have any categories yet",
|
||||
"watching":"Watching",
|
||||
"plan_to_watch":"Plan to watch",
|
||||
"re_watching":"Rewatching"
|
||||
"re_watching":"Rewatching",
|
||||
"episodes":"Episodes",
|
||||
"download":"Download",
|
||||
"new_update_available":"New update available",
|
||||
"app_version":"App Version : v{v}",
|
||||
"searching_for_updates":"Searching for updates...",
|
||||
"no_new_updates_available":"No new updates available"
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -193,5 +193,11 @@
|
|||
"library_no_category_exist":"Vous n'avez pas encore de catégories",
|
||||
"watching":"En lecture",
|
||||
"plan_to_watch":"À regarder",
|
||||
"re_watching":"Revisionnage"
|
||||
"re_watching":"Revisionnage",
|
||||
"episodes":"Épisodes",
|
||||
"download":"Télécharger",
|
||||
"new_update_available":"Une nouvelle version est disponible",
|
||||
"app_version":"Version de l'application : v{v}",
|
||||
"searching_for_updates":"Vérification des mise à jours",
|
||||
"no_new_updates_available":"Aucune mise à jours disponible"
|
||||
}
|
||||
|
|
@ -114,8 +114,14 @@ int compareVersions(String version1, String version2) {
|
|||
List<String> v2Components = version2.split('.');
|
||||
|
||||
for (int i = 0; i < v1Components.length && i < v2Components.length; i++) {
|
||||
int v1Value = int.parse(v1Components[i]);
|
||||
int v2Value = int.parse(v2Components[i]);
|
||||
int v1Value = int.parse(
|
||||
v1Components.length == i + 1 && v1Components[i].length == 1
|
||||
? "${v1Components[i]}0"
|
||||
: v1Components[i]);
|
||||
int v2Value = int.parse(
|
||||
v2Components.length == i + 1 && v2Components[i].length == 1
|
||||
? "${v2Components[i]}0"
|
||||
: v2Components[i]);
|
||||
|
||||
if (v1Value < v2Value) {
|
||||
return -1;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:mangayomi/modules/more/about/providers/check_for_update.dart';
|
||||
import 'package:mangayomi/providers/l10n_providers.dart';
|
||||
import 'package:mangayomi/router/router.dart';
|
||||
import 'package:mangayomi/utils/colors.dart';
|
||||
|
|
@ -11,16 +12,16 @@ import 'package:mangayomi/utils/media_query.dart';
|
|||
import 'package:mangayomi/modules/library/providers/library_state_provider.dart';
|
||||
import 'package:mangayomi/modules/more/providers/incognito_mode_state_provider.dart';
|
||||
|
||||
class MainScreen extends StatelessWidget {
|
||||
class MainScreen extends ConsumerWidget {
|
||||
const MainScreen({super.key, required this.child});
|
||||
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final l10n = l10nLocalizations(context)!;
|
||||
final route = GoRouter.of(context);
|
||||
|
||||
ref.watch(checkForUpdateProvider(context: context));
|
||||
return Consumer(builder: (context, ref, chuld) {
|
||||
final location = ref.watch(
|
||||
routerCurrentLocationStateProvider(context),
|
||||
|
|
|
|||
|
|
@ -1632,9 +1632,6 @@ class _MangaDetailViewState extends ConsumerState<MangaDetailView>
|
|||
context,
|
||||
DraggableMenu(
|
||||
ui: SoftModernDraggableMenu(radius: 20, barItem: Container()),
|
||||
levels: [
|
||||
DraggableMenuLevel.ratio(ratio: 0.9),
|
||||
],
|
||||
child: Material(
|
||||
color: isLight(context)
|
||||
? Theme.of(context).scaffoldBackgroundColor.withOpacity(0.9)
|
||||
|
|
|
|||
|
|
@ -216,7 +216,7 @@ class _TrackerWidgetState extends ConsumerState<TrackerWidget> {
|
|||
builder: (context) {
|
||||
return AlertDialog(
|
||||
title: Text(
|
||||
l10n!.chapters,
|
||||
widget.isManga ? l10n!.chapters : l10n!.episodes,
|
||||
),
|
||||
content: StatefulBuilder(
|
||||
builder: (context, setState) => SizedBox(
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ part of 'download_provider.dart';
|
|||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$downloadChapterHash() => r'c9e99dfc6dac4d501611822490ee73f31270677c';
|
||||
String _$downloadChapterHash() => r'f60e8bbbd4b1bd05f7cb52c08be0f2462d465e8e';
|
||||
|
||||
/// Copied from Dart SDK
|
||||
class _SystemHash {
|
||||
|
|
|
|||
|
|
@ -1,17 +1,19 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:mangayomi/modules/more/about/providers/check_for_update.dart';
|
||||
import 'package:mangayomi/providers/l10n_providers.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
|
||||
class AboutScreen extends StatefulWidget {
|
||||
class AboutScreen extends ConsumerStatefulWidget {
|
||||
const AboutScreen({super.key});
|
||||
|
||||
@override
|
||||
State<AboutScreen> createState() => _AboutScreenState();
|
||||
ConsumerState<AboutScreen> createState() => _AboutScreenState();
|
||||
}
|
||||
|
||||
class _AboutScreenState extends State<AboutScreen> {
|
||||
class _AboutScreenState extends ConsumerState<AboutScreen> {
|
||||
Future<void> _launchInBrowser(Uri url) async {
|
||||
if (!await launchUrl(
|
||||
url,
|
||||
|
|
@ -55,15 +57,15 @@ class _AboutScreenState extends State<AboutScreen> {
|
|||
body: Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: 150,
|
||||
// child: Center(
|
||||
// child: Image.asset(
|
||||
// "assets/icon.png",
|
||||
// color: Theme.of(context).brightness == Brightness.light
|
||||
// ? Colors.black
|
||||
// : Colors.white,
|
||||
// ))
|
||||
),
|
||||
height: 150,
|
||||
// child: Center(
|
||||
// child: Image.asset(
|
||||
// "assets/icon.png",
|
||||
// color: Theme.of(context).brightness == Brightness.light
|
||||
// ? Colors.black
|
||||
// : Colors.white,
|
||||
// ))
|
||||
),
|
||||
Flexible(
|
||||
flex: 3,
|
||||
child: Column(
|
||||
|
|
@ -80,7 +82,10 @@ class _AboutScreenState extends State<AboutScreen> {
|
|||
),
|
||||
),
|
||||
ListTile(
|
||||
onTap: () {},
|
||||
onTap: () {
|
||||
ref.read(checkForUpdateProvider(
|
||||
context: context, manualUpdate: true));
|
||||
},
|
||||
title: Text(l10n.check_for_update),
|
||||
),
|
||||
// ListTile(
|
||||
92
lib/modules/more/about/providers/check_for_update.dart
Normal file
92
lib/modules/more/about/providers/check_for_update.dart
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
// ignore_for_file: use_build_context_synchronously
|
||||
import 'dart:convert';
|
||||
import 'package:bot_toast/bot_toast.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:mangayomi/modules/browse/extension/providers/fetch_manga_sources.dart';
|
||||
import 'package:mangayomi/providers/l10n_providers.dart';
|
||||
import 'package:mangayomi/utils/extensions.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
part 'check_for_update.g.dart';
|
||||
|
||||
@riverpod
|
||||
checkForUpdate(CheckForUpdateRef ref,
|
||||
{BuildContext? context, bool? manualUpdate}) async {
|
||||
manualUpdate = manualUpdate ?? false;
|
||||
final l10n = l10nLocalizations(context!)!;
|
||||
if (manualUpdate) {
|
||||
BotToast.showText(text: l10n.searching_for_updates);
|
||||
}
|
||||
final info = await PackageInfo.fromPlatform();
|
||||
|
||||
final updateAvailable = await _checkUpdate();
|
||||
if (compareVersions(info.version, updateAvailable.$1) < 0) {
|
||||
if (manualUpdate) {
|
||||
BotToast.showText(text: l10n.new_update_available);
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
}
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
title: Text(l10n.new_update_available),
|
||||
content: Text(
|
||||
"${l10n.app_version(updateAvailable.$1)}\n\n${updateAvailable.$2}"),
|
||||
actions: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: Text(l10n.cancel)),
|
||||
const SizedBox(
|
||||
width: 15,
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
_launchInBrowser(Uri.parse(updateAvailable.$3));
|
||||
},
|
||||
child: Text(l10n.download)),
|
||||
],
|
||||
)
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
} else if (compareVersions(info.version, updateAvailable.$1) == 0) {
|
||||
if (manualUpdate) {
|
||||
BotToast.showText(text: l10n.no_new_updates_available);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _launchInBrowser(Uri url) async {
|
||||
if (!await launchUrl(
|
||||
url,
|
||||
mode: LaunchMode.externalApplication,
|
||||
)) {
|
||||
throw 'Could not launch $url';
|
||||
}
|
||||
}
|
||||
|
||||
Future<(String, String, String)> _checkUpdate() async {
|
||||
try {
|
||||
final res = await http.get(Uri.parse(
|
||||
"https://api.github.com/repos/kodjodevf/Mangayomi/releases?page=1&per_page=10"));
|
||||
List resListJson = jsonDecode(res.body) as List;
|
||||
return (
|
||||
resListJson.first["name"]
|
||||
.toString()
|
||||
.substringAfter('v')
|
||||
.substringBefore('-'),
|
||||
resListJson.first["body"].toString(),
|
||||
resListJson.first["html_url"].toString()
|
||||
);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
122
lib/modules/more/about/providers/check_for_update.g.dart
Normal file
122
lib/modules/more/about/providers/check_for_update.g.dart
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'check_for_update.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$checkForUpdateHash() => r'15446e5da6f28a873be47b541a9c4f0f144520c5';
|
||||
|
||||
/// Copied from Dart SDK
|
||||
class _SystemHash {
|
||||
_SystemHash._();
|
||||
|
||||
static int combine(int hash, int value) {
|
||||
// ignore: parameter_assignments
|
||||
hash = 0x1fffffff & (hash + value);
|
||||
// ignore: parameter_assignments
|
||||
hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10));
|
||||
return hash ^ (hash >> 6);
|
||||
}
|
||||
|
||||
static int finish(int hash) {
|
||||
// ignore: parameter_assignments
|
||||
hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3));
|
||||
// ignore: parameter_assignments
|
||||
hash = hash ^ (hash >> 11);
|
||||
return 0x1fffffff & (hash + ((0x00003fff & hash) << 15));
|
||||
}
|
||||
}
|
||||
|
||||
typedef CheckForUpdateRef = AutoDisposeProviderRef<dynamic>;
|
||||
|
||||
/// See also [checkForUpdate].
|
||||
@ProviderFor(checkForUpdate)
|
||||
const checkForUpdateProvider = CheckForUpdateFamily();
|
||||
|
||||
/// See also [checkForUpdate].
|
||||
class CheckForUpdateFamily extends Family<dynamic> {
|
||||
/// See also [checkForUpdate].
|
||||
const CheckForUpdateFamily();
|
||||
|
||||
/// See also [checkForUpdate].
|
||||
CheckForUpdateProvider call({
|
||||
BuildContext? context,
|
||||
bool? manualUpdate,
|
||||
}) {
|
||||
return CheckForUpdateProvider(
|
||||
context: context,
|
||||
manualUpdate: manualUpdate,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
CheckForUpdateProvider getProviderOverride(
|
||||
covariant CheckForUpdateProvider provider,
|
||||
) {
|
||||
return call(
|
||||
context: provider.context,
|
||||
manualUpdate: provider.manualUpdate,
|
||||
);
|
||||
}
|
||||
|
||||
static const Iterable<ProviderOrFamily>? _dependencies = null;
|
||||
|
||||
@override
|
||||
Iterable<ProviderOrFamily>? get dependencies => _dependencies;
|
||||
|
||||
static const Iterable<ProviderOrFamily>? _allTransitiveDependencies = null;
|
||||
|
||||
@override
|
||||
Iterable<ProviderOrFamily>? get allTransitiveDependencies =>
|
||||
_allTransitiveDependencies;
|
||||
|
||||
@override
|
||||
String? get name => r'checkForUpdateProvider';
|
||||
}
|
||||
|
||||
/// See also [checkForUpdate].
|
||||
class CheckForUpdateProvider extends AutoDisposeProvider<dynamic> {
|
||||
/// See also [checkForUpdate].
|
||||
CheckForUpdateProvider({
|
||||
this.context,
|
||||
this.manualUpdate,
|
||||
}) : super.internal(
|
||||
(ref) => checkForUpdate(
|
||||
ref,
|
||||
context: context,
|
||||
manualUpdate: manualUpdate,
|
||||
),
|
||||
from: checkForUpdateProvider,
|
||||
name: r'checkForUpdateProvider',
|
||||
debugGetCreateSourceHash:
|
||||
const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$checkForUpdateHash,
|
||||
dependencies: CheckForUpdateFamily._dependencies,
|
||||
allTransitiveDependencies:
|
||||
CheckForUpdateFamily._allTransitiveDependencies,
|
||||
);
|
||||
|
||||
final BuildContext? context;
|
||||
final bool? manualUpdate;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return other is CheckForUpdateProvider &&
|
||||
other.context == context &&
|
||||
other.manualUpdate == manualUpdate;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
var hash = _SystemHash.combine(0, runtimeType.hashCode);
|
||||
hash = _SystemHash.combine(hash, context.hashCode);
|
||||
hash = _SystemHash.combine(hash, manualUpdate.hashCode);
|
||||
|
||||
return _SystemHash.finish(hash);
|
||||
}
|
||||
}
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member
|
||||
|
|
@ -20,7 +20,7 @@ import 'package:mangayomi/modules/manga/detail/manga_detail_main.dart';
|
|||
import 'package:mangayomi/modules/manga/home/manga_home_screen.dart';
|
||||
import 'package:mangayomi/modules/manga/home/manga_search_screen.dart';
|
||||
import 'package:mangayomi/modules/manga/reader/reader_view.dart';
|
||||
import 'package:mangayomi/modules/more/about_screen.dart';
|
||||
import 'package:mangayomi/modules/more/about/about_screen.dart';
|
||||
import 'package:mangayomi/modules/more/download_queue/download_queue_screen.dart';
|
||||
import 'package:mangayomi/modules/more/more_screen.dart';
|
||||
import 'package:mangayomi/modules/more/settings/appearance/appearance_screen.dart';
|
||||
|
|
|
|||
|
|
@ -73,6 +73,8 @@ flutter:
|
|||
|
||||
assets:
|
||||
- assets/
|
||||
- assets/trackers_icons/
|
||||
- assets/app_icons/
|
||||
flutter_launcher_icons:
|
||||
android: "launcher_icon"
|
||||
ios: true
|
||||
|
|
|
|||
Loading…
Reference in a new issue