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
fix intent handling on ios
ammarahm-eded0c60b0a66c
diff --git a/apps/mobile/App.js b/apps/mobile/App.jsindex 24f7155b9..4bd2626c6 100644--- a/apps/mobile/App.js+++ b/apps/mobile/App.js@@ -141,11 +141,16 @@ const App = () => {};const _handleIntent = async (res) => {+if (intentInit) {let url = res ? res.url : '';+try {- if (res && res.startsWith('ShareMedia://dataUrl')) {+ if (url.startsWith('ShareMedia://dataUrl')) {+ console.log(url);_data = await ReceiveSharingIntent.getFileNames(url);+ _data = IntentService.iosSortedData(_data)+ console.log("DONE","DATA GETTING");}if (_data) {IntentService.setIntent(_data);@@ -155,7 +160,9 @@ const App = () => {Navigation.closeDrawer();});}- } catch (e) {}+ } catch (e) {+ console.log(e,"ERROR HERE")+ }}};diff --git a/apps/mobile/ios/Add to Notes/ShareViewController.swift b/apps/mobile/ios/Add to Notes/ShareViewController.swiftindex 3b00723ab..e60b7bebb 100644--- a/apps/mobile/ios/Add to Notes/ShareViewController.swift+++ b/apps/mobile/ios/Add to Notes/ShareViewController.swift@@ -5,7 +5,7 @@ import Photosclass ShareViewController: SLComposeServiceViewController {// TODO: IMPORTANT: This should be your host app bundle identifier- let hostAppBundleIdentifier = "org.reactjs.native.example.Notesnook"+ let hostAppBundleIdentifier = "org.streetwriters.notesnook"let sharedKey = "ShareKey"var sharedMedia: [SharedMediaFile] = []var sharedText: [String] = []diff --git a/apps/mobile/src/services/IntentService.js b/apps/mobile/src/services/IntentService.jsindex a8dca9b4d..4be2b9521 100644--- a/apps/mobile/src/services/IntentService.js+++ b/apps/mobile/src/services/IntentService.js@@ -1,4 +1,4 @@-import {NativeModules, Platform} from 'react-native';+import {Linking, NativeModules, Platform} from 'react-native';const {ReceiveSharingIntent} = NativeModules;let currentIntent = null;const isIos = Platform.OS === 'ios';@@ -11,7 +11,8 @@ function getIntent() {if (isIos) {initialUrlIOS = await Linking.getInitialURL();if (initialUrlIOS && initialUrlIOS.startsWith('ShareMedia://dataUrl')) {- _data = await ReceiveSharingIntent.getFileNames(initialUrlIOS.url);+ _data = await ReceiveSharingIntent.getFileNames(initialUrlIOS);+ _data = iosSortedData(_data);} else {reject('unsupported url');}@@ -65,8 +66,73 @@ function check(callback) {currentIntent = null;}++const iosSortedData = (data) => {+ let objects = {+ filePath: null,+ text: null,+ weblink: null,+ mimeType: null,+ contentUri: null,+ fileName: null,+ extension: null,+ };+ let file = data;+ if (file.startsWith('text:')) {+ let text = file.replace('text:', '');+ if (text.startsWith('http')) {+ let object = [{...objects, weblink: text}];+ return object;+ }+ let object = [{...objects, text: text}];+ return object;+ } else if (file.startsWith('webUrl:')) {+ let weblink = file.replace('webUrl:', '');+ let object = [{...objects, weblink: weblink}];+ return object;+ } else {+ try {+ let files = JSON.parse(file);+ let object = [];+ for (let i = 0; i < files.length; i++) {+ let path = files[i].path;+ let obj = {+ ...objects,+ fileName: getFileName(path),+ extension: getExtension(path),+ mimeType: getMimeType(path),+ filePath: path,+ };+ object.push(obj);+ }+ return object;+ } catch (error) {+ return [{...objects}];+ }+ }+};++const getFileName = (file) => {+ return file.replace(/^.*(\\|\/|\:)/, '');+};++const getExtension = (fileName) => {+ return fileName.substr(fileName.lastIndexOf('.') + 1);+};++const getMimeType = (file) => {+ let ext = getExtension(file);+ let extension = '.' + ext.toLowerCase();+ if (MimeTypes[extension]) {+ return MimeTypes[extension];+ }+ return null;+};+export default {getIntent,check,setIntent,+ iosSortedData,+};diff --git a/apps/mobile/src/views/Editor/Functions.js b/apps/mobile/src/views/Editor/Functions.jsindex d73e3a522..7c673ff72 100644--- a/apps/mobile/src/views/Editor/Functions.js+++ b/apps/mobile/src/views/Editor/Functions.js@@ -440,6 +440,8 @@ export let isFromIntent = false;const loadNoteInEditor = async () => {saveCounter = 0;if (intent) {+ console.log("POSTING DELTA")+ await sleep(1500);post('delta', content.data);intent = true;await saveNote();