Skip to content

Commit

Permalink
Fix issues reported by pre-alpha users - patch 2 (#906)
Browse files Browse the repository at this point in the history
* delete background_action key before action done

* force to delete BACKGROUND_ACTION.
in case app is shutdowned while running bg actions
  • Loading branch information
nyagami authored Jan 24, 2024
1 parent 0cf75fd commit 8f6c390
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 5 deletions.
6 changes: 6 additions & 0 deletions App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import LottieSplashScreen from 'react-native-lottie-splash-screen';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { Provider as PaperProvider } from 'react-native-paper';
import * as Notifications from 'expo-notifications';
import BackgroundService from 'react-native-background-actions';

import { createTables } from '@database/db';
import AppErrorBoundary from '@components/AppErrorBoundary/AppErrorBoundary';
Expand All @@ -18,6 +19,8 @@ import { collectPlugins } from '@plugins/pluginManager';
import Main from './src/navigators/Main';
import { BottomSheetModalProvider } from '@gorhom/bottom-sheet';
import { usePlugins } from '@hooks/persisted';
import { MMKVStorage } from '@utils/mmkv/mmkv';
import { BACKGROUND_ACTION } from '@services/constants';

Notifications.setNotificationHandler({
handleNotification: async () => {
Expand All @@ -35,6 +38,9 @@ const App = () => {
createTables();
collectPlugins().then(() => LottieSplashScreen.hide());
refreshPlugins();
if (!BackgroundService.isRunning()) {
MMKVStorage.delete(BACKGROUND_ACTION);
}
}, []);

return (
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/persisted/useDownload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ const downloadChapterAction = async (taskData?: TaskData) => {
}
}
} finally {
MMKVStorage.delete(BACKGROUND_ACTION);
await Notifications.scheduleNotificationAsync({
content: {
title: 'Downloader',
body: 'Download completed',
},
trigger: null,
});
MMKVStorage.delete(BACKGROUND_ACTION);
BackgroundService.stop();
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/services/backup/drive/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ const driveBackupAction = async (taskData?: TaskData) => {
},
trigger: null,
});
await BackgroundService.stop();
}
} finally {
MMKVStorage.delete(BACKGROUND_ACTION);
await BackgroundService.stop();
}
};

Expand Down Expand Up @@ -172,10 +172,10 @@ const driveRestoreAction = async (taskData?: TaskData) => {
},
trigger: null,
});
await BackgroundService.stop();
}
} finally {
MMKVStorage.delete(BACKGROUND_ACTION);
await BackgroundService.stop();
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/services/backup/legacy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const createBackup = async () => {
showToast(error.message);
} finally {
MMKVStorage.delete(BACKGROUND_ACTION);
BackgroundService.stop();
}
};

Expand Down Expand Up @@ -122,6 +123,7 @@ export const restoreBackup = async (filePath?: string) => {
},
trigger: null,
});
MMKVStorage.delete(BACKGROUND_ACTION);
resolve();
}

Expand Down Expand Up @@ -170,8 +172,6 @@ export const restoreBackup = async (filePath?: string) => {
}
} catch (error: any) {
showToast(error.message);
} finally {
MMKVStorage.delete(BACKGROUND_ACTION);
}
};

Expand Down
1 change: 1 addition & 0 deletions src/services/migrate/migrateNovel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ export const migrateNovel = async (
}
} finally {
MMKVStorage.delete(BACKGROUND_ACTION);
BackgroundService.stop();
}
};
await BackgroundService.start(veryIntensiveTask, options);
Expand Down
1 change: 1 addition & 0 deletions src/services/updates/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ const updateLibrary = async (categoryId?: number) => {
}
} finally {
MMKVStorage.delete(BACKGROUND_ACTION);
BackgroundService.stop();
}
};

Expand Down

0 comments on commit 8f6c390

Please sign in to comment.