diff --git a/src/Core/Client.js b/src/Core/Client.js index 61b9b92..1598999 100644 --- a/src/Core/Client.js +++ b/src/Core/Client.js @@ -79,6 +79,7 @@ define(function( require ) var last_tick = Date.now(); var list = []; var i, count; + var temporaryStorage; if (files.length) { // Progressbar @@ -142,12 +143,28 @@ define(function( require ) } } - // Initialize client files (load GRF, etc). - Thread.send( 'CLIENT_INIT', { - files: list, - grfList: Configs.get('grfList') || 'DATA.INI', - save: !!Configs.get('saveFiles') - }, Client.onFilesLoaded ); + // Get temporary storage info at main thread, the worker can't access it. + // https://github.com/vthibault/roBrowser/issues/110 + temporaryStorage = navigator.temporaryStorage || navigator.webkitTemporaryStorage || { + queryUsageAndQuota: function(callback) { + callback(0, 0); + } + }; + + temporaryStorage.queryUsageAndQuota(function(used, remaining) { + var quota = { + used: used, + remaining: remaining + }; + + // Initialize client files (load GRF, etc). + Thread.send( 'CLIENT_INIT', { + files: list, + grfList: Configs.get('grfList') || 'DATA.INI', + save: !!Configs.get('saveFiles'), + quota: quota + }, Client.onFilesLoaded ); + }); } @@ -389,4 +406,4 @@ define(function( require ) }; return Client; -}); \ No newline at end of file +}); diff --git a/src/Core/FileSystem.js b/src/Core/FileSystem.js index 2d07092..39c4f9b 100644 --- a/src/Core/FileSystem.js +++ b/src/Core/FileSystem.js @@ -67,8 +67,9 @@ define(function() * * @param {Array} FileList * @param {boolean} save files + * @param {Object} quota information */ - function init( files, save ) + function init( files, save, quota ) { var requestFileSystemSync, requestFileSystem, temporaryStorage; _files = normalizeFilesPath(files); @@ -82,26 +83,22 @@ define(function() requestFileSystemSync = self.requestFileSystemSync || self.webkitRequestFileSystemSync; requestFileSystem = self.requestFileSystem || self.webkitRequestFileSystem; - temporaryStorage = navigator.temporaryStorage || navigator.webkitTemporaryStorage; - temporaryStorage.queryUsageAndQuota(function(used, remaining){ - var size = _clientSize || used || remaining; + var size = _clientSize || quota.used || quota.remaining; - requestFileSystem( self.TEMPORARY, size, function( fs ){ - _fs = fs; - _fs_sync = requestFileSystemSync( self.TEMPORARY, size ); + requestFileSystem( self.TEMPORARY, size, function( fs ){ + _fs = fs; + _fs_sync = requestFileSystemSync( self.TEMPORARY, size ); - if (save && _files.length) { - cleanUp(); - buildHierarchy(); - processUpload(0); - } - - _save = save; - trigger('onready'); - }, errorHandler); + if (save && _files.length) { + cleanUp(); + buildHierarchy(); + processUpload(0); + } - }); + _save = save; + trigger('onready'); + }, errorHandler); } @@ -485,4 +482,4 @@ define(function() search: search, saveFile: saveFile }; -}); \ No newline at end of file +}); diff --git a/src/Core/ThreadEventHandler.js b/src/Core/ThreadEventHandler.js index 01a763a..f9b517e 100644 --- a/src/Core/ThreadEventHandler.js +++ b/src/Core/ThreadEventHandler.js @@ -93,7 +93,7 @@ function( FileManager, FileSystem, MapLoader ) }); // Saving full client - FileSystem.init( msg.data.files, msg.data.save ); + FileSystem.init( msg.data.files, msg.data.save, msg.data.quota ); break; // Files alias @@ -177,4 +177,4 @@ function( FileManager, FileSystem, MapLoader ) * Once the thread is ready */ postMessage({ type: 'THREAD_READY' }); -}); \ No newline at end of file +});