@@ -143,11 +143,11 @@ function hidePopup () {
143143
144144const allOptions : Array < { format : FileFormat , handler : FormatHandler } > = [ ] ;
145145
146- let supportedFormatCache : Map < string , FileFormat [ ] > = new Map ( ) ;
146+ window . supportedFormatCache = new Map ( ) ;
147147
148- function printSupportedFormatCache ( ) {
148+ window . printSupportedFormatCache = ( ) => {
149149 const entries = [ ] ;
150- for ( const entry of supportedFormatCache ) {
150+ for ( const entry of window . supportedFormatCache ) {
151151 entries . push ( entry ) ;
152152 }
153153 return JSON . stringify ( entries , null , 2 ) ;
@@ -160,16 +160,15 @@ async function buildOptionList () {
160160 ui . outputList . innerHTML = "" ;
161161
162162 for ( const handler of handlers ) {
163- if ( ! supportedFormatCache . has ( handler . name ) ) {
163+ if ( ! window . supportedFormatCache . has ( handler . name ) ) {
164164 console . warn ( `Cache miss for formats of handler "${ handler . name } ".` ) ;
165165 await handler . init ( ) ;
166166 if ( handler . supportedFormats ) {
167- supportedFormatCache . set ( handler . name , handler . supportedFormats ) ;
168- console . log ( "Updated supported format cache:" ) ;
169- console . log ( printSupportedFormatCache ( ) ) ;
167+ window . supportedFormatCache . set ( handler . name , handler . supportedFormats ) ;
168+ console . info ( `Updated supported format cache for "${ handler . name } ".` ) ;
170169 }
171170 }
172- const supportedFormats = supportedFormatCache . get ( handler . name ) ;
171+ const supportedFormats = window . supportedFormatCache . get ( handler . name ) ;
173172 if ( ! supportedFormats ) {
174173 console . warn ( `Handler "${ handler . name } " doesn't support any formats.` ) ;
175174 continue ;
@@ -242,9 +241,15 @@ async function buildOptionList () {
242241( async ( ) => {
243242 try {
244243 const cacheJSON = await fetch ( "cache.json" ) . then ( r => r . json ( ) ) ;
245- supportedFormatCache = new Map ( cacheJSON ) ;
244+ window . supportedFormatCache = new Map ( cacheJSON ) ;
245+ } catch {
246+ console . warn (
247+ "Missing supported format precache.\n\n" +
248+ "Consider saving the output of printSupportedFormatCache() to cache.json."
249+ ) ;
246250 } finally {
247- buildOptionList ( ) ;
251+ await buildOptionList ( ) ;
252+ console . log ( "Built initial format list." ) ;
248253 }
249254} ) ( ) ;
250255
@@ -271,7 +276,7 @@ async function attemptConvertPath (files: FileData[], path: ConvertPathNode[]) {
271276 if ( ! handler . ready ) {
272277 await handler . init ( ) ;
273278 if ( handler . supportedFormats ) {
274- supportedFormatCache . set ( handler . name , handler . supportedFormats ) ;
279+ window . supportedFormatCache . set ( handler . name , handler . supportedFormats ) ;
275280 }
276281 }
277282 files = await handler . doConvert ( files , path [ i ] . format , path [ i + 1 ] . format ) ;
@@ -302,7 +307,7 @@ async function buildConvertPath (
302307
303308 // Get handlers that support *taking in* the previous node's format
304309 const validHandlers = handlers . filter ( handler => (
305- supportedFormatCache . get ( handler . name ) ?. some ( format => (
310+ window . supportedFormatCache . get ( handler . name ) ?. some ( format => (
306311 format . mime === previous . format . mime &&
307312 format . from
308313 ) )
@@ -328,7 +333,7 @@ async function buildConvertPath (
328333
329334 // Look for untested mime types among valid handlers and add to queue
330335 for ( const handler of validHandlers ) {
331- const supportedFormats = supportedFormatCache . get ( handler . name ) ;
336+ const supportedFormats = window . supportedFormatCache . get ( handler . name ) ;
332337 if ( ! supportedFormats ) continue ;
333338 for ( const format of supportedFormats ) {
334339 if ( ! format . to ) continue ;
0 commit comments