From 2845cb19d61c78d36d2c47768b35de19d5727cf5 Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Fri, 16 Dec 2022 12:35:22 +0500 Subject: [PATCH] mobile: add sync controls --- apps/mobile/app/hooks/use-app-events.js | 1 + .../app/screens/settings/settings-data.tsx | 63 +++++++++++++------ apps/mobile/app/services/sync.js | 7 ++- apps/mobile/app/stores/use-setting-store.ts | 2 + 4 files changed, 53 insertions(+), 20 deletions(-) diff --git a/apps/mobile/app/hooks/use-app-events.js b/apps/mobile/app/hooks/use-app-events.js index e3bb78579..cd0774b68 100644 --- a/apps/mobile/app/hooks/use-app-events.js +++ b/apps/mobile/app/hooks/use-app-events.js @@ -277,6 +277,7 @@ export const useAppEvents = () => { }; const onRequestPartialSync = async (full, force) => { + if (SettingsService.get().disableAutoSync) return; DatabaseLogger.info(`onRequestPartialSync full:${full}, force:${force}`); if (full || force) { await Sync.run("global", force, full); diff --git a/apps/mobile/app/screens/settings/settings-data.tsx b/apps/mobile/app/screens/settings/settings-data.tsx index e90f5de24..ae7a018ae 100644 --- a/apps/mobile/app/screens/settings/settings-data.tsx +++ b/apps/mobile/app/screens/settings/settings-data.tsx @@ -381,27 +381,52 @@ export const settingsGroups: SettingSection[] = [ ] }, { - id: "sync-issues-fix", - name: "Having problems with sync", - description: "Try force sync to resolve issues with syncing", - icon: "sync-alert", - modifer: async () => { - presentDialog({ - title: "Force sync", - paragraph: - "If your data on two devices is out of sync even after trying to sync normally. You can run force sync to solve such problems. Usually you should never need to run this otherwise. Force sync means that all your data on this device is reuploaded to the server.", - negativeText: "Cancel", - positiveText: "Start", - positivePress: async () => { - eSendEvent(eCloseProgressDialog); - await sleep(300); - Progress.present(); - Sync.run("global", true, true, () => { - eSendEvent(eCloseProgressDialog); + id: "sync-settings", + name: "Sync settings", + description: "Configure syncing for this device", + type: "screen", + icon: "autorenew", + sections: [ + { + id: "auto-sync", + name: "Disable auto sync", + description: + "Turn of automatic syncing. Changes from this client will be synced only when you run sync manually.", + type: "switch", + property: "disableAutoSync" + }, + { + id: "disable-sync", + name: "Disable syncing", + description: + "Turns off syncing completely on this device. Any changes made will remain local only and new changes from your other devices won't sync to this device.", + type: "switch", + property: "disableSync", + }, + { + id: "sync-issues-fix", + name: "Having problems with sync", + description: "Try force sync to resolve issues with syncing", + icon: "sync-alert", + modifer: async () => { + presentDialog({ + title: "Force sync", + paragraph: + "If your data on two devices is out of sync even after trying to sync normally. You can run force sync to solve such problems. Usually you should never need to run this otherwise. Force sync means that all your data on this device is reuploaded to the server.", + negativeText: "Cancel", + positiveText: "Start", + positivePress: async () => { + eSendEvent(eCloseProgressDialog); + await sleep(300); + Progress.present(); + Sync.run("global", true, true, () => { + eSendEvent(eCloseProgressDialog); + }); + } }); } - }); - } + } + ] } ] }, diff --git a/apps/mobile/app/services/sync.js b/apps/mobile/app/services/sync.js index f00540ec7..4ac0f7c73 100644 --- a/apps/mobile/app/services/sync.js +++ b/apps/mobile/app/services/sync.js @@ -25,6 +25,7 @@ import { doInBackground } from "../utils"; import { db } from "../common/database"; import { DatabaseLogger } from "../common/database/index"; import { ToastEvent } from "./event-manager"; +import SettingsService from "./settings"; NetInfo.configure({ reachabilityUrl: "https://notesnook.com", @@ -56,7 +57,11 @@ const run = async ( if (!status.isInternetReachable) { DatabaseLogger.warn("Internet not reachable"); } - if (!user || !status.isInternetReachable) { + if ( + !user || + !status.isInternetReachable || + SettingsService.get().disableSync + ) { initAfterSync(); return onCompleted?.(false); } diff --git a/apps/mobile/app/stores/use-setting-store.ts b/apps/mobile/app/stores/use-setting-store.ts index b6651621c..33be77fb4 100644 --- a/apps/mobile/app/stores/use-setting-store.ts +++ b/apps/mobile/app/stores/use-setting-store.ts @@ -63,6 +63,8 @@ export type Settings = { sessionExpired: boolean; version: string | null; doubleSpacedLines?: boolean; + disableAutoSync?: boolean; + disableSync?: boolean; }; type DimensionsType = {