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
add intent sharing support (Android)
ammarahm-ed5917871da6cf
diff --git a/apps/mobile/App.js b/apps/mobile/App.jsindex e905651b6..04fc25cfb 100644--- a/apps/mobile/App.js+++ b/apps/mobile/App.js@@ -6,6 +6,7 @@ import {SafeAreaProvider} from 'react-native-safe-area-context';import {useTracked} from './src/provider';import {Actions} from './src/provider/Actions';import {defaultState} from './src/provider/DefaultState';+import ReceiveSharingIntent from 'react-native-receive-sharing-intent';import {eSendEvent,eSubscribeEvent,@@ -30,7 +31,7 @@ import {MMKV} from './src/utils/mmkv';import Backup from './src/services/Backup';import {setLoginMessage} from './src/services/Message';import SplashScreen from 'react-native-splash-screen';-import {SORT, sortSettings} from "./src/utils";+import {sortSettings} from './src/utils';let firstLoad = true;let note = null;@@ -161,8 +162,8 @@ const App = () => {dispatch({type: Actions.ALL});setInit(true);-- backupData().then(r=> r)+ backupData().then((r) => r);+ checkForIntent();setTimeout(() => {if (error) {@@ -174,6 +175,31 @@ const App = () => {});}, []);+ const checkForIntent = () => {+ ReceiveSharingIntent.getReceivedFiles(+ (d) => {+ console.log(data, 'DATA');+ let data = d[0];+ if (data.text) {+ let delta = {ops: [{insert: `${data.text}`}]};++ eSendEvent(eOnLoadNote, {+ type: 'intent',+ data: delta,+ text: data.text,+ });+ if (DDS.isPhone || DDS.isSmallTab) {+ openEditorAnimation();+ }+ }+ ReceiveSharingIntent.clearReceivedFiles();+ },+ (error) => {+ console.log(error, 'INTENT ERROR');+ },+ );+ };+async function backupData() {await sleep(1000);let settings = await MMKV.getStringAsync('settings');diff --git a/apps/mobile/android/app/src/main/AndroidManifest.xml b/apps/mobile/android/app/src/main/AndroidManifest.xmlindex 906667ae1..009b6f3d8 100644--- a/apps/mobile/android/app/src/main/AndroidManifest.xml+++ b/apps/mobile/android/app/src/main/AndroidManifest.xml@@ -22,6 +22,13 @@android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"android:launchMode="singleTask"android:windowSoftInputMode="adjustResize">++ <intent-filter>+ <action android:name="android.intent.action.SEND" />+ <category android:name="android.intent.category.DEFAULT" />+ <data android:mimeType="text/*" />+ </intent-filter>+<intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" />diff --git a/apps/mobile/android/app/src/main/java/com/streetwriters/notesnook/MainActivity.java b/apps/mobile/android/app/src/main/java/com/streetwriters/notesnook/MainActivity.javaindex b013c6d87..3db5330f7 100644--- a/apps/mobile/android/app/src/main/java/com/streetwriters/notesnook/MainActivity.java+++ b/apps/mobile/android/app/src/main/java/com/streetwriters/notesnook/MainActivity.java@@ -4,6 +4,7 @@ import com.facebook.react.ReactActivity;import android.content.Intent;import android.content.res.Configuration;import android.os.Bundle;+import android.content.Intent;import org.devio.rn.splashscreen.SplashScreen;@@ -21,6 +22,13 @@ public class MainActivity extends ReactActivity {super.onCreate(savedInstanceState);}++@Override+public void onNewIntent(Intent intent) {+ super.onNewIntent(intent);+ setIntent(intent);+}+@Overridepublic void onConfigurationChanged(Configuration newConfig) {super.onConfigurationChanged(newConfig);diff --git a/apps/mobile/src/views/Editor/EditorHeader.js b/apps/mobile/src/views/Editor/EditorHeader.jsindex 38d4d8866..d4cf82baa 100644--- a/apps/mobile/src/views/Editor/EditorHeader.js+++ b/apps/mobile/src/views/Editor/EditorHeader.js@@ -85,9 +85,11 @@ const EditorHeader = ({noMenu}) => {const load = async (item) => {await loadNote(item);- if (item.type === 'new') {+ if (item.type === 'new' && item.data) {textInput.current?.focus();post('focusTitle');++Platform.OS === 'android' ? EditorWebView.current?.requestFocus() : null;}if (!DDS.isTab) {diff --git a/apps/mobile/src/views/Editor/Functions.js b/apps/mobile/src/views/Editor/Functions.jsindex b07d0f0c0..00d0854e8 100644--- a/apps/mobile/src/views/Editor/Functions.js+++ b/apps/mobile/src/views/Editor/Functions.js@@ -3,18 +3,18 @@ import {Linking, Platform} from 'react-native';import {updateEvent} from '../../components/DialogManager/recievers';import {Actions} from '../../provider/Actions';import {eSendEvent, sendNoteEditedEvent} from '../../services/EventManager';-import {eOnNoteEdited, refreshNotesPage} from '../../utils/Events';+import {refreshNotesPage} from '../../utils/Events';import {editing} from '../../utils';-import {sleep, timeConverter} from "../../utils/TimeUtils";-import {normalize} from "../../utils/SizeUtils";-import {db} from "../../utils/DB";+import {sleep, timeConverter} from '../../utils/TimeUtils';+import {normalize} from '../../utils/SizeUtils';+import {db} from '../../utils/DB';export const EditorWebView = createRef();export const params = 'platform=' + Platform.OS;export const sourceUri =- (Platform.OS === 'android' ? 'file:///android_asset/' : '') +- 'Web.bundle/loader.html';+ (Platform.OS === 'android' ? 'file:///android_asset/' : '') ++ 'Web.bundle/loader.html';export const injectedJS = `if (!window.location.search) {var link = document.getElementById('progress-bar');link.href = './site/index.html?${params}';@@ -32,26 +32,25 @@ let canSave = false;let timer = null;export function isNotedEdited() {- return noteEdited;+ return noteEdited;}export function clearTimer() {- if (timer){- clearTimeout(timer);- timer = null;- }-+ if (timer) {+ clearTimeout(timer);+ timer = null;+ }}export const INJECTED_JAVASCRIPT = (premium) =>- premium- ? `(function() {+ premium+ ? `(function() {setTimeout(() => {loadAction(true,false);},100)})();`- : `(function() {+ : `(function() {setTimeout(() => {loadAction(false,false);@@ -60,270 +59,276 @@ export const INJECTED_JAVASCRIPT = (premium) =>})();`;export function getNote() {- return note;+ return note;}-export const textInput = createRef();-export function post(type, value = null) {- let message = {- type,- value,- };- EditorWebView.current?.postMessage(JSON.stringify(message));+ let message = {+ type,+ value,+ };+ EditorWebView.current?.postMessage(JSON.stringify(message));}export const _onShouldStartLoadWithRequest = async (request) => {- if (request.url.includes('https')) {- await Linking.openURL(request.url);- return false;- } else {- return true;- }+ if (request.url.includes('https')) {+ await Linking.openURL(request.url);+ return false;+ } else {+ return true;+ }};export function checkNote() {- return note && note.id;+ return note && note.id;}async function setNote(item) {- note = item;- saveCounter = 0;- noteEdited = false;- title = note.title;- id = note.id;- content = {};- content.text = await db.notes.note(id).text();- content.delta = note.content.delta;- if (!note.locked) {- content.delta = await db.notes.note(id).delta();- }+ note = item;+ saveCounter = 0;+ noteEdited = false;+ title = note.title;+ id = note.id;+ content = {};+ content.text = await db.notes.note(id).text();+ content.delta = note.content.delta;+ if (!note.locked) {+ content.delta = await db.notes.note(id).delta();+ }}function clearNote() {- note = null;- noteEdited = false;- title = null;- id = null;- content = null;+ note = null;+ noteEdited = false;+ title = null;+ id = null;+ content = null;}export async function loadNote(item) {- editing.currentlyEditing = true;- post('blur');- if (item && item.type === 'new') {- await clearEditor();- clearNote();- post('focusTitle');- canSave = true;- id = null;-- } else {- await setNote(item);- canSave = false;- sendNoteEditedEvent(item.id)- await loadNoteInEditor();- }- noteEdited = false;+ editing.currentlyEditing = true;+ post('blur');+ if (item && item.type === 'new') {+ await clearEditor();+ clearNote();+ post('focusTitle');+ canSave = true;+ id = null;+ } else if (item && item.type === 'intent') {+ await clearEditor();+ clearNote();+ canSave = true;+ id = null;+ content = {+ delta: item.data,+ text: item.text,+ };+ post('delta', content.delta);+ await saveNote();+ } else {+ await setNote(item);+ canSave = false;+ sendNoteEditedEvent(item.id);+ await loadNoteInEditor();+ }+ noteEdited = false;}const onChange = (data) => {- if (!data || data === '') return;- let rawData = JSON.parse(data);- if (rawData.type === 'content') {- if (- !id && rawData.text !== "" ||- (content &&- JSON.stringify(content.delta) !== JSON.stringify(rawData.delta))- ) {- noteEdited = true;- }- content = rawData;- } else {- if (!id || (rawData.value !== '' && rawData.value !== title)) {- noteEdited = true;- }- title = rawData.value;+ if (!data || data === '') return;+ let rawData = JSON.parse(data);+ if (rawData.type === 'content') {+ if (+ (!id && rawData.text !== '') ||+ (content &&+ JSON.stringify(content.delta) !== JSON.stringify(rawData.delta))+ ) {+ noteEdited = true;}-+ content = rawData;+ } else {+ if (!id || (rawData.value !== '' && rawData.value !== title)) {+ noteEdited = true;+ }+ title = rawData.value;+ }};export const _onMessage = async (evt) => {- if (!evt || !evt.nativeEvent || !evt.nativeEvent.data) return;- let message = evt.nativeEvent.data;- clearTimeout(timer);- timer = null;- if (message === 'loaded') {- } else if (message !== '' && message !== 'loaded') {- onChange(message);- timer = setTimeout(() => {- if (noteEdited) {- saveNote("onMessage");- }- }, 500);- }+ if (!evt || !evt.nativeEvent || !evt.nativeEvent.data) return;+ let message = evt.nativeEvent.data;+ clearTimeout(timer);+ timer = null;+ if (message === 'loaded') {+ } else if (message !== '' && message !== 'loaded') {+ onChange(message);+ timer = setTimeout(() => {+ if (noteEdited) {+ saveNote('onMessage');+ }+ }, 500);+ }};export async function clearEditor() {- clearTimer();- if (noteEdited && id) {- await saveNote("clearEditor");- }- if (note && note.id) {- sendNoteEditedEvent(note.id,true)- }- saveCounter = 0;- post('reset');+ clearTimer();+ if (noteEdited && id) {+ await saveNote('clearEditor');+ }+ if (note && note.id) {+ sendNoteEditedEvent(note.id, true);+ }+ saveCounter = 0;+ post('reset');}function checkIfContentIsSavable() {- if (!title && !content) return false;- if (content && content.text.length < 2 && title && title?.length < 2)- return false;- if (!content && title && title.length < 2) return false;- if (!title && content.text.length < 2) return false;- if (title && !content) {- content = {- text: '',- delta: {ops: []},- };- }+ if (!title && !content) return false;+ if (content && content.text.length < 2 && title && title?.length < 2)+ return false;+ if (!content && title && title.length < 2) return false;+ if (!title && content.text.length < 2) return false;+ if (title && !content) {+ content = {+ text: '',+ delta: {ops: []},+ };+ }- return true;+ return true;}async function setNoteInEditorAfterSaving(oldId, currentId) {- if (oldId !== currentId) {- id = currentId;+ if (oldId !== currentId) {+ id = currentId;+ note = db.notes.note(id);+ if (note) {+ note = note.data;+ } else {+ setTimeout(() => {note = db.notes.note(id);if (note) {- note = note.data;- } else {- setTimeout(() => {- note = db.notes.note(id);- if (note) {- note = note.data;- }- }, 500);+ note = note.data;}+ }, 500);}+ }}async function addToCollection(id) {- switch (editing.actionAfterFirstSave.type) {- case 'topic': {- await db.notes.move(- {- topic: editing.actionAfterFirstSave.id,- id: editing.actionAfterFirstSave.notebook,- },- id,- );- editing.actionAfterFirstSave = {- type: null,- };-- break;- }- case 'tag': {- await db.notes.note(note.id).tag(editing.actionAfterFirstSave.id);- editing.actionAfterFirstSave = {- type: null,- };+ switch (editing.actionAfterFirstSave.type) {+ case 'topic': {+ await db.notes.move(+ {+ topic: editing.actionAfterFirstSave.id,+ id: editing.actionAfterFirstSave.notebook,+ },+ id,+ );+ editing.actionAfterFirstSave = {+ type: null,+ };++ break;+ }+ case 'tag': {+ await db.notes.note(note.id).tag(editing.actionAfterFirstSave.id);+ editing.actionAfterFirstSave = {+ type: null,+ };- break;- }- case 'color': {- await db.notes.note(id).color(editing.actionAfterFirstSave.id);+ break;+ }+ case 'color': {+ await db.notes.note(id).color(editing.actionAfterFirstSave.id);- editing.actionAfterFirstSave = {- type: null,- };+ editing.actionAfterFirstSave = {+ type: null,+ };- break;- }- default: {- break;- }+ break;}+ default: {+ break;+ }+ }}-export async function saveNote(caller) {- if (!checkIfContentIsSavable()) return;- let lockedNote = id ? db.notes.note(id).data.locked : null;-- if (!lockedNote) {- let rId = await db.notes.add({- title,- content: {- text: content.text,- delta: content.delta,- },- id: id,- });- if (!id || saveCounter < 3) {- updateEvent({- type: Actions.NOTES,- });- eSendEvent(refreshNotesPage);- }-- sendNoteEditedEvent(rId)+export async function saveNote() {+ if (!checkIfContentIsSavable()) return;+ let lockedNote = id ? db.notes.note(id).data.locked : null;++ if (!lockedNote) {+ let rId = await db.notes.add({+ title,+ content: {+ text: content.text,+ delta: content.delta,+ },+ id: id,+ });+ if (!id || saveCounter < 3) {+ updateEvent({+ type: Actions.NOTES,+ });+ eSendEvent(refreshNotesPage);+ }- await setNoteInEditorAfterSaving(id, rId);+ sendNoteEditedEvent(rId);+ await setNoteInEditorAfterSaving(id, rId);- if (id) {- await addToCollection(id);- updateEvent({- type: Actions.CURRENT_EDITING_NOTE,- id: id,- });- }- saveCounter++;- } else {- await db.vault.save({- title,- content: {- text: content.text,- delta: content.delta,- },- id: id,- });+ if (id) {+ await addToCollection(id);+ updateEvent({+ type: Actions.CURRENT_EDITING_NOTE,+ id: id,+ });}- let n = db.notes.note(id).data.dateEdited;- post('dateEdited', timeConverter(n));- post('saving', 'Saved');+ saveCounter++;+ } else {+ await db.vault.save({+ title,+ content: {+ text: content.text,+ delta: content.delta,+ },+ id: id,+ });+ }+ let n = db.notes.note(id).data.dateEdited;+ post('dateEdited', timeConverter(n));+ post('saving', 'Saved');}export async function onWebViewLoad(noMenu, premium, colors) {- EditorWebView.current?.injectJavaScript(INJECTED_JAVASCRIPT(premium, false));-+ EditorWebView.current?.injectJavaScript(INJECTED_JAVASCRIPT(premium, false));- await loadNoteInEditor();- if (!checkNote()) {- post('blur');- Platform.OS === 'android' ? EditorWebView.current?.requestFocus() : null;- }+ await loadNoteInEditor();+ if (!checkNote()) {post('blur');+ Platform.OS === 'android' ? EditorWebView.current?.requestFocus() : null;+ }+ post('blur');- await sleep(1000);- let theme = {...colors, factor: normalize(1)};- post('theme', theme);+ await sleep(1000);+ let theme = {...colors, factor: normalize(1)};+ post('theme', theme);}const loadNoteInEditor = async () => {- saveCounter = 0;- if (note?.id) {- post('dateEdited', timeConverter(note.dateEdited));- await sleep(50);- post('title', title);- post('delta', content.delta);- } else {- post('focusTitle');- }+ saveCounter = 0;+ if (note?.id) {+ post('dateEdited', timeConverter(note.dateEdited));await sleep(50);- post('clearHistory');+ post('title', title);+ post('delta', content.delta);+ console.log(content.delta);+ } else {+ post('focusTitle');+ }+ await sleep(50);+ post('clearHistory');};diff --git a/apps/mobile/src/views/Editor/index.js b/apps/mobile/src/views/Editor/index.jsindex 212321cb4..f555ebe20 100755--- a/apps/mobile/src/views/Editor/index.js+++ b/apps/mobile/src/views/Editor/index.js@@ -1,18 +1,25 @@import React, {createRef} from 'react';-import {KeyboardAvoidingView, Platform, SafeAreaView, StatusBar, TextInput, View,} from 'react-native';+import {+ KeyboardAvoidingView,+ Platform,+ SafeAreaView,+ StatusBar,+ TextInput,+ View,+} from 'react-native';import WebView from 'react-native-webview';import {useTracked} from '../../provider';import {- _onMessage,- _onShouldStartLoadWithRequest,- EditorWebView,- injectedJS,- onWebViewLoad,- sourceUri, textInput,+ _onMessage,+ _onShouldStartLoadWithRequest,+ EditorWebView,+ injectedJS,+ onWebViewLoad,+ sourceUri,+ textInput,} from './Functions';import {DDS} from '../../services/DeviceDetection';-import EditorHeader from "./EditorHeader";-+import EditorHeader from './EditorHeader';const Editor = ({noMenu}) => {const [state] = useTracked();@@ -39,8 +46,7 @@ const Editor = ({noMenu}) => {height: '100%',width: '100%',}}>-- <EditorHeader noMenu={noMenu} />+ <EditorHeader noMenu={noMenu} /><WebViewtestID="editor"ref={EditorWebView}