1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-26 19:47:20 +00:00

Start updating the boot kernel for more node-webkit integration

The goal is to make it possible to use the Node.js boot code under
node-webkit, so that we can directly load wiki folders
This commit is contained in:
Jermolene 2014-01-14 14:09:04 +00:00
parent aefc7b7ce2
commit c7fb0bd349
2 changed files with 33 additions and 12 deletions

View File

@ -38,7 +38,7 @@ $tw.boot = $tw.boot || {};
/////////////////////////// Standard node.js libraries /////////////////////////// Standard node.js libraries
var fs, path, vm; var fs, path, vm;
if(!$tw.browser) { if($tw.node) {
fs = require("fs"); fs = require("fs");
path = require("path"); path = require("path");
vm = require("vm"); vm = require("vm");
@ -1100,7 +1100,7 @@ $tw.modules.define("$:/boot/tiddlerdeserializer/dom","tiddlerdeserializer",{
} }
}); });
$tw.loadTiddlers = function() { $tw.loadTiddlersBrowser = function() {
// In the browser, we load tiddlers from certain elements // In the browser, we load tiddlers from certain elements
var containerIds = [ var containerIds = [
"libraryModules", "libraryModules",
@ -1135,6 +1135,12 @@ $tw.boot.decryptEncryptedTiddlers = function(callback) {
callback(); callback();
}; };
}
/////////////////////////// Node definitions
if($tw.node) {
/* /*
Load the tiddlers contained in a particular file (and optionally extract fields from the accompanying .meta file) returned as {filepath:,type:,tiddlers:[],hasMetaFile:} Load the tiddlers contained in a particular file (and optionally extract fields from the accompanying .meta file) returned as {filepath:,type:,tiddlers:[],hasMetaFile:}
*/ */
@ -1363,7 +1369,7 @@ $tw.loadWikiTiddlers = function(wikiPath,parentPaths) {
return wikiInfo; return wikiInfo;
}; };
$tw.loadTiddlers = function() { $tw.loadTiddlersNode = function() {
// Load the boot tiddlers // Load the boot tiddlers
$tw.utils.each($tw.loadTiddlersFromPath($tw.boot.bootPath),function(tiddlerFile) { $tw.utils.each($tw.loadTiddlersFromPath($tw.boot.bootPath),function(tiddlerFile) {
$tw.wiki.addTiddlers(tiddlerFile.tiddlers); $tw.wiki.addTiddlers(tiddlerFile.tiddlers);
@ -1376,12 +1382,19 @@ $tw.loadTiddlers = function() {
} }
}; };
// End of if(!$tw.browser) // End of if($tw.node)
} }
/////////////////////////// Main startup function called once tiddlers have been decrypted /////////////////////////// Main startup function called once tiddlers have been decrypted
$tw.boot.startup = function() { /*
Startup TiddlyWiki. Options are:
readBrowserTiddlers: whether to read tiddlers from the HTML file we're executing within
readNodeTiddlers: whether to read tiddlers from the file system
wikiFolderPath: the path to the wiki folder in the file system
*/
$tw.boot.startup = function(options) {
options = options || {};
// Initialise some more $tw properties // Initialise some more $tw properties
$tw.utils.deepDefaults($tw,{ $tw.utils.deepDefaults($tw,{
modules: { // Information about each module modules: { // Information about each module
@ -1450,7 +1463,11 @@ $tw.boot.startup = function() {
$tw.Wiki.tiddlerDeserializerModules = {}; $tw.Wiki.tiddlerDeserializerModules = {};
$tw.modules.applyMethods("tiddlerdeserializer",$tw.Wiki.tiddlerDeserializerModules); $tw.modules.applyMethods("tiddlerdeserializer",$tw.Wiki.tiddlerDeserializerModules);
// Load tiddlers // Load tiddlers
$tw.loadTiddlers(); if($tw.browser) {
$tw.loadTiddlersBrowser();
} else {
$tw.loadTiddlersNode();
}
// Unpack plugin tiddlers // Unpack plugin tiddlers
$tw.wiki.registerPluginTiddlers("plugin"); $tw.wiki.registerPluginTiddlers("plugin");
$tw.wiki.unpackPluginTiddlers(); $tw.wiki.unpackPluginTiddlers();
@ -1459,7 +1476,9 @@ $tw.boot.startup = function() {
// And any modules within plugins // And any modules within plugins
$tw.wiki.defineShadowModules(); $tw.wiki.defineShadowModules();
// Make sure the crypto state tiddler is up to date // Make sure the crypto state tiddler is up to date
$tw.crypto.updateCryptoStateTiddler(); if($tw.crypto) {
$tw.crypto.updateCryptoStateTiddler();
}
// Run any startup modules // Run any startup modules
$tw.modules.forEachModuleOfType("startup",function(title,module) { $tw.modules.forEachModuleOfType("startup",function(title,module) {
if(module.startup) { if(module.startup) {
@ -1486,7 +1505,7 @@ $tw.boot.boot = function() {
/////////////////////////// Autoboot in the browser /////////////////////////// Autoboot in the browser
if($tw.browser) { if($tw.browser && !$tw.boot.suppressBoot) {
$tw.boot.boot(); $tw.boot.boot();
} }

View File

@ -16,7 +16,12 @@ var _bootprefix = (function($tw) {
"use strict"; "use strict";
$tw = $tw || {browser: typeof(window) !== "undefined" ? {} : null}; $tw = $tw || {};
// Detect platforms
$tw.browser = typeof(window) !== "undefined" ? {} : null;
$tw.node = typeof(process) === "object" ? {} : null;
$tw.nodeWebKit = $tw.node && global.window && global.window.nwDispatcher ? {} : null;
/* /*
Information about each module is kept in an object with these members: Information about each module is kept in an object with these members:
@ -92,6 +97,3 @@ if(typeof(exports) === "undefined") {
// Export functionality as a module // Export functionality as a module
exports.bootprefix = _bootprefix; exports.bootprefix = _bootprefix;
} }