Skip to content

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

mobile: fix new note loading from shortcut on cold launch

Ammar Ahmedca19fd923099
diff --git a/apps/mobile/app/app.tsx b/apps/mobile/app/app.tsx
index e549ae93a..bee37dbe5 100644
--- a/apps/mobile/app/app.tsx
+++ b/apps/mobile/app/app.tsx
@@ -46,6 +46,7 @@ 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";
@@ -59,6 +60,10 @@ if (appLockEnabled || appLockMode !== "none") {
}
Shortcuts.getInitialShortcut().then((shortcut) => {
+ if (shortcut?.type === "notesnook.action.newnote") {
+ launchNewNoteTab();
+ }
+
useSettingStore.setState({
pendingShortcut: shortcut ?? null,
pendingShortcutLoaded: true
diff --git a/apps/mobile/app/hooks/use-shortcut-manager.ts b/apps/mobile/app/hooks/use-shortcut-manager.ts
index 224ac9a09..9b990560c 100644
--- a/apps/mobile/app/hooks/use-shortcut-manager.ts
+++ b/apps/mobile/app/hooks/use-shortcut-manager.ts
@@ -21,6 +21,7 @@ import { NativeEventEmitter, NativeModule, Platform } from "react-native";
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";
const ShortcutsEmitter = new NativeEventEmitter(
Shortcuts as unknown as NativeModule
@@ -59,7 +60,24 @@ export function initShortcutListener() {
ShortcutsEmitter.addListener(
"onShortcutItemPressed",
(shortcut: ShortcutItem) => {
+ console.time("shortcut");
useSettingStore.setState({ pendingShortcut: shortcut });
}
);
}
+
+export function launchNewNoteTab() {
+ let tabId;
+ const currentTab = useTabStore
+ .getState()
+ .getTab(useTabStore.getState().currentTab as string);
+
+ if (useTabStore.getState().tabs.length === 0 || currentTab?.pinned) {
+ tabId = useTabStore.getState().newTab();
+ } else {
+ tabId = useTabStore.getState().currentTab;
+ if (useTabStore.getState().getTab(tabId)?.session?.noteId) {
+ useTabStore.getState().newTabSession(tabId, {});
+ }
+ }
+}
diff --git a/apps/mobile/app/navigation/navigation-stack.tsx b/apps/mobile/app/navigation/navigation-stack.tsx
index d590c7ac1..ab1ebf957 100644
--- a/apps/mobile/app/navigation/navigation-stack.tsx
+++ b/apps/mobile/app/navigation/navigation-stack.tsx
@@ -37,7 +37,7 @@ import { eOnLoadNote } from "../utils/events";
import { strings } from "@notesnook/intl";
import PaywallSheet from "../components/sheets/paywall";
import { presentDialog } from "../components/dialog/functions";
-import { useTabStore } from "../screens/editor/tiptap/use-tab-store";
+import { launchNewNoteTab } from "../hooks/use-shortcut-manager";
const RootStack = createNativeStackNavigator();
const AppStack = createNativeStackNavigator();
@@ -358,30 +358,16 @@ export const RootNavigation = () => {
useSettingStore.setState({ pendingShortcut: null });
return;
}
-
rootNavigatorRef.current?.navigate("AddReminder" as any);
useSettingStore.setState({ pendingShortcut: null });
} else if (pendingShortcut.type === "notesnook.action.newnote") {
- let tabId;
-
if (fluidTabsRef.current) {
rootNavigatorRef.current?.navigate("FluidPanelsView" as any);
eSendEvent(eOnLoadNote, { newNote: true });
editorState().movedAway = false;
fluidTabsRef.current.goToPage("editor", true);
} else {
- const currentTab = useTabStore
- .getState()
- .getTab(useTabStore.getState().currentTab as string);
-
- if (useTabStore.getState().tabs.length === 0 || currentTab?.pinned) {
- tabId = useTabStore.getState().newTab();
- } else {
- tabId = useTabStore.getState().currentTab;
- if (useTabStore.getState().getTab(tabId)?.session?.noteId) {
- useTabStore.getState().newTabSession(tabId, {});
- }
- }
+ launchNewNoteTab();
rootNavigatorRef.current?.navigate("FluidPanelsView" as any, {
initialPage: "editor"