More WIP component indexing

This commit is contained in:
David Baker 2015-11-30 17:33:04 +00:00
parent 4a144ac03d
commit 730b33535a
4 changed files with 137 additions and 74 deletions

View file

@ -38,8 +38,9 @@
"//depsbuglink": "https://github.com/webpack/webpack/issues/1472",
"devDependencies": {
"babel": "^5.8.23",
"rimraf": "^2.4.3",
"json-loader": "^0.5.3",
"require-json": "0.0.1",
"rimraf": "^2.4.3",
"source-map-loader": "^0.1.5"
}
}

View file

@ -8,40 +8,13 @@ var args = require('optimist').argv;
var header = args.h || args.header;
if (args._.length == 0) {
console.log("No skin given");
process.exit(1);
}
var componenetsDir = path.join('src', 'components');
var skin = args._[0];
var componentIndex = path.join('src', 'component-index.js');
try {
fs.accessSync(path.join('src', 'skins', skin), fs.F_OK);
} catch (e) {
console.log("Skin "+skin+" not found: "+e);
process.exit(1);
}
var packageJson = JSON.parse(fs.readFileSync('./package.json'));
var skinfoFile = path.join('src', 'skins', skin, 'skinfo.json');
try {
fs.accessSync(skinfoFile, fs.F_OK);
} catch (e) {
console.log("Skin "+skin+" has no skinfo.json");
process.exit(1);
}
try {
fs.accessSync(path.join('src', 'skins', skin, 'views'), fs.F_OK);
} catch (e) {
console.log("Skin "+skin+" has no views directory");
process.exit(1);
}
var skindex = path.join('src', 'skins', skin, 'skindex.js');
var viewsDir = path.join('src', 'skins', skin, 'views');
var strm = fs.createWriteStream(skindex);
var strm = fs.createWriteStream(componentIndex);
if (header) {
strm.write(fs.readFileSync(header));
@ -55,28 +28,38 @@ strm.write(" * so you'd just be trying to swim upstream like a salmon.\n");
strm.write(" * You are not a salmon.\n");
strm.write(" */\n\n");
var mySkinfo = JSON.parse(fs.readFileSync(skinfoFile, "utf8"));
if (packageJson['matrix-react-parent']) {
strm.write("module.exports.components = require('"+packageJson['matrix-react-parent']+"/lib/component-index').components;\n\n");
} else {
strm.write("module.exports.components = {};\n");
}
strm.write("var skin = {};\n");
strm.write('\n');
var files = glob.sync('**/*.js', {cwd: viewsDir});
var files = glob.sync('**/*.js', {cwd: componenetsDir});
for (var i = 0; i < files.length; ++i) {
var file = files[i].replace('.js', '');
var module = (file.replace(/\//g, '.'));
strm.write("skin['"+module+"'] = require('./views/"+file+"');\n");
strm.write("module.exports.components['"+module+"'] = require('./components/"+file+"');");
strm.write('\n');
strm.uncork();
}
strm.write("\n");
// Temporary Vector transition
var vectorViewsPath = path.join('src', 'skins', 'vector', 'views');
if (fs.existsSync(vectorViewsPath)) {
strm.write('\n');
strm.write('// Old, unported Vector views:\n');
var files = glob.sync('**/*.js', {cwd: vectorViewsPath});
for (var i = 0; i < files.length; ++i) {
var file = files[i].replace('.js', '');
if (mySkinfo.baseSkin) {
strm.write("module.exports = require('"+mySkinfo.baseSkin+"');");
strm.write("var extend = require('matrix-react-sdk/lib/extend');\n");
strm.write("extend(module.exports, skin);\n");
} else {
strm.write("module.exports = skin;");
var module = (file.replace(/\//g, '.'));
strm.write("module.exports.components['"+module+"'] = require('./skins/vector/views/"+file+"');");
strm.write('\n');
strm.uncork();
}
}
strm.end();

View file

@ -18,6 +18,7 @@ limitations under the License.
var q = require('q');
var extend = require('./extend');
var dis = require('./dispatcher');
function infoForImageFile(imageFile) {
var deferred = q.defer();
@ -48,7 +49,13 @@ function infoForImageFile(imageFile) {
return deferred.promise;
}
function sendContentToRoom(file, roomId, matrixClient) {
class ContentMessages {
constructor() {
this.inprogress = [];
this.nextId = 0;
}
sendContentToRoom(file, roomId, matrixClient) {
var content = {
body: file.name,
info: {
@ -73,14 +80,63 @@ function sendContentToRoom(file, roomId, matrixClient) {
def.resolve();
}
var upload = {
fileName: file.name,
roomId: roomId,
total: 0,
loaded: 0
};
this.inprogress.push(upload);
dis.dispatch({action: 'upload_started'});
var self = this;
return def.promise.then(function() {
return matrixClient.uploadContent(file);
upload.promise = matrixClient.uploadContent(file);
return upload.promise;
}).then(function(url) {
content.url = url;
return matrixClient.sendMessage(roomId, content);
}).progress(function(ev) {
if (ev) {
upload.total = ev.total;
upload.loaded = ev.loaded;
dis.dispatch({action: 'upload_progress', upload: upload});
}
}).then(function() {
dis.dispatch({action: 'upload_finished', upload: upload});
}, function(err) {
dis.dispatch({action: 'upload_failed', upload: upload});
}).finally(function() {
var inprogressKeys = Object.keys(self.inprogress);
for (var i = 0; i < self.inprogress.length; ++i) {
var k = inprogressKeys[i];
if (self.inprogress[k].promise === upload_promise) {
delete self.inprogress[k];
break;
}
}
});
}
module.exports = {
sendContentToRoom: sendContentToRoom
};
getCurrentUploads() {
return this.inprogress;
}
cancelUpload(promise) {
var inprogressKeys = Object.keys(self.inprogress);
for (var i = 0; i < self.inprogress.length; ++i) {
var k = inprogressKeys[i];
if (self.inprogress[k].promise === promise) {
self.inprogress[k].canceled = true;
break;
}
}
MatrixClientPeg.get().cancelUpload(promise);
}
}
if (global.mx_ContentMessage === undefined) {
global.mx_ContentMessage = new ContentMessages();
}
module.exports = global.mx_ContentMessage;

View file

@ -32,6 +32,11 @@ class Skinner {
if (comp) {
return comp;
}
// XXX
var comp = this.components['views.'+name];
if (comp) {
return comp;
}
throw new Error("No such component: "+name);
}
@ -42,7 +47,25 @@ class Skinner {
"If you want to change the active skin, call resetSkin first"
);
}
this.components = skinObject;
this.components = {};
var compKeys = Object.keys(skinObject.components);
for (var i = 0; i < compKeys.length; ++i) {
var comp = skinObject.components[compKeys[i]];
this.addComponent(compKeys[i], comp);
}
}
addComponent(name, comp) {
var slot = name;
if (comp.replaces !== undefined) {
if (comp.replaces.indexOf('.') > -1) {
slot = comp.replaces;
} else {
slot = name.substr(0, name.lastIndexOf('.') + 1) + comp.replaces.split('.').pop();
}
}
console.log(slot+" = "+name);
this.components[slot] = comp;
}
reset() {