This commit is contained in:
ammarahm-ed
2022-02-28 23:56:12 +05:00
parent e1adb1982c
commit 68f105d4b4
12 changed files with 39 additions and 60 deletions

View File

@@ -156,7 +156,7 @@ const Intro = () => {
maxWidth: 500 maxWidth: 500
}} }}
onPress={async () => { onPress={async () => {
await SettingsService.set('telemetry', !isTelemetryEnabled); await SettingsService.set({ telemetry: !isTelemetryEnabled });
}} }}
> >
<Icon <Icon

View File

@@ -128,10 +128,11 @@ export const SectionHeader = ({ item, index, type, color, screen }) => {
color={colors.icon} color={colors.icon}
name={listMode == 'compact' ? 'view-list' : 'view-list-outline'} name={listMode == 'compact' ? 'view-list' : 'view-list-outline'}
onPress={() => { onPress={() => {
SettingsService.set( let settings = {};
type !== 'notebooks' ? 'notesListMode' : 'notebooksListMode', settings[type !== 'notebooks' ? 'notesListMode' : 'notebooksListMode'] =
listMode === 'normal' ? 'compact' : 'normal' listMode === 'normal' ? 'compact' : 'normal';
);
SettingsService.set(settings);
}} }}
size={SIZE.lg - 2} size={SIZE.lg - 2}
/> />

View File

@@ -6,14 +6,12 @@ import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import ToggleSwitch from 'toggle-switch-react-native'; import ToggleSwitch from 'toggle-switch-react-native';
import { PressableButton } from '../../components/ui/pressable'; import { PressableButton } from '../../components/ui/pressable';
import Paragraph from '../../components/ui/typography/paragraph'; import Paragraph from '../../components/ui/typography/paragraph';
import { useThemeStore } from '../../stores/theme';
import { Actions } from '../../stores/Actions';
import { useSettingStore } from '../../stores/stores';
import { DDS } from '../../services/device-detection'; import { DDS } from '../../services/device-detection';
import { ToastEvent } from '../../services/event-manager'; import { ToastEvent } from '../../services/event-manager';
import PremiumService from '../../services/premium'; import PremiumService from '../../services/premium';
import SettingsService from '../../services/settings'; import SettingsService from '../../services/settings';
import { MenuItemsList } from '../../utils/constants'; import { useSettingStore } from '../../stores/stores';
import { useThemeStore } from '../../stores/theme';
import { import {
ACCENT, ACCENT,
COLOR_SCHEME, COLOR_SCHEME,
@@ -23,6 +21,7 @@ import {
setColorScheme setColorScheme
} from '../../utils/color-scheme'; } from '../../utils/color-scheme';
import { hexToRGBA, RGB_Linear_Shade } from '../../utils/color-scheme/utils'; import { hexToRGBA, RGB_Linear_Shade } from '../../utils/color-scheme/utils';
import { MenuItemsList } from '../../utils/constants';
import { MMKV } from '../../utils/database/mmkv'; import { MMKV } from '../../utils/database/mmkv';
import { tabBarRef } from '../../utils/global-refs'; import { tabBarRef } from '../../utils/global-refs';
import { pv, SIZE } from '../../utils/size'; import { pv, SIZE } from '../../utils/size';
@@ -39,21 +38,14 @@ const SettingsAppearanceSection = () => {
useThemeStore.getState().setColors({ ...newColors }); useThemeStore.getState().setColors({ ...newColors });
} }
function changeAccentColor(accentColor) {
ACCENT.color = accentColor;
ACCENT.shade = accentColor + '12';
changeColorScheme();
}
const switchTheme = async () => { const switchTheme = async () => {
if (SettingsService.get().useSystemTheme) { if (SettingsService.get().useSystemTheme) {
await SettingsService.set('useSystemTheme', false); await SettingsService.set({ useSystemTheme: false });
} else { } else {
await PremiumService.verify(async () => { await PremiumService.verify(async () => {
await SettingsService.set( await SettingsService.set({
'useSystemTheme', useSystemTheme: !SettingsService.get().useSystemTheme
SettingsService.get().useSystemTheme ? false : true });
);
if (SettingsService.get().useSystemTheme) { if (SettingsService.get().useSystemTheme) {
await MMKV.setStringAsync( await MMKV.setStringAsync(
'theme', 'theme',
@@ -68,7 +60,7 @@ const SettingsAppearanceSection = () => {
}; };
const pitchBlack = async () => { const pitchBlack = async () => {
await SettingsService.set('pitchBlack', SettingsService.get().pitchBlack ? false : true); await SettingsService.set({ pitchBlack: !SettingsService.get().pitchBlack });
let theme = await MMKV.getStringAsync('theme'); let theme = await MMKV.getStringAsync('theme');
if (!theme) return; if (!theme) return;
theme = JSON.parse(theme); theme = JSON.parse(theme);
@@ -80,13 +72,6 @@ const SettingsAppearanceSection = () => {
} }
}; };
// const reduceAnimations = async () => {
// await SettingsService.set(
// 'reduceAnimations',
// SettingsService.get().reduceAnimations ? false : true
// );
// };
return ( return (
<> <>
<SectionHeader collapsed={collapsed} setCollapsed={setCollapsed} title="Appearance" /> <SectionHeader collapsed={collapsed} setCollapsed={setCollapsed} title="Appearance" />
@@ -238,7 +223,7 @@ const SettingsAppearanceSection = () => {
key={item.name} key={item.name}
onPress={async () => { onPress={async () => {
menuRef.current?.hide(); menuRef.current?.hide();
await SettingsService.set('homepage', item.name); await SettingsService.set({ homepage: item.name });
ToastEvent.show({ ToastEvent.show({
heading: 'Homepage set to ' + item.name, heading: 'Homepage set to ' + item.name,
message: 'Restart the app for changes to take effect.', message: 'Restart the app for changes to take effect.',

View File

@@ -94,7 +94,7 @@ const AppLock = ({ welcome, s = 0 }) => {
key={item.title} key={item.title}
type={settings.appLockMode === item.value ? 'grayBg' : 'transparent'} type={settings.appLockMode === item.value ? 'grayBg' : 'transparent'}
onPress={() => { onPress={() => {
SettingsService.set('appLockMode', item.value); SettingsService.set({ appLockMode: item.value });
}} }}
customStyle={{ customStyle={{
justifyContent: 'flex-start', justifyContent: 'flex-start',

View File

@@ -150,7 +150,7 @@ const SettingsBackupAndRestore = ({ isSheet }) => {
}); });
return; return;
} }
await SettingsService.set('encryptedBackup', !settings.encryptedBackup); await SettingsService.set({ encryptedBackup: !settings.encryptedBackup });
}; };
const updateAskForBackup = async () => { const updateAskForBackup = async () => {
@@ -232,7 +232,7 @@ const SettingsBackupAndRestore = ({ isSheet }) => {
activeOpacity={0.9} activeOpacity={0.9}
onPress={async () => { onPress={async () => {
if (item.value === 'useroff') { if (item.value === 'useroff') {
await SettingsService.set('reminder', item.value); await SettingsService.set({ reminder: item.value });
} else { } else {
await PremiumService.verify(async () => { await PremiumService.verify(async () => {
if (Platform.OS === 'android') { if (Platform.OS === 'android') {
@@ -242,7 +242,7 @@ const SettingsBackupAndRestore = ({ isSheet }) => {
return; return;
} }
} }
await SettingsService.set('reminder', item.value); await SettingsService.set({ reminder: item.value });
}); });
} }
updateAskForBackup(); updateAskForBackup();

View File

@@ -12,7 +12,7 @@ const SettingsDeveloperOptions = ({ isSheet }) => {
const [collapsed, setCollapsed] = useState(isSheet ? false : true); const [collapsed, setCollapsed] = useState(isSheet ? false : true);
const toggleDevMode = () => { const toggleDevMode = () => {
SettingsService.set('devMode', !settings.devMode); SettingsService.set({ devMode: !settings.devMode });
}; };
const devModeList = [ const devModeList = [

View File

@@ -17,7 +17,7 @@ export const SettingsGeneralOptions = ({ isSheet }) => {
} else { } else {
Notifications.pinQuickNote(); Notifications.pinQuickNote();
} }
SettingsService.set('notifNotes', !settings.notifNotes); SettingsService.set({ notifNotes: !settings.notifNotes });
}; };
const generalList = [ const generalList = [

View File

@@ -73,7 +73,7 @@ const SettingsPrivacyAndSecurity = () => {
title="Enable telemetry" title="Enable telemetry"
tagline="Help improve Notesnook by sending completely anonymized private analytics and bug reports." tagline="Help improve Notesnook by sending completely anonymized private analytics and bug reports."
onPress={() => { onPress={() => {
SettingsService.set('telemetry', !settings.telemetry); SettingsService.set({ telemetry: !settings.telemetry });
}} }}
maxWidth="90%" maxWidth="90%"
customComponent={ customComponent={
@@ -84,7 +84,7 @@ const SettingsPrivacyAndSecurity = () => {
size="small" size="small"
animationSpeed={150} animationSpeed={150}
onToggle={isOn => { onToggle={isOn => {
SettingsService.set('telemetry', isOn); SettingsService.set({ telemetry: isOn });
}} }}
/> />
} }
@@ -99,7 +99,7 @@ const SettingsPrivacyAndSecurity = () => {
? AndroidModule.setSecureMode(!settings.privacyScreen) ? AndroidModule.setSecureMode(!settings.privacyScreen)
: enabled(true); : enabled(true);
SettingsService.set('privacyScreen', !settings.privacyScreen); SettingsService.set({ privacyScreen: !settings.privacyScreen });
}} }}
maxWidth="90%" maxWidth="90%"
customComponent={ customComponent={
@@ -111,7 +111,7 @@ const SettingsPrivacyAndSecurity = () => {
animationSpeed={150} animationSpeed={150}
onToggle={isOn => { onToggle={isOn => {
Platform.OS === 'android' ? AndroidModule.setSecureMode(isOn) : enabled(true); Platform.OS === 'android' ? AndroidModule.setSecureMode(isOn) : enabled(true);
SettingsService.set('privacyScreen', isOn); SettingsService.set({ privacyScreen: isOn });
}} }}
/> />
} }

View File

@@ -9,11 +9,11 @@ import {
} from '../utils/events'; } from '../utils/events';
const eventManager = new EventManager(); const eventManager = new EventManager();
export const eSubscribeEvent = (eventName: string, action?: () => void) => { export const eSubscribeEvent = (eventName: string, action?: (data: any) => void) => {
eventManager.subscribe(eventName, action); eventManager.subscribe(eventName, action);
}; };
export const eUnSubscribeEvent = (eventName: string, action?: () => void) => { export const eUnSubscribeEvent = (eventName: string, action?: (data: any) => void) => {
eventManager.unsubscribe(eventName, action); eventManager.unsubscribe(eventName, action);
}; };

View File

@@ -143,7 +143,7 @@ function pinQuickNote(launch: boolean) {
async function unpinQuickNote() { async function unpinQuickNote() {
remove('notesnook_note_input', 256266 + ''); remove('notesnook_note_input', 256266 + '');
SettingsService.set('notifNotes', false); SettingsService.set({ notifNotes: false });
} }
function present({ function present({

View File

@@ -1,4 +1,4 @@
import { Platform, Settings } from 'react-native'; import { Platform } from 'react-native';
import { enabled } from 'react-native-privacy-snapshot'; import { enabled } from 'react-native-privacy-snapshot';
import { SettingStore } from '../stores/interfaces'; import { SettingStore } from '../stores/interfaces';
import { useSettingStore } from '../stores/stores'; import { useSettingStore } from '../stores/stores';
@@ -16,20 +16,10 @@ async function init() {
if (!settingsJson) { if (!settingsJson) {
await MMKV.setItem('appSettings', JSON.stringify(settingsJson)); await MMKV.setItem('appSettings', JSON.stringify(settingsJson));
} else { } else {
settings = JSON.parse(settingsJson); settings = {
if (!settings.appLockMode) { ...settings,
settings.appLockMode = 'none'; ...JSON.parse(settingsJson)
} };
// eslint-disable-next-line no-prototype-builtins
if (!settings.hasOwnProperty('telemetry')) {
settings.telemetry = true;
}
if (!settings.notesListMode) {
settings.notesListMode = 'normal';
}
if (!settings.notebooksListMode) {
settings.notebooksListMode = 'normal';
}
} }
if (settings.notifNotes) { if (settings.notifNotes) {
Notifications.pinQuickNote(true); Notifications.pinQuickNote(true);
@@ -63,9 +53,12 @@ const setTheme = async () => {
useThemeStore.getState().setColors({ ...newColors }); useThemeStore.getState().setColors({ ...newColors });
}; };
async function set(name: keyof SettingStore['settings'], value: any) { async function set(next: Partial<SettingStore['settings']>) {
let settings = get(); let settings = get();
settings[name] = value; settings = {
...settings,
...next
};
useSettingStore.getState().setSettings(settings); useSettingStore.getState().setSettings(settings);
await MMKV.setItem('appSettings', JSON.stringify(settings)); await MMKV.setItem('appSettings', JSON.stringify(settings));
} }

View File

@@ -356,7 +356,7 @@ export const useAppEvents = () => {
user = await db.user.getUser(); user = await db.user.getUser();
if (PremiumService.get() && user) { if (PremiumService.get() && user) {
if (SettingsService.get().reminder === 'off') { if (SettingsService.get().reminder === 'off') {
await SettingsService.set('reminder', 'daily'); await SettingsService.set({ reminder: 'daily' });
} }
if (Backup.checkBackupRequired()) { if (Backup.checkBackupRequired()) {
sleep(2000).then(() => Backup.checkAndRun()); sleep(2000).then(() => Backup.checkAndRun());