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';
|
|
|
|
|
|
2023-10-28 17:04:17 +01:00
|
|
|
export class SendIntentService {
|
2023-10-27 16:46:41 +01:00
|
|
|
|
|
|
|
|
Router!: Router
|
|
|
|
|
|
|
|
|
|
callbackScheduler = new CallbackScheduler()
|
|
|
|
|
|
|
|
|
|
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)=> {
|
|
|
|
|
let resultUrl = decodeURIComponent(result.url);
|
|
|
|
|
Filesystem.readFile({path: resultUrl}).then(async (content) => {
|
|
|
|
|
|
2023-10-28 17:04:17 +01:00
|
|
|
this.Router.navigateByUrl("/home/publications");
|
2023-10-27 16:46:41 +01:00
|
|
|
|
2023-10-28 17:04:17 +01:00
|
|
|
window["sharedContent"] = content.data;
|
2023-10-27 16:46:41 +01:00
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-28 17:04:17 +01:00
|
|
|
export const sendIntent = new SendIntentService()
|