Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

enable backups for pro users automatically

ammarahm-ed55faf81ecb78
diff --git a/apps/mobile/src/services/Backup.js b/apps/mobile/src/services/Backup.js
index 42f3be59c..06f3cd9e9 100644
--- a/apps/mobile/src/services/Backup.js
+++ b/apps/mobile/src/services/Backup.js
@@ -1,17 +1,17 @@
const {MMKV} = require('../utils/MMKV');
-import storage from '../utils/storage';
-import {db} from '../utils/database';
-import {eSendEvent, presentSheet, ToastEvent} from './EventManager';
-import SettingsService from './SettingsService';
-import {eCloseProgressDialog, eOpenProgressDialog} from '../utils/Events';
-import Share from 'react-native-share';
import {Platform} from 'react-native';
-import {sanitizeFilename} from '../utils/filename';
+import FileViewer from 'react-native-file-viewer';
import * as ScopedStorage from 'react-native-scoped-storage';
+import Share from 'react-native-share';
import {presentDialog} from '../components/Dialog/functions';
-import FileViewer from 'react-native-file-viewer';
+import {db} from '../utils/database';
+import {eCloseProgressDialog} from '../utils/Events';
+import {sanitizeFilename} from '../utils/filename';
+import storage from '../utils/storage';
+import {eSendEvent, presentSheet, ToastEvent} from './EventManager';
+import SettingsService from './SettingsService';
-const MS_DAY = 86400000;
+const MS_DAY = 864; //00000;
const MS_WEEK = MS_DAY * 7;
async function getDirectoryAndroid() {
@@ -47,11 +47,11 @@ async function checkBackupDirExists() {
presentDialog({
title: 'Select backup folder',
paragraph:
- 'Please select the folder where you would like to store backup files.',
+ 'Daily backups are turned on. Please select a folder where you would like to store backup files. You can change or disable automatic backups in settings however we highly recommend that you keep them on.',
positivePress: async () => {
resolve(await getDirectoryAndroid());
},
- positiveText: 'Open file manager'
+ positiveText: 'Select'
});
});
}
@@ -117,7 +117,7 @@ async function run() {
context: 'global'
});
- presentSheet( {
+ presentSheet({
title: 'Backup complete',
icon: 'cloud-upload',
paragraph:
@@ -167,7 +167,7 @@ async function getLastBackupDate() {
}
async function checkBackupRequired(type) {
- if (type === 'off') return;
+ if (type === 'off' || type === 'useroff') return;
let now = Date.now();
let lastBackupDate = await getLastBackupDate();
if (!lastBackupDate || lastBackupDate === 'never') {
diff --git a/apps/mobile/src/utils/useAppEvents.js b/apps/mobile/src/utils/useAppEvents.js
index 35df3fc6f..e9d288eaa 100644
--- a/apps/mobile/src/utils/useAppEvents.js
+++ b/apps/mobile/src/utils/useAppEvents.js
@@ -59,6 +59,7 @@ import {
} from '../views/Editor/Functions';
import tiny from '../views/Editor/tiny/tiny';
import {ProFeatures} from '../components/ResultDialog/pro-features';
+import Backup from '../services/Backup';
const SodiumEventEmitter = new NativeEventEmitter(NativeModules.Sodium);
@@ -157,8 +158,7 @@ export const useAppEvents = () => {
Navigation.routeNames.Trash,
Navigation.routeNames.Notebook
]);
- eSendEvent(eClearEditor, id);
-
+ eSendEvent(eClearEditor, id);
} catch (e) {}
};
@@ -204,7 +204,6 @@ export const useAppEvents = () => {
try {
if (url.startsWith('https://app.notesnook.com/account/verified')) {
await onEmailVerified();
-
} else {
return;
}
@@ -350,6 +349,7 @@ export const useAppEvents = () => {
}
if (user) {
setUser(user);
+
clearMessage();
attachIAPListeners();
await Sync.run();
@@ -390,6 +390,12 @@ export const useAppEvents = () => {
}
} finally {
await PremiumService.setPremiumStatus();
+ if (PremiumService.get()) {
+ if (SettingsService.get().reminder === "off") {
+ await SettingsService.set('reminder', 'daily');
+ sleep(2000).then(() => Backup.checkAndRun());
+ }
+ }
refValues.current.isUserReady = true;
if (login) {
eSendEvent(eCloseProgressDialog);
diff --git a/apps/mobile/src/views/Settings/backuprestore.js b/apps/mobile/src/views/Settings/backuprestore.js
index c4e7fcc01..f7203ea48 100644
--- a/apps/mobile/src/views/Settings/backuprestore.js
+++ b/apps/mobile/src/views/Settings/backuprestore.js
@@ -196,7 +196,7 @@ const SettingsBackupAndRestore = ({isSheet}) => {
{[
{
title: 'Never',
- value: 'off'
+ value: 'useroff'
},
{
title: 'Daily',
@@ -210,7 +210,7 @@ const SettingsBackupAndRestore = ({isSheet}) => {
<TouchableOpacity
activeOpacity={1}
onPress={async () => {
- if (item.value === 'off') {
+ if (item.value === 'useroff') {
await SettingsService.set('reminder', item.value);
} else {
await PremiumService.verify(async () => {