2023-10-27 16:46:41 +01:00
|
|
|
import { Filesystem } from '@capacitor/filesystem';
|
|
|
|
|
import { SendIntent } from "send-intent";
|
|
|
|
|
import { Router } from '@angular/router';
|
|
|
|
|
import { CallbackScheduler } from './callbackScheduler';
|
2024-03-01 14:37:42 +01:00
|
|
|
import { AlertController, Platform } from '@ionic/angular';
|
2023-10-27 16:46:41 +01:00
|
|
|
|
2023-10-28 17:04:17 +01:00
|
|
|
export class SendIntentService {
|
2023-10-27 16:46:41 +01:00
|
|
|
|
|
|
|
|
Router!: Router
|
|
|
|
|
|
|
|
|
|
callbackScheduler = new CallbackScheduler()
|
2024-03-01 14:37:42 +01:00
|
|
|
alertController = new AlertController()
|
2023-10-27 16:46:41 +01:00
|
|
|
|
2024-03-01 14:37:42 +01:00
|
|
|
constructor(
|
|
|
|
|
) {
|
2023-11-16 12:07:22 +01:00
|
|
|
|
2023-10-27 16:46:41 +01:00
|
|
|
SendIntent.checkSendIntentReceived().then((result: any) => {
|
|
|
|
|
// logger
|
|
|
|
|
if (result) {
|
|
|
|
|
console.log('SendIntent received');
|
|
|
|
|
console.log(JSON.stringify(result));
|
|
|
|
|
}
|
|
|
|
|
// event handler
|
|
|
|
|
if (result.url) {
|
|
|
|
|
this.onReceive(result)
|
2023-10-28 17:04:17 +01:00
|
|
|
|
2023-10-27 16:46:41 +01:00
|
|
|
}
|
|
|
|
|
}).catch(err => console.error(err));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private initialize() {
|
|
|
|
|
this.callbackScheduler.start()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setRouteService(Router: Router) {
|
|
|
|
|
this.Router = Router
|
|
|
|
|
this.initialize()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private onReceive = this.callbackScheduler.function<any>((result)=> {
|
2024-03-01 14:37:42 +01:00
|
|
|
this.Router.navigateByUrl("/home/publications").then(() => {
|
|
|
|
|
if(Platform.prototype.is('ios')) {
|
|
|
|
|
this.alertIos();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
2023-10-27 16:46:41 +01:00
|
|
|
|
2023-11-20 14:12:32 +01:00
|
|
|
window["sharedContent"] = result;
|
2023-10-27 16:46:41 +01:00
|
|
|
})
|
|
|
|
|
|
2024-03-01 14:37:42 +01:00
|
|
|
private alertIos() {
|
|
|
|
|
this.alertController .create({
|
|
|
|
|
header: 'Selecione uma acção para criar a publicação',
|
|
|
|
|
message: '',
|
|
|
|
|
buttons: [
|
|
|
|
|
{
|
|
|
|
|
text: 'Ok',
|
|
|
|
|
handler: () => {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}).then(res => {
|
|
|
|
|
res.present();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-27 16:46:41 +01:00
|
|
|
}
|
|
|
|
|
|
2023-10-28 17:04:17 +01:00
|
|
|
export const sendIntent = new SendIntentService()
|