Skip to content

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

refactor

ammarahm-ed136e73ea11c9
diff --git a/apps/mobile/App.js b/apps/mobile/App.js
index 19c367130..c9bc7ceb0 100644
--- a/apps/mobile/App.js
+++ b/apps/mobile/App.js
@@ -3,42 +3,30 @@ import Orientation from 'react-native-orientation';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import Launcher from './src/components/launcher';
import { ApplicationHolder } from './src/navigation';
-import { useThemeStore } from './src/stores/theme';
-import { initialize, useSettingStore, useUserStore } from './src/stores/stores';
import { DDS } from './src/services/device-detection';
import { eSendEvent } from './src/services/event-manager';
import Notifications from './src/services/notifications';
import SettingsService from './src/services/settings';
import { TipManager } from './src/services/tip-manager';
+import { initialize, useSettingStore, useUserStore } from './src/stores/stores';
import { db } from './src/utils/database';
-import { MMKV } from './src/utils/database/mmkv';
import { useAppEvents } from './src/utils/hooks/use-app-events';
let databaseHasLoaded = false;
const loadDatabase = async () => {
- let requireIntro = await MMKV.getItem('introCompleted');
- useSettingStore.getState().setIntroCompleted(requireIntro ? true : false);
await db.init();
Notifications.get();
- await checkFirstLaunch();
+ await configureFirstLaunch();
};
-async function checkFirstLaunch() {
- let requireIntro = useSettingStore.getState().isIntroCompleted;
- if (!requireIntro) {
- await MMKV.setItem(
- 'askForRating',
- JSON.stringify({
- timestamp: Date.now() + 86400000 * 2
- })
- );
- await MMKV.setItem(
- 'askForBackup',
- JSON.stringify({
- timestamp: Date.now() + 86400000 * 3
- })
- );
+async function configureFirstLaunch() {
+ let introCompleted = SettingsService.get().introCompleted;
+ if (!introCompleted) {
+ await SettingsService.set({
+ rateApp: Date.now() + 86400000 * 2,
+ nextBackupRequestTime: Date.now() + 86400000 * 3
+ });
}
}
diff --git a/apps/mobile/share/store.js b/apps/mobile/share/store.js
index 3de7b6525..e370cef6c 100644
--- a/apps/mobile/share/store.js
+++ b/apps/mobile/share/store.js
@@ -7,11 +7,15 @@ export const useShareStore = create((set, get) => ({
colors: Appearance.getColorScheme() === 'dark' ? COLOR_SCHEME_DARK : COLOR_SCHEME_LIGHT,
accent: ACCENT,
setAccent: async () => {
- let accent = await MMKV.getItem('accentColor');
- if (accent) {
- accent = {
- color: accent,
- shade: accent + '12'
+ let appSettings = await MMKV.getItem('appSettings');
+
+ if (appSettings) {
+ appSettings = JSON.parse(appSettings);
+ let accentColor = appSettings.theme?.accent || ACCENT.color;
+
+ let accent = {
+ color: accentColor,
+ shade: accentColor + '12'
};
set({ accent: accent });
}
diff --git a/apps/mobile/src/components/auth/forgotpassword.js b/apps/mobile/src/components/auth/forgotpassword.js
index d2ade888e..2b74a2861 100644
--- a/apps/mobile/src/components/auth/forgotpassword.js
+++ b/apps/mobile/src/components/auth/forgotpassword.js
@@ -13,6 +13,7 @@ import Input from '../ui/input';
import Seperator from '../ui/seperator';
import Heading from '../ui/typography/heading';
import Paragraph from '../ui/typography/paragraph';
+import SettingsService from '../../services/settings';
export const ForgotPassword = () => {
const colors = useThemeStore(state => state.colors);
@@ -33,12 +34,14 @@ export const ForgotPassword = () => {
}
setLoading(true);
try {
- let lastRecoveryEmailTime = await MMKV.getItem('lastRecoveryEmailTime');
+ let lastRecoveryEmailTime = SettingsService.get().lastRecoveryEmailTime;
if (lastRecoveryEmailTime && Date.now() - JSON.parse(lastRecoveryEmailTime) < 60000 * 3) {
throw new Error('Please wait before requesting another email');
}
await db.user.recoverAccount(email.current.toLowerCase());
- await MMKV.setItem('lastRecoveryEmailTime', JSON.stringify(Date.now()));
+ SettingsService.set({
+ lastRecoveryEmailTime: Date.now()
+ });
ToastEvent.show({
heading: `Check your email to reset password`,
message: `Recovery email has been sent to ${email.current.toLowerCase()}`,
diff --git a/apps/mobile/src/components/auth/sessionexpired.js b/apps/mobile/src/components/auth/sessionexpired.js
index 6e8fece4f..b50b90214 100644
--- a/apps/mobile/src/components/auth/sessionexpired.js
+++ b/apps/mobile/src/components/auth/sessionexpired.js
@@ -25,6 +25,7 @@ import Input from '../ui/input';
import { Toast } from '../toast';
import Heading from '../ui/typography/heading';
import Paragraph from '../ui/typography/paragraph';
+import SettingsService from '../../services/settings';
function getEmail(email) {
if (!email) return null;
@@ -54,7 +55,9 @@ export const SessionExpired = () => {
try {
await db.user.logout();
await BiometricService.resetCredentials();
- await Storage.write('introCompleted', 'true');
+ await SettingsService.set({
+ introCompleted: true
+ });
setVisible(false);
} catch (e) {
ToastEvent.show({
diff --git a/apps/mobile/src/components/intro/index.js b/apps/mobile/src/components/intro/index.js
index e913dff1d..fae271b38 100644
--- a/apps/mobile/src/components/intro/index.js
+++ b/apps/mobile/src/components/intro/index.js
@@ -24,9 +24,9 @@ const SVG_Z = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 245.487 113.
const Intro = () => {
const colors = useThemeStore(state => state.colors);
- const isIntroCompleted = useSettingStore(state => state.isIntroCompleted);
- const setIntroCompleted = useSettingStore(state => state.setIntroCompleted);
+
const settings = useSettingStore(state => state.settings);
+ const introCompleted = settings.introCompleted;
const isTelemetryEnabled = settings.telemetry;
const { height } = useWindowDimensions();
@@ -36,7 +36,7 @@ const Intro = () => {
const insets = useSafeAreaInsets();
useEffect(() => {
- if (!isIntroCompleted) {
+ if (!introCompleted) {
umami.pageView('/welcome', '', []);
setTimeout(() => {
timing(opacity, {
@@ -51,14 +51,16 @@ const Intro = () => {
}).start();
}, 15);
}
- }, [isIntroCompleted]);
+ }, [introCompleted]);
const hide = async () => {
- setIntroCompleted(true);
+ SettingsService.set({
+ introCompleted: true
+ });
};
return (
- !isIntroCompleted && (
+ !introCompleted && (
<Animated.View
testID="notesnook.splashscreen"
style={{
@@ -185,7 +187,9 @@ const Intro = () => {
AppLock.present(true);
await sleep(500);
await hide();
- await MMKV.setItem('introCompleted', 'true');
+ SettingsService.set({
+ introCompleted: true
+ });
umami.pageView('/home', '/welcome');
}}
style={{
diff --git a/apps/mobile/src/components/launcher/index.js b/apps/mobile/src/components/launcher/index.js
index ca3b73811..08fe48a43 100644
--- a/apps/mobile/src/components/launcher/index.js
+++ b/apps/mobile/src/components/launcher/index.js
@@ -39,6 +39,7 @@ import Intro from '../intro';
import Heading from '../ui/typography/heading';
import Paragraph from '../ui/typography/paragraph';
import { Update } from '../sheets/update';
+import SettingsService from '../../services/settings';
let passwordValue = null;
let didVerifyUser = false;
@@ -92,7 +93,7 @@ const Launcher = ({ onLoad }) => {
useEffect(() => {
(async () => {
- let introCompleted = await MMKV.getItem('introCompleted');
+ let introCompleted = SettingsService.get().introCompleted;
setRequireIntro({
updated: true,
value: !introCompleted
@@ -158,25 +159,18 @@ const Launcher = ({ onLoad }) => {
};
const checkForRateAppRequest = async () => {
- let askForRating = await MMKV.getItem('askForRating');
- if (askForRating !== 'never' || askForRating !== 'completed') {
- askForRating = JSON.parse(askForRating);
- if (askForRating?.timestamp < Date.now()) {
- if (!useMessageStore.getState().message.visible) {
- setRateAppMessage();
- }
- return true;
- }
+ let rateApp = SettingsService.get().rateApp;
+ if (rateApp && rateApp < Date.now() && useMessageStore.getState().message.visible) {
+ setRateAppMessage();
+ return true;
}
return false;
};
const checkNeedsBackup = async () => {
- let settingsStore = useSettingStore.getState();
- let askForBackup = await MMKV.getItem('askForBackup');
- if (settingsStore.settings.reminder === 'off' || !settingsStore.settings.reminder) {
- askForBackup = JSON.parse(askForBackup);
- if (askForBackup?.timestamp < Date.now()) {
+ let { nextBackupRequestTime, reminder } = SettingsService.get();
+ if (reminder === 'off' || !reminder) {
+ if (nextBackupRequestTime < Date.now()) {
presentSheet({
title: 'Backup & restore',
paragraph: 'Please enable automatic backups to keep your data safe',
diff --git a/apps/mobile/src/components/list/empty.js b/apps/mobile/src/components/list/empty.js
index c5712a920..4793df74a 100644
--- a/apps/mobile/src/components/list/empty.js
+++ b/apps/mobile/src/components/list/empty.js
@@ -17,7 +17,9 @@ export const Empty = React.memo(
const colors = useThemeStore(state => state.colors);
const insets = useSafeAreaInsets();
const { height } = useWindowDimensions();
- const introCompleted = useSettingStore(state => state.isIntroCompleted);
+ const settings = useSettingStore(state => state.settings);
+ const introCompleted = settings.introCompleted;
+
const tip = useTip(
screen === 'Notes' && introCompleted ? 'first-note' : placeholderData.type || type,
screen === 'Notes' ? 'notes' : null
diff --git a/apps/mobile/src/components/sheets/rateapp/index.js b/apps/mobile/src/components/sheets/rateapp/index.js
index b618974f2..c23a190a5 100644
--- a/apps/mobile/src/components/sheets/rateapp/index.js
+++ b/apps/mobile/src/components/sheets/rateapp/index.js
@@ -1,16 +1,16 @@
import React, { useEffect, useRef, useState } from 'react';
-import { Linking, Platform, View } from 'react-native';
+import { Linking, View } from 'react-native';
import { eSubscribeEvent, eUnSubscribeEvent } from '../../../services/event-manager';
+import { clearMessage } from '../../../services/message';
+import SettingsService from '../../../services/settings';
+import { STORE_LINK } from '../../../utils/constants';
import { eCloseRateDialog, eOpenRateDialog } from '../../../utils/events';
-import { MMKV } from '../../../utils/database/mmkv';
import { SIZE } from '../../../utils/size';
-import SheetWrapper from '../../ui/sheet';
import { Button } from '../../ui/button';
import Seperator from '../../ui/seperator';
+import SheetWrapper from '../../ui/sheet';
import Heading from '../../ui/typography/heading';
import Paragraph from '../../ui/typography/paragraph';
-import { STORE_LINK } from '../../../utils/constants';
-import { clearMessage } from '../../../services/message';
const RateAppSheet = () => {
const [visible, setVisible] = useState(false);
@@ -38,21 +38,25 @@ const RateAppSheet = () => {
actionSheetRef.current?.hide();
};
+ const onClose = async () => {
+ SettingsService.set({
+ rateApp: Date.now() + 86400000 * 7
+ });
+ setVisible(false);
+ clearMessage();
+ };
+
+ const rateApp = async () => {
+ await Linking.openURL(STORE_LINK);
+ SettingsService.set({
+ rateApp: false
+ });
+ setVisible(false);
+ clearMessage();
+ };
+
return !visible ? null : (
- <SheetWrapper
- centered={false}
- fwdRef={actionSheetRef}
- onClose={async () => {
- await MMKV.setItem(
- 'askForRating',
- JSON.stringify({
- timestamp: Date.now() + 86400000 * 2
- })
- );
- setVisible(false);
- clearMessage();
- }}
- >
+ <SheetWrapper centered={false} fwdRef={actionSheetRef} onClose={onClose}>
<View
style={{
width: '100%',
@@ -68,12 +72,7 @@ const RateAppSheet = () => {
<Seperator half />
<Button
- onPress={async () => {
- await Linking.openURL(STORE_LINK);
- await MMKV.setItem('askForRating', 'completed');
- setVisible(false);
- clearMessage();
- }}
+ onPress={rateApp}
fontSize={SIZE.md}
width="100%"
height={50}
@@ -92,7 +91,9 @@ const RateAppSheet = () => {
>
<Button
onPress={async () => {
- await MMKV.setItem('askForRating', 'never');
+ SettingsService.set({
+ rateApp: false
+ });
setVisible(false);
clearMessage();
}}
@@ -103,16 +104,7 @@ const RateAppSheet = () => {
title="Never"
/>
<Button
- onPress={async () => {
- await MMKV.setItem(
- 'askForRating',
- JSON.stringify({
- timestamp: Date.now() + 86400000 * 2
- })
- );
- setVisible(false);
- clearMessage();
- }}
+ onPress={onClose}
fontSize={SIZE.md}
width="48%"
height={50}
diff --git a/apps/mobile/src/components/sheets/recoverykey/index.js b/apps/mobile/src/components/sheets/recoverykey/index.js
index f2ef5eab0..cc688e090 100644
--- a/apps/mobile/src/components/sheets/recoverykey/index.js
+++ b/apps/mobile/src/components/sheets/recoverykey/index.js
@@ -20,6 +20,7 @@ import DialogHeader from '../../dialog/dialog-header';
import Seperator from '../../ui/seperator';
import SheetWrapper from '../../ui/sheet';
import Paragraph from '../../ui/typography/paragraph';
+import SettingsService from '../../../services/settings';
let RNFetchBlob;
@@ -69,7 +70,9 @@ class RecoveryKeySheet extends React.Component {
visible: false
});
});
- MMKV.setItem('userHasSavedRecoveryKey', 'true');
+ SettingsService.set({
+ recoveryKeySaved: true
+ });
clearMessage();
// if (this.signup) {
// this.signup = false;
diff --git a/apps/mobile/src/components/sheets/restoredata/index.js b/apps/mobile/src/components/sheets/restoredata/index.js
index 7fe70e775..cd33ac20a 100644
--- a/apps/mobile/src/components/sheets/restoredata/index.js
+++ b/apps/mobile/src/components/sheets/restoredata/index.js
@@ -20,6 +20,7 @@ import { Button } from '../../ui/button';
import Seperator from '../../ui/seperator';
import SheetWrapper from '../../ui/sheet';
import Paragraph from '../../ui/typography/paragraph';
+import SettingsService from '../../../services/settings';
const actionSheetRef = createRef();
let RNFetchBlob;
@@ -163,9 +164,8 @@ const RestoreDataComponent = ({ close, setRestoring, restoring }) => {
try {
let files = [];
if (Platform.OS === 'android') {
- let backupDirectory = await MMKV.getItem('backupStorageDir');
+ let backupDirectory = SettingsService.get().backupDirectoryAndroid;
if (backupDirectory) {
- backupDirectory = JSON.parse(backupDirectory);
setBackupDirectoryAndroid(backupDirectory);
files = await ScopedStorage.listFiles(backupDirectory.uri);
} else {
@@ -369,7 +369,9 @@ const RestoreDataComponent = ({ close, setRestoring, restoring }) => {
subfolder = folder;
}
console.log(subfolder, folder);
- MMKV.setItem('backupStorageDir', JSON.stringify(subfolder));
+ SettingsService.set({
+ backupDirectoryAndroid: subfolder
+ });
setBackupDirectoryAndroid(subfolder);
setLoading(true);
checkBackups();
diff --git a/apps/mobile/src/components/sidemenu/index.js b/apps/mobile/src/components/sidemenu/index.js
index 34a2924dd..a60859d4f 100644
--- a/apps/mobile/src/components/sidemenu/index.js
+++ b/apps/mobile/src/components/sidemenu/index.js
@@ -2,24 +2,14 @@ import React, { useCallback } from 'react';
import { FlatList, View } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { notesnook } from '../../../e2e/test.ids';
-import { useThemeStore } from '../../stores/theme';
-import { Actions } from '../../stores/Actions';
-import { useSettingStore, useUserStore } from '../../stores/stores';
import { DDS } from '../../services/device-detection';
import { eSendEvent } from '../../services/event-manager';
-import SettingsService from '../../services/settings';
-import {
- ACCENT,
- COLOR_SCHEME,
- COLOR_SCHEME_DARK,
- COLOR_SCHEME_LIGHT,
- COLOR_SCHEME_PITCH_BLACK,
- setColorScheme
-} from '../../utils/color-scheme';
-import { eOpenPremiumDialog } from '../../utils/events';
-import { MenuItemsList, SUBSCRIPTION_STATUS } from '../../utils/constants';
-import { MMKV } from '../../utils/database/mmkv';
+import { useSettingStore, useUserStore } from '../../stores/stores';
+import { useThemeStore } from '../../stores/theme';
import umami from '../../utils/analytics';
+import { toggleDarkMode } from '../../utils/color-scheme/utils';
+import { MenuItemsList, SUBSCRIPTION_STATUS } from '../../utils/constants';
+import { eOpenPremiumDialog } from '../../utils/events';
import { ColorSection } from './color-section';
import { MenuItem } from './menu-item';
import { TagsSection } from './pinned-section';
@@ -33,26 +23,11 @@ export const SideMenu = React.memo(
const user = useUserStore(state => state.user);
const noTextMode = false;
- function changeColorScheme(colors = COLOR_SCHEME, accent = ACCENT) {
- let newColors = setColorScheme(colors, accent);
- useThemeStore.getState().setColors({ ...newColors });
- }
-
const BottomItemsList = [
{
name: colors.night ? 'Day' : 'Night',
icon: 'theme-light-dark',
- func: () => {
- if (!COLOR_SCHEME.night) {
- MMKV.setStringAsync('theme', JSON.stringify({ night: true }));
- changeColorScheme(
- SettingsService.get().pitchBlack ? COLOR_SCHEME_PITCH_BLACK : COLOR_SCHEME_DARK
- );
- } else {
- MMKV.setStringAsync('theme', JSON.stringify({ night: false }));
- changeColorScheme(COLOR_SCHEME_LIGHT);
- }
- },
+ func: toggleDarkMode,
switch: true,
on: !!colors.night,
close: false
diff --git a/apps/mobile/src/components/tip/index.tsx b/apps/mobile/src/components/tip/index.tsx
index baafac2db..f1f5f1b98 100644
--- a/apps/mobile/src/components/tip/index.tsx
+++ b/apps/mobile/src/components/tip/index.tsx
@@ -1,15 +1,14 @@
import React from 'react';
import { Image, TextStyle, View, ViewStyle } from 'react-native';
-import { useThemeStore } from '../../stores/theme';
import { eSendEvent, presentSheet } from '../../services/event-manager';
import { TTip } from '../../services/tip-manager';
-import { eCloseProgressDialog } from '../../utils/events';
+import { ThemeStore, useThemeStore } from '../../stores/theme';
import { MMKV } from '../../utils/database/mmkv';
+import { eCloseProgressDialog } from '../../utils/events';
import { SIZE } from '../../utils/size';
import { Button } from '../ui/button';
import Seperator from '../ui/seperator';
import Paragraph from '../ui/typography/paragraph';
-import { defaultState } from '../../stores/DefaultState';
export const Tip = ({
tip,
@@ -24,7 +23,7 @@ export const Tip = ({
textStyle?: TextStyle;
neverShowAgain: boolean;
noImage?: boolean;
- color?: keyof typeof defaultState['colors'];
+ color?: keyof ThemeStore['colors'];
}) => {
const colors = useThemeStore(state => state.colors);
diff --git a/apps/mobile/src/components/ui/pressable/index.tsx b/apps/mobile/src/components/ui/pressable/index.tsx
index eae6f3ae4..d783d1fab 100644
--- a/apps/mobile/src/components/ui/pressable/index.tsx
+++ b/apps/mobile/src/components/ui/pressable/index.tsx
@@ -6,18 +6,17 @@ import {
PressableStateCallbackType,
ViewStyle
} from 'react-native';
-import { useThemeStore } from '../../../stores/theme';
-import { BUTTON_TYPES } from '../../../utils/constants';
+import { ThemeStore, useThemeStore } from '../../../stores/theme';
import { hexToRGBA, RGB_Linear_Shade } from '../../../utils/color-scheme/utils';
+import { BUTTON_TYPES } from '../../../utils/constants';
import { br } from '../../../utils/size';
-import { defaultState } from '../../../stores/DefaultState';
export interface PressableButtonProps extends PressableProps {
customStyle?: ViewStyle;
noborder?: boolean;
type?: keyof typeof BUTTON_TYPES;
- accentColor?: keyof typeof defaultState['colors'];
- accentText?: keyof typeof defaultState['colors'];
+ accentColor?: keyof ThemeStore['colors'];
+ accentText?: keyof ThemeStore['colors'];
customColor?: ColorValue;
customSelectedColor?: ColorValue;
customAlpha?: number;
diff --git a/apps/mobile/src/screens/settings/appearance.js b/apps/mobile/src/screens/settings/appearance.js
index 3557caecb..446e3236e 100644
--- a/apps/mobile/src/screens/settings/appearance.js
+++ b/apps/mobile/src/screens/settings/appearance.js
@@ -12,17 +12,14 @@ import PremiumService from '../../services/premium';
import SettingsService from '../../services/settings';
import { useSettingStore } from '../../stores/stores';
import { useThemeStore } from '../../stores/theme';
+import { ACCENT, COLOR_SCHEME, setColorScheme } from '../../utils/color-scheme';
import {
- ACCENT,
- COLOR_SCHEME,
- COLOR_SCHEME_DARK,
- COLOR_SCHEME_LIGHT,
- COLOR_SCHEME_PITCH_BLACK,
- setColorScheme
-} from '../../utils/color-scheme';
-import { hexToRGBA, RGB_Linear_Shade } from '../../utils/color-scheme/utils';
+ getColorScheme,
+ hexToRGBA,
+ RGB_Linear_Shade,
+ toggleDarkMode
+} from '../../utils/color-scheme/utils';
import { MenuItemsList } from '../../utils/constants';
-import { MMKV } from '../../utils/database/mmkv';
import { tabBarRef } from '../../utils/global-refs';
import { pv, SIZE } from '../../utils/size';
import { CustomButton } from './button';
@@ -33,43 +30,26 @@ const SettingsAppearanceSection = () => {
const settings = useSettingStore(state => state.settings);
const [collapsed, setCollapsed] = useState(true);
const menuRef = useRef();
- function changeColorScheme(colors = COLOR_SCHEME, accent = ACCENT) {
- let newColors = setColorScheme(colors, accent);
- useThemeStore.getState().setColors({ ...newColors });
- }
const switchTheme = async () => {
if (SettingsService.get().useSystemTheme) {
await SettingsService.set({ useSystemTheme: false });
} else {
- await PremiumService.verify(async () => {
- await SettingsService.set({
- useSystemTheme: !SettingsService.get().useSystemTheme
- });
- if (SettingsService.get().useSystemTheme) {
- await MMKV.setStringAsync(
- 'theme',
- JSON.stringify({ night: Appearance.getColorScheme() === 'dark' })
- );
- changeColorScheme(
- Appearance.getColorScheme() === 'dark' ? COLOR_SCHEME_DARK : COLOR_SCHEME_LIGHT
- );
+ if (!PremiumService.get()) return;
+ await SettingsService.set({
+ useSystemTheme: !SettingsService.get().useSystemTheme,
+ theme: {
+ ...SettingsService.get().theme,
+ dark: Appearance.getColorScheme() === 'dark'
}
});
+ getColorScheme();
}
};
const pitchBlack = async () => {
await SettingsService.set({ pitchBlack: !SettingsService.get().pitchBlack });
- let theme = await MMKV.getStringAsync('theme');
- if (!theme) return;
- theme = JSON.parse(theme);
- if (!theme.night) return;
- if (SettingsService.get().pitchBlack) {
- changeColorScheme(COLOR_SCHEME_PITCH_BLACK);
- } else {
- changeColorScheme(COLOR_SCHEME_DARK);
- }
+ getColorScheme();
};
return (
@@ -153,18 +133,7 @@ const SettingsAppearanceSection = () => {
<CustomButton
title="Dark mode"
tagline="Switch on dark mode at night to protect your eyes."
- onPress={async () => {
- if (!colors.night) {
- await MMKV.setStringAsync('theme', JSON.stringify({ night: true }));
- changeColorScheme(
- SettingsService.get().pitchBlack ? COLOR_SCHEME_PITCH_BLACK : COLOR_SCHEME_DARK
- );
- } else {
- await MMKV.setStringAsync('theme', JSON.stringify({ night: false }));
-
- changeColorScheme(COLOR_SCHEME_LIGHT);
- }
- }}
+ onPress={toggleDarkMode}
maxWidth="90%"
customComponent={
<ToggleSwitch
@@ -173,16 +142,7 @@ const SettingsAppearanceSection = () => {
offColor={colors.icon}
size="small"
animationSpeed={150}
- onToggle={async () => {
- if (!colors.night) {
- await MMKV.setStringAsync('theme', JSON.stringify({ night: true }));
- changeColorScheme(COLOR_SCHEME_DARK);
- } else {
- await MMKV.setStringAsync('theme', JSON.stringify({ night: false }));
-
- changeColorScheme(COLOR_SCHEME_LIGHT);
- }
- }}
+ onToggle={toggleDarkMode}
/>
}
/>
@@ -322,7 +282,12 @@ export const AccentColorPicker = ({ settings = true }) => {
onPress={async () => {
await PremiumService.verify(async () => {
changeAccentColor(item);
- await MMKV.setStringAsync('accentColor', item);
+ SettingsService.set({
+ theme: {
+ accent: item,
+ dark: SettingsService.get().theme.dark
+ }
+ });
});
}}
customStyle={{
diff --git a/apps/mobile/src/screens/settings/backuprestore.js b/apps/mobile/src/screens/settings/backuprestore.js
index 69fd9bcc4..cfea70eda 100644
--- a/apps/mobile/src/screens/settings/backuprestore.js
+++ b/apps/mobile/src/screens/settings/backuprestore.js
@@ -23,18 +23,7 @@ const SettingsBackupAndRestore = ({ isSheet }) => {
const settings = useSettingStore(state => state.settings);
const user = useUserStore(state => state.user);
const [collapsed, setCollapsed] = useState(isSheet ? false : true);
- const [backupDir, setBackupDir] = useState(null);
-
- useEffect(() => {
- if (!isSheet) {
- MMKV.getItem('backupStorageDir').then(dir => {
- if (dir) {
- setBackupDir(JSON.parse(dir));
- console.log(dir);
- }
- });
- }
- }, []);
+ const backupDirectoryAndroid = settings.backupDirectoryAndroid;
const optItems = isSheet
? []
@@ -95,16 +84,11 @@ const SettingsBackupAndRestore = ({ isSheet }) => {
if (Platform.OS === 'android' && !isSheet) {
optItems.push({
- name: backupDir ? 'Change backups directory' : 'Select backups directory',
+ name: backupDirectoryAndroid ? 'Change backups directory' : 'Select backups directory',
func: async () => {
let dir;
try {
- dir = await Backup.checkBackupDirExists(true);
- if (!dir) {
- dir = MMKV.getItem('backupStorageDir');
- dir = JSON.parse(dir);
- }
- setBackupDir(dir);
+ let dir = await Backup.checkBackupDirExists(true);
} catch (e) {
} finally {
if (!dir) {
@@ -115,7 +99,7 @@ const SettingsBackupAndRestore = ({ isSheet }) => {
}
}
},
- desc: backupDir ? backupDir.name : 'No backup directory selected'
+ desc: backupDirectoryAndroid ? backupDirectoryAndroid.name : 'No backup directory selected'
});
}
@@ -154,12 +138,9 @@ const SettingsBackupAndRestore = ({ isSheet }) => {
};
const updateAskForBackup = async () => {
- await MMKV.setItem(
- 'askForBackup',
- JSON.stringify({
- timestamp: Date.now() + 86400000 * 3
- })
- );
+ SettingsService.set({
+ nextBackupRequestTime: Date.now() + 86400000 * 3
+ });
};
return (
diff --git a/apps/mobile/src/screens/settings/logout.js b/apps/mobile/src/screens/settings/logout.js
index 7d96984a5..98b9baa8a 100644
--- a/apps/mobile/src/screens/settings/logout.js
+++ b/apps/mobile/src/screens/settings/logout.js
@@ -14,6 +14,7 @@ import { db } from '../../utils/database';
import { SIZE } from '../../utils/size';
import Storage from '../../utils/database/storage';
import { sleep } from '../../utils/time';
+import SettingsService from '../../services/settings';
const AccoutLogoutSection = () => {
const colors = useThemeStore(state => state.colors);
@@ -67,7 +68,9 @@ const AccoutLogoutSection = () => {
await sleep(10);
await db.user.logout();
await BiometricService.resetCredentials();
- await Storage.write('introCompleted', 'true');
+ await SettingsService.set({
+ introCompleted: true
+ });
setLoading(false);
} catch (e) {
setLoading(false);
@@ -121,7 +124,9 @@ const AccoutLogoutSection = () => {
setLoading(true);
await db.user.deleteUser(value);
await BiometricService.resetCredentials();
- await Storage.write('introCompleted', 'true');
+ SettingsService.set({
+ introCompleted: true
+ });
setLoading(false);
} else {
setLoading(false);
diff --git a/apps/mobile/src/services/backup.js b/apps/mobile/src/services/backup.js
index 4d9a8dc34..45828b871 100644
--- a/apps/mobile/src/services/backup.js
+++ b/apps/mobile/src/services/backup.js
@@ -35,13 +35,15 @@ async function getDirectoryAndroid() {
} else {
subfolder = folder;
}
- MMKV.setItem('backupStorageDir', JSON.stringify(subfolder));
+ SettingsService.set({
+ backupDirectoryAndroid: subfolder
+ });
return subfolder;
}
async function checkBackupDirExists(reset = false) {
if (Platform.OS === 'ios') return true;
- let dir = await MMKV.getItem('backupStorageDir');
+ let dir = SettingsService.get().backupDirectoryAndroid;
if (reset) dir = null;
if (dir) {
dir = JSON.parse(dir);
@@ -106,7 +108,9 @@ async function presentBackupCompleteSheet(backupFilePath) {
{
action: async () => {
eSendEvent(eCloseProgressDialog);
- await MMKV.setItem('dontShowCompleteSheet', 'yes');
+ SettingsService.set({
+ showBackupCompleteSheet: false
+ });
},
actionText: 'Never ask again',
type: 'grayBg'
@@ -116,13 +120,10 @@ async function presentBackupCompleteSheet(backupFilePath) {
}
async function updateNextBackupTime() {
- await MMKV.setItem('backupDate', JSON.stringify(Date.now()));
- await MMKV.setItem(
- 'askForBackup',
- JSON.stringify({
- timestamp: Date.now() + 86400000 * 3
- })
- );
+ SettingsService.set({
+ nextBackupRequestTime: Date.now() + 86400000 * 3,
+ lastBackupDate: Date.now()
+ });
}
async function run() {
@@ -176,10 +177,10 @@ async function run() {
context: 'global'
});
- let dontShowCompleteSheet = await MMKV.getItem('dontShowCompleteSheet');
+ let showBackupCompleteSheet = SettingsService.get().showBackupCompleteSheet;
console.log(backupFilePath);
await sleep(300);
- if (!dontShowCompleteSheet) {
+ if (showBackupCompleteSheet) {
presentBackupCompleteSheet(backupFilePath);
} else {
eSendEvent(eCloseProgressDialog);
@@ -193,7 +194,7 @@ async function run() {
}
async function getLastBackupDate() {
- return await MMKV.getItem('backupDate');
+ return SettingsService.get().lastBackupDate;
}
async function checkBackupRequired(type) {
diff --git a/apps/mobile/src/services/biometrics.ts b/apps/mobile/src/services/biometrics.ts
index d3d5b1305..acc467489 100644
--- a/apps/mobile/src/services/biometrics.ts
+++ b/apps/mobile/src/services/biometrics.ts
@@ -6,7 +6,7 @@ import { MMKV } from '../utils/database/mmkv';
import Storage from '../utils/database/storage';
import { ShowToastEvent, ToastEvent } from './event-manager';
-const CRYPT_CONFIG = Platform.select({
+const KeychainConfig = Platform.select({
ios: {
accessible: Keychain.ACCESSIBLE.WHEN_UNLOCKED_THIS_DEVICE_ONLY
},
@@ -33,7 +33,7 @@ async function isFingerprintAuthEnabled() {
}
async function storeCredentials(password: string) {
- await Keychain.setInternetCredentials('nn_vault', 'notesnookvault', password, CRYPT_CONFIG);
+ await Keychain.setInternetCredentials('nn_vault', 'notesnookvault', password, KeychainConfig);
}
async function resetCredentials() {
diff --git a/apps/mobile/src/services/message.js b/apps/mobile/src/services/message.js
index 1f0fc80c0..f16bb011a 100644
--- a/apps/mobile/src/services/message.js
+++ b/apps/mobile/src/services/message.js
@@ -6,6 +6,7 @@ import { verifyUser } from '../screens/settings/functions';
import { MMKV } from '../utils/database/mmkv';
import { Platform } from 'react-native';
import umami from '../utils/analytics';
+import SettingsService from './settings';
const rateAppMessage = {
visible: true,
@@ -35,7 +36,9 @@ const recoveryKeyMessage = {
},
true,
async () => {
- await MMKV.setItem('userHasSavedRecoveryKey', 'true');
+ SettingsService.set({
+ recoveryKeySaved: true
+ });
clearMessage();
},
'I have saved my key already'
diff --git a/apps/mobile/src/services/premium.js b/apps/mobile/src/services/premium.js
index 9fcb0b68f..fe5c2b6f7 100644
--- a/apps/mobile/src/services/premium.js
+++ b/apps/mobile/src/services/premium.js
@@ -12,6 +12,7 @@ import { db } from '../utils/database';
import { eOpenPremiumDialog, eOpenTrialEndingDialog, eShowGetPremium } from '../utils/events';
import { MMKV } from '../utils/database/mmkv';
import { eSendEvent, presentSheet, ToastEvent } from './event-manager';
+import SettingsService from './settings';
let premiumStatus = 0;
let products = [];
@@ -143,8 +144,8 @@ const showVerifyEmailDialog = () => {
'We have sent you an email confirmation link. Please check your email inbox. If you cannot find the email, check your spam folder.',
action: async () => {
try {
- let lastEmailTime = await MMKV.getItem('lastEmailTime');
- if (lastEmailTime && Date.now() - JSON.parse(lastEmailTime) < 60000 * 2) {
+ let lastVerificationEmailTime = SettingsService.get().lastVerificationEmailTime;
+ if (lastVerificationEmailTime && Date.now() - lastVerificationEmailTime < 60000 * 2) {
ToastEvent.show({
heading: 'Please wait before requesting another email',
type: 'error',
@@ -154,7 +155,9 @@ const showVerifyEmailDialog = () => {
return;
}
await db.user.sendVerificationEmail();
- await MMKV.setItem('lastEmailTime', JSON.stringify(Date.now()));
+ SettingsService.set({
+ lastVerificationEmailTime: Date.now()
+ });
ToastEvent.show({
heading: 'Verification email sent!',
diff --git a/apps/mobile/src/services/settings.ts b/apps/mobile/src/services/settings.ts
index 5b945f62f..eb1bb25b7 100644
--- a/apps/mobile/src/services/settings.ts
+++ b/apps/mobile/src/services/settings.ts
@@ -2,13 +2,82 @@ import { Platform } from 'react-native';
import { enabled } from 'react-native-privacy-snapshot';
import { SettingStore } from '../stores/interfaces';
import { useSettingStore } from '../stores/stores';
-import { useThemeStore } from '../stores/theme';
import { AndroidModule } from '../utils';
import { getColorScheme } from '../utils/color-scheme/utils';
import { MMKV } from '../utils/database/mmkv';
import { scale, updateSize } from '../utils/size';
import Notifications from './notifications';
+async function migrate(settings: SettingStore['settings']) {
+ if (settings.migrated) return true;
+
+ let askForRating = await MMKV.getItem('askForRating');
+ if (askForRating) {
+ if (askForRating === 'completed' || askForRating === 'never') {
+ settings.rateApp = false;
+ } else {
+ askForRating = JSON.parse(askForRating);
+ //@ts-ignore
+ settings.rateApp = askForRating.timestamp;
+ }
+ MMKV.removeItem('askForRating');
+ }
+
+ let askForBackup = await MMKV.getItem('askForBackup');
+ if (askForBackup) {
+ askForBackup = JSON.parse(askForBackup);
+ //@ts-ignore
+ settings.rateApp = askForBackup.timestamp;
+ MMKV.removeItem('askForBackup');
+ }
+
+ let introCompleted = await MMKV.getItem('introCompleted');
+ if (introCompleted) {
+ settings.introCompleted = true;
+ MMKV.removeItem('introCompleted');
+ }
+
+ let lastBackupDate = await MMKV.getItem('backupDate');
+ if (lastBackupDate) settings.lastBackupDate = parseInt(lastBackupDate);
+ MMKV.removeItem('backupDate');
+
+ let isUserEmailConfirmed = await MMKV.getItem('isUserEmailConfirmed');
+ if (isUserEmailConfirmed === 'yes') settings.userEmailConfirmed = true;
+ if (isUserEmailConfirmed === 'no') settings.userEmailConfirmed = false;
+
+ MMKV.removeItem('isUserEmailConfirmed');
+
+ let userHasSavedRecoveryKey = await MMKV.getItem('userHasSavedRecoveryKey');
+ if (userHasSavedRecoveryKey) settings.recoveryKeySaved = true;
+ MMKV.removeItem('userHasSavedRecoveryKey');
+
+ let accentColor = await MMKV.getItem('accentColor');
+ if (accentColor) settings.theme.accent = accentColor;
+ MMKV.removeItem('accentColor');
+
+ let theme = await MMKV.getItem('theme');
+ if (theme) {
+ theme = JSON.parse(theme);
+ //@ts-ignore
+ if (theme.night) settings.theme.dark = true;
+ MMKV.removeItem('theme');
+ }
+
+ let backupStorageDir = await MMKV.getItem('backupStorageDir');
+ if (backupStorageDir) settings.backupDirectoryAndroid = JSON.parse(backupStorageDir);
+ MMKV.removeItem('backupStorageDir');
+
+ let dontShowCompleteSheet = await MMKV.getItem('dontShowCompleteSheet');
+ if (dontShowCompleteSheet) settings.showBackupCompleteSheet = false;
+ MMKV.removeItem('dontShowCompleteSheet');
+
+ settings.migrated = true;
+
+ await set(settings);
+
+ return true;
+}
+
async function init() {
scale.fontScale = 1;
let settingsJson = await MMKV.getItem('appSettings');
@@ -43,16 +112,11 @@ async function init() {
}
updateSize();
useSettingStore.getState().setSettings({ ...settings });
- setTheme();
+ await migrate(settings);
+ getColorScheme();
return;
}
-const setTheme = async () => {
- let settings = get();
- let newColors = await getColorScheme(settings.useSystemTheme);
- useThemeStore.getState().setColors({ ...newColors });
-};
-
async function set(next: Partial<SettingStore['settings']>) {
let settings = get();
settings = {
@@ -63,15 +127,27 @@ async function set(next: Partial<SettingStore['settings']>) {
await MMKV.setItem('appSettings', JSON.stringify(settings));
}
+async function toggle(id: keyof SettingStore['settings']) {
+ let settings = get();
+ if (typeof settings[id] !== 'boolean') return;
+ settings = {
+ ...settings
+ };
+ //@ts-ignore
+ settings[id] = !settings[id];
+ useSettingStore.getState().setSettings(settings);
+ await MMKV.setItem('appSettings', JSON.stringify(settings));
+}
+
function get() {
return { ...useSettingStore.getState().settings };
}
const SettingsService = {
init,
- setTheme,
set,
- get
+ get,
+ toggle
};
export default SettingsService;
diff --git a/apps/mobile/src/stores/interfaces.ts b/apps/mobile/src/stores/interfaces.ts
index e8550358c..01f8b52ba 100644
--- a/apps/mobile/src/stores/interfaces.ts
+++ b/apps/mobile/src/stores/interfaces.ts
@@ -1,3 +1,4 @@
+import { FileType } from 'react-native-scoped-storage';
import { State } from 'zustand';
export type Item = {
@@ -70,6 +71,21 @@ export type Settings = {
notifNotes?: boolean;
pitchBlack?: boolean;
reduceAnimations?: boolean;
+ rateApp?: boolean | number;
+ migrated?: boolean;
+ introCompleted?: boolean;
+ nextBackupRequestTime?: number | undefined;
+ lastBackupDate?: number | undefined;
+ userEmailConfirmed?: boolean;
+ recoveryKeySaved?: boolean;
+ theme: {
+ accent: string;
+ dark: false;
+ };
+ backupDirectoryAndroid?: FileType | null;
+ showBackupCompleteSheet: boolean;
+ lastRecoveryEmailTime?: number;
+ lastVerificationEmailTime?: number;
};
type Dimensions = {
@@ -88,8 +104,6 @@ export interface SettingStore extends State {
setDimensions: (dimensions: Dimensions) => void;
appLoading: boolean;
setAppLoading: (appLoading: boolean) => void;
- isIntroCompleted: boolean;
- setIntroCompleted: (isIntroCompleted: boolean) => void;
setSheetKeyboardHandler: (sheetKeyboardHandler: boolean) => void;
sheetKeyboardHandler: boolean;
requestBiometrics: boolean;
diff --git a/apps/mobile/src/stores/stores.ts b/apps/mobile/src/stores/stores.ts
index 6f89c2605..628baee34 100644
--- a/apps/mobile/src/stores/stores.ts
+++ b/apps/mobile/src/stores/stores.ts
@@ -28,6 +28,7 @@ import {
TrashStore,
UserStore
} from './interfaces';
+import { ACCENT } from '../utils/color-scheme';
export const useNoteStore = create<NoteStore>((set, get) => ({
notes: [],
@@ -242,20 +243,30 @@ export const useSettingStore = create<SettingStore>((set, get) => ({
devMode: false,
notifNotes: false,
pitchBlack: false,
- reduceAnimations: false
+ reduceAnimations: false,
+ rateApp: false,
+ migrated: false,
+ introCompleted: false,
+ nextBackupRequestTime: undefined,
+ lastBackupDate: undefined,
+ userEmailConfirmed: false,
+ recoveryKeySaved: false,
+ theme: {
+ accent: ACCENT.color,
+ dark: false
+ },
+ showBackupCompleteSheet: true
},
sheetKeyboardHandler: true,
fullscreen: false,
deviceMode: 'mobile',
dimensions: { width, height },
appLoading: true,
- isIntroCompleted: false,
setSettings: settings => set({ settings }),
setFullscreen: fullscreen => set({ fullscreen }),
setDeviceMode: mode => set({ deviceMode: mode }),
setDimensions: dimensions => set({ dimensions: dimensions }),
setAppLoading: appLoading => set({ appLoading }),
- setIntroCompleted: isIntroCompleted => set({ isIntroCompleted }),
setSheetKeyboardHandler: sheetKeyboardHandler => set({ sheetKeyboardHandler }),
requestBiometrics: false,
setRequestBiometrics: requestBiometrics => set({ requestBiometrics })
diff --git a/apps/mobile/src/utils/colorscheme/index.js b/apps/mobile/src/utils/colorscheme/index.js
index 28e34bb43..f410f2f07 100644
--- a/apps/mobile/src/utils/colorscheme/index.js
+++ b/apps/mobile/src/utils/colorscheme/index.js
@@ -1,6 +1,7 @@
import { Platform, StatusBar } from 'react-native';
import { AndroidModule } from '..';
import { eSendEvent } from '../../services/event-manager';
+import { useThemeStore } from '../../stores/theme';
import { eThemeUpdated } from '../events';
export const ACCENT = {
@@ -110,6 +111,8 @@ export function getCurrentColors() {
export function setColorScheme(colors = COLOR_SCHEME, accent = ACCENT) {
COLOR_SCHEME = { ...colors, accent: accent.color, shade: accent.shade };
+ useThemeStore.getState().setColors({ ...COLOR_SCHEME });
+
StatusBar.setBarStyle(COLOR_SCHEME.night ? 'light-content' : 'dark-content', true);
if (Platform.OS === 'android') {
AndroidModule.setBackgroundColor(COLOR_SCHEME.bg);
diff --git a/apps/mobile/src/utils/colorscheme/utils.js b/apps/mobile/src/utils/colorscheme/utils.js
index 9e74db46b..f18c8f03d 100644
--- a/apps/mobile/src/utils/colorscheme/utils.js
+++ b/apps/mobile/src/utils/colorscheme/utils.js
@@ -1,8 +1,5 @@
import { Appearance } from 'react-native';
-import { eSendEvent, eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';
-import SettingsService from '../../services/settings';
import {
- ACCENT,
COLOR_SCHEME,
COLOR_SCHEME_DARK,
COLOR_SCHEME_LIGHT,
@@ -10,8 +7,7 @@ import {
setAccentColor,
setColorScheme
} from '.';
-import { eThemeUpdated } from '../events';
-import { MMKV } from '../database/mmkv';
+import SettingsService from '../../services/settings';
const isValidHex = hex => /^#([A-Fa-f0-9]{3,4}){1,2}$/.test(hex);
const getChunksFromString = (st, chunkSize) => st.match(new RegExp(`.{${chunkSize}}`, 'g'));
@@ -69,23 +65,9 @@ export const RGB_Linear_Shade = (p, rgba) => {
);
};
-export async function getColorScheme(useSystemTheme) {
- let accentColor = await MMKV.getItem('accentColor');
- let theme = await MMKV.getItem('theme');
- let isPitchBlack = SettingsService.get().pitchBlack;
- const darkTheme = isPitchBlack ? COLOR_SCHEME_PITCH_BLACK : COLOR_SCHEME_DARK;
-
- if (!accentColor) {
- await MMKV.setItem('accentColor', ACCENT.color);
- accentColor = ACCENT.color;
- }
-
- if (!theme) {
- await MMKV.setItem('theme', JSON.stringify({ night: false }));
- theme = COLOR_SCHEME_LIGHT;
- } else {
- theme = JSON.parse(theme);
- }
+export function getColorScheme() {
+ let { pitchBlack, theme, useSystemTheme } = SettingsService.get();
+ const darkTheme = pitchBlack ? COLOR_SCHEME_PITCH_BLACK : COLOR_SCHEME_DARK;
if (useSystemTheme) {
Appearance.getColorScheme() === 'dark'
@@ -95,16 +77,17 @@ export async function getColorScheme(useSystemTheme) {
return COLOR_SCHEME;
}
- setColorScheme(theme.night ? darkTheme : COLOR_SCHEME_LIGHT);
- setAccentColor(accentColor);
-
- eSendEvent(eThemeUpdated);
+ setColorScheme(theme.dark ? darkTheme : COLOR_SCHEME_LIGHT);
+ setAccentColor(theme.accent);
return COLOR_SCHEME;
}
-export const onThemeUpdate = (func = () => {}) => {
- return eSubscribeEvent(eThemeUpdated, func);
-};
-export const clearThemeUpdateListener = (func = () => {}) => {
- return eUnSubscribeEvent(eThemeUpdated, func);
+export const toggleDarkMode = async () => {
+ await SettingsService.set({
+ theme: {
+ ...SettingsService.get().theme,
+ dark: !SettingsService.get().dark
+ }
+ });
+ getColorScheme();
};
diff --git a/apps/mobile/src/utils/hooks/useActions.js b/apps/mobile/src/utils/hooks/useActions.js
index c4bc2fe6d..2531e64f9 100644
--- a/apps/mobile/src/utils/hooks/useActions.js
+++ b/apps/mobile/src/utils/hooks/useActions.js
@@ -2,16 +2,13 @@ import Clipboard from '@react-native-clipboard/clipboard';
import React, { useEffect, useState } from 'react';
import { Platform } from 'react-native';
import Share from 'react-native-share';
+import { editing, toTXT } from '..';
import { notesnook } from '../../../e2e/test.ids';
-import { useThemeStore } from '../../stores/theme';
-import { Actions } from '../../stores/Actions';
-import {
- useEditorStore,
- useMenuStore,
- useSelectionStore,
- useTagStore,
- useUserStore
-} from '../../stores/stores';
+import { presentDialog } from '../../components/dialog/functions';
+import NoteHistory from '../../components/note-history';
+import { MoveNotes } from '../../components/sheets/move-notes/movenote';
+import { EditorWebView } from '../../screens/editor/Functions';
+import tiny from '../../screens/editor/tiny/tiny.js';
import {
eSendEvent,
eSubscribeEvent,
@@ -22,16 +19,15 @@ import {
} from '../../services/event-manager';
import Navigation from '../../services/navigation';
import Notifications from '../../services/notifications';
-import SettingsService from '../../services/settings';
-import { editing, toTXT } from '..';
import {
- ACCENT,
- COLOR_SCHEME,
- COLOR_SCHEME_DARK,
- COLOR_SCHEME_LIGHT,
- COLOR_SCHEME_PITCH_BLACK,
- setColorScheme
-} from '../color-scheme';
+ useEditorStore,
+ useMenuStore,
+ useSelectionStore,
+ useTagStore,
+ useUserStore
+} from '../../stores/stores';
+import { useThemeStore } from '../../stores/theme';
+import { toggleDarkMode } from '../color-scheme/utils';
import { db } from '../database';
import {
eOpenAddNotebookDialog,
@@ -43,13 +39,7 @@ import {
eOpenPublishNoteDialog
} from '../events';
import { deleteItems } from '../functions';
-import { MMKV } from '../database/mmkv';
import { sleep } from '../time';
-import { presentDialog } from '../../components/dialog/functions';
-import { MoveNotes } from '../../components/sheets/move-notes/movenote';
-import NoteHistory from '../../components/note-history';
-import tiny from '../../screens/editor/tiny/tiny.js';
-import { EditorWebView } from '../../screens/editor/Functions';
export const useActions = ({ close = () => {}, item }) => {
const colors = useThemeStore(state => state.colors);
@@ -115,22 +105,8 @@ export const useActions = ({ close = () => {}, item }) => {
};
}, [item]);
- function changeColorScheme(colors = COLOR_SCHEME, accent = ACCENT) {
- let newColors = setColorScheme(colors, accent);
- useThemeStore.getState().setColors({ ...newColors });
- }
-
function switchTheme() {
- if (!colors.night) {
- MMKV.setStringAsync('theme', JSON.stringify({ night: true }));
- let nextTheme = SettingsService.get().pitchBlack
- ? COLOR_SCHEME_PITCH_BLACK
- : COLOR_SCHEME_DARK;
- changeColorScheme(nextTheme);
- return;
- }
- MMKV.setStringAsync('theme', JSON.stringify({ night: false }));
- changeColorScheme(COLOR_SCHEME_LIGHT);
+ toggleDarkMode();
}
function addTo() {
diff --git a/apps/mobile/src/utils/hooks/useAppEvents.js b/apps/mobile/src/utils/hooks/useAppEvents.js
index f7b421d55..3216b1441 100644
--- a/apps/mobile/src/utils/hooks/useAppEvents.js
+++ b/apps/mobile/src/utils/hooks/useAppEvents.js
@@ -198,7 +198,9 @@ export const useAppEvents = () => {
let user = await db.user.getUser();
setUser(user);
if (!user) return;
- MMKV.setItem('isUserEmailConfirmed', 'yes');
+ SettingsService.set({
+ userEmailConfirmed: true
+ });
await PremiumService.setPremiumStatus();
Walkthrough.present('emailconfirmed', false, true);
if (user?.isEmailConfirmed) {
@@ -263,7 +265,9 @@ export const useAppEvents = () => {
setSyncing(false);
setLoginMessage();
await PremiumService.setPremiumStatus();
- await MMKV.setItem('introCompleted', 'true');
+ SettingsService.set({
+ introCompleted: true
+ });
presentSheet({
title: reason ? reason : 'User logged out',
paragraph: `You have been logged out of your account.`,
@@ -315,33 +319,26 @@ export const useAppEvents = () => {
}, 1000);
}
- if (user.isEmailConfirmed) {
- let hasSavedRecoveryKey = await MMKV.getItem('userHasSavedRecoveryKey');
- if (!hasSavedRecoveryKey) {
- setRecoveryKeyMessage();
- }
+ if (user.isEmailConfirmed && !SettingsService.get().recoveryKeySaved) {
+ setRecoveryKeyMessage();
}
await Sync.run();
+ setUser(user);
+ SettingsService.set({
+ userEmailConfirmed: user.isEmailConfirmed
+ });
+
if (!user.isEmailConfirmed) {
setEmailVerifyMessage();
- MMKV.setItem('isUserEmailConfirmed', 'no');
- return;
- } else {
- MMKV.setItem('isUserEmailConfirmed', 'yes');
}
-
- setUser(user);
} else {
setLoginMessage();
}
} catch (e) {
user = await db.user.getUser();
- if (user?.isEmailConfirmed) {
- let hasSavedRecoveryKey = await MMKV.getItem('userHasSavedRecoveryKey');
- if (!hasSavedRecoveryKey) {
- setRecoveryKeyMessage();
- }
+ if (user?.isEmailConfirmed && !SettingsService.get().recoveryKeySaved) {
+ setRecoveryKeyMessage();
}
if (user && !user.isEmailConfirmed) {