Skip to content

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

mobile: fix shortcut not working properly on app launch

Ammar Ahmed8694e5d687f2
diff --git a/apps/mobile/app/app.tsx b/apps/mobile/app/app.tsx
index e17993b52..fc0642f5f 100644
--- a/apps/mobile/app/app.tsx
+++ b/apps/mobile/app/app.tsx
@@ -16,6 +16,7 @@ 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/>.
*/
+import { parseInternalLink } from "@notesnook/core";
import {
ScopedThemeProvider,
THEME_COMPATIBILITY_VERSION,
@@ -23,32 +24,31 @@ import {
} from "@notesnook/theme";
import React, { PropsWithChildren, useEffect, useState } from "react";
import { Appearance, I18nManager, Linking, StatusBar } from "react-native";
+import Shortcuts from "react-native-actions-shortcuts";
+import RNBootSplash from "react-native-bootsplash";
import "react-native-gesture-handler";
import { GestureHandlerRootView } from "react-native-gesture-handler";
import { SafeAreaProvider } from "react-native-safe-area-context";
+import AppLocked from "./components/app-lock";
import DialogProvider from "./components/dialog-provider";
import { withErrorBoundry } from "./components/exception-handler";
import GlobalSafeAreaProvider from "./components/globalsafearea";
import { Toast } from "./components/toast";
import { useAppEvents } from "./hooks/use-app-events";
-import { NotePreviewConfigure } from "./screens/note-preview-configure";
+import {
+ initShortcutListener,
+ launchNewNoteTab,
+ registerAppShortcuts
+} from "./hooks/use-shortcut-manager";
import { RootNavigation } from "./navigation/navigation-stack";
+import { NotePreviewConfigure } from "./screens/note-preview-configure";
import { themeTrpcClient } from "./screens/settings/theme-selector";
import Notifications from "./services/notifications";
import SettingsService from "./services/settings";
import { TipManager } from "./services/tip-manager";
+import { useSettingStore } from "./stores/use-setting-store";
import { changeSystemBarColors, useThemeStore } from "./stores/use-theme-store";
import { useUserStore } from "./stores/use-user-store";
-import RNBootSplash from "react-native-bootsplash";
-import AppLocked from "./components/app-lock";
-import { useSettingStore } from "./stores/use-setting-store";
-import {
- initShortcutListener,
- launchNewNoteTab,
- registerAppShortcuts
-} from "./hooks/use-shortcut-manager";
-import Shortcuts from "react-native-actions-shortcuts";
-import { parseInternalLink } from "@notesnook/core";
I18nManager.allowRTL(false);
I18nManager.forceRTL(false);
I18nManager.swapLeftAndRightInRTL(false);
@@ -143,11 +143,11 @@ export const withTheme = (
if (theme) {
theme.colorScheme === "dark"
? useThemeStore.setState({
- darkTheme: theme
- })
+ darkTheme: theme
+ })
: useThemeStore.setState({
- lightTheme: theme
- });
+ lightTheme: theme
+ });
}
})
.catch(() => {
diff --git a/apps/mobile/app/hooks/use-shortcut-manager.ts b/apps/mobile/app/hooks/use-shortcut-manager.ts
index c2b0efea1..3e7c5b2f4 100644
--- a/apps/mobile/app/hooks/use-shortcut-manager.ts
+++ b/apps/mobile/app/hooks/use-shortcut-manager.ts
@@ -16,12 +16,12 @@ 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/>.
*/
-import Shortcuts, { ShortcutItem } from "react-native-actions-shortcuts";
+import { strings } from "@notesnook/intl";
import { NativeEventEmitter, NativeModule, Platform } from "react-native";
+import Shortcuts, { ShortcutItem } from "react-native-actions-shortcuts";
import deviceInfoModule from "react-native-device-info";
-import { strings } from "@notesnook/intl";
-import { useSettingStore } from "../stores/use-setting-store";
import { useTabStore } from "../screens/editor/tiptap/use-tab-store";
+import { useSettingStore } from "../stores/use-setting-store";
const ShortcutsEmitter = new NativeEventEmitter(
Shortcuts as unknown as NativeModule
diff --git a/apps/mobile/app/screens/editor/tiptap/use-tab-store.ts b/apps/mobile/app/screens/editor/tiptap/use-tab-store.ts
index 4c9413933..7ce7981a1 100644
--- a/apps/mobile/app/screens/editor/tiptap/use-tab-store.ts
+++ b/apps/mobile/app/screens/editor/tiptap/use-tab-store.ts
@@ -258,7 +258,7 @@ export const useTabStore = create<TabStore, any>(
const sessionId =
oldSessionId &&
- tabSessionHistory.currentSessionId(tabId) === oldSessionId
+ tabSessionHistory.currentSessionId(tabId) === oldSessionId
? oldSessionId
: tabSessionHistory.add(tabId, oldSessionId);
@@ -389,7 +389,7 @@ export const useTabStore = create<TabStore, any>(
focusPreviewTab: (
noteId: string,
options: Omit<Partial<TabItem>, "id" | "noteId">
- ) => { },
+ ) => {},
removeTab: (id: string) => {
const index = get().tabs.findIndex((t) => t.id === id);
@@ -508,7 +508,19 @@ export const useTabStore = create<TabStore, any>(
}),
{
name: "tabs-storage-v5",
- getStorage: () => MMKV as unknown as StateStorage,
+ getStorage: () =>
+ ({
+ getItem(name: string) {
+ return MMKV.getString(name);
+ },
+ setItem(name: string, value: string) {
+ MMKV.setString(name, value);
+ return;
+ },
+ removeItem(name: string) {
+ MMKV.removeItem(name);
+ }
+ }) as unknown as StateStorage,
onRehydrateStorage: () => {
return (state) => {
history.history = state?.historyNew || [];
diff --git a/apps/mobile/app/screens/settings/editor/state.ts b/apps/mobile/app/screens/settings/editor/state.ts
index 4ddd3b8c6..81902984f 100644
--- a/apps/mobile/app/screens/settings/editor/state.ts
+++ b/apps/mobile/app/screens/settings/editor/state.ts
@@ -129,7 +129,19 @@ export const useDragState = create<DragState, any>(
}),
{
name: "drag-state-storage", // unique name
- getStorage: () => MMKV as unknown as StateStorage,
+ getStorage: () =>
+ ({
+ getItem(name: string) {
+ return MMKV.getString(name);
+ },
+ setItem(name: string, value: string) {
+ MMKV.setString(name, value);
+ return;
+ },
+ removeItem(name: string) {
+ MMKV.removeItem(name);
+ }
+ }) as unknown as StateStorage,
onRehydrateStorage: () => {
return () => {
if (!useSettingStore.getState().isAppLoading) {
diff --git a/apps/mobile/app/stores/create-notebook-tree-stores.ts b/apps/mobile/app/stores/create-notebook-tree-stores.ts
index 3206843d3..e850f67fe 100644
--- a/apps/mobile/app/stores/create-notebook-tree-stores.ts
+++ b/apps/mobile/app/stores/create-notebook-tree-stores.ts
@@ -230,7 +230,19 @@ export function createNotebookTreeStores(
}),
{
name: persistKey || "side-menu-notebook-expanded",
- getStorage: () => MMKV as unknown as StateStorage
+ getStorage: () =>
+ ({
+ getItem(name: string) {
+ return MMKV.getString(name);
+ },
+ setItem(name: string, value: string) {
+ MMKV.setString(name, value);
+ return;
+ },
+ removeItem(name: string) {
+ MMKV.removeItem(name);
+ }
+ }) as unknown as StateStorage
}
)
);