A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
mobile: add support for internal links
Ammar Ahmed590902597652
diff --git a/apps/mobile/android/app/src/main/AndroidManifest.xml b/apps/mobile/android/app/src/main/AndroidManifest.xmlindex 58f3080cd..2635ab38c 100644--- a/apps/mobile/android/app/src/main/AndroidManifest.xml+++ b/apps/mobile/android/app/src/main/AndroidManifest.xml@@ -155,6 +155,15 @@<data android:scheme="notesnook" /></intent-filter>+ <intent-filter android:label="Notesnook">+ <action android:name="android.intent.action.VIEW" />++ <category android:name="android.intent.category.DEFAULT" />+ <category android:name="android.intent.category.BROWSABLE" />++ <data android:scheme="nn" />+ </intent-filter>+</activity><activityandroid:name="com.facebook.react.devsupport.DevSettingsActivity"diff --git a/apps/mobile/android/app/src/main/java/com/streetwriters/notesnook/NotePreviewWidget.java b/apps/mobile/android/app/src/main/java/com/streetwriters/notesnook/NotePreviewWidget.javaindex 341711fc3..831eaaa87 100644--- a/apps/mobile/android/app/src/main/java/com/streetwriters/notesnook/NotePreviewWidget.java+++ b/apps/mobile/android/app/src/main/java/com/streetwriters/notesnook/NotePreviewWidget.java@@ -33,7 +33,7 @@ public class NotePreviewWidget extends AppWidgetProvider {intent.putExtra(OpenNoteId, note.getId());intent.setAction(Intent.ACTION_VIEW);intent.putExtra(RCTNNativeModule.IntentType, "OpenNote");- intent.setData(Uri.parse("https://app.notesnook.com/open_note?id=" + note.getId()));+ intent.setData(Uri.parse("nn://note/" + note.getId()));PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE, getActivityOptionsBundle());views.setOnClickPendingIntent(R.id.open_note, pendingIntent);diff --git a/apps/mobile/android/app/src/main/java/com/streetwriters/notesnook/RCTNNativeModule.java b/apps/mobile/android/app/src/main/java/com/streetwriters/notesnook/RCTNNativeModule.javaindex 178fe31ab..f2b93f9bf 100644--- a/apps/mobile/android/app/src/main/java/com/streetwriters/notesnook/RCTNNativeModule.java+++ b/apps/mobile/android/app/src/main/java/com/streetwriters/notesnook/RCTNNativeModule.java@@ -259,7 +259,7 @@ public class RCTNNativeModule extends ReactContextBaseJavaModule {return;}- String uri = "https://app.notesnook.com/open_" + type + "?id=" + id;+ String uri = "nn://" + type + "/" + id;Intent intent = new Intent(Intent.ACTION_VIEW, android.net.Uri.parse(uri));intent.setPackage(mContext.getPackageName());diff --git a/apps/mobile/app/components/properties/items.tsx b/apps/mobile/app/components/properties/items.tsxindex ebbadcc44..ba81b6c2d 100644--- a/apps/mobile/app/components/properties/items.tsx+++ b/apps/mobile/app/components/properties/items.tsx@@ -79,6 +79,7 @@ const COLUMN_BAR_ITEMS: ActionId[] = ["rename-color","rename-tag","launcher-shortcut",+ "copy-link","restore","trash","delete"diff --git a/apps/mobile/app/hooks/use-actions.tsx b/apps/mobile/app/hooks/use-actions.tsxindex f2aec438a..b2148e5bc 100644--- a/apps/mobile/app/hooks/use-actions.tsx+++ b/apps/mobile/app/hooks/use-actions.tsx@@ -1002,20 +1002,6 @@ export const useActions = ({icon: "history",onPress: openHistory},- {- id: "copy-link",- title: strings.copyLink(),- icon: "link",- onPress: () => {- Clipboard.setString(createInternalLink("note", item.id));- ToastManager.show({- heading: strings.linkCopied(),- message: createInternalLink("note", item.id),- context: "local",- type: "success"- });- }- },{id: "reminders",title: strings.dataTypesPluralCamelCase.reminder(),@@ -1271,5 +1257,28 @@ export const useActions = ({});}+ if (+ item.type === "tag" ||+ item.type === "note" ||+ item.type === "notebook" ||+ item.type === "color"+ ) {+ actions.push({+ id: "copy-link",+ title: strings.copyLink(),+ icon: "link",+ onPress: () => {+ const link = createInternalLink(item.type, item.id);+ Clipboard.setString(link);+ ToastManager.show({+ heading: strings.linkCopied(),+ message: link,+ context: "local",+ type: "success"+ });+ }+ });+ }+return actions;};diff --git a/apps/mobile/app/hooks/use-app-events.tsx b/apps/mobile/app/hooks/use-app-events.tsxindex e2f0fb115..b9a6d7a86 100644--- a/apps/mobile/app/hooks/use-app-events.tsx+++ b/apps/mobile/app/hooks/use-app-events.tsx@@ -25,7 +25,9 @@ import {SYNC_CHECK_IDS,SubscriptionPlan,SyncStatusEvent,- User+ User,+ isInternalLink,+ parseInternalLink} from "@notesnook/core";import { strings } from "@notesnook/intl";import notifee from "@notifee/react-native";@@ -169,6 +171,8 @@ const onAppOpenedFromURL = async (event: {}) => {const url = event.url;+ const parsedLink = isInternalLink(url) ? parseInternalLink(url) : undefined;+try {if (url.startsWith("https://app.notesnook.com/account/verified")) {await onUserEmailVerified();@@ -178,8 +182,12 @@ const onAppOpenedFromURL = async (event: {eSendEvent(eOnLoadNote, { newNote: true });fluidTabsRef.current?.goToPage("editor", false);return;- } else if (url.startsWith("https://app.notesnook.com/open_note?")) {- const id = new URL(url).searchParams.get("id");+ } else if (+ parsedLink?.type === "note" ||+ url.startsWith("https://app.notesnook.com/open_note?")+ ) {+ const id = parsedLink?.id || new URL(url).searchParams.get("id");+if (id) {const note = await db.notes.note(id);if (note) {@@ -191,10 +199,11 @@ const onAppOpenedFromURL = async (event: {}}} else if (- url.startsWith("https://app.notesnook.com/open_notebook?") &&+ (parsedLink?.type === "notebook" ||+ url.startsWith("https://app.notesnook.com/open_notebook?")) &&!event.isInitialUrl) {- const id = new URL(url).searchParams.get("id");+ const id = parsedLink?.id || new URL(url).searchParams.get("id");if (id) {const notebook = await db.notebooks.notebook(id);if (notebook) {@@ -206,10 +215,11 @@ const onAppOpenedFromURL = async (event: {}}} else if (- url.startsWith("https://app.notesnook.com/open_tag?") &&+ (parsedLink?.type === "tag" ||+ url.startsWith("https://app.notesnook.com/open_tag?")) &&!event.isInitialUrl) {- const id = new URL(url).searchParams.get("id");+ const id = parsedLink?.id || new URL(url).searchParams.get("id");if (id) {const tag = await db.tags.tag(id);if (tag) {@@ -222,10 +232,11 @@ const onAppOpenedFromURL = async (event: {}}} else if (- url.startsWith("https://app.notesnook.com/open_color?") &&+ (parsedLink?.type === "color" ||+ url.startsWith("https://app.notesnook.com/open_color?")) &&!event.isInitialUrl) {- const id = new URL(url).searchParams.get("id");+ const id = parsedLink?.id || new URL(url).searchParams.get("id");if (id) {const color = await db.colors.color(id);if (color) {diff --git a/apps/mobile/app/navigation/navigation-stack.tsx b/apps/mobile/app/navigation/navigation-stack.tsxindex dc4139f6e..ffb89919b 100644--- a/apps/mobile/app/navigation/navigation-stack.tsx+++ b/apps/mobile/app/navigation/navigation-stack.tsx@@ -31,6 +31,7 @@ import { useSettingStore } from "../stores/use-setting-store";import { rootNavigatorRef } from "../utils/global-refs";import Navigation from "../services/navigation";import { isFeatureAvailable } from "@notesnook/common";+import { isInternalLink, parseInternalLink } from "@notesnook/core";const RootStack = createNativeStackNavigator();const AppStack = createNativeStackNavigator();@@ -63,10 +64,17 @@ const AppNavigation = React.memo(React.useEffect(() => {if (!home) {- if (useSettingStore.getState().initialUrl) {- const url = useSettingStore.getState().initialUrl;- if (url?.startsWith("https://app.notesnook.com/open_notebook?")) {- const id = new URL(url).searchParams.get("id");+ const url = useSettingStore.getState().initialUrl;+ if (url) {+ const parsedLink = isInternalLink(url)+ ? parseInternalLink(url)+ : undefined;++ if (+ parsedLink?.type === "notebook" ||+ url?.startsWith("https://app.notesnook.com/open_notebook?")+ ) {+ const id = parsedLink?.id || new URL(url).searchParams.get("id");if (id) {setHome({name: "Notebook",@@ -76,8 +84,11 @@ const AppNavigation = React.memo(});return;}- } else if (url?.startsWith("https://app.notesnook.com/open_tag?")) {- const id = new URL(url).searchParams.get("id");+ } else if (+ parsedLink?.type === "tag" ||+ url?.startsWith("https://app.notesnook.com/open_tag?")+ ) {+ const id = parsedLink?.id || new URL(url).searchParams.get("id");if (id) {setHome({name: "TaggedNotes",@@ -88,8 +99,11 @@ const AppNavigation = React.memo(});return;}- } else if (url?.startsWith("https://app.notesnook.com/open_color?")) {- const id = new URL(url).searchParams.get("id");+ } else if (+ parsedLink?.type === "color" ||+ url?.startsWith("https://app.notesnook.com/open_color?")+ ) {+ const id = parsedLink?.id || new URL(url).searchParams.get("id");if (id) {setHome({name: "ColoredNotes",diff --git a/apps/mobile/ios/Notesnook/Info.plist b/apps/mobile/ios/Notesnook/Info.plistindex baeaa1347..49fac7dc9 100644--- a/apps/mobile/ios/Notesnook/Info.plist+++ b/apps/mobile/ios/Notesnook/Info.plist@@ -52,6 +52,7 @@<key>CFBundleURLSchemes</key><array><string>ShareMedia</string>+ <string>nn</string></array></dict><dict>