diff --git a/README.md b/README.md index 2308900..d3497e3 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # amWiki 文库 amWiki是一款基于atom编辑器markdown语法的轻量级wiki文库系统。 -使用amWiki创建文库,仅需要您使用atom编辑markdown文档和支持http静态访问网页空间! +使用amWiki,您无需服务端开发,只需使用atom编辑markdown文档和支持http静态访问网页空间! 传送门:[amWiki项目托管地址](https://github.com/TevinLi/amWiki "amWiki项目托管地址") ### amWiki优势 diff --git a/lib/automatic.js b/lib/automatic.js index 4d23809..957a458 100644 --- a/lib/automatic.js +++ b/lib/automatic.js @@ -31,6 +31,7 @@ module.exports = { //监听用户操作 this.subscriptions = new CompositeDisposable(); this.subscriptions.add(atom.commands.onDidDispatch(function (e) { + //console.log(e.type); //重命名、新增文件夹或文件、创建副本 if (/core\:confirm/.test(e.type) && e.target.className == 'editor mini is-focused') { that.toCheckLib(state); @@ -39,11 +40,13 @@ module.exports = { else if (/tree-view\:(remove|cut|paste)/.test(e.type)) { that.toCheckLib(state); } + //删除项目文件夹 + //tree-view:remove-project-folder })); //拖拽操作监听 atom.packages.activatePackage('tree-view').then(function (pkg) { - that.treeView = pkg.mainModule.treeView; - that.treeViewState = pkg.mainModule.state; + that.treeView = pkg.mainModule.treeView; //目录树主对象 + that.treeState = pkg.mainModule.state; //目录树全局状态 that.treeView[0].addEventListener('drop', function (e) { for (var i = 0; i < e.path.length; i++) { if (e.path[i].className.indexOf('project-root') >= 0) { @@ -60,13 +63,14 @@ module.exports = { lastTimestamp = Date.now(); }); window.addEventListener('focus', function () { + //如果atom插件设置“得到焦点时检查库变化”项处于开启状态 if (atom.config.get('amWiki.checkLibraryOnWindowFocus')) { if (Date.now() - lastTimestamp > 30000) { that.toCheckLib(state); } } }); - //当atom启动时,全量检查文库 + //当atom启动时,如果插件设置“启动时全量检查文库变化”项处于开启状态,全量检查文库 if (atom.config.get('amWiki.checkAllLibraryOnAtomStart')) { for (var l = 0; l < state.libraryList.length; l++) { this.checkLibrary(state, state.libraryList[l]); @@ -76,32 +80,55 @@ module.exports = { //准备检查文库 toCheckLib: function (state, curLibrary, recursive) { var that = this; + //当存在curLibrary参数时,直接检查此文库 if (curLibrary) { this.checkLibrary(state, curLibrary); - } else { - if (this.treeView) { + } + //当不存在curLibrary参数时,尝试获取当前库 + else { + //如果treeView已经准备完毕 + if (this.treeView && this.treeView.selectedPath) { curLibrary = this.treeView.selectedPath.replace(/library(.|\s)*$/, 'library/').replace(/\\/g, '/'); + //如果treeView当前路径包含library if (curLibrary && curLibrary.indexOf('library') >= 0) { this.checkLibrary(state, curLibrary); - } else if (this.treeViewState) { - curLibrary = this.treeViewState.selectedPath.replace(/library(.|\s)*$/, 'library/').replace(/\\/g, '/'); + } + //如果treeView当前路径补/library/字段后,是已存在的wiki + else if (typeof state.libraryMD5[curLibrary + '/library/'] != 'undefined') { + this.checkLibrary(state, curLibrary + '/library/'); + } + //从treeState获取路径 + else if (this.treeState && this.treeState.selectedPath) { + curLibrary = this.treeState.selectedPath.replace(/library(.|\s)*$/, 'library/').replace(/\\/g, '/'); + //如果treeState当前路径包含library if (curLibrary && curLibrary.indexOf('library') >= 0) { this.checkLibrary(state, curLibrary); } + //如果treeState当前路径补/library/字段后,是已存在的wiki + else if (typeof state.libraryMD5[curLibrary + '/library/'] != 'undefined') { + this.checkLibrary(state, curLibrary + '/library/'); + } + //如果treeState当前路径也不匹配,不检查文库更新 } - } else { - //如果treeView未准备完毕,0.1秒后重新检查,且最多只递归3次 + } + //如果treeView未准备完毕,0.2秒后重新检查,且最多只递归3次 + else { setTimeout(function () { recursive = recursive ? recursive + 1 : 1; if (recursive <= 3) { that.toCheckLib(state, curLibrary, recursive); } - }, 100); + }, 200); } } }, //检查文库变化 checkLibrary: function (state, curLibrary) { + curLibrary = curLibrary.split('library/')[0] + 'library/'; + if (typeof state.libraryMD5[curLibrary] == 'undefined') { + return; + } + console.log(curLibrary); //延迟0.1秒,等待系统文件操作完毕再读取 setTimeout(function () { directories.readLibraryDir(curLibrary, function (err, tree, files) { diff --git a/lib/webServer.js b/lib/webServer.js index 135f07a..50cfee0 100644 --- a/lib/webServer.js +++ b/lib/webServer.js @@ -204,8 +204,7 @@ module.exports = { child_process.exec(cmd + ' ' + url); }, //关闭服务器 - destroy: function(){ - this.server.close(); + destroy: function () { + this.server && this.server.close(); } - }; \ No newline at end of file