From f5903b55bbb2903912b34bb9c85cc71de7f6a403 Mon Sep 17 00:00:00 2001 From: chaos Date: Sun, 28 Jun 2020 11:00:33 +0800 Subject: [PATCH] fix compatibilies with electron9 for plugins --- main.js | 1 + node_modules/pdf_main.js | 27 +++- public/plugins/export_evernote/plugin.js | 17 +- public/plugins/export_html/plugin.js | 16 +- public/plugins/export_leanote/plugin.js | 17 +- public/plugins/export_pdf/plugin.js | 194 ++++++++++++----------- public/plugins/import_evernote/plugin.js | 108 +++++++------ public/plugins/import_html/plugin.js | 113 +++++++------ public/plugins/import_leanote/plugin.js | 109 +++++++------ 9 files changed, 362 insertions(+), 240 deletions(-) diff --git a/main.js b/main.js index f8ed482a..21fa54d5 100644 --- a/main.js +++ b/main.js @@ -204,6 +204,7 @@ function openIt() { height: 595, frame: process.platform != 'darwin', transparent: false, + autoHideMenuBar: true, webPreferences: { nodeIntegration: true } diff --git a/node_modules/pdf_main.js b/node_modules/pdf_main.js index f24d4087..e8adfe99 100644 --- a/node_modules/pdf_main.js +++ b/node_modules/pdf_main.js @@ -15,11 +15,7 @@ var exportPdf = { win.webContents.on('did-finish-load', function() { console.log('load ok'); setTimeout(function() { - win.webContents.printToPDF({ - printBackground: true, - landscape: false, - pageSize: 'A4' - }, function(err, data) { + var callback = function(err, data) { fs.writeFile(targetPdfPath, data, function(err) { if (err) { callbcak(false); @@ -29,7 +25,26 @@ var exportPdf = { } // win.close(); }); - }) + }; + var po = win.webContents.printToPDF({ + printBackground: true, + landscape: false, + pageSize: 'A4' + }, + callbcak + ); + + if(typeof(po) != "object"){ + return; + } + + po.then(data => { + callback(null, data); + } + ).catch( err => { + callback(err, null); + } + ); }, isMarkdown ? 1000 : 100); }); diff --git a/public/plugins/export_evernote/plugin.js b/public/plugins/export_evernote/plugin.js index 7de6880d..ccb45c9e 100644 --- a/public/plugins/export_evernote/plugin.js +++ b/public/plugins/export_evernote/plugin.js @@ -405,7 +405,7 @@ define(function() { getTargetPath: function(callback) { // showSaveDialog 不支持property选择文件夹 - Api.gui.dialog.showOpenDialog(Api.gui.getCurrentWindow(), + var po = Api.gui.dialog.showOpenDialog(Api.gui.getCurrentWindow(), { defaultPath: Api.gui.app.getPath('userDesktop') + '/', properties: ['openDirectory'] @@ -414,6 +414,21 @@ define(function() { callback(targetPath); } ); + + if(typeof(po) != "object"){ + return; + } + + po.then(function(re){ + if(re.canceled !== false || re.filePaths.length < 1){ + return; + } + callback(re.filePaths[0]); + }, + function(err){ + alert(err); + } + ); }, loadingIsClosed: false, diff --git a/public/plugins/export_html/plugin.js b/public/plugins/export_html/plugin.js index aa827a18..897eb75f 100644 --- a/public/plugins/export_html/plugin.js +++ b/public/plugins/export_html/plugin.js @@ -185,7 +185,7 @@ define(function() { getTargetPath: function(callback) { // showSaveDialog 不支持property选择文件夹 - Api.gui.dialog.showOpenDialog(Api.gui.getCurrentWindow(), + var po = Api.gui.dialog.showOpenDialog(Api.gui.getCurrentWindow(), { defaultPath: Api.gui.app.getPath('userDesktop') + '/', properties: ['openDirectory'] @@ -194,6 +194,20 @@ define(function() { callback(targetPath); } ); + if(typeof(po) != "object"){ + return; + } + + po.then(function(re){ + if(re.canceled !== false || re.filePaths.length < 1){ + return; + } + callback(re.filePaths[0]); + }, + function(err){ + alert(err); + } + ); }, loadingIsClosed: false, diff --git a/public/plugins/export_leanote/plugin.js b/public/plugins/export_leanote/plugin.js index d506a7df..e84c67b6 100644 --- a/public/plugins/export_leanote/plugin.js +++ b/public/plugins/export_leanote/plugin.js @@ -419,7 +419,7 @@ define(function() { getTargetPath: function(callback) { // showSaveDialog 不支持property选择文件夹 - Api.gui.dialog.showOpenDialog(Api.gui.getCurrentWindow(), + var po = Api.gui.dialog.showOpenDialog(Api.gui.getCurrentWindow(), { defaultPath: Api.gui.app.getPath('userDesktop') + '/', properties: ['openDirectory'] @@ -428,6 +428,21 @@ define(function() { callback(targetPath); } ); + + if(typeof(po) != "object"){ + return; + } + + po.then(function(re){ + if(re.canceled !== false || re.filePaths.length < 1){ + return; + } + callback(re.filePaths[0]); + }, + function(err){ + alert(err); + } + ); }, loadingIsClosed: false, diff --git a/public/plugins/export_pdf/plugin.js b/public/plugins/export_pdf/plugin.js index ee5bffb4..3a215e74 100644 --- a/public/plugins/export_pdf/plugin.js +++ b/public/plugins/export_pdf/plugin.js @@ -4,7 +4,7 @@ * 选择目录, 将图片保存到文件夹中, 有个html文件(以笔记名命名) * 注意, fs.existsSync总返回false, readFileSync可用 */ -define(function() { +define(function () { var async; // = require('async'); var exportPDF = { @@ -40,7 +40,7 @@ define(function() { }, _inited: false, - init: function() { + init: function () { var me = this; if (me._inited) { return; @@ -56,7 +56,7 @@ define(function() { _initExportPdf: function () { var me = this; // console.log('_initExportPdf'); - Api.ipc.on('export-pdf-ret', function(event, arg) { + Api.ipc.on('export-pdf-ret', function (event, arg) { var seq = arg.seq; // console.log('export-pdf-ret'); // console.log(arg); @@ -66,22 +66,22 @@ define(function() { } }); }, - exportPdf: function (htmlPath, targetPdfPath, isMarkdown, callback) { - this._exportPdfSeq++; - this._exportPdfCallback[this._exportPdfSeq] = callback; - Api.ipc.send('export-pdf', - {htmlPath: htmlPath, targetPdfPath: targetPdfPath, isMarkdown: isMarkdown, seq: this._exportPdfSeq}); - }, + exportPdf: function (htmlPath, targetPdfPath, isMarkdown, callback) { + this._exportPdfSeq++; + this._exportPdfCallback[this._exportPdfSeq] = callback; + Api.ipc.send('export-pdf', + { htmlPath: htmlPath, targetPdfPath: targetPdfPath, isMarkdown: isMarkdown, seq: this._exportPdfSeq }); + }, - getPluginPath: function() { - return Api.evtService.getProjectBasePath() + '/public/plugins/export_pdf' ; + getPluginPath: function () { + return Api.evtService.getProjectBasePath() + '/public/plugins/export_pdf'; }, htmlTpl: '', markdownTpl: '', - getTpl: function(isMarkdown) { + getTpl: function (isMarkdown) { var tpl = isMarkdown ? this.markdownTpl : this.htmlTpl; - if(tpl) { + if (tpl) { return tpl; } var basePluginPath = this.getPluginPath(); @@ -93,7 +93,7 @@ define(function() { return tpl; }, // 生成html或markdown - render: function(note) { + render: function (note) { var tpl = this.getTpl(note.IsMarkdown); var title = note.Title || getMsg('Untitled'); tpl = tpl.replace(/\{title\}/g, title); @@ -103,24 +103,24 @@ define(function() { return tpl; }, - replaceAll: function(src, pattern, to) { - if(!src) { + replaceAll: function (src, pattern, to) { + if (!src) { return src; } - while(true) { + while (true) { var oldSrc = src; src = src.replace(pattern, to); - if(oldSrc === src) { + if (oldSrc === src) { return src; } } }, - fixFilename: function(filename) { + fixFilename: function (filename) { var reg = new RegExp("/|#|\\$|!|\\^|\\*|'| |\"|%|&|\\(|\\)|\\+|\\,|/|:|;|<|>|=|\\?|@|\\||\\\\", 'g'); filename = filename.replace(reg, "-"); // 防止出现两个连续的- - while(filename.indexOf('--') != -1) { + while (filename.indexOf('--') != -1) { filename = this.replaceAll(filename, '--', '-'); } if (filename.length > 1) { @@ -131,36 +131,50 @@ define(function() { }, // 得到可用的文件名, 避免冲突 - getPdfFilePath: function(pathInfo, n, cb) { + getPdfFilePath: function (pathInfo, n, cb) { var me = this; - if(n > 1) { - pathInfo.nameNotExt = pathInfo.nameNotExtRaw + '-' + n; + if (n > 1) { + pathInfo.nameNotExt = pathInfo.nameNotExtRaw + '-' + n; } var absPath = pathInfo.getFullPath(); // Api.nodeFs.existsSync(absPath) 总是返回false, 不知道什么原因 // 在控制台上是可以的 - Api.nodeFs.exists(absPath, function(exists) { - if(!exists) { + Api.nodeFs.exists(absPath, function (exists) { + if (!exists) { cb(absPath); } else { - me.getPdfFilePath(pathInfo, n+1, cb); + me.getPdfFilePath(pathInfo, n + 1, cb); } }); }, - getTargetPath: function(callback) { + getTargetPath: function (callback) { // showSaveDialog 不支持property选择文件夹 - Api.gui.dialog.showOpenDialog(Api.gui.getCurrentWindow(), + var po = Api.gui.dialog.showOpenDialog(Api.gui.getCurrentWindow(), { defaultPath: Api.gui.app.getPath('userDesktop') + '/', properties: ['openDirectory'] - }, - function(targetPath) { + }, + function (targetPath) { callback(targetPath); } ); + if(typeof(po) != "object"){ + return; + } + + po.then(function(re){ + if(re.canceled !== false || re.filePaths.length < 1){ + return; + } + callback(re.filePaths[0]); + }, + function(err){ + alert(err); + } + ); }, loadingIsClosed: false, @@ -170,25 +184,26 @@ define(function() { if (!notebookId) { return; } - me.getTargetPath(function(targetPath) { + me.getTargetPath(function (targetPath) { if (!targetPath) { return; } me.loadingIsClosed = false; - Api.loading.show(Api.getMsg('plugin.export_pdf.Exporting'), + Api.loading.show(Api.getMsg('plugin.export_pdf.Exporting'), { - hasProgress: true, + hasProgress: true, isLarge: true, onClose: function () { me.loadingIsClosed = true; - setTimeout(function() { + setTimeout(function () { me.hideLoading(); - }); - }}); + }); + } + }); Api.loading.setProgress(1); - Api.noteService.getNotes(notebookId, function(notes) { + Api.noteService.getNotes(notebookId, function (notes) { if (!notes) { me.hideLoading(); return; @@ -196,7 +211,7 @@ define(function() { var total = notes.length; var i = 0; - async.eachSeries(notes, function(note, cb) { + async.eachSeries(notes, function (note, cb) { if (me.loadingIsClosed) { cb(); me.hideLoading(); @@ -204,12 +219,12 @@ define(function() { } i++; Api.loading.setProgress(100 * i / total); - me._exportPDF(note, targetPath, function() { + me._exportPDF(note, targetPath, function () { cb(); - }, i, total); - }, function() { + }, i, total); + }, function () { me.hideLoading(); - Notify.show({title: 'Info', body: getMsg('plugin.export_pdf.exportSuccess')}); + Notify.show({ title: 'Info', body: getMsg('plugin.export_pdf.exportSuccess') }); }); }); }); @@ -226,28 +241,29 @@ define(function() { if (!noteIds || noteIds.length == 0) { return; } - me.getTargetPath(function(targetPath) { + me.getTargetPath(function (targetPath) { if (!targetPath) { return; } me.loadingIsClosed = false; - Api.loading.show(Api.getMsg('plugin.export_pdf.Exporting'), + Api.loading.show(Api.getMsg('plugin.export_pdf.Exporting'), { - hasProgress: true, + hasProgress: true, isLarge: true, onClose: function () { me.loadingIsClosed = true; - setTimeout(function() { + setTimeout(function () { me.hideLoading(); - }); - }}); + }); + } + }); Api.loading.setProgress(1); var i = 0; var total = noteIds.length; - async.eachSeries(noteIds, function(noteId, cb) { + async.eachSeries(noteIds, function (noteId, cb) { if (me.loadingIsClosed) { cb(); return; @@ -255,30 +271,30 @@ define(function() { i++; Api.loading.setProgress(100 * i / total); - Api.noteService.getNote(noteId, function(note) { + Api.noteService.getNote(noteId, function (note) { - me._exportPDF(note, targetPath, function(ok) { - cb(); - }, i, total); - }); + me._exportPDF(note, targetPath, function (ok) { + cb(); + }, i, total); + }); }, function () { me.hideLoading(); - Notify.show({title: 'Info', body: getMsg('plugin.export_pdf.exportSuccess')}); + Notify.show({ title: 'Info', body: getMsg('plugin.export_pdf.exportSuccess') }); }); }); }, - _exportPDF: function(note, path, callback, i, total) { + _exportPDF: function (note, path, callback, i, total) { var me = this; setTimeout(function () { me._exportPDF(note, path, callback, i, total); }, 1000); }, - _exportPDF: function(note, path, callback, i, total) { + _exportPDF: function (note, path, callback, i, total) { var me = this; - if(!note) { + if (!note) { return; } @@ -304,12 +320,12 @@ define(function() { pathInfo.nameNotExtRaw = pathInfo.nameNotExt; // 得到可用文件的绝对路径 - me.getPdfFilePath(pathInfo, 1, function(absPdfFilePath) { + me.getPdfFilePath(pathInfo, 1, function (absPdfFilePath) { // 得到存放assets的目录 var html = me.render(note); var tempPath = Api.gui.app.getPath('temp'); - var last = tempPath[tempPath.length-1]; - if ( last == '/' || last == '\\') { + var last = tempPath[tempPath.length - 1]; + if (last == '/' || last == '\\') { tempPath = tempPath.substr(0, tempPath.length - 1); } var targetHtmlPath = tempPath + '/' + (new Date().getTime()) + '.html'; @@ -324,42 +340,42 @@ define(function() { }, // 打开前要执行的 - onOpen: function() { + onOpen: function () { var me = this; var gui = Api.gui; - var menu = { - label: Api.getMsg('plugin.export_pdf.export'), - enabled: function(noteIds) { - return true; - }, - click: (function() { - return function(noteIds) { - me.init(); - me.exportPDF(noteIds); - } - })() - }; - Api.addExportMenu(menu); + var menu = { + label: Api.getMsg('plugin.export_pdf.export'), + enabled: function (noteIds) { + return true; + }, + click: (function () { + return function (noteIds) { + me.init(); + me.exportPDF(noteIds); + } + })() + }; + Api.addExportMenu(menu); - Api.addExportMenuForNotebook({ - label: Api.getMsg('plugin.export_pdf.export'), - enabled: function(notebookId) { - return true; - }, - click: (function() { - return function(notebookId) { - me.init(); - me.exportPDFForNotebook(notebookId); - } - })() - }); + Api.addExportMenuForNotebook({ + label: Api.getMsg('plugin.export_pdf.export'), + enabled: function (notebookId) { + return true; + }, + click: (function () { + return function (notebookId) { + me.init(); + me.exportPDFForNotebook(notebookId); + } + })() + }); }, // 打开后 - onOpenAfter: function() { + onOpenAfter: function () { }, // 关闭时需要运行的 - onClose: function() { + onClose: function () { } }; diff --git a/public/plugins/import_evernote/plugin.js b/public/plugins/import_evernote/plugin.js index 987ef410..0a16fc2e 100644 --- a/public/plugins/import_evernote/plugin.js +++ b/public/plugins/import_evernote/plugin.js @@ -118,61 +118,77 @@ define(function() { // 导入, 选择文件 $('#chooseEvernoteFile').click(function() { + var callback = function(paths) { + if(!paths) { + return; + } - Api.gui.dialog.showOpenDialog(Api.gui.getCurrentWindow(), + var notebookId = me._curNotebook.NotebookId; + + var n = 0; + + me.clear(); + if (!importService) { + importService = nodeRequire('./public/plugins/import_evernote/import'); + } + + importService.importFromEvernote(notebookId, paths, + // 全局 + function(ok) { + // $('#importEvernoteMsg .curImportFile').html(""); + // $('#importEvernoteMsg .curImportNote').html(""); + setTimeout(function() { + $('#importEvernoteMsg .allImport').html(me.getMsg('Done! %s notes imported!', n)); + }, 500); + }, + // 单个文件 + function(ok, filename) { + if(ok) { + $('#importEvernoteMsg .curImportFile').html(me.getMsg("Import file: %s Success!", filename)); + } else { + $('#importEvernoteMsg .curImportFile').html(me.getMsg("Import file: %s Failure, is evernote file ?", filename)); + } + }, + // 单个笔记 + function(note) { + if(note) { + n++; + $('#importEvernoteMsg .curImportNote').html(me.getMsg("Import: %s Success!", note.Title)); + + // 不要是新的, 不然切换笔记时又会保存一次 + note.IsNew = false; + // 插入到当前笔记中 + Note.addSync([note]); + } + } + ); + }; + + var po = Api.gui.dialog.showOpenDialog(Api.gui.getCurrentWindow(), { properties: ['openFile', 'multiSelections'], filters: [ { name: 'Evernote', extensions: ['enex'] } ] }, - function(paths) { - if(!paths) { - return; - } - - var notebookId = me._curNotebook.NotebookId; - - var n = 0; - - me.clear(); - if (!importService) { - importService = nodeRequire('./public/plugins/import_evernote/import'); - } - - importService.importFromEvernote(notebookId, paths, - // 全局 - function(ok) { - // $('#importEvernoteMsg .curImportFile').html(""); - // $('#importEvernoteMsg .curImportNote').html(""); - setTimeout(function() { - $('#importEvernoteMsg .allImport').html(me.getMsg('Done! %s notes imported!', n)); - }, 500); - }, - // 单个文件 - function(ok, filename) { - if(ok) { - $('#importEvernoteMsg .curImportFile').html(me.getMsg("Import file: %s Success!", filename)); - } else { - $('#importEvernoteMsg .curImportFile').html(me.getMsg("Import file: %s Failure, is evernote file ?", filename)); - } - }, - // 单个笔记 - function(note) { - if(note) { - n++; - $('#importEvernoteMsg .curImportNote').html(me.getMsg("Import: %s Success!", note.Title)); - - // 不要是新的, 不然切换笔记时又会保存一次 - note.IsNew = false; - // 插入到当前笔记中 - Note.addSync([note]); - } - } - ); - } + callback ); + if(typeof(po) != "object"){ + return; + } + + po.then( + function(re){ + if(re.canceled !== false || re.filePaths.length < 1){ + return; + } + callback(re.filePaths); + }, + function(err){ + alert(err); + } + ); }); }, diff --git a/public/plugins/import_html/plugin.js b/public/plugins/import_html/plugin.js index a37e6bf0..c3c9b2cc 100644 --- a/public/plugins/import_html/plugin.js +++ b/public/plugins/import_html/plugin.js @@ -118,63 +118,78 @@ define(function() { // 导入, 选择文件 $('#chooseHTMLFile').click(function() { + var callback = function(paths) { + if(!paths) { + return; + } - Api.gui.dialog.showOpenDialog(Api.gui.getCurrentWindow(), + var notebookId = me._curNotebook.NotebookId; + + var n = 0; + + me.clear(); + if (!importService) { + importService = nodeRequire('./public/plugins/import_html/import'); + } + + importService.importFromHTML(notebookId, paths, + // 全局 + function(ok) { + // $('#importHTMLMsg .curImportFile').html(""); + // $('#importHTMLMsg .curImportNote').html(""); + setTimeout(function() { + $('#importHTMLMsg .allImport').html(me.getMsg('Done! %s notes imported!', n)); + }, 500); + }, + // 单个文件 + function(ok, filename) { + if(ok) { + $('#importHTMLMsg .curImportFile').html(me.getMsg("Import file: %s Success!", filename)); + } else { + $('#importHTMLMsg .curImportFile').html(me.getMsg("Import file: %s Failure, is html file ?", filename)); + } + }, + // 单个笔记 + function(note) { + if(note) { + n++; + $('#importHTMLMsg .curImportNote').html(me.getMsg("Import: %s Success!", note.Title)); + + // 不要是新的, 不然切换笔记时又会保存一次 + note.IsNew = false; + // 插入到当前笔记中 + Note.addSync([note]); + } + } + ); + }; + + var po = Api.gui.dialog.showOpenDialog(Api.gui.getCurrentWindow(), { properties: ['openFile', 'multiSelections'], filters: [ { name: 'HTML', extensions: ['html'] } ] - }, - function(paths) { - if(!paths) { - return; - } - - var notebookId = me._curNotebook.NotebookId; - - var n = 0; - - me.clear(); - if (!importService) { - importService = nodeRequire('./public/plugins/import_html/import'); - } - - importService.importFromHTML(notebookId, paths, - // 全局 - function(ok) { - // $('#importHTMLMsg .curImportFile').html(""); - // $('#importHTMLMsg .curImportNote').html(""); - setTimeout(function() { - $('#importHTMLMsg .allImport').html(me.getMsg('Done! %s notes imported!', n)); - }, 500); - }, - // 单个文件 - function(ok, filename) { - if(ok) { - $('#importHTMLMsg .curImportFile').html(me.getMsg("Import file: %s Success!", filename)); - } else { - $('#importHTMLMsg .curImportFile').html(me.getMsg("Import file: %s Failure, is html file ?", filename)); - } - }, - // 单个笔记 - function(note) { - if(note) { - n++; - $('#importHTMLMsg .curImportNote').html(me.getMsg("Import: %s Success!", note.Title)); - - // 不要是新的, 不然切换笔记时又会保存一次 - note.IsNew = false; - // 插入到当前笔记中 - Note.addSync([note]); - } - } - ); } - ); + , callback + ); + if(typeof(po) != "object"){ + return; + } - }); - }, + po.then( + function(re){ + if(re.canceled !== false || re.filePaths.length < 1){ + return; + } + callback(re.filePaths); + }, + function(err){ + alert(err); + } + ); + }); + }, clear: function() { $('#importHTMLMsg .curImportFile').html(""); diff --git a/public/plugins/import_leanote/plugin.js b/public/plugins/import_leanote/plugin.js index a574005e..bc23f346 100644 --- a/public/plugins/import_leanote/plugin.js +++ b/public/plugins/import_leanote/plugin.js @@ -118,63 +118,78 @@ define(function() { // 导入, 选择文件 $('#chooseLeanoteFile').click(function() { + var callback = function(paths) { - Api.gui.dialog.showOpenDialog(Api.gui.getCurrentWindow(), + if(!paths) { + return; + } + + var notebookId = me._curNotebook.NotebookId; + + var n = 0; + + me.clear(); + + if (!importService) { + importService = nodeRequire('./public/plugins/import_leanote/import'); + } + + importService.importFromLeanote(notebookId, paths, + // 全局 + function(ok) { + // $('#importLeanoteMsg .curImportFile').html(""); + // $('#importLeanoteMsg .curImportNote').html(""); + setTimeout(function() { + $('#importLeanoteMsg .allImport').html(me.getMsg('Done! %s notes imported!', n)); + }, 500); + }, + // 单个文件 + function(ok, filename) { + if(ok) { + $('#importLeanoteMsg .curImportFile').html(me.getMsg("Import file: %s Success!", filename)); + } else { + $('#importLeanoteMsg .curImportFile').html(me.getMsg("Import file: %s Failure, is leanote file ?", filename)); + } + }, + // 单个笔记 + function(note) { + if(note) { + n++; + $('#importLeanoteMsg .curImportNote').html(me.getMsg("Import: %s Success!", note.Title)); + + // 不要是新的, 不然切换笔记时又会保存一次 + note.IsNew = false; + + // 插入到当前笔记中 + Note.addSync([note]); + } + } + ); + } + var po = Api.gui.dialog.showOpenDialog(Api.gui.getCurrentWindow(), { properties: ['openFile', 'multiSelections'], filters: [ { name: 'Leanote', extensions: ['leanote'] } ] }, - function(paths) { - if(!paths) { - return; - } + callback + ); + if(typeof(po) != "object"){ + return; + } - var notebookId = me._curNotebook.NotebookId; - - var n = 0; - - me.clear(); - - if (!importService) { - importService = nodeRequire('./public/plugins/import_leanote/import'); - } - - importService.importFromLeanote(notebookId, paths, - // 全局 - function(ok) { - // $('#importLeanoteMsg .curImportFile').html(""); - // $('#importLeanoteMsg .curImportNote').html(""); - setTimeout(function() { - $('#importLeanoteMsg .allImport').html(me.getMsg('Done! %s notes imported!', n)); - }, 500); - }, - // 单个文件 - function(ok, filename) { - if(ok) { - $('#importLeanoteMsg .curImportFile').html(me.getMsg("Import file: %s Success!", filename)); - } else { - $('#importLeanoteMsg .curImportFile').html(me.getMsg("Import file: %s Failure, is leanote file ?", filename)); - } - }, - // 单个笔记 - function(note) { - if(note) { - n++; - $('#importLeanoteMsg .curImportNote').html(me.getMsg("Import: %s Success!", note.Title)); - - // 不要是新的, 不然切换笔记时又会保存一次 - note.IsNew = false; - - // 插入到当前笔记中 - Note.addSync([note]); - } - } - ); + po.then( + function(re){ + if(re.canceled !== false || re.filePaths.length < 1){ + return; + } + callback(re.filePaths); + }, + function(err){ + alert(err); } ); - }); },