diff --git a/data/version b/data/version index 69dcd5f0..a051966f 100644 --- a/data/version +++ b/data/version @@ -1 +1 @@ -{"version":"2.2","updatedTime":"2016-12-29T07:21:51.505Z"} \ No newline at end of file +{"version":"2.3","updatedTime":"2017-01-20T07:21:51.505Z"} \ No newline at end of file diff --git a/login.html b/login.html index 60e011f5..f2929932 100644 --- a/login.html +++ b/login.html @@ -190,7 +190,7 @@ $(function() { // setTimeout(function() { $body.removeClass('loading'); goToMainPage(); - gui.getCurrentWindow().close(); + // gui.getCurrenstWindow().close(); // }, 2000); } // 不成功, 则用api登录 @@ -228,7 +228,7 @@ $(function() { setTimeout(function(){ $body.removeClass('loading'); goToMainPage(); - gui.getCurrentWindow().close(); + // gui.getCurrentWindow().close(); }, 2000); } else { $body.removeClass('loading'); diff --git a/main.js b/main.js index 124cdd1f..67a80ec9 100644 --- a/main.js +++ b/main.js @@ -109,6 +109,64 @@ var DB = { // initialization and ready for creating browser windows. app.on('ready', openIt); +function removeEvents (win) { + win.removeAllListeners('closed'); + win.removeAllListeners('focus'); + win.removeAllListeners('blur'); + win.removeAllListeners('close'); +} + +function bindEvents (win) { + + // Emitted when the window is closed. + win.on('closed', function() { + console.log('closed'); + // Dereference the window object, usually you would store windows + // in an array if your app supports multi windows, this is the time + // when you should delete the corresponding element. + win = null; + }); + + win.on('focus', function() { + console.log('focus'); + // ipc.send('focusWindow'); mainProcess没有该方法 + if(win && win.webContents) + win.webContents.send('focusWindow'); + }); + win.on('blur', function() { + console.log('blur'); + if(win && win.webContents) + win.webContents.send('blurWindow'); + }); + + function close (e, force) { + console.log('close:', force); + if (win) { + win.hide(); + e && e.preventDefault(); + win.webContents.send('closeWindow'); + } else { + app.quit(); + } + } + + // 以前的关闭是真关闭, 现是是假关闭了 + // 关闭,先保存数据 + win.on('close', function(e) { + // windows支持tray, 点close就是隐藏 + if (process.platform.toLowerCase().indexOf('win') === 0) { // win32 + win.hide(); + e.preventDefault(); + return; + } + + // mac 在docker下quit; + // linux直接点x linux不支持Tray + close(e, false); + }); + +} + function openIt() { // 数据库 DB.init(); @@ -131,52 +189,7 @@ function openIt() { // and load the index.html of the app. mainWindow.loadURL('file://' + __dirname + '/note.html'); - // Emitted when the window is closed. - mainWindow.on('closed', function() { - console.log('closed'); - // Dereference the window object, usually you would store windows - // in an array if your app supports multi windows, this is the time - // when you should delete the corresponding element. - mainWindow = null; - }); - - mainWindow.on('focus', function() { - console.log('focus'); - // ipc.send('focusWindow'); mainProcess没有该方法 - if(mainWindow && mainWindow.webContents) - mainWindow.webContents.send('focusWindow'); - }); - mainWindow.on('blur', function() { - console.log('blur'); - if(mainWindow && mainWindow.webContents) - mainWindow.webContents.send('blurWindow'); - }); - - function close (e, force) { - console.log('close:', force); - if (mainWindow) { - mainWindow.hide(); - e && e.preventDefault(); - mainWindow.webContents.send('closeWindow'); - } else { - app.quit(); - } - } - - // 以前的关闭是真关闭, 现是是假关闭了 - // 关闭,先保存数据 - mainWindow.on('close', function(e) { - // windows支持tray, 点close就是隐藏 - if (process.platform.toLowerCase().indexOf('win') === 0) { // win32 - mainWindow.hide(); - e.preventDefault(); - return; - } - - // mac 在docker下quit; - // linux直接点x linux不支持Tray - close(e, false); - }); + bindEvents(mainWindow); // 前端发来可以关闭了 ipc.on('quit-app', function(event, arg) { @@ -189,6 +202,25 @@ function openIt() { } }); + // open login.html and note.html + ipc.on('openUrl', function(event, arg) { + console.log('openUrl', arg); + + var html = arg.html; + var everWindow = mainWindow; + var win2 = new BrowserWindow(arg); + win2.loadURL('file://' + __dirname + '/' + html); + mainWindow = win2; + + // remove all events then close it + removeEvents(everWindow); + everWindow.close(); + + if (html.indexOf('note.html') >= 0) { + bindEvents(mainWindow) + } + }); + pdfMain.init(); function show () { diff --git a/node_modules/api.js b/node_modules/api.js index 00906f26..2760a927 100644 --- a/node_modules/api.js +++ b/node_modules/api.js @@ -39,7 +39,7 @@ var Api = { "List": null, "Item": null }*/ - var ret = resp; + var ret = resp.body; try { if(typeof ret == 'object') { if(!ret['Ok'] && ret['Msg'] == 'NOTLOGIN') { @@ -195,12 +195,7 @@ var Api = { return callback && callback(false); } var ret = response.body; - // console.log('1. getSyncStateRet:') - if(Common.isOk(ret)) { - callback && callback(ret); - } else { - callback && callback(false); - } + callback && callback(ret); }); }, // 获取笔记内容, 获取之后保存到笔记中 diff --git a/node_modules/sync.js b/node_modules/sync.js index fe16ea82..4d345894 100644 --- a/node_modules/sync.js +++ b/node_modules/sync.js @@ -718,8 +718,7 @@ var Sync = { me.fixConflicts(function() { callback(); // 已结束 - Web.syncFinished(); - me.incrSyncStart = false; + me.setSyncFinished(); }) }, // 同步状态 @@ -736,10 +735,11 @@ var Sync = { // 增量同步 incrSyncStart: false, // 如果第一次insync, 网络错误导致incrSyncStart不结束, 第二次就会永远转动 - setSyncFinished: function() { + setSyncFinished: function(hasError) { var me = this; me.incrSyncStart = false; - Web.syncProgress(0); + // Web.syncProgress(0); + Web.syncFinished(hasError); }, incrSync: function(again) { if (User.isLocal()) { @@ -776,9 +776,9 @@ var Sync = { } // 先从服务器上得到usn, 与本地的判断, 是否需要pull Api.getLastSyncState(function(serverState) { - if(!serverState) { + if(!Common.isOk(serverState)) { console.error(' get Server LastSyncState error!!'); - me.setSyncFinished(); + me.setSyncFinished(true); return; } console.log(' get Server LastSyncState ret', serverState.LastSyncUsn + ' ' + lastSyncUsn); diff --git a/node_modules/web.js b/node_modules/web.js index 0d3ec0bb..5998fcd3 100644 --- a/node_modules/web.js +++ b/node_modules/web.js @@ -104,9 +104,9 @@ var Web = { }, //-------------- - syncFinished: function() { + syncFinished: function(hasError) { var me = this; - me.Note.syncFinished(); + me.Note.syncFinished(hasError); }, // 删除笔记时, 更新左侧导航标签的count diff --git a/public/js/app/note.js b/public/js/app/note.js index 462d31a0..0040eec1 100644 --- a/public/js/app/note.js +++ b/public/js/app/note.js @@ -1225,11 +1225,12 @@ Note.hideSpin = function() { me.startInterval(); }; // nodejs调用 -Note.syncFinished = function() { +Note.syncFinished = function(hasError) { var me = this; me.hideSpin(); - me._syncWarningE.hide(); - + if (!hasError) { + me._syncWarningE.hide(); + } Note.hideSyncProgress(); }; // 过时 @@ -1278,9 +1279,9 @@ Note.notLogin = function() { }; Note.needUpgradeAccount = function () { var me = this; - me._syncWarningE.show(); me.hideSpin(); SyncService.setSyncFinished(); + me._syncWarningE.show(); me._syncWarningE.data('reason', 'NEED-UPGRADE-ACCOUNT'); me._syncWarningE.attr('title', getMsg('You need to upgrade Leanote account')); }; diff --git a/public/js/common.js b/public/js/common.js index f674b3fa..3863dc2b 100644 --- a/public/js/common.js +++ b/public/js/common.js @@ -1507,25 +1507,26 @@ var ContextTips = { }; function goToMainPage() { - var BrowserWindow = gui.remote.BrowserWindow; - var win = new BrowserWindow(getMainWinParams()); - win.loadURL('file://' + __dirname + '/note.html?from=login'); + // var BrowserWindow = gui.remote.BrowserWindow; + // var win = new BrowserWindow(getMainWinParams()); + // win.loasdURL('file://' + __dirname + '/note.html?from=login'); + const {ipcRenderer} = require('electron'); + var ipc = ipcRenderer; + var params = getMainWinParams(); + params.html = 'note.html?from=login'; + ipc.send('openUrl', params); } function toLogin() { - var BrowserWindow = gui.remote.BrowserWindow; + const {ipcRenderer} = require('electron'); + var ipc = ipcRenderer; + // var BrowserWindow = gui.remote.BrowserWindow; if(isMac()) { - var win = new BrowserWindow( - { width: 278, height: 370, show: true, frame: false, resizable: false } - ); - win.loadURL('file://' + __dirname + '/login.html'); + ipc.send('openUrl', {html: 'login.html', width: 278, height: 370, show: true, frame: false, resizable: false }) } else { - var win = new BrowserWindow( - { width: 278, height: 400, show: true, frame: true, resizable: false } - ); - win.loadURL('file://' + __dirname + '/login.html'); + ipc.send('openUrl', { width: 278, height: 400, show: true, frame: true, resizable: false }) } - gui.getCurrentWindow().close(); + // gui.getCurrentWindow().close(); } // 添加用户 function switchAccount() {