Skip to content

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

migrate mmkv storage

ammarahm-ed69e723124528
diff --git a/apps/mobile/App.js b/apps/mobile/App.js
index 57522387d..386a2a9fe 100644
--- a/apps/mobile/App.js
+++ b/apps/mobile/App.js
@@ -15,12 +15,13 @@ const App = () => {
useEffect(() => {
(async () => {
try {
- await SettingsService.init();
+ SettingsService.init();
+
let appLockMode = SettingsService.get().appLockMode;
if (appLockMode && appLockMode !== 'none') {
useUserStore.getState().setVerifyUser(true);
}
- await TipManager.init();
+ TipManager.init();
Notifications.get();
await SettingsService.onFirstLaunch();
} catch (e) {}
diff --git a/apps/mobile/share/store.js b/apps/mobile/share/store.js
index e370cef6c..a9ba1acbd 100644
--- a/apps/mobile/share/store.js
+++ b/apps/mobile/share/store.js
@@ -7,7 +7,7 @@ export const useShareStore = create((set, get) => ({
colors: Appearance.getColorScheme() === 'dark' ? COLOR_SCHEME_DARK : COLOR_SCHEME_LIGHT,
accent: ACCENT,
setAccent: async () => {
- let appSettings = await MMKV.getItem('appSettings');
+ let appSettings = MMKV.getString('appSettings');
if (appSettings) {
appSettings = JSON.parse(appSettings);
@@ -31,7 +31,7 @@ export const useShareStore = create((set, get) => ({
set({ appendNote: note });
},
restoreAppendNote: async () => {
- let note = await MMKV.getItem('shareMenuAppendNote');
+ let note = MMKV.getString('shareMenuAppendNote');
if (note) {
note = JSON.parse(note);
set({ appendNote: note });
diff --git a/apps/mobile/src/components/launcher/index.js b/apps/mobile/src/components/launcher/index.js
index e6c1da042..9d3b07c4a 100644
--- a/apps/mobile/src/components/launcher/index.js
+++ b/apps/mobile/src/components/launcher/index.js
@@ -163,7 +163,7 @@ const Launcher = React.memo(
};
const restoreEditorState = async () => {
- let appState = await MMKV.getItem('appState');
+ let appState = MMKV.getString('appState');
if (appState) {
appState = JSON.parse(appState);
if (
diff --git a/apps/mobile/src/components/tabs/index.js b/apps/mobile/src/components/tabs/index.js
index 9f56b4a4a..a8f098032 100644
--- a/apps/mobile/src/components/tabs/index.js
+++ b/apps/mobile/src/components/tabs/index.js
@@ -257,7 +257,6 @@ export default class Tabs extends Component {
scrollToOverflowEnabled={false}
scrollsToTop={false}
scrollEventThrottle={10}
- directionalLockEnabled
overScrollMode="never"
maxToRenderPerBatch={100}
keyboardDismissMode="none"
diff --git a/apps/mobile/src/components/tip/index.tsx b/apps/mobile/src/components/tip/index.tsx
index f1f5f1b98..01dfd0347 100644
--- a/apps/mobile/src/components/tip/index.tsx
+++ b/apps/mobile/src/components/tip/index.tsx
@@ -140,7 +140,7 @@ export const Tip = ({
Tip.present = async (tip: TTip) => {
if (!tip) return;
- let dontShow = await MMKV.getItem('neverShowSheetTips');
+ let dontShow = MMKV.getString('neverShowSheetTips');
if (dontShow) return;
presentSheet({
component: (
diff --git a/apps/mobile/src/components/walkthroughs/index.tsx b/apps/mobile/src/components/walkthroughs/index.tsx
index b7572c4df..bbae270ba 100644
--- a/apps/mobile/src/components/walkthroughs/index.tsx
+++ b/apps/mobile/src/components/walkthroughs/index.tsx
@@ -117,7 +117,7 @@ Walkthrough.update = async (id: 'notebooks' | 'trialstarted' | 'emailconfirmed'
};
Walkthrough.init = async () => {
- let json = await MMKV.getItem('walkthroughState');
+ let json = MMKV.getString('walkthroughState');
if (json) {
walkthroughState = JSON.parse(json);
console.log(walkthroughState);
diff --git a/apps/mobile/src/navigation/navigationstack.js b/apps/mobile/src/navigation/navigationstack.js
index 2d5b87842..f25e3cf9b 100644
--- a/apps/mobile/src/navigation/navigationstack.js
+++ b/apps/mobile/src/navigation/navigationstack.js
@@ -38,7 +38,7 @@ export const NavigationStack = React.memo(
React.useEffect(() => {
(async () => {
- let settings = await MMKV.getItem('appSettings');
+ let settings = MMKV.getString('appSettings');
if (settings) {
settings = JSON.parse(settings);
homepage.current = settings.homepage;
diff --git a/apps/mobile/src/screens/editor/Functions.js b/apps/mobile/src/screens/editor/Functions.js
index 54f752211..c3c21a126 100644
--- a/apps/mobile/src/screens/editor/Functions.js
+++ b/apps/mobile/src/screens/editor/Functions.js
@@ -917,7 +917,7 @@ export async function onWebViewLoad(premium, colors) {
}
async function restoreEditorState() {
- let appState = await MMKV.getItem('appState');
+ let appState = MMKV.getString('appState');
if (appState) {
appState = JSON.parse(appState);
if (
diff --git a/apps/mobile/src/screens/editor/tiny/toolbar/coloritem.js b/apps/mobile/src/screens/editor/tiny/toolbar/coloritem.js
index 98379b88f..d721d4a43 100644
--- a/apps/mobile/src/screens/editor/tiny/toolbar/coloritem.js
+++ b/apps/mobile/src/screens/editor/tiny/toolbar/coloritem.js
@@ -60,7 +60,7 @@ const ColorItem = ({ value, format, onCustomPress, checked }) => {
await MMKV.removeItem(`d${format}`);
} else {
formatSelection(execCommands[format](value));
- await MMKV.setItem(`d${format}`, value);
+ MMKV.setString(`d${format}`, value);
}
eSendEvent('onColorChange');
};
diff --git a/apps/mobile/src/screens/editor/tiny/toolbar/item.js b/apps/mobile/src/screens/editor/tiny/toolbar/item.js
index 5c6ba9807..8c5dcae44 100644
--- a/apps/mobile/src/screens/editor/tiny/toolbar/item.js
+++ b/apps/mobile/src/screens/editor/tiny/toolbar/item.js
@@ -80,7 +80,7 @@ const ToolbarItem = ({
const onColorChange = async () => {
if (/^(dhilitecolor|dforecolor)$/.test(format)) {
- let _color = await MMKV.getItem(format);
+ let _color = MMKV.getString(format);
let defColor = format === 'dhilitecolor' ? colors.accent + '60' : colors.accent;
setColor(_color || defColor);
}
diff --git a/apps/mobile/src/services/premium.js b/apps/mobile/src/services/premium.js
index 545eb81f9..5a71e732b 100644
--- a/apps/mobile/src/services/premium.js
+++ b/apps/mobile/src/services/premium.js
@@ -188,12 +188,12 @@ const showVerifyEmailDialog = () => {
const subscriptions = {
get: async () => {
- let _subscriptions = await MMKV.getItem('subscriptionsIOS');
+ let _subscriptions = MMKV.getString('subscriptionsIOS');
if (!_subscriptions) return [];
return JSON.parse(_subscriptions);
},
set: async subscription => {
- let _subscriptions = await MMKV.getItem('subscriptionsIOS');
+ let _subscriptions = MMKV.getString('subscriptionsIOS');
if (_subscriptions) {
_subscriptions = JSON.parse(_subscriptions);
} else {
@@ -205,10 +205,10 @@ const subscriptions = {
} else {
_subscriptions[index] = subscription;
}
- await MMKV.setItem('subscriptionsIOS', JSON.stringify(_subscriptions));
+ MMKV.setString('subscriptionsIOS', JSON.stringify(_subscriptions));
},
remove: async transactionId => {
- let _subscriptions = await MMKV.getItem('subscriptionsIOS');
+ let _subscriptions = MMKV.getString('subscriptionsIOS');
if (_subscriptions) {
_subscriptions = JSON.parse(_subscriptions);
} else {
@@ -217,7 +217,7 @@ const subscriptions = {
let index = _subscriptions.findIndex(s => s.transactionId === transactionId);
if (index !== -1) {
_subscriptions.splice(index);
- await MMKV.setItem('subscriptionsIOS', JSON.stringify(_subscriptions));
+ MMKV.setString('subscriptionsIOS', JSON.stringify(_subscriptions));
}
},
verify: async subscription => {
@@ -282,7 +282,7 @@ async function getRemainingTrialDaysStatus() {
let current = Date.now() - user.subscription.start;
current = (current / total) * 100;
console.log(current);
- let lastTrialDialogShownAt = await MMKV.getItem('lastTrialDialogShownAt');
+ let lastTrialDialogShownAt = MMKV.getString('lastTrialDialogShownAt');
if (current > 75 && isTrial && lastTrialDialogShownAt !== 'ending') {
eSendEvent(eOpenTrialEndingDialog, {
diff --git a/apps/mobile/src/services/settings.ts b/apps/mobile/src/services/settings.ts
index f19d29c79..53db27902 100644
--- a/apps/mobile/src/services/settings.ts
+++ b/apps/mobile/src/services/settings.ts
@@ -10,10 +10,10 @@ import Notifications from './notifications';
import Orientation from 'react-native-orientation';
import { DDS } from './device-detection';
-async function migrate(settings: SettingStore['settings']) {
+function migrate(settings: SettingStore['settings']) {
if (settings.migrated) return true;
- let introCompleted = await MMKV.getItem('introCompleted');
+ let introCompleted = MMKV.getString('introCompleted');
if (!introCompleted) {
console.log('no need to migrate');
@@ -26,7 +26,7 @@ async function migrate(settings: SettingStore['settings']) {
MMKV.removeItem('introCompleted');
console.log('migrated introCompleted', introCompleted);
- let askForRating = await MMKV.getItem('askForRating');
+ let askForRating = MMKV.getString('askForRating');
if (askForRating) {
if (askForRating === 'completed' || askForRating === 'never') {
settings.rateApp = false;
@@ -39,7 +39,7 @@ async function migrate(settings: SettingStore['settings']) {
MMKV.removeItem('askForRating');
}
- let askForBackup = await MMKV.getItem('askForBackup');
+ let askForBackup = MMKV.getString('askForBackup');
if (askForBackup) {
askForBackup = JSON.parse(askForBackup);
//@ts-ignore
@@ -48,29 +48,29 @@ async function migrate(settings: SettingStore['settings']) {
console.log('migrated askForBackup', askForBackup);
}
- let lastBackupDate = await MMKV.getItem('backupDate');
+ let lastBackupDate = MMKV.getString('backupDate');
if (lastBackupDate) settings.lastBackupDate = parseInt(lastBackupDate);
MMKV.removeItem('backupDate');
console.log('migrated backupDate', lastBackupDate);
- let isUserEmailConfirmed = await MMKV.getItem('isUserEmailConfirmed');
+ let isUserEmailConfirmed = MMKV.getString('isUserEmailConfirmed');
if (isUserEmailConfirmed === 'yes') settings.userEmailConfirmed = true;
if (isUserEmailConfirmed === 'no') settings.userEmailConfirmed = false;
console.log('migrated useEmailConfirmed', isUserEmailConfirmed);
MMKV.removeItem('isUserEmailConfirmed');
- let userHasSavedRecoveryKey = await MMKV.getItem('userHasSavedRecoveryKey');
+ let userHasSavedRecoveryKey = MMKV.getString('userHasSavedRecoveryKey');
if (userHasSavedRecoveryKey) settings.recoveryKeySaved = true;
MMKV.removeItem('userHasSavedRecoveryKey');
console.log('migrated userHasSavedRecoveryKey', userHasSavedRecoveryKey);
- let accentColor = await MMKV.getItem('accentColor');
+ let accentColor = MMKV.getString('accentColor');
if (accentColor) settings.theme.accent = accentColor;
MMKV.removeItem('accentColor');
console.log('migrated accentColor', accentColor);
- let theme = await MMKV.getItem('theme');
+ let theme = MMKV.getString('theme');
if (theme) {
theme = JSON.parse(theme);
//@ts-ignore
@@ -80,30 +80,32 @@ async function migrate(settings: SettingStore['settings']) {
console.log('migrated theme', theme);
- let backupStorageDir = await MMKV.getItem('backupStorageDir');
+ let backupStorageDir = MMKV.getString('backupStorageDir');
if (backupStorageDir) settings.backupDirectoryAndroid = JSON.parse(backupStorageDir);
MMKV.removeItem('backupStorageDir');
console.log('migrated backupStorageDir', backupStorageDir);
- let dontShowCompleteSheet = await MMKV.getItem('dontShowCompleteSheet');
+ let dontShowCompleteSheet = MMKV.getString('dontShowCompleteSheet');
if (dontShowCompleteSheet) settings.showBackupCompleteSheet = false;
MMKV.removeItem('dontShowCompleteSheet');
console.log('migrated dontShowCompleteSheet', dontShowCompleteSheet);
settings.migrated = true;
-
- await set(settings);
+ set(settings);
console.log('migrated completed');
return true;
}
-async function init() {
+function init() {
scale.fontScale = 1;
- let settingsJson = await MMKV.getItem('appSettings');
+ let now = performance.now();
+ let settingsJson = MMKV.getString('appSettings');
+
+ console.log('fetch data done', performance.now() - now);
let settings = get();
if (!settingsJson) {
- await MMKV.setItem('appSettings', JSON.stringify(settings));
+ MMKV.setString('appSettings', JSON.stringify(settings));
} else {
settings = {
...settings,
@@ -117,15 +119,15 @@ async function init() {
if (settings.fontScale) {
scale.fontScale = settings.fontScale;
}
- setPrivacyScreen(settings);
+ setTimeout(() => setPrivacyScreen(settings));
updateSize();
useSettingStore.getState().setSettings({ ...settings });
- await migrate(settings);
+ migrate(settings);
getColorScheme();
return;
}
-async function setPrivacyScreen(settings: SettingStore['settings']) {
+function setPrivacyScreen(settings: SettingStore['settings']) {
if (settings.privacyScreen || settings.appLockMode === 'background') {
if (Platform.OS === 'android') {
AndroidModule.setSecureMode(true);
@@ -141,7 +143,7 @@ async function setPrivacyScreen(settings: SettingStore['settings']) {
}
}
-async function set(next: Partial<SettingStore['settings']>) {
+function set(next: Partial<SettingStore['settings']>) {
let settings = get();
settings = {
...settings,
@@ -149,10 +151,10 @@ async function set(next: Partial<SettingStore['settings']>) {
};
useSettingStore.getState().setSettings(settings);
- setTimeout(async () => await MMKV.setItem('appSettings', JSON.stringify(settings)), 1);
+ setTimeout(async () => MMKV.setString('appSettings', JSON.stringify(settings)), 1);
}
-async function toggle(id: keyof SettingStore['settings']) {
+function toggle(id: keyof SettingStore['settings']) {
let settings = get();
if (typeof settings[id] !== 'boolean') return;
settings = {
@@ -161,7 +163,7 @@ async function toggle(id: keyof SettingStore['settings']) {
//@ts-ignore
settings[id] = !settings[id];
useSettingStore.getState().setSettings(settings);
- await MMKV.setItem('appSettings', JSON.stringify(settings));
+ MMKV.setString('appSettings', JSON.stringify(settings));
}
function get() {
@@ -171,7 +173,7 @@ function get() {
async function onFirstLaunch() {
let introCompleted = get().introCompleted;
if (!introCompleted) {
- await set({
+ set({
rateApp: Date.now() + 86400000 * 2,
nextBackupRequestTime: Date.now() + 86400000 * 3
});
diff --git a/apps/mobile/src/services/tipmanager.ts b/apps/mobile/src/services/tipmanager.ts
index bfb838802..f49cb464a 100644
--- a/apps/mobile/src/services/tipmanager.ts
+++ b/apps/mobile/src/services/tipmanager.ts
@@ -46,8 +46,8 @@ let tipState: { [name: string]: boolean } = {};
let popState: { [name: string]: boolean } = {};
export class TipManager {
- static async init() {
- let tipStateJson = await MMKV.getItem('tipState');
+ static init() {
+ let tipStateJson = MMKV.getString('tipState');
if (tipStateJson) {
tipState = JSON.parse(tipStateJson);
} else {
@@ -55,7 +55,7 @@ export class TipManager {
tipState = {};
}
- let popStateJson = await MMKV.getItem('popupState');
+ let popStateJson = MMKV.getString('popupState');
if (popStateJson) {
popState = JSON.parse(popStateJson);
} else {
@@ -71,7 +71,7 @@ export class TipManager {
if (tipState[context]) return;
//@ts-ignore
tipState[context] = true;
- MMKV.setItem('tipState', JSON.stringify(tipState));
+ MMKV.setString('tipState', JSON.stringify(tipState));
}
let tipsForCtx = tips.filter(tip => tip.contexts.indexOf(context) > -1);
@@ -91,7 +91,7 @@ export class TipManager {
static markPopupUsed(id: string) {
//@ts-ignore
popState[id] = true;
- MMKV.setItem('popupState', JSON.stringify(popState));
+ MMKV.setString('popupState', JSON.stringify(popState));
}
static placeholderTip() {
diff --git a/apps/mobile/src/utils/analytics/index.js b/apps/mobile/src/utils/analytics/index.js
index 307d2133d..47fe215a4 100644
--- a/apps/mobile/src/utils/analytics/index.js
+++ b/apps/mobile/src/utils/analytics/index.js
@@ -19,7 +19,7 @@ Mozilla/5.0 (Linux; Android 8.0.0; SM-G960F Build/R16NW) AppleWebKit/537.36 (KHT
*/
async function canUpdateAnalytics(route, conditions = []) {
if (!useSettingStore?.getState()?.settings?.telemetry) return false;
- let eventsList = await MMKV.getItem('notesnookUserEvents');
+ let eventsList = MMKV.getString('notesnookUserEvents');
if (eventsList) {
eventsList = JSON.parse(eventsList);
@@ -42,14 +42,14 @@ async function canUpdateAnalytics(route, conditions = []) {
}
async function saveAnalytics(route, value = true) {
- let eventsList = await MMKV.getItem('notesnookUserEvents');
+ let eventsList = MMKV.getString('notesnookUserEvents');
if (eventsList) {
eventsList = JSON.parse(eventsList);
} else {
eventsList = {};
}
eventsList[route] = value;
- await MMKV.setItem('notesnookUserEvents', JSON.stringify(eventsList));
+ MMKV.setString('notesnookUserEvents', JSON.stringify(eventsList));
}
/**
diff --git a/apps/mobile/src/utils/hooks/useAppEvents.js b/apps/mobile/src/utils/hooks/useAppEvents.js
index 548c5051d..4752c2cfc 100644
--- a/apps/mobile/src/utils/hooks/useAppEvents.js
+++ b/apps/mobile/src/utils/hooks/useAppEvents.js
@@ -468,14 +468,14 @@ export const useAppEvents = () => {
movedAway: editing.movedAway,
timestamp: Date.now()
});
- await MMKV.setItem('appState', state);
+ MMKV.setString('appState', state);
}
}
async function checkIntentState() {
try {
- let notesAddedFromIntent = await MMKV.getItem('notesAddedFromIntent');
- let shareExtensionOpened = await MMKV.getItem('shareExtensionOpened');
+ let notesAddedFromIntent = MMKV.getString('notesAddedFromIntent');
+ let shareExtensionOpened = MMKV.getString('shareExtensionOpened');
if (notesAddedFromIntent) {
if (Platform.OS === 'ios') {
await db.init();