笔记历史记录问题, 关闭隐藏问题, 强制只能打开一个实例

This commit is contained in:
life
2015-05-07 00:42:49 +08:00
parent 83326a438d
commit 8fb5f28939
6 changed files with 69 additions and 41 deletions

View File

@@ -150,13 +150,14 @@ $(function() {
host = '';
}
ApiService.auth(email, pwd, host, function(ret) {
$('#loadingLogo').removeClass('loading');
if(ret.Ok) {
setTimeout(function(){
$('#loadingLogo').removeClass('loading');
goToMainPage();
gui.getCurrentWindow().close();
}, 2000);
} else {
$('#loadingLogo').removeClass('loading');
showMsg(getMsg("Email or Password Error"));
}
});

View File

@@ -10,10 +10,34 @@ var mainWindow = null;
// Quit when all windows are closed.
app.on('window-all-closed', function() {
if (process.platform != 'darwin')
// if (process.platform != 'darwin')
app.quit();
});
// 避免可以启动多个app
app.on('open-file', function(e) {
console.log('reopen');
if(mainWindow) {
mainWindow.show();
mainWindow.focus();
} else {
openIt();
}
});
app.on('activate-with-no-open-windows', function() {
if(mainWindow) {
mainWindow.show();
}
else {
openIt();
}
});
// This method will be called when Electron has done everything
// initialization and ready for creating browser windows.
app.on('ready', openIt);
var Menu = require('menu');
var MenuItem = require('menu-item');
@@ -178,8 +202,7 @@ function setMenu() {
}
function openIt() {
app.getPath('appData');
// app.getPath('appData');
// var Evt = require('evt');
// var basePath = '/Users/life/Library/Application Support/Leanote'; // require('nw.gui').App.dataPath;
@@ -198,7 +221,6 @@ function openIt() {
// and load the index.html of the app.
mainWindow.loadUrl('file://' + __dirname + '/note.html');
// 不能放在这里, 刚开始有图片, 之后添加的图片不能显示 ??
// // 启动服务器, 图片
// var Server = require('server');
@@ -223,32 +245,19 @@ function openIt() {
mainWindow.webContents.send('blurWindow');
});
/*
mainWindow.on('close', function() {
// 关闭,先保存数据
mainWindow.on('close', function(e) {
mainWindow.hide();
e.preventDefault();
mainWindow.webContents.send('closeWindow');
});
*/
/*
ipc.on('asynchronous-message', function(event, arg) {
console.log(arg); // prints "ping"
event.sender.send('asynchronous-reply', 'pong');
// 前端发来可以关闭了
ipc.on('quit-app', function(event, arg) {
console.log('get quit-app request');
mainWindow.destroy();
mainWindow = null;
});
ipc.on('synchronous-message', function(event, arg) {
console.log(arg); // prints "ping"
event.returnValue = 'pong';
});
*/
// 作为调试
// setMenu();
}
// This method will be called when Electron has done everything
// initialization and ready for creating browser windows.
app.on('ready', openIt);
app.on('activate-with-no-open-windows', function() {
openIt();
});

View File

@@ -24,7 +24,7 @@ $(function() {
$('.tool-close, .tool-close-blur').click(function() {
// mac下关闭才是隐藏
onClose(function() {
gui.win.close();
gui.win.hide();
});
// gui.win.showInactive();
});

View File

@@ -1432,7 +1432,8 @@ Note.listNoteContentHistories = function() {
for (i in re) {
var content = re[i]
content.Ab = Note.genAbstract(content.Content, 200);
str += tt('<tr><td seq="?">#?<? class="each-content">?</?> <div class="btns">' + getMsg("datetime") + ': <span class="label label-default">?</span> <button class="btn btn-default all">' + getMsg("unfold") + '</button> <button class="btn btn-primary back">' + getMsg('restoreFromThisVersion') + '</button></div></td></tr>', i, (+i+1), s, content.Ab, s, goNowToDatetime(content.UpdatedTime))
// 为什么不用tt(), 因为content可能含??
str += '<tr><td seq="' + i + '">#' + (i+1) +'<' + s + ' class="each-content">' + content.Ab + '</' + s + '> <div class="btns">' + getMsg("datetime") + ': <span class="label label-default">' + goNowToDatetime(content.UpdatedTime) + '</span> <button class="btn btn-default all">' + getMsg("unfold") + '</button> <button class="btn btn-primary back">' + getMsg('restoreFromThisVersion') + '</button></div></td></tr>';
}
str += "</table></div>";
$content.html(str);

View File

@@ -719,16 +719,18 @@ LeaAce = {
return "leanote_ace_" + (new Date()).getTime() + "_" + this._aceId;
},
initAce: function(id, val, force) {
var me = this;
if(!force && !me.canAndIsAce()) {
return;
}
var $pre = $('#' + id);
if($pre.length == 0) {
return;
}
var rawCode = $pre.html(); // 原生code
try {
var me = this;
if(!force && !me.canAndIsAce()) {
return;
}
me.disableAddHistory();
var $pre = $('#' + id);
if($pre.length == 0) {
return;
}
// 本身就有格式的, 防止之前有格式的显示为<span>(ace下)
if($pre.attr('style') || $pre.html().indexOf('style') != -1) {
$pre.html($pre.text());
@@ -740,7 +742,7 @@ LeaAce = {
$pre.removeClass('ace-to-pre');
$pre.attr("contenteditable", false); // ? 避免tinymce编辑
var aceEditor = ace.edit(id);
aceEditor.setShowInvisibles(false);
aceEditor.setTheme("ace/theme/tomorrow");
var brush = me.getPreBrush($pre);
@@ -756,7 +758,8 @@ LeaAce = {
// retina
if(window.devicePixelRatio == 2) {
aceEditor.setFontSize("12px");
} else {
}
else {
aceEditor.setFontSize("14px");
}
aceEditor.getSession().setUseWorker(false); // 不用语法检查
@@ -793,11 +796,17 @@ LeaAce = {
}
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
me.resetAddHistory();
return aceEditor;
} catch(e) {
// 当有错误时, 会有XXXXX的形式, 此时不要ace, 直接原生的!!!
console.error('ace error!!!!');
console.error(e);
$pre.attr("contenteditable", true);
$pre.removeClass('ace-tomorrow ace_editor ace-tm');
$pre.html(rawCode);
me.resetAddHistory();
}
},
clearIntervalForInitAce: null,
@@ -1288,6 +1297,13 @@ function initPage(initedCallback) {
ipc.on('blurWindow', function(arg) {
$('body').addClass('blur');
});
// 后端发来event, 告诉要关闭了, 处理好后发送给后端说可以关闭了
ipc.on('closeWindow', function(arg) {
console.log('Front get closeWindow message')
onClose(function() {
ipc.sendSync('quit-app');
});
});
// 注入前端变量#
WebService.set(Notebook, Note, Attach, Tag);

View File

@@ -366,6 +366,7 @@ function _setEditorContent(content, isMarkdown, preview) {
if(typeof tinymce != "undefined" && tinymce.activeEditor) {
var editor = tinymce.activeEditor;
editor.setContent(content);
/*
if(LeaAce.canAce() && LeaAce.isAce) {
try {