From e0dd5edf199e5bf85cec4905e2ce2283e7586067 Mon Sep 17 00:00:00 2001 From: Moustapha Kodjo Amadou <107993382+kodjodevf@users.noreply.github.com> Date: Sun, 23 Feb 2025 16:13:10 +0100 Subject: [PATCH] add confirmation dialog for adding repositories --- lib/l10n/app_en.arb | 3 +- lib/main.dart | 151 +++++++++++++----- .../xcshareddata/xcschemes/Runner.xcscheme | 1 + 3 files changed, 112 insertions(+), 43 deletions(-) diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index fa1d641e..d559efcb 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -447,5 +447,6 @@ "clear_all_sources": "Clear all sources", "clear_all_sources_msg": "This will completely erase all sources of the application. Are you sure you want to continue?", "sources_cleared": "Sources cleared!!!", - "repo_added": "Source repository added!" + "repo_added": "Source repository added!", + "add_repo": "Add Repository?" } \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index 0a76addd..29054a0b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -69,7 +69,7 @@ void main(List args) async { runApp(const ProviderScope(child: MyApp())); } -void iniDateFormatting() { +void _iniDateFormatting() { initializeDateFormatting(); final supportedLocales = DateFormat.allLocalesWithSymbols(); for (var locale in supportedLocales) { @@ -90,8 +90,8 @@ class _MyAppState extends ConsumerState { @override void initState() { - iniDateFormatting(); - initDeepLinks(); + _iniDateFormatting(); + _initDeepLinks(); WidgetsBinding.instance.addPostFrameCallback((_) { if (ref.read(clearChapterCacheOnAppLaunchStateProvider)) { ref @@ -168,8 +168,7 @@ class _MyAppState extends ConsumerState { super.dispose(); } - Future initDeepLinks() async { - final l10n = l10nLocalizations(context); + Future _initDeepLinks() async { _appLinks = AppLinks(); _linkSubscription = _appLinks.uriLinkStream.listen((uri) { switch (uri.host) { @@ -179,43 +178,111 @@ class _MyAppState extends ConsumerState { final mangaRepoUrls = uri.queryParametersAll["manga_url"]; final animeRepoUrls = uri.queryParametersAll["anime_url"]; final novelRepoUrls = uri.queryParametersAll["novel_url"]; - if (mangaRepoUrls != null) { - final mangaRepos = - ref.read(extensionsRepoStateProvider(ItemType.manga)).toList(); - mangaRepos.addAll( - mangaRepoUrls.map( - (e) => Repo(name: repoName, jsonUrl: e, website: repoUrl), - ), - ); - ref - .read(extensionsRepoStateProvider(ItemType.manga).notifier) - .set(mangaRepos); - } - if (animeRepoUrls != null) { - final animeRepos = - ref.read(extensionsRepoStateProvider(ItemType.anime)).toList(); - animeRepos.addAll( - animeRepoUrls.map( - (e) => Repo(name: repoName, jsonUrl: e, website: repoUrl), - ), - ); - ref - .read(extensionsRepoStateProvider(ItemType.anime).notifier) - .set(animeRepos); - } - if (novelRepoUrls != null) { - final novelRepos = - ref.read(extensionsRepoStateProvider(ItemType.novel)).toList(); - novelRepos.addAll( - novelRepoUrls.map( - (e) => Repo(name: repoName, jsonUrl: e, website: repoUrl), - ), - ); - ref - .read(extensionsRepoStateProvider(ItemType.novel).notifier) - .set(novelRepos); - } - botToast(l10n?.repo_added ?? "Source repository added!"); + final context = navigatorKey.currentContext; + if (!(context?.mounted ?? false)) return; + final l10n = context!.l10n; + showDialog( + context: navigatorKey.currentContext!, + builder: (BuildContext context) { + return AlertDialog( + title: Text(l10n.add_repo), + content: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text("${l10n.name}: ${repoName ?? 'Unknown'}"), + const SizedBox(height: 8), + Text("URL: ${repoUrl ?? 'Unknown'}"), + ], + ), + actions: [ + TextButton( + child: Text(l10n.cancel), + onPressed: () => Navigator.of(context).pop(), + ), + FilledButton( + child: Text(l10n.add), + onPressed: () { + Navigator.of(context).pop(); + if (mangaRepoUrls != null) { + final mangaRepos = + ref + .read( + extensionsRepoStateProvider(ItemType.manga), + ) + .toList(); + mangaRepos.addAll( + mangaRepoUrls.map( + (e) => Repo( + name: repoName, + jsonUrl: e, + website: repoUrl, + ), + ), + ); + ref + .read( + extensionsRepoStateProvider( + ItemType.manga, + ).notifier, + ) + .set(mangaRepos); + } + if (animeRepoUrls != null) { + final animeRepos = + ref + .read( + extensionsRepoStateProvider(ItemType.anime), + ) + .toList(); + animeRepos.addAll( + animeRepoUrls.map( + (e) => Repo( + name: repoName, + jsonUrl: e, + website: repoUrl, + ), + ), + ); + ref + .read( + extensionsRepoStateProvider( + ItemType.anime, + ).notifier, + ) + .set(animeRepos); + } + if (novelRepoUrls != null) { + final novelRepos = + ref + .read( + extensionsRepoStateProvider(ItemType.novel), + ) + .toList(); + novelRepos.addAll( + novelRepoUrls.map( + (e) => Repo( + name: repoName, + jsonUrl: e, + website: repoUrl, + ), + ), + ); + ref + .read( + extensionsRepoStateProvider( + ItemType.novel, + ).notifier, + ) + .set(novelRepos); + } + botToast(l10n.repo_added); + }, + ), + ], + ); + }, + ); break; default: } diff --git a/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index ce3be83d..acb02858 100644 --- a/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -59,6 +59,7 @@ ignoresPersistentStateOnLaunch = "NO" debugDocumentVersioning = "YES" debugServiceExtension = "internal" + enableGPUValidationMode = "1" allowLocationSimulation = "YES">