pwlin / cordova-plugin-file-opener2

A File Opener Plugin for Cordova
MIT License
314 stars 584 forks source link

Present notification view controller by inappbrowser v #244

Closed Bruno-bm closed 5 years ago

Bruno-bm commented 5 years ago

iew controller

shnist commented 5 years ago

hi @Bruno-bm, thanks for this. I'll have a test of the code at some point early next week and then we'll get it merged in if everything is good.

shnist commented 5 years ago

hi @Bruno-bm, apologies for the delay, would you mind sending me an example code snippet for how I can reproduce the issue? I'm struggling to reproduce the issue locally so I can't test the fix. Thanks

jokel81 commented 5 years ago

hi there...

if you still need some piece of code, this is mine:

` // start browser instance this.browserRef = this.inAppBrowser.create(url, '_blank', browserOptions);

// associate event handler this.browserRef.on('loadstart').subscribe(event => {

// this.browserRef.executeScript({code: "alert('"+event.url+"')"})

// get clean file url without get parameters
let intermediateUrl = event.url.replace(/\?.*/, '');

// get file extension
let extension = intermediateUrl.match(/\..{3,4}$/) ? intermediateUrl.match(/\..{3,4}$/).toString().substr(1) : null;

// get filename
let filename = intermediateUrl.match(/.*\/(.+?\..{3,4})$/)
    ? (0 < intermediateUrl.match(/.*\/(.+?\..{3,4})$/).length
        ? intermediateUrl.match(/.*\/(.+?\..{3,4})$/)[1]
        : intermediateUrl.match(/.*\/(.+?\..{3,4})$/))
    : null;

if (extension && filename && -1 != ['pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx'].indexOf(extension)) {
    // if file extension is viewable
    this.zone.run(() => {
        this.showBrowser = true;
        this.downloadService.openFile(event.url, this.browserRef);
    });

} else if (event.url.match(/.*closebrowser$/)) {
    // if close browser button was pressed
    this.browserRef.close();
}

}); `

shnist commented 5 years ago

Thanks both, happy to merge this in now.