2022-08-31 06:33:37 +05:00
|
|
|
/*
|
|
|
|
|
This file is part of the Notesnook project (https://notesnook.com/)
|
|
|
|
|
|
2023-01-16 13:44:52 +05:00
|
|
|
Copyright (C) 2023 Streetwriters (Private) Limited
|
2022-08-31 06:33:37 +05:00
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
2022-08-30 16:13:11 +05:00
|
|
|
|
2023-08-01 12:07:21 +05:00
|
|
|
import { ThemeDark, ThemeLight, useThemeEngineStore } from "@notesnook/theme";
|
2022-08-26 16:19:39 +05:00
|
|
|
import { Appearance } from "react-native";
|
|
|
|
|
import create from "zustand";
|
2023-04-15 23:23:04 +05:00
|
|
|
import { db } from "../app/common/database";
|
2023-08-01 12:07:21 +05:00
|
|
|
import { MMKV } from "../app/common/database/mmkv";
|
2023-04-15 23:23:04 +05:00
|
|
|
export async function initDatabase() {
|
|
|
|
|
if (!db.isInitialized) {
|
2023-04-26 15:15:08 +05:00
|
|
|
await db.init();
|
2023-07-05 12:07:48 +05:00
|
|
|
} else {
|
|
|
|
|
await db.initCollections();
|
2023-04-15 23:23:04 +05:00
|
|
|
}
|
2023-04-26 08:53:27 +05:00
|
|
|
await db.notes.init();
|
2023-04-15 23:23:04 +05:00
|
|
|
}
|
2021-10-11 11:25:22 +05:00
|
|
|
|
2023-04-03 23:52:32 +05:00
|
|
|
const StorageKeys = {
|
|
|
|
|
appendNote: "shareMenuAppendNote",
|
|
|
|
|
selectedNotebooks: "shareMenuSelectedNotebooks",
|
|
|
|
|
selectedTag: "shareMenuSelectedTag",
|
|
|
|
|
appSettings: "appSettings"
|
|
|
|
|
};
|
|
|
|
|
|
2023-08-01 12:07:21 +05:00
|
|
|
let appSettings = MMKV.getString(StorageKeys.appSettings);
|
|
|
|
|
if (appSettings) {
|
|
|
|
|
appSettings = JSON.parse(appSettings);
|
|
|
|
|
}
|
2022-03-03 15:09:30 +05:00
|
|
|
|
2023-08-09 09:30:00 +05:00
|
|
|
const systemColorScheme = Appearance.getColorScheme();
|
2023-08-09 09:33:06 +05:00
|
|
|
const appColorScheme = appSettings?.colorScheme;
|
|
|
|
|
const useSystemTheme = appSettings?.useSystemTheme;
|
2023-08-09 09:30:00 +05:00
|
|
|
const currentColorScheme = useSystemTheme ? systemColorScheme : appColorScheme;
|
|
|
|
|
|
2023-08-09 09:33:06 +05:00
|
|
|
const theme =
|
|
|
|
|
currentColorScheme === "dark"
|
|
|
|
|
? appSettings?.darkTheme
|
|
|
|
|
: appSettings?.lightTheme;
|
2023-08-09 09:30:00 +05:00
|
|
|
|
|
|
|
|
const currentTheme =
|
|
|
|
|
theme || (currentColorScheme === "dark" ? ThemeDark : ThemeLight);
|
|
|
|
|
|
|
|
|
|
useThemeEngineStore.getState().setTheme(currentTheme);
|
2022-03-03 15:09:30 +05:00
|
|
|
|
2023-08-01 12:07:21 +05:00
|
|
|
export const useShareStore = create((set) => ({
|
2023-08-09 09:30:00 +05:00
|
|
|
theme: currentTheme,
|
2021-10-11 11:25:22 +05:00
|
|
|
appendNote: null,
|
2022-08-26 16:19:39 +05:00
|
|
|
setAppendNote: (note) => {
|
2023-04-03 23:52:32 +05:00
|
|
|
MMKV.setItem(StorageKeys.appendNote, JSON.stringify(note));
|
2022-01-25 11:10:22 +05:00
|
|
|
set({ appendNote: note });
|
2021-10-11 11:25:22 +05:00
|
|
|
},
|
2023-04-03 23:52:32 +05:00
|
|
|
restore: () => {
|
|
|
|
|
let appendNote = MMKV.getString(StorageKeys.appendNote);
|
|
|
|
|
let selectedNotebooks = MMKV.getString(StorageKeys.selectedNotebooks);
|
|
|
|
|
let selectedTags = MMKV.getString(StorageKeys.selectedTag);
|
|
|
|
|
appendNote = JSON.parse(appendNote);
|
|
|
|
|
set({
|
|
|
|
|
appendNote: appendNote ? JSON.parse(appendNote) : null,
|
|
|
|
|
selectedNotebooks: selectedNotebooks ? JSON.parse(selectedNotebooks) : [],
|
|
|
|
|
selectedTag: selectedTags ? JSON.parse(selectedTags) : []
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
selectedTags: [],
|
|
|
|
|
selectedNotebooks: [],
|
|
|
|
|
setSelectedNotebooks: (selectedNotebooks) => {
|
|
|
|
|
MMKV.setItem(
|
|
|
|
|
StorageKeys.selectedNotebooks,
|
|
|
|
|
JSON.stringify(selectedNotebooks)
|
|
|
|
|
);
|
|
|
|
|
set({ selectedNotebooks });
|
|
|
|
|
},
|
|
|
|
|
setSelectedTags: (selectedTags) => {
|
|
|
|
|
MMKV.setItem(StorageKeys.selectedTag, JSON.stringify(selectedTags));
|
|
|
|
|
set({ selectedTags });
|
2021-10-11 11:25:22 +05:00
|
|
|
}
|
|
|
|
|
}));
|
2023-09-18 07:06:58 +05:00
|
|
|
|
|
|
|
|
export const Config = {
|
|
|
|
|
corsProxy: appSettings?.corsProxy
|
|
|
|
|
};
|