Refactoring + mise en place store Redux
This commit is contained in:
12
js/util/debug.js
Normal file
12
js/util/debug.js
Normal file
@ -0,0 +1,12 @@
|
||||
var debug = require('debug');
|
||||
var util = require('util');
|
||||
|
||||
module.exports = function createLogger(namespace) {
|
||||
var logger = debug('pitaya:'+namespace);
|
||||
var console = global.window ? global.window.console : global.console;
|
||||
logger.log = function() {
|
||||
var str = util.format.apply(util, arguments);
|
||||
console.log(str);
|
||||
};
|
||||
return logger;
|
||||
};
|
@ -1,6 +1,7 @@
|
||||
var path = require('path');
|
||||
var System = require('./system');
|
||||
var debug = require('debug')('pitaya:desktop-apps');
|
||||
var debug = require('./debug')('desktop-apps');
|
||||
var Cache = require('./cache');
|
||||
|
||||
// Constants
|
||||
var ICON_REALPATH_REGEX = /\..+$/;
|
||||
@ -69,6 +70,8 @@ exports.loadDesktopFile = function(filePath) {
|
||||
return System.loadINIFile(filePath);
|
||||
};
|
||||
|
||||
var iconCache = new Cache();
|
||||
|
||||
/**
|
||||
* Find the absolute path of a desktop icon
|
||||
*
|
||||
@ -77,6 +80,13 @@ exports.loadDesktopFile = function(filePath) {
|
||||
*/
|
||||
exports.findIcon = function(iconName, themeName, size, themeIgnore) {
|
||||
|
||||
var cachedIcon = iconCache.get([iconName, themeName, size]);
|
||||
|
||||
if(cachedIcon) {
|
||||
debug('Icon %s:%s:%s found in cache !', iconName, themeName, size);
|
||||
return Promise.resolve(cachedIcon);
|
||||
}
|
||||
|
||||
themeIgnore = themeIgnore || [];
|
||||
if(themeIgnore.indexOf(themeIgnore) !== -1) {
|
||||
debug('Theme %s already processed, ignoring...', themeName);
|
||||
@ -101,6 +111,7 @@ exports.findIcon = function(iconName, themeName, size, themeIgnore) {
|
||||
.then(exports._selectBestIcon)
|
||||
;
|
||||
})
|
||||
.then(_cacheIcon)
|
||||
;
|
||||
}
|
||||
|
||||
@ -122,8 +133,15 @@ exports.findIcon = function(iconName, themeName, size, themeIgnore) {
|
||||
;
|
||||
|
||||
})
|
||||
.then(_cacheIcon)
|
||||
;
|
||||
|
||||
|
||||
function _cacheIcon(iconPath) {
|
||||
iconCache.set([iconName, themeName, size], iconPath);
|
||||
return iconPath;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
exports.findParentsThemeIcon = function(iconName, themeName, size, themeIgnore) {
|
||||
|
@ -1,3 +1,4 @@
|
||||
exports.System = require('./system');
|
||||
exports.DesktopApps = require('./desktop-apps');
|
||||
exports.Cache = require('./cache');
|
||||
exports.Debug = require('./debug');
|
||||
|
Reference in New Issue
Block a user