Skip to content

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

feat: ask user to backup their data

ammarahm-ed731581d1e9a3
diff --git a/apps/mobile/App.js b/apps/mobile/App.js
index e609d52fb..2dc3d335d 100644
--- a/apps/mobile/App.js
+++ b/apps/mobile/App.js
@@ -65,6 +65,12 @@ const loadDatabase = async () => {
timestamp: Date.now() + 86400000 * 2
})
);
+ await MMKV.setItem(
+ 'askForBackup',
+ JSON.stringify({
+ timestamp: Date.now() + 86400000 * 3
+ })
+ );
}
};
diff --git a/apps/mobile/AppRootEvents.js b/apps/mobile/AppRootEvents.js
index b61b20846..c3ae78ff4 100644
--- a/apps/mobile/AppRootEvents.js
+++ b/apps/mobile/AppRootEvents.js
@@ -182,7 +182,6 @@ export const AppRootEvents = React.memo(
await onEmailVerified();
}
await setCurrentUser();
- await Backup.checkAndRun();
let version = await db.version();
if (version.mobile > APP_VERSION) {
eSendEvent('updateDialog', ver);
diff --git a/apps/mobile/src/components/AppLoader/index.js b/apps/mobile/src/components/AppLoader/index.js
index 2c117e4cd..b215f1c16 100644
--- a/apps/mobile/src/components/AppLoader/index.js
+++ b/apps/mobile/src/components/AppLoader/index.js
@@ -6,8 +6,10 @@ import {useTracked} from '../../provider';
import {
useFavoriteStore,
useNoteStore,
+ useSettingStore,
useUserStore
} from '../../provider/stores';
+import Backup from '../../services/Backup';
import BiometricService from '../../services/BiometricService';
import {DDS} from '../../services/DeviceDetection';
import {
@@ -17,11 +19,16 @@ import {
} from '../../services/EventManager';
import {editing} from '../../utils';
import {db} from '../../utils/DB';
-import {eOpenLoginDialog, eOpenRateDialog} from '../../utils/Events';
+import {
+ eOpenLoginDialog,
+ eOpenProgressDialog,
+ eOpenRateDialog
+} from '../../utils/Events';
import {MMKV} from '../../utils/mmkv';
import {tabBarRef} from '../../utils/Refs';
import {SIZE} from '../../utils/SizeUtils';
import {sleep} from '../../utils/TimeUtils';
+import {SettingsBackupAndRestore} from '../../views/Settings';
import {Button} from '../Button';
import Input from '../Input';
import Seperator from '../Seperator';
@@ -84,16 +91,41 @@ const AppLoader = ({onLoad}) => {
setNotes();
setFavorites();
_setLoading(false);
- await sleep(1000);
+ await sleep(2000);
if ((await MMKV.getItem('loginSessionHasExpired')) === 'expired') {
eSendEvent(eOpenLoginDialog, 4);
return;
}
+ let settingsStore = useSettingStore.getState();
+ if (await Backup.checkBackupRequired(settingsStore.settings.reminder)) {
+ await Backup.checkAndRun();
+ return;
+ }
let askForRating = await MMKV.getItem('askForRating');
if (askForRating !== 'never' || askForRating !== 'completed') {
askForRating = JSON.parse(askForRating);
if (askForRating?.timestamp < Date.now()) {
eSendEvent(eOpenRateDialog);
+ return;
+ }
+ }
+
+ let askForBackup = await MMKV.getItem('askForBackup');
+ if (
+ (settingsStore.settings.reminder === 'off' ||
+ !settingsStore.settings.reminder)
+ ) {
+ askForBackup = JSON.parse(askForBackup);
+
+ if (askForBackup?.timestamp < Date.now()) {
+ eSendEvent(eOpenProgressDialog, {
+ title: 'Backup & restore',
+ paragraph: 'Please enable automatic backups to keep your data safe',
+ noProgress: true,
+ noIcon: true,
+ component: <SettingsBackupAndRestore isSheet={true} />
+ });
+ return;
}
}
};
diff --git a/apps/mobile/src/components/ProgressDialog/index.js b/apps/mobile/src/components/ProgressDialog/index.js
index 00e212e88..b2bcc6d57 100644
--- a/apps/mobile/src/components/ProgressDialog/index.js
+++ b/apps/mobile/src/components/ProgressDialog/index.js
@@ -19,7 +19,7 @@ const ProgressDialog = () => {
const [visible, setVisible] = useState(false);
const [dialogData, setDialogData] = useState({
title: 'Loading',
- paragraph: 'Loading tagline',
+ paragraph: 'Loading tagline'
});
const actionSheetRef = useRef();
useEffect(() => {
@@ -57,7 +57,7 @@ const ProgressDialog = () => {
justifyContent: 'center',
alignItems: 'center',
marginBottom: 10,
- paddingHorizontal: 12,
+ paddingHorizontal: 12
}}>
{!dialogData?.noProgress ? (
<ActivityIndicator size={50} color={colors.accent} />
@@ -83,10 +83,13 @@ const ProgressDialog = () => {
</Paragraph>
)}
</View>
+
+ {dialogData.component}
+
{dialogData?.learnMore ? (
<Paragraph
style={{
- alignSelf: 'center',
+ alignSelf: 'center'
}}
onPress={dialogData.learnMorePress}
color={colors.icon}>
@@ -97,7 +100,7 @@ const ProgressDialog = () => {
<View
style={{
paddingHorizontal: 12,
- marginBottom: 12,
+ marginBottom: 12
}}>
{dialogData.valueArray &&
dialogData.valueArray.map(v => (
@@ -110,7 +113,7 @@ const ProgressDialog = () => {
width="100%"
style={{
justifyContent: 'flex-start',
- backgroundColor: 'transparent',
+ backgroundColor: 'transparent'
}}
/>
))}
@@ -118,7 +121,7 @@ const ProgressDialog = () => {
<View
style={{
- paddingHorizontal: 12,
+ paddingHorizontal: 12
}}>
{dialogData?.action ? (
<Button
@@ -143,7 +146,7 @@ const ProgressDialog = () => {
type="accent"
height={50}
style={{
- marginBottom: 10,
+ marginBottom: 10
}}
width="100%"
fontSize={SIZE.md}
diff --git a/apps/mobile/src/components/SimpleList/announcement.js b/apps/mobile/src/components/SimpleList/announcement.js
index 4f4ccd416..e79c888bf 100644
--- a/apps/mobile/src/components/SimpleList/announcement.js
+++ b/apps/mobile/src/components/SimpleList/announcement.js
@@ -4,12 +4,13 @@ import {useTracked} from '../../provider';
import {
allowedPlatforms,
useMessageStore,
- useSelectionStore,
+ useSelectionStore
} from '../../provider/stores';
import {eSendEvent} from '../../services/EventManager';
-import {eOpenPremiumDialog} from '../../utils/Events';
+import {eOpenPremiumDialog, eOpenProgressDialog} from '../../utils/Events';
import {openLinkInBrowser} from '../../utils/functions';
import {SIZE} from '../../utils/SizeUtils';
+import {SettingsBackupAndRestore} from '../../views/Settings';
import {Button} from '../Button';
import Seperator from '../Seperator';
import Heading from '../Typography/Heading';
@@ -27,24 +28,24 @@ export const Announcement = () => {
<View
style={{
backgroundColor: colors.bg,
- width: '100%',
+ width: '100%'
}}>
<View
style={{
paddingHorizontal: 12,
paddingVertical: 12,
- width: '100%',
+ width: '100%'
}}>
<View
style={{
flexDirection: 'row',
alignItems: 'center',
- justifyContent: 'space-between',
+ justifyContent: 'space-between'
}}>
<View
style={{
flexDirection: 'row',
- alignItems: 'center',
+ alignItems: 'center'
}}>
<View
style={{
@@ -54,7 +55,7 @@ export const Announcement = () => {
height: 20,
justifyContent: 'center',
alignItems: 'center',
- marginRight: 2.5,
+ marginRight: 2.5
}}>
<Paragraph color={colors.light} size={SIZE.xs}>
{announcements.length}
@@ -67,7 +68,7 @@ export const Announcement = () => {
height={null}
icon="bullhorn"
style={{
- paddingVertical: 4,
+ paddingVertical: 4
}}
/>
</View>
@@ -81,7 +82,7 @@ export const Announcement = () => {
remove(announcement.id);
}}
style={{
- paddingVertical: 4,
+ paddingVertical: 4
}}
/>
</View>
@@ -90,12 +91,12 @@ export const Announcement = () => {
style={{
flexDirection: 'row',
alignItems: 'center',
- justifyContent: 'space-between',
+ justifyContent: 'space-between'
}}>
{announcement?.title && (
<Heading
style={{
- width: '100%',
+ width: '100%'
}}
size={SIZE.lg}
color={colors.heading}>
@@ -112,12 +113,12 @@ export const Announcement = () => {
style={{
flexDirection: 'row',
justifyContent: 'space-between',
- flexWrap: 'wrap',
+ flexWrap: 'wrap'
}}>
{announcement?.callToActions &&
announcement.callToActions.map((item, index) =>
item.platforms.some(
- platform => allowedPlatforms.indexOf(platform) > -1,
+ platform => allowedPlatforms.indexOf(platform) > -1
) ? (
<>
<Button
@@ -133,17 +134,26 @@ export const Announcement = () => {
} else if (item.type === 'promo') {
eSendEvent(eOpenPremiumDialog, {
promoCode: item.data,
- text: item.title,
+ text: item.title
+ });
+ } else if (item.type === 'backup') {
+ eSendEvent(eOpenProgressDialog, {
+ title: 'Backup & restore',
+ paragraph:
+ 'Please enable automatic backups to keep your data safe',
+ noProgress: true,
+ noIcon: true,
+ component: <SettingsBackupAndRestore isSheet={true} />
});
}
}}
width={'100%'}
style={{
- marginBottom: 10,
+ marginBottom: 10
}}
/>
</>
- ) : null,
+ ) : null
)}
</View>
</View>
diff --git a/apps/mobile/src/services/Backup.js b/apps/mobile/src/services/Backup.js
index f106fd1e6..ded14fac8 100644
--- a/apps/mobile/src/services/Backup.js
+++ b/apps/mobile/src/services/Backup.js
@@ -20,7 +20,7 @@ async function run() {
heading: 'Cannot backup data',
message: 'You must provide phone storage access to backup data.',
type: 'error',
- context: 'local',
+ context: 'local'
});
return;
}
@@ -30,14 +30,14 @@ async function run() {
eSendEvent(eOpenProgressDialog, {
title: 'Backing up your data',
paragraph:
- "All your backups are stored in 'Phone Storage/Notesnook/backups/' folder",
+ "All your backups are stored in 'Phone Storage/Notesnook/backups/' folder"
});
let backup;
let error;
try {
backup = await db.backup.export(
'mobile',
- SettingsService.get().encryptedBackup,
+ SettingsService.get().encryptedBackup
);
} catch (e) {
error = true;
@@ -57,7 +57,7 @@ async function run() {
heading: 'Backup successful',
message: 'Your backup is stored in Notesnook folder on your phone.',
type: 'success',
- context: 'local',
+ context: 'local'
});
eSendEvent(eOpenProgressDialog, {
@@ -75,13 +75,20 @@ async function run() {
Platform.OS === 'ios'
? path + backupName
: 'file:/' + path + backupName,
- title: 'Save Backup to Cloud',
+ title: 'Save Backup to Cloud'
}).catch(e => console.log);
},
- actionText: 'Share Backup File',
- },
- ],
+ actionText: 'Share Backup File'
+ }
+ ]
});
+ console.log('updated ask for backup date');
+ await MMKV.setItem(
+ 'askForBackup',
+ JSON.stringify({
+ timestamp: Date.now() + 86400000 * 3
+ })
+ );
return path + backupName;
} catch (e) {
@@ -93,7 +100,7 @@ async function run() {
ToastEvent.show({
heading: 'Backup failed',
type: 'error',
- context: 'local',
+ context: 'local'
});
return null;
@@ -139,5 +146,5 @@ const checkAndRun = async () => {
export default {
checkBackupRequired,
run,
- checkAndRun,
+ checkAndRun
};
diff --git a/apps/mobile/src/views/Settings/index.js b/apps/mobile/src/views/Settings/index.js
index 48dd91250..7a79c4d29 100644
--- a/apps/mobile/src/views/Settings/index.js
+++ b/apps/mobile/src/views/Settings/index.js
@@ -404,9 +404,7 @@ const SectionHeader = ({title, collapsed, setCollapsed}) => {
{title}
</Paragraph>
) : (
- <Heading
- size={SIZE.md + 1}
- color={colors.accent}>
+ <Heading size={SIZE.md + 1} color={colors.accent}>
{title}
</Heading>
)}
@@ -1651,57 +1649,78 @@ const SettingsPrivacyAndSecurity = () => {
);
};
-const SettingsBackupAndRestore = () => {
+export const SettingsBackupAndRestore = ({isSheet}) => {
const [state] = useTracked();
const {colors} = state;
const settings = useSettingStore(state => state.settings);
const user = useUserStore(state => state.user);
- const [collapsed, setCollapsed] = useState(true);
+ const [collapsed, setCollapsed] = useState(isSheet ? false : true);
+
+ const optItems = isSheet
+ ? []
+ : [
+ {
+ name: 'Restore backup',
+ func: async () => {
+ if (isSheet) {
+ eSendEvent(eCloseProgressDialog);
+ await sleep(300);
+ }
+ eSendEvent(eOpenRestoreDialog);
+ },
+ desc: 'Restore backup from phone storage.'
+ },
+ {
+ name: 'Import notes from other note apps',
+ desc: 'Get all your notes in one place with Notesnook Importer.',
+ func: async () => {
+ if (isSheet) {
+ eSendEvent(eCloseProgressDialog);
+ await sleep(300);
+ }
+ eSendEvent(eOpenProgressDialog, {
+ title: 'Notesnook Importer',
+ icon: 'import',
+ noProgress: true,
+ action: async () => {
+ try {
+ await openLinkInBrowser(
+ 'https://importer.notesnook.com',
+ colors
+ );
+ } catch (e) {}
+ },
+ actionText: 'Go to Notesnook Importer',
+ learnMore: 'Learn how this works',
+ learnMorePress: async () => {
+ try {
+ await openLinkInBrowser(
+ 'https://docs.notesnook.com/importing/notesnook-importer/',
+ colors
+ );
+ } catch (e) {}
+ },
+ paragraph:
+ 'Now you can import your notes from all the popular note taking apps. Go to https://importer.notesnook.com to import your notes.'
+ });
+ },
+ new: true
+ }
+ ];
const backupItemsList = [
{
- name: 'Backup data',
+ name: 'Backup now',
func: async () => {
+ if (isSheet) {
+ eSendEvent(eCloseProgressDialog);
+ await sleep(300);
+ }
await Backup.run();
},
desc: 'Backup your data to phone storage'
},
- {
- name: 'Restore backup',
- func: () => {
- eSendEvent(eOpenRestoreDialog);
- },
- desc: 'Restore backup from phone storage.'
- },
- {
- name: 'Import notes from other note apps',
- desc: 'Get all your notes in one place with Notesnook Importer.',
- func: () => {
- eSendEvent(eOpenProgressDialog, {
- title: 'Notesnook Importer',
- icon: 'import',
- noProgress: true,
- action: async () => {
- try {
- await openLinkInBrowser('https://importer.notesnook.com', colors);
- } catch (e) {}
- },
- actionText: 'Go to Notesnook Importer',
- learnMore: 'Learn how this works',
- learnMorePress: async () => {
- try {
- await openLinkInBrowser(
- 'https://docs.notesnook.com/importing/notesnook-importer/',
- colors
- );
- } catch (e) {}
- },
- paragraph:
- 'Now you can import your notes from all the popular note taking apps. Go to https://importer.notesnook.com to import your notes.'
- });
- },
- new: true
- }
+ ...optItems
];
const toggleEncryptedBackups = async () => {
@@ -1719,13 +1738,24 @@ const SettingsBackupAndRestore = () => {
await SettingsService.set('encryptedBackup', !settings.encryptedBackup);
};
+ const updateAskForBackup = async () => {
+ await MMKV.setItem(
+ 'askForBackup',
+ JSON.stringify({
+ timestamp: Date.now() + 86400000 * 3
+ })
+ );
+ }
+
return (
<>
- <SectionHeader
- collapsed={collapsed}
- setCollapsed={setCollapsed}
- title="Backup & restore"
- />
+ {!isSheet && (
+ <SectionHeader
+ collapsed={collapsed}
+ setCollapsed={setCollapsed}
+ title="Backup & restore"
+ />
+ )}
{!collapsed && (
<>
@@ -1758,7 +1788,7 @@ const SettingsBackupAndRestore = () => {
textAlignVertical: 'center',
maxWidth: '100%'
}}>
- Auto Backup
+ Automatic backups
</Paragraph>
<Paragraph color={colors.icon} size={SIZE.sm}>
Backup your data automatically.
@@ -1792,6 +1822,7 @@ const SettingsBackupAndRestore = () => {
onPress={async () => {
if (item.value === 'off') {
await SettingsService.set('reminder', item.value);
+
} else {
await PremiumService.verify(async () => {
if (Platform.OS === 'android') {
@@ -1811,6 +1842,7 @@ const SettingsBackupAndRestore = () => {
//await Backup.run();
});
}
+ updateAskForBackup();
}}
key={item.value}
style={{
@@ -1835,21 +1867,23 @@ const SettingsBackupAndRestore = () => {
</View>
</View>
- <CustomButton
- title="Backup encryption"
- tagline="Encrypt all your backups."
- onPress={toggleEncryptedBackups}
- customComponent={
- <ToggleSwitch
- isOn={settings.encryptedBackup}
- onColor={colors.accent}
- offColor={colors.icon}
- size="small"
- animationSpeed={150}
- onToggle={toggleEncryptedBackups}
- />
- }
- />
+ {!isSheet && (
+ <CustomButton
+ title="Backup encryption"
+ tagline="Encrypt all your backups."
+ onPress={toggleEncryptedBackups}
+ customComponent={
+ <ToggleSwitch
+ isOn={settings.encryptedBackup}
+ onColor={colors.accent}
+ offColor={colors.icon}
+ size="small"
+ animationSpeed={150}
+ onToggle={toggleEncryptedBackups}
+ />
+ }
+ />
+ )}
</>
)}
</>