From 8fb5f2893963ec2089c57c79004ea7a2137eff08 Mon Sep 17 00:00:00 2001 From: life Date: Thu, 7 May 2015 00:42:49 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=94=E8=AE=B0=E5=8E=86=E5=8F=B2=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E9=97=AE=E9=A2=98,=20=E5=85=B3=E9=97=AD=E9=9A=90?= =?UTF-8?q?=E8=97=8F=E9=97=AE=E9=A2=98,=20=E5=BC=BA=E5=88=B6=E5=8F=AA?= =?UTF-8?q?=E8=83=BD=E6=89=93=E5=BC=80=E4=B8=80=E4=B8=AA=E5=AE=9E=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/login.html | 3 +- src/main.js | 61 +++++++++++++++++++++---------------- src/public/js/app/native.js | 2 +- src/public/js/app/note.js | 3 +- src/public/js/app/page.js | 40 ++++++++++++++++-------- src/public/js/common.js | 1 + 6 files changed, 69 insertions(+), 41 deletions(-) diff --git a/src/login.html b/src/login.html index 609d69f7..8b544ae4 100644 --- a/src/login.html +++ b/src/login.html @@ -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")); } }); diff --git a/src/main.js b/src/main.js index 70f236b3..7cf0b3b7 100644 --- a/src/main.js +++ b/src/main.js @@ -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(); -}); \ No newline at end of file diff --git a/src/public/js/app/native.js b/src/public/js/app/native.js index ff5b0c49..d95bcdef 100644 --- a/src/public/js/app/native.js +++ b/src/public/js/app/native.js @@ -24,7 +24,7 @@ $(function() { $('.tool-close, .tool-close-blur').click(function() { // mac下关闭才是隐藏 onClose(function() { - gui.win.close(); + gui.win.hide(); }); // gui.win.showInactive(); }); diff --git a/src/public/js/app/note.js b/src/public/js/app/note.js index 15d1e632..0fe16d95 100644 --- a/src/public/js/app/note.js +++ b/src/public/js/app/note.js @@ -1432,7 +1432,8 @@ Note.listNoteContentHistories = function() { for (i in re) { var content = re[i] content.Ab = Note.genAbstract(content.Content, 200); - str += tt('#??
' + getMsg("datetime") + ': ?
', i, (+i+1), s, content.Ab, s, goNowToDatetime(content.UpdatedTime)) + // 为什么不用tt(), 因为content可能含?? + str += '#' + (i+1) +'<' + s + ' class="each-content">' + content.Ab + '
' + getMsg("datetime") + ': ' + goNowToDatetime(content.UpdatedTime) + '
'; } str += ""; $content.html(str); diff --git a/src/public/js/app/page.js b/src/public/js/app/page.js index 523c0e45..d4ebb9d6 100644 --- a/src/public/js/app/page.js +++ b/src/public/js/app/page.js @@ -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; - } + // 本身就有格式的, 防止之前有格式的显示为(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); diff --git a/src/public/js/common.js b/src/public/js/common.js index f06a3316..babc787a 100644 --- a/src/public/js/common.js +++ b/src/public/js/common.js @@ -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 {