Skip to content

Commit

Permalink
chore: prevent backup/restore while related things are runnning
Browse files Browse the repository at this point in the history
  • Loading branch information
MSOB7YY committed Jun 20, 2024
1 parent e58be1c commit 356d68b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
27 changes: 15 additions & 12 deletions lib/ui/widgets/settings/backup_restore_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import 'package:namida/ui/widgets/circular_percentages.dart';
import 'package:namida/ui/widgets/custom_widgets.dart';
import 'package:namida/ui/widgets/settings/extra_settings.dart';
import 'package:namida/ui/widgets/settings_card.dart';
import 'package:namida/youtube/controller/youtube_history_controller.dart';

enum _BackupAndRestoreKeys {
create,
Expand All @@ -46,8 +47,16 @@ class BackupAndRestore extends SettingSubpageProvider {
_BackupAndRestoreKeys.importLastfm: [lang.IMPORT_LAST_FM_HISTORY],
};

bool _canDoImport() {
if (JsonToHistoryParser.inst.isParsing.value || HistoryController.inst.isLoadingHistory) {
bool _canDoImport({required bool isYT}) {
if (JsonToHistoryParser.inst.isParsing.value || HistoryController.inst.isLoadingHistory || (isYT && YoutubeHistoryController.inst.isLoadingHistory)) {
snackyy(title: lang.NOTE, message: lang.ANOTHER_PROCESS_IS_RUNNING);
return false;
}
return true;
}

bool _canCreateRestoreBackup() {
if (JsonToHistoryParser.inst.isParsing.value || HistoryController.inst.isLoadingHistory || YoutubeHistoryController.inst.isLoadingHistory) {
snackyy(title: lang.NOTE, message: lang.ANOTHER_PROCESS_IS_RUNNING);
return false;
}
Expand Down Expand Up @@ -77,10 +86,7 @@ class BackupAndRestore extends SettingSubpageProvider {
child: const LoadingIndicator(),
),
onTap: () async {
if (BackupController.inst.isRestoringBackup.value) {
snackyy(title: lang.NOTE, message: lang.ANOTHER_PROCESS_IS_RUNNING);
return;
}
if (!_canCreateRestoreBackup()) return;

NamidaNavigator.inst.navigateDialog(
dialog: CustomBlurryDialog(
Expand Down Expand Up @@ -164,10 +170,7 @@ class BackupAndRestore extends SettingSubpageProvider {
child: const LoadingIndicator(),
),
onTap: () {
if (BackupController.inst.isCreatingBackup.value) {
snackyy(title: lang.NOTE, message: lang.ANOTHER_PROCESS_IS_RUNNING);
return;
}
if (!_canCreateRestoreBackup()) return;

bool isActive(List<String> items) => items.every((element) => settings.backupItemslist.contains(element));

Expand Down Expand Up @@ -569,7 +572,7 @@ class BackupAndRestore extends SettingSubpageProvider {
),
),
onTap: () {
if (!_canDoImport()) return;
if (!_canDoImport(isYT: true)) return;

NamidaNavigator.inst.navigateDialog(
dialog: CustomBlurryDialog(
Expand Down Expand Up @@ -717,7 +720,7 @@ class BackupAndRestore extends SettingSubpageProvider {
),
),
onTap: () {
if (!_canDoImport()) return;
if (!_canDoImport(isYT: false)) return;

NamidaNavigator.inst.navigateDialog(
dialog: CustomBlurryDialog(
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: namida
description: A Beautiful and Feature-rich Music Player, With YouTube & Video Support Built in Flutter
publish_to: "none"
version: 2.7.3-beta+240609199
version: 2.7.4-beta+240620137

environment:
sdk: ">=3.4.0 <4.0.0"
Expand Down

0 comments on commit 356d68b

Please sign in to comment.