Skip to content

Commit

Permalink
Merge pull request vthibault#111 from vthibault/fix-queryUsageAndQuota
Browse files Browse the repository at this point in the history
Fix #110, moved queryUsageAndQuota from worker thread
  • Loading branch information
herenow committed Jan 29, 2015
2 parents d63ae85 + fcdd79e commit 14796c9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 27 deletions.
31 changes: 24 additions & 7 deletions src/Core/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ define(function( require )
var last_tick = Date.now();
var list = [];
var i, count;
var temporaryStorage;

if (files.length) {
// Progressbar
Expand Down Expand Up @@ -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 );
});
}


Expand Down Expand Up @@ -389,4 +406,4 @@ define(function( require )
};

return Client;
});
});
33 changes: 15 additions & 18 deletions src/Core/FileSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}


Expand Down Expand Up @@ -485,4 +482,4 @@ define(function()
search: search,
saveFile: saveFile
};
});
});
4 changes: 2 additions & 2 deletions src/Core/ThreadEventHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -177,4 +177,4 @@ function( FileManager, FileSystem, MapLoader )
* Once the thread is ready
*/
postMessage({ type: 'THREAD_READY' });
});
});

0 comments on commit 14796c9

Please sign in to comment.