TF-2737 Separate PDF view handler between each browser

This commit is contained in:
DatDang
2024-03-21 17:46:22 +07:00
committed by Dat H. Pham
parent 6ccdbd66c4
commit 754987b59e
4 changed files with 262 additions and 35 deletions
@@ -109,17 +109,25 @@ class DownloadManager {
}
}
Future<void> openDownloadedFileWeb(Uint8List bytes, String? mimeType) async {
Future<void> openDownloadedFileWeb(
Uint8List bytes,
String? mimeType,
String? fileName
) async {
try {
fileName ??= 'unknown.pdf';
final deviceInfo = await _deviceInfoPlugin.deviceInfo;
if ('${deviceInfo.data['browserName']}' != 'BrowserName.chrome'
|| mimeType != Constant.pdfMimeType) {
if (mimeType != Constant.pdfMimeType
|| '${deviceInfo.data['browserName']}' == 'BrowserName.firefox') {
final blob = html.Blob([bytes], mimeType);
final url = html.Url.createObjectUrlFromBlob(blob);
final file = html.File([blob], fileName, {'type': mimeType});
final url = html.Url.createObjectUrl(file);
html.window.open(url, '_blank');
html.Url.revokeObjectUrl(url);
} else if ('${deviceInfo.data['browserName']}' == 'BrowserName.chrome') {
HtmlUtils.openNewTabHtmlDocument(HtmlUtils.chromePdfViewer(bytes, fileName));
} else {
HtmlUtils.openNewTabHtmlDocument(HtmlUtils.pdfViewer(bytes));
HtmlUtils.openNewTabHtmlDocument(HtmlUtils.safariPdfViewer(bytes, fileName));
}
} catch (exception) {
logError('DownloadManager::openDownloadedFileWeb(): ERROR: $exception');