David PHAM-VAN

Fix loading pdfjs in debug mode

1 # Changelog 1 # Changelog
2 2
  3 +## 5.10.1
  4 +
  5 +- Fix loading pdfjs in debug mode
  6 +
3 ## 5.10.0 7 ## 5.10.0
4 8
5 - Remove deprecated Android embedding 9 - Remove deprecated Android embedding
@@ -65,6 +65,15 @@ class PrintingPlugin extends PrintingPlatform { @@ -65,6 +65,15 @@ class PrintingPlugin extends PrintingPlatform {
65 await _loading.acquire(); 65 await _loading.acquire();
66 66
67 if (!_hasPdfJsLib) { 67 if (!_hasPdfJsLib) {
  68 + dynamic amd;
  69 + dynamic define;
  70 + if (js.context['define'] != null) {
  71 + // In dev, requireJs is loaded in. Disable it here.
  72 + define = js.JsObject.fromBrowserObject(js.context['define']);
  73 + amd = define['amd'];
  74 + define['amd'] = false;
  75 + }
  76 +
68 final script = ScriptElement() 77 final script = ScriptElement()
69 ..type = 'text/javascript' 78 ..type = 'text/javascript'
70 ..async = true 79 ..async = true
@@ -73,35 +82,9 @@ class PrintingPlugin extends PrintingPlatform { @@ -73,35 +82,9 @@ class PrintingPlugin extends PrintingPlatform {
73 document.head!.append(script); 82 document.head!.append(script);
74 await script.onLoad.first; 83 await script.onLoad.first;
75 84
76 - if (js.context['pdfjsLib'] == null) {  
77 - // In dev, requireJs is loaded in  
78 - final require = js.JsObject.fromBrowserObject(js.context['require']);  
79 - require.callMethod('config', <dynamic>[  
80 - js.JsObject.jsify({  
81 - 'paths': {  
82 - 'pdfjs-dist/build/pdf': '$_pdfJsUrlBase/build/pdf.min',  
83 - 'pdfjs-dist/build/pdf.worker':  
84 - '$_pdfJsUrlBase/build/pdf.worker.min',  
85 - }  
86 - })  
87 - ]);  
88 -  
89 - final completer = Completer<void>();  
90 -  
91 - js.context.callMethod('require', <dynamic>[  
92 - js.JsObject.jsify(  
93 - [  
94 - 'pdfjs-dist/build/pdf',  
95 - 'pdfjs-dist/build/pdf.worker',  
96 - ],  
97 - ),  
98 - (dynamic app) {  
99 - js.context['pdfjsLib'] = app;  
100 - completer.complete();  
101 - }  
102 - ]);  
103 -  
104 - await completer.future; 85 + if (amd != null) {
  86 + // Re-enable requireJs
  87 + define['amd'] = amd;
105 } 88 }
106 89
107 js.context['pdfjsLib']['GlobalWorkerOptions']['workerSrc'] = 90 js.context['pdfjsLib']['GlobalWorkerOptions']['workerSrc'] =
@@ -9,7 +9,7 @@ issue_tracker: https://github.com/DavBfr/dart_pdf/issues @@ -9,7 +9,7 @@ issue_tracker: https://github.com/DavBfr/dart_pdf/issues
9 screenshots: 9 screenshots:
10 - description: 'Printing a document on iOS' 10 - description: 'Printing a document on iOS'
11 path: example.png 11 path: example.png
12 -version: 5.10.0 12 +version: 5.10.1
13 13
14 environment: 14 environment:
15 sdk: ">=2.18.0 <3.0.0" 15 sdk: ">=2.18.0 <3.0.0"