fix some issues with intent opening

This commit is contained in:
ammarahm-ed
2020-11-07 15:22:13 +05:00
parent 92d4ea4474
commit 95b86ffbb0
2 changed files with 29 additions and 13 deletions

View File

@@ -35,6 +35,11 @@ import {sortSettings} from './src/utils';
let firstLoad = true;
let note = null;
let prevIntent = {
text: null,
weblink: null,
};
const App = () => {
const [, dispatch] = useTracked(),
[init, setInit] = useState(false),
@@ -163,7 +168,6 @@ const App = () => {
dispatch({type: Actions.ALL});
setInit(true);
backupData().then((r) => r);
checkForIntent();
setTimeout(() => {
if (error) {
@@ -171,14 +175,16 @@ const App = () => {
ToastEvent.show('Error initializing database.');
}
SplashScreen.hide();
checkForIntent();
}, 500);
});
}, []);
const checkForIntent = () => {
console.log('check for intent called');
ReceiveSharingIntent.getReceivedFiles(
(d) => {
console.log(d, 'DATA');
console.log(d,"DATA");
let data = d[0];
if (data.text || data.weblink) {
let text = data.text;
@@ -186,15 +192,19 @@ const App = () => {
let delta = null;
if (weblink && text) {
delta = {ops: [{insert: `${data.text + ' ' + data.weblink}`}]};
delta = {ops: [{insert: `${text + ' ' + weblink}`}]};
text = data.text + ' ' + data.weblink;
} else if (text && !weblink) {
delta = {ops: [{insert: `${data.text}`}]};
delta = {ops: [{insert: `${text}`}]};
text = data.text;
} else if (weblink) {
delta = {ops: [{insert: `${data.weblink}`}]};
text = data.weblink;
console.log('putting link')
delta = {ops: [{insert: `${weblink}`}]};
text = weblink
}
console.log(text,weblink,"HERE SHOWING",delta);
prevIntent.text = text;
prevIntent.weblink = weblink;
eSendEvent(eOnLoadNote, {
type: 'intent',
data: delta,

View File

@@ -30,6 +30,8 @@ let title = null;
let saveCounter = 0;
let canSave = false;
let timer = null;
let webviewInit = false;
let intent = false;
export function isNotedEdited() {
return noteEdited;
@@ -121,12 +123,14 @@ export async function loadNote(item) {
clearNote();
canSave = true;
id = null;
intent = true;
content = {
delta: item.data,
text: item.text,
};
post('delta', content.delta);
await saveNote();
if (webviewInit) {
await loadNoteInEditor();
}
} else {
await setNote(item);
canSave = false;
@@ -305,27 +309,29 @@ export async function saveNote() {
export async function onWebViewLoad(noMenu, premium, colors) {
EditorWebView.current?.injectJavaScript(INJECTED_JAVASCRIPT(premium, false));
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 loadNoteInEditor();
webviewInit = true;
}
const loadNoteInEditor = async () => {
saveCounter = 0;
if (note?.id) {
if (intent) {
await saveNote();
intent = false;
post('delta', content.delta);
} else if (note?.id) {
post('dateEdited', timeConverter(note.dateEdited));
await sleep(50);
post('title', title);
post('delta', content.delta);
console.log(content.delta);
} else {
post('focusTitle');
}