TiddlyWiki.org

Ticket #54: ticket54.patch

File ticket54.patch, 2.2 kB (added by UdoBorkowski, 1 year ago)

Patch to fix this ticket, using the "Requires" slice approach

  • js/main.js

    old new  
    106106{ 
    107107        if(safeMode) 
    108108                return false; 
    109         var configTiddlers = store.getTaggedTiddlers("systemConfig"); 
     109        var tiddlers = store.getTaggedTiddlers("systemConfig"); 
     110        var i, n, p, toLoad = [], nLoaded = 0, map = {}, nPlugins = tiddlers.length; 
     111 
    110112        installedPlugins = []; 
    111         var hadProblem = false; 
    112         for(var t=0; t<configTiddlers.length; t++) { 
    113                 tiddler = configTiddlers[t]; 
    114                 pluginInfo = getPluginInfo(tiddler); 
    115                 if(isPluginExecutable(pluginInfo)) { 
    116                         pluginInfo.executed = true; 
    117                         pluginInfo.error = false; 
     113        for(i=0; i<nPlugins; i++) { 
     114                p = installedPlugins[i] = getPluginInfo(tiddlers[i]); 
     115                n = p.Name; 
     116                if(n)  
     117                        map[n] = p; 
     118                if(n = p.Source)  
     119                        map[n] = p; 
     120        } 
     121 
     122        var visit = function(p) { 
     123                if(!p || p.done) return; 
     124                p.done = 1; 
     125                var reqs = p.Requires; 
     126                if(reqs) { 
     127                        reqs = reqs.readBracketedList(); 
     128                        for(var i=0; i<reqs.length; i++) 
     129                                visit(map[reqs[i]]); 
     130                } 
     131                toLoad.push(p); 
     132        }; 
     133         
     134        for(n in map)  
     135                visit(map[n]); 
     136                 
     137        for(i=0; i<toLoad.length; i++) { 
     138                pluginInfo = p = toLoad[i]; 
     139                tiddler = p.tiddler; 
     140                if(isPluginExecutable(p)) { 
     141                        p.executed = true; 
    118142                        try { 
    119                                 if(tiddler.text && tiddler.text != ""
     143                                if(tiddler.text
    120144                                        window.eval(tiddler.text); 
     145                                nLoaded++; 
    121146                        } catch(ex) { 
    122                                 pluginInfo.log.push(config.messages.pluginError.format([exceptionText(ex)])); 
    123                                 pluginInfo.error = true; 
    124                                 hadProblem = true; 
     147                                p.log.push(config.messages.pluginError.format([exceptionText(ex)])); 
     148                                p.error = true; 
    125149                        } 
    126150                } else { 
    127                         pluginInfo.warning = true; 
     151                        p.warning = true; 
    128152                } 
    129                 installedPlugins.push(pluginInfo); 
    130153        } 
    131         return hadProblem; 
     154         
     155        return nLoaded != nPlugins; 
    132156} 
    133157 
    134158function getPluginInfo(tiddler) 
    135159{ 
    136         var p = store.getTiddlerSlices(tiddler.title,["Name","Description","Version","CoreVersion","Date","Source","Author","License","Browsers"]); 
     160        var p = store.getTiddlerSlices(tiddler.title,["Name","Description","Version","Requires","CoreVersion","Date","Source","Author","License","Browsers"]); 
    137161        p.tiddler = tiddler; 
    138162        p.title = tiddler.title; 
    139163        p.log = [];