Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
espresso3389 committed Feb 13, 2025
1 parent 6784197 commit b9edb0a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/src/web/pdf.js.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
library;

import 'dart:js_interop';
import 'dart:js_interop_unsafe';
import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'package:synchronized/extension.dart';
import 'package:web/helpers.dart';
import 'package:web/web.dart' as web;

import '../../pdfrx.dart';
Expand Down Expand Up @@ -286,6 +289,15 @@ final _dummyJsSyncContext = {};

bool _pdfjsInitialized = false;

bool get _isSharedArrayBufferSupported {
try {
// Check if SharedArrayBuffer exists in the global JavaScript context
return window.hasProperty('SharedArrayBuffer'.toJS).toDart;
} catch (e) {
return false;
}
}

Future<void> ensurePdfjsInitialized() async {
if (_pdfjsInitialized) return;
await _dummyJsSyncContext.synchronized(() async {
Expand All @@ -295,6 +307,11 @@ Future<void> ensurePdfjsInitialized() async {
return;
}

const isRunningWithWasm = bool.fromEnvironment('dart.tool.dart2wasm');
debugPrint(
'Running WASM: $isRunningWithWasm\nSharedArrayBuffer ${_isSharedArrayBufferSupported ? 'supported' : 'not supported'}}',
);

final pdfJsSrc = PdfJsConfiguration.configuration?.pdfJsSrc ?? _pdfjsUrl;
try {
final script =
Expand Down

0 comments on commit b9edb0a

Please sign in to comment.