mobile: stop bg fetch events when toggled off

This commit is contained in:
Ammar Ahmed
2023-12-05 08:47:17 +05:00
committed by Abdullah Atta
parent 8736a58a02
commit c8eea0a0e4
3 changed files with 15 additions and 3 deletions

View File

@@ -57,10 +57,10 @@ const _SectionItem = ({ item }: { item: SettingSection }) => {
return;
}
if (!item.property) return;
item.onChange?.(!settings[item.property]);
SettingsService.set({
[item.property]: !settings[item.property]
});
item.onChange?.(!settings[item.property]);
};
const styles =

View File

@@ -70,6 +70,7 @@ import { SettingSection } from "./types";
import { getTimeLeft } from "./user-section";
import { AppLockPassword } from "../../components/dialogs/applock-password";
import { validateAppLockPassword } from "../../common/database/encryption";
import { BackgroundSync } from "../../services/background-sync";
type User = any;
export const settingsGroups: SettingSection[] = [
@@ -406,7 +407,14 @@ export const settingsGroups: SettingSection[] = [
description:
"Periodically wake up the app in background to sync your notes from other devices.",
type: "switch",
property: "backgroundSync"
property: "backgroundSync",
onChange: (value) => {
if (value) {
BackgroundSync.start();
} else {
BackgroundSync.stop();
}
}
},
{
id: "sync-issues-fix",

View File

@@ -87,6 +87,7 @@ async function start() {
onEvent,
onTimeout
);
DatabaseLogger.info(`[BackgroundFetch] configure status: ${status}`);
}
@@ -159,7 +160,10 @@ const registerHeadlessTask = () =>
);
export const BackgroundSync = {
start,
registerHeadlessTask
registerHeadlessTask,
stop: () => {
BackgroundFetch.stop();
}
};
export default { doInBackground };