From a0609e5ba20ba9cb019056b741e458fc4f01b13f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eudes=20In=C3=A1cio?= Date: Fri, 27 Oct 2023 16:21:15 +0100 Subject: [PATCH] add checkintent to main file --- android/app/src/main/AndroidManifest.xml | 23 ++-- src/app/home/home.page.ts | 104 ++++++++++++------ .../pages/publications/publications.page.html | 8 +- .../pages/publications/publications.page.ts | 3 + src/environments/environment.prod.ts | 2 +- src/environments/environment.ts | 2 +- src/main.ts | 47 +++++++- 7 files changed, 144 insertions(+), 45 deletions(-) diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 8f68e888a..3826020b1 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -14,13 +14,20 @@ - - - - - - - + + + + + + + + + + + + + + - \ No newline at end of file + diff --git a/src/app/home/home.page.ts b/src/app/home/home.page.ts index 467407fff..7c5469df9 100644 --- a/src/app/home/home.page.ts +++ b/src/app/home/home.page.ts @@ -23,10 +23,11 @@ import { PermissionList } from '../models/permission/permissionList'; import { SendIntent } from "send-intent"; import { Plugins } from '@capacitor/core'; -import { Filesystem } from '@capacitor/filesystem'; import { NewActionPage } from '../pages/publications/new-action/new-action.page'; import { PublicationsPage } from '../pages/publications/publications.page'; import { fetchData } from 'plugins/Echo'; +import { Encoding, Filesystem, FilesystemDirectory } from '@capacitor/filesystem'; + const { App } = Plugins; @@ -147,6 +148,8 @@ export class HomePage implements OnInit { ); }); */ + /* this.checkSendIntentReceived(''); */ + } goto(url) { @@ -157,44 +160,52 @@ export class HomePage implements OnInit { - async checkSendIntentReceived() { + async checkSendIntentReceived(result) { - try { - const result: any = await SendIntent.checkSendIntentReceived(); + + SendIntent.checkSendIntentReceived().then((result: any) => { + alert('shared') if (result) { - console.log('SendIntent received'); - console.log('JSON RESULT', JSON.stringify(result)); - const modal = await this.modalController.create({ - component: PublicationsPage, - componentProps: { - item: "item", - intent: JSON.stringify(result) - }, - cssClass: 'new-action modal modal-desktop', - backdropDismiss: false - }); - - /* modal.onDidDismiss().then(() => { - this.getActions(); - }); */ - await modal.present(); + console.log('SendIntent received'); + console.log(JSON.stringify(result)); } if (result.url) { - console.log('SendIntent received URL'); - let resultUrl = decodeURIComponent(result.url); - Filesystem.readFile({ path: resultUrl }) - .then((content) => { - console.log('CONtent data', content.data); + let resultUrl = decodeURIComponent(result.url); + Filesystem.readFile({path: resultUrl}) + + .then(async (content) => { + + const modal = await this.modalController.create({ + component: PublicationsPage, + componentProps: { + item: "item", + intent: content.data + }, + cssClass: 'new-action modal modal-desktop', + backdropDismiss: false + }); + + modal.onDidDismiss().then(() => { + SendIntent.finish(); + }); + await modal.present(); + + + console.log(content.data); }) - .catch((err) => console.log('Erro filesystem', err)); + .catch((err) => console.error(err)); } - } catch (error) { - console.error('error check intent', error); - } + }).catch(err => console.error(err)); } ngOnInit() { + if(window["sharedintend"]) { + this.router.navigateByUrl("/home/publication"); + } + + window["this.router"] = this.router + /* this.checkSendIntentReceived() */ if ("serviceWorker" in navigator) { @@ -291,14 +302,27 @@ export class HomePage implements OnInit { if (!this.platform.is('desktop')) { App.addListener('appStateChange', ({ isActive }) => { if (isActive) { + /* this.checkSendIntentReceived("value") */ // The app is in the foreground. - fetchData() + /* fetchData() .then((value) => { - console.log('fetchData was successful in file2.ts',value); + console.log('fetchData was successful in file2.ts', value); + this.imageToBase64(value) + .then((base64Data) => {s + if (base64Data) { + // Use the base64 data as needed + console.log('Base64 data:', base64Data); + } else { + console.error('Base64 data is null'); + } + }); + if (value) + this.checkSendIntentReceived(value) + }) .catch((error) => { console.error('Error in file2.ts:', error); - }); + }); */ console.log('App is in the foreground'); /* this.checkSendIntentReceived() */ } else { @@ -311,6 +335,22 @@ export class HomePage implements OnInit { } + async imageToBase64(imageUri: string): Promise { + try { + const result = await Filesystem.readFile({ + path: imageUri, + directory: FilesystemDirectory.External, // Adjust the directory as needed + encoding: Encoding.UTF8, + }); + + // The result will contain the base64-encoded data + return result.data; + } catch (error) { + console.error('Error reading image:', error); + return null; + } + } + clearTabButtonSelection() { this.tabButton.home = false; this.tabButton.agenda = false; diff --git a/src/app/pages/publications/publications.page.html b/src/app/pages/publications/publications.page.html index 4bbde9b92..ae07be1ea 100644 --- a/src/app/pages/publications/publications.page.html +++ b/src/app/pages/publications/publications.page.html @@ -21,7 +21,7 @@ Acções -
+
+
+ + +
diff --git a/src/app/pages/publications/publications.page.ts b/src/app/pages/publications/publications.page.ts index b526cbc9a..eea526bcf 100644 --- a/src/app/pages/publications/publications.page.ts +++ b/src/app/pages/publications/publications.page.ts @@ -132,6 +132,9 @@ export class PublicationsPage implements OnInit { }, 250); } + close() { + this.modalController.dismiss(); + } get windowInnerWidth(): number { return window.innerWidth } diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts index 726ebb13e..a9256d5a8 100644 --- a/src/environments/environment.prod.ts +++ b/src/environments/environment.prod.ts @@ -4,4 +4,4 @@ import { doneITProd } from './suport/doneIt' import { DevDev } from './suport/dev' -export const environment: Environment = oaprProd; +export const environment: Environment = DevDev; diff --git a/src/environments/environment.ts b/src/environments/environment.ts index e2d79dff9..16a865ce9 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -4,4 +4,4 @@ import { doneITDev } from './suport/doneIt' import { DevDev } from './suport/dev' -export const environment: Environment = oaprDev \ No newline at end of file +export const environment: Environment = DevDev \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index 7fa3e2dbc..390700473 100644 --- a/src/main.ts +++ b/src/main.ts @@ -7,12 +7,13 @@ import { environment } from './environments/environment'; import { defineCustomElements } from '@ionic/pwa-elements/loader'; import "hammerjs"; // HAMMER TIME +import { SendIntent } from "send-intent"; +import { Filesystem } from '@capacitor/filesystem'; + if (environment.production) { enableProdMode(); } - - /* Sentry.init( { dsn: 'https://5b345a3ae70b4e4da463da65881b4aaa@o4504340905525248.ingest.sentry.io/4504345615794176', @@ -46,5 +47,47 @@ platformBrowserDynamic().bootstrapModule(AppModule) .catch(err => console.log(err)); // Call the element loader after the platform has been bootstrapped + + SendIntent.checkSendIntentReceived().then((result: any) => { + + if (result) { + console.log('SendIntent received'); + console.log(JSON.stringify(result)); + } + if (result.url) { + let resultUrl = decodeURIComponent(result.url); + Filesystem.readFile({path: resultUrl}) + + .then(async (content) => { + + /* const modal = await this.modalController.create({ + component: PublicationsPage, + componentProps: { + item: "item", + intent: content.data + }, + cssClass: 'new-action modal modal-desktop', + backdropDismiss: false + }); + + modal.onDidDismiss().then(() => { + SendIntent.finish(); + }); + await modal.present(); + */ + + window["sharedintend"] = content.data + + window["this.router"].navigateByUrl("/home/publication"); + + + + alert('shared') + console.log(content.data); + + }) + .catch((err) => console.error(err)); + } +}).catch(err => console.error(err)); defineCustomElements(window);