Merge pull request #351 from chaosue/master

fix compatibilies with electron9 for plugins; auto hide default menubar
This commit is contained in:
life
2021-03-26 16:51:35 +08:00
committed by GitHub
9 changed files with 362 additions and 240 deletions

View File

@@ -204,6 +204,7 @@ function openIt() {
height: 595, height: 595,
frame: process.platform != 'darwin', frame: process.platform != 'darwin',
transparent: false, transparent: false,
autoHideMenuBar: true,
webPreferences: { webPreferences: {
nodeIntegration: true nodeIntegration: true
} }

27
node_modules/pdf_main.js generated vendored
View File

@@ -15,11 +15,7 @@ var exportPdf = {
win.webContents.on('did-finish-load', function() { win.webContents.on('did-finish-load', function() {
console.log('load ok'); console.log('load ok');
setTimeout(function() { setTimeout(function() {
win.webContents.printToPDF({ var callback = function(err, data) {
printBackground: true,
landscape: false,
pageSize: 'A4'
}, function(err, data) {
fs.writeFile(targetPdfPath, data, function(err) { fs.writeFile(targetPdfPath, data, function(err) {
if (err) { if (err) {
callbcak(false); callbcak(false);
@@ -29,7 +25,26 @@ var exportPdf = {
} }
// win.close(); // 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); }, isMarkdown ? 1000 : 100);
}); });

View File

@@ -405,7 +405,7 @@ define(function() {
getTargetPath: function(callback) { getTargetPath: function(callback) {
// showSaveDialog 不支持property选择文件夹 // showSaveDialog 不支持property选择文件夹
Api.gui.dialog.showOpenDialog(Api.gui.getCurrentWindow(), var po = Api.gui.dialog.showOpenDialog(Api.gui.getCurrentWindow(),
{ {
defaultPath: Api.gui.app.getPath('userDesktop') + '/', defaultPath: Api.gui.app.getPath('userDesktop') + '/',
properties: ['openDirectory'] properties: ['openDirectory']
@@ -414,6 +414,21 @@ define(function() {
callback(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, loadingIsClosed: false,

View File

@@ -185,7 +185,7 @@ define(function() {
getTargetPath: function(callback) { getTargetPath: function(callback) {
// showSaveDialog 不支持property选择文件夹 // showSaveDialog 不支持property选择文件夹
Api.gui.dialog.showOpenDialog(Api.gui.getCurrentWindow(), var po = Api.gui.dialog.showOpenDialog(Api.gui.getCurrentWindow(),
{ {
defaultPath: Api.gui.app.getPath('userDesktop') + '/', defaultPath: Api.gui.app.getPath('userDesktop') + '/',
properties: ['openDirectory'] properties: ['openDirectory']
@@ -194,6 +194,20 @@ define(function() {
callback(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, loadingIsClosed: false,

View File

@@ -419,7 +419,7 @@ define(function() {
getTargetPath: function(callback) { getTargetPath: function(callback) {
// showSaveDialog 不支持property选择文件夹 // showSaveDialog 不支持property选择文件夹
Api.gui.dialog.showOpenDialog(Api.gui.getCurrentWindow(), var po = Api.gui.dialog.showOpenDialog(Api.gui.getCurrentWindow(),
{ {
defaultPath: Api.gui.app.getPath('userDesktop') + '/', defaultPath: Api.gui.app.getPath('userDesktop') + '/',
properties: ['openDirectory'] properties: ['openDirectory']
@@ -428,6 +428,21 @@ define(function() {
callback(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, loadingIsClosed: false,

View File

@@ -4,7 +4,7 @@
* 选择目录, 将图片保存到文件夹中, 有个html文件(以笔记名命名) * 选择目录, 将图片保存到文件夹中, 有个html文件(以笔记名命名)
* 注意, fs.existsSync总返回false, readFileSync可用 * 注意, fs.existsSync总返回false, readFileSync可用
*/ */
define(function() { define(function () {
var async; // = require('async'); var async; // = require('async');
var exportPDF = { var exportPDF = {
@@ -40,7 +40,7 @@ define(function() {
}, },
_inited: false, _inited: false,
init: function() { init: function () {
var me = this; var me = this;
if (me._inited) { if (me._inited) {
return; return;
@@ -56,7 +56,7 @@ define(function() {
_initExportPdf: function () { _initExportPdf: function () {
var me = this; var me = this;
// console.log('_initExportPdf'); // 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; var seq = arg.seq;
// console.log('export-pdf-ret'); // console.log('export-pdf-ret');
// console.log(arg); // console.log(arg);
@@ -66,22 +66,22 @@ define(function() {
} }
}); });
}, },
exportPdf: function (htmlPath, targetPdfPath, isMarkdown, callback) { exportPdf: function (htmlPath, targetPdfPath, isMarkdown, callback) {
this._exportPdfSeq++; this._exportPdfSeq++;
this._exportPdfCallback[this._exportPdfSeq] = callback; this._exportPdfCallback[this._exportPdfSeq] = callback;
Api.ipc.send('export-pdf', Api.ipc.send('export-pdf',
{htmlPath: htmlPath, targetPdfPath: targetPdfPath, isMarkdown: isMarkdown, seq: this._exportPdfSeq}); { htmlPath: htmlPath, targetPdfPath: targetPdfPath, isMarkdown: isMarkdown, seq: this._exportPdfSeq });
}, },
getPluginPath: function() { getPluginPath: function () {
return Api.evtService.getProjectBasePath() + '/public/plugins/export_pdf' ; return Api.evtService.getProjectBasePath() + '/public/plugins/export_pdf';
}, },
htmlTpl: '', htmlTpl: '',
markdownTpl: '', markdownTpl: '',
getTpl: function(isMarkdown) { getTpl: function (isMarkdown) {
var tpl = isMarkdown ? this.markdownTpl : this.htmlTpl; var tpl = isMarkdown ? this.markdownTpl : this.htmlTpl;
if(tpl) { if (tpl) {
return tpl; return tpl;
} }
var basePluginPath = this.getPluginPath(); var basePluginPath = this.getPluginPath();
@@ -93,7 +93,7 @@ define(function() {
return tpl; return tpl;
}, },
// 生成html或markdown // 生成html或markdown
render: function(note) { render: function (note) {
var tpl = this.getTpl(note.IsMarkdown); var tpl = this.getTpl(note.IsMarkdown);
var title = note.Title || getMsg('Untitled'); var title = note.Title || getMsg('Untitled');
tpl = tpl.replace(/\{title\}/g, title); tpl = tpl.replace(/\{title\}/g, title);
@@ -103,24 +103,24 @@ define(function() {
return tpl; return tpl;
}, },
replaceAll: function(src, pattern, to) { replaceAll: function (src, pattern, to) {
if(!src) { if (!src) {
return src; return src;
} }
while(true) { while (true) {
var oldSrc = src; var oldSrc = src;
src = src.replace(pattern, to); src = src.replace(pattern, to);
if(oldSrc === src) { if (oldSrc === src) {
return src; return src;
} }
} }
}, },
fixFilename: function(filename) { fixFilename: function (filename) {
var reg = new RegExp("/|#|\\$|!|\\^|\\*|'| |\"|%|&|\\(|\\)|\\+|\\,|/|:|;|<|>|=|\\?|@|\\||\\\\", 'g'); var reg = new RegExp("/|#|\\$|!|\\^|\\*|'| |\"|%|&|\\(|\\)|\\+|\\,|/|:|;|<|>|=|\\?|@|\\||\\\\", 'g');
filename = filename.replace(reg, "-"); filename = filename.replace(reg, "-");
// 防止出现两个连续的- // 防止出现两个连续的-
while(filename.indexOf('--') != -1) { while (filename.indexOf('--') != -1) {
filename = this.replaceAll(filename, '--', '-'); filename = this.replaceAll(filename, '--', '-');
} }
if (filename.length > 1) { if (filename.length > 1) {
@@ -131,36 +131,50 @@ define(function() {
}, },
// 得到可用的文件名, 避免冲突 // 得到可用的文件名, 避免冲突
getPdfFilePath: function(pathInfo, n, cb) { getPdfFilePath: function (pathInfo, n, cb) {
var me = this; var me = this;
if(n > 1) { if (n > 1) {
pathInfo.nameNotExt = pathInfo.nameNotExtRaw + '-' + n; pathInfo.nameNotExt = pathInfo.nameNotExtRaw + '-' + n;
} }
var absPath = pathInfo.getFullPath(); var absPath = pathInfo.getFullPath();
// Api.nodeFs.existsSync(absPath) 总是返回false, 不知道什么原因 // Api.nodeFs.existsSync(absPath) 总是返回false, 不知道什么原因
// 在控制台上是可以的 // 在控制台上是可以的
Api.nodeFs.exists(absPath, function(exists) { Api.nodeFs.exists(absPath, function (exists) {
if(!exists) { if (!exists) {
cb(absPath); cb(absPath);
} }
else { else {
me.getPdfFilePath(pathInfo, n+1, cb); me.getPdfFilePath(pathInfo, n + 1, cb);
} }
}); });
}, },
getTargetPath: function(callback) { getTargetPath: function (callback) {
// showSaveDialog 不支持property选择文件夹 // showSaveDialog 不支持property选择文件夹
Api.gui.dialog.showOpenDialog(Api.gui.getCurrentWindow(), var po = Api.gui.dialog.showOpenDialog(Api.gui.getCurrentWindow(),
{ {
defaultPath: Api.gui.app.getPath('userDesktop') + '/', defaultPath: Api.gui.app.getPath('userDesktop') + '/',
properties: ['openDirectory'] properties: ['openDirectory']
}, },
function(targetPath) { function (targetPath) {
callback(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, loadingIsClosed: false,
@@ -170,25 +184,26 @@ define(function() {
if (!notebookId) { if (!notebookId) {
return; return;
} }
me.getTargetPath(function(targetPath) { me.getTargetPath(function (targetPath) {
if (!targetPath) { if (!targetPath) {
return; return;
} }
me.loadingIsClosed = false; 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, isLarge: true,
onClose: function () { onClose: function () {
me.loadingIsClosed = true; me.loadingIsClosed = true;
setTimeout(function() { setTimeout(function () {
me.hideLoading(); me.hideLoading();
}); });
}}); }
});
Api.loading.setProgress(1); Api.loading.setProgress(1);
Api.noteService.getNotes(notebookId, function(notes) { Api.noteService.getNotes(notebookId, function (notes) {
if (!notes) { if (!notes) {
me.hideLoading(); me.hideLoading();
return; return;
@@ -196,7 +211,7 @@ define(function() {
var total = notes.length; var total = notes.length;
var i = 0; var i = 0;
async.eachSeries(notes, function(note, cb) { async.eachSeries(notes, function (note, cb) {
if (me.loadingIsClosed) { if (me.loadingIsClosed) {
cb(); cb();
me.hideLoading(); me.hideLoading();
@@ -204,12 +219,12 @@ define(function() {
} }
i++; i++;
Api.loading.setProgress(100 * i / total); Api.loading.setProgress(100 * i / total);
me._exportPDF(note, targetPath, function() { me._exportPDF(note, targetPath, function () {
cb(); cb();
}, i, total); }, i, total);
}, function() { }, function () {
me.hideLoading(); 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) { if (!noteIds || noteIds.length == 0) {
return; return;
} }
me.getTargetPath(function(targetPath) { me.getTargetPath(function (targetPath) {
if (!targetPath) { if (!targetPath) {
return; return;
} }
me.loadingIsClosed = false; 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, isLarge: true,
onClose: function () { onClose: function () {
me.loadingIsClosed = true; me.loadingIsClosed = true;
setTimeout(function() { setTimeout(function () {
me.hideLoading(); me.hideLoading();
}); });
}}); }
});
Api.loading.setProgress(1); Api.loading.setProgress(1);
var i = 0; var i = 0;
var total = noteIds.length; var total = noteIds.length;
async.eachSeries(noteIds, function(noteId, cb) { async.eachSeries(noteIds, function (noteId, cb) {
if (me.loadingIsClosed) { if (me.loadingIsClosed) {
cb(); cb();
return; return;
@@ -255,30 +271,30 @@ define(function() {
i++; i++;
Api.loading.setProgress(100 * i / total); Api.loading.setProgress(100 * i / total);
Api.noteService.getNote(noteId, function(note) { Api.noteService.getNote(noteId, function (note) {
me._exportPDF(note, targetPath, function(ok) { me._exportPDF(note, targetPath, function (ok) {
cb(); cb();
}, i, total); }, i, total);
}); });
}, function () { }, function () {
me.hideLoading(); 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; var me = this;
setTimeout(function () { setTimeout(function () {
me._exportPDF(note, path, callback, i, total); me._exportPDF(note, path, callback, i, total);
}, 1000); }, 1000);
}, },
_exportPDF: function(note, path, callback, i, total) { _exportPDF: function (note, path, callback, i, total) {
var me = this; var me = this;
if(!note) { if (!note) {
return; return;
} }
@@ -304,12 +320,12 @@ define(function() {
pathInfo.nameNotExtRaw = pathInfo.nameNotExt; pathInfo.nameNotExtRaw = pathInfo.nameNotExt;
// 得到可用文件的绝对路径 // 得到可用文件的绝对路径
me.getPdfFilePath(pathInfo, 1, function(absPdfFilePath) { me.getPdfFilePath(pathInfo, 1, function (absPdfFilePath) {
// 得到存放assets的目录 // 得到存放assets的目录
var html = me.render(note); var html = me.render(note);
var tempPath = Api.gui.app.getPath('temp'); var tempPath = Api.gui.app.getPath('temp');
var last = tempPath[tempPath.length-1]; var last = tempPath[tempPath.length - 1];
if ( last == '/' || last == '\\') { if (last == '/' || last == '\\') {
tempPath = tempPath.substr(0, tempPath.length - 1); tempPath = tempPath.substr(0, tempPath.length - 1);
} }
var targetHtmlPath = tempPath + '/' + (new Date().getTime()) + '.html'; var targetHtmlPath = tempPath + '/' + (new Date().getTime()) + '.html';
@@ -324,42 +340,42 @@ define(function() {
}, },
// 打开前要执行的 // 打开前要执行的
onOpen: function() { onOpen: function () {
var me = this; var me = this;
var gui = Api.gui; var gui = Api.gui;
var menu = { var menu = {
label: Api.getMsg('plugin.export_pdf.export'), label: Api.getMsg('plugin.export_pdf.export'),
enabled: function(noteIds) { enabled: function (noteIds) {
return true; return true;
}, },
click: (function() { click: (function () {
return function(noteIds) { return function (noteIds) {
me.init(); me.init();
me.exportPDF(noteIds); me.exportPDF(noteIds);
} }
})() })()
}; };
Api.addExportMenu(menu); Api.addExportMenu(menu);
Api.addExportMenuForNotebook({ Api.addExportMenuForNotebook({
label: Api.getMsg('plugin.export_pdf.export'), label: Api.getMsg('plugin.export_pdf.export'),
enabled: function(notebookId) { enabled: function (notebookId) {
return true; return true;
}, },
click: (function() { click: (function () {
return function(notebookId) { return function (notebookId) {
me.init(); me.init();
me.exportPDFForNotebook(notebookId); me.exportPDFForNotebook(notebookId);
} }
})() })()
}); });
}, },
// 打开后 // 打开后
onOpenAfter: function() { onOpenAfter: function () {
}, },
// 关闭时需要运行的 // 关闭时需要运行的
onClose: function() { onClose: function () {
} }
}; };

View File

@@ -118,61 +118,77 @@ define(function() {
// 导入, 选择文件 // 导入, 选择文件
$('#chooseEvernoteFile').click(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'], properties: ['openFile', 'multiSelections'],
filters: [ filters: [
{ name: 'Evernote', extensions: ['enex'] } { name: 'Evernote', extensions: ['enex'] }
] ]
}, },
function(paths) { callback
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]);
}
}
);
}
); );
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);
}
);
}); });
}, },

View File

@@ -118,63 +118,78 @@ define(function() {
// 导入, 选择文件 // 导入, 选择文件
$('#chooseHTMLFile').click(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'], properties: ['openFile', 'multiSelections'],
filters: [ filters: [
{ name: 'HTML', extensions: ['html'] } { 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() { clear: function() {
$('#importHTMLMsg .curImportFile').html(""); $('#importHTMLMsg .curImportFile').html("");

View File

@@ -118,63 +118,78 @@ define(function() {
// 导入, 选择文件 // 导入, 选择文件
$('#chooseLeanoteFile').click(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'], properties: ['openFile', 'multiSelections'],
filters: [ filters: [
{ name: 'Leanote', extensions: ['leanote'] } { name: 'Leanote', extensions: ['leanote'] }
] ]
}, },
function(paths) { callback
if(!paths) { );
return; if(typeof(po) != "object"){
} return;
}
var notebookId = me._curNotebook.NotebookId; po.then(
function(re){
var n = 0; if(re.canceled !== false || re.filePaths.length < 1){
return;
me.clear(); }
callback(re.filePaths);
if (!importService) { },
importService = nodeRequire('./public/plugins/import_leanote/import'); function(err){
} alert(err);
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]);
}
}
);
} }
); );
}); });
}, },