var protocol = require('protocol'); var File = require('file_main'); var leanoteProtocol = { destroy: function (callback) { protocol.unregisterProtocol('leanote', function () { callback(); }); }, init: function () { // 先注销, 为了防止刷新 // this.destroy(funciton () { protocol.registerFileProtocol('leanote', function(request, callback) { // console.log(request.url); var url = request.url; var ret = /fileId=([a-zA-Z0-9]{24})/.exec(url); if (ret && ret[1]) { var fileId = ret[1]; // console.log(fileId); File.getImage(ret[1], function(fileLocalPath) { if(fileLocalPath) { callback({path: fileLocalPath}); } else { callback(); } }); } // var url = request.url.substr(7); // callback({path: '/Users/life/Desktop/newicon/blog@2x.png'}); }, function (error) { if (error) { console.error('Failed to register protocol') console.error(error); } }); // }); } } module.exports = leanoteProtocol;