diff --git a/main.js b/main.js index 67a80ec9..589878d6 100644 --- a/main.js +++ b/main.js @@ -116,7 +116,19 @@ function removeEvents (win) { win.removeAllListeners('close'); } +function close (e, force) { + console.log('close:', force); + if (mainWindow) { + mainWindow.hide(); + e && e.preventDefault(); + mainWindow.webContents.send('closeWindow'); + } else { + app.quit(); + } +} + function bindEvents (win) { + mainWindow = win; // Emitted when the window is closed. win.on('closed', function() { @@ -138,17 +150,6 @@ function bindEvents (win) { 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(); - } - } // 以前的关闭是真关闭, 现是是假关闭了 // 关闭,先保存数据 diff --git a/node_modules/api.js b/node_modules/api.js index f398e934..a83887eb 100644 --- a/node_modules/api.js +++ b/node_modules/api.js @@ -28,7 +28,7 @@ var Api = { // 检查错误 checkError: function(error, resp) { var me = this; - me.unConnected(error); + var unConnected = me.unConnected(error); // console.error(error); // 是否需要重新登录 /*{ @@ -44,18 +44,25 @@ var Api = { if(typeof ret == 'object') { if(!ret['Ok'] && ret['Msg'] == 'NOTLOGIN') { Web.notLogin(); + return; } if(!ret['Ok'] && ret['Msg'] == 'NEED-UPGRADE-ACCOUNT') { Web.needUpgradeAccount(); + return; } } else { // 出现问题 Web.unConnected(); + return; } } catch(e) { // 出错问题 Web.unConnected(); + return; } + + // 没有断网 + !unConnected && Web.connected(); }, // 是否断网 unConnected: function(error) { diff --git a/node_modules/sync.js b/node_modules/sync.js index 9989aa93..dc38a1ef 100644 --- a/node_modules/sync.js +++ b/node_modules/sync.js @@ -581,6 +581,7 @@ var Sync = { }, // 全量同步 + // callback(error, info) fullSync: function(callback) { var me = this; me._stop = false; @@ -607,44 +608,53 @@ var Sync = { console.log('fullSync ' + notebookUsn + ' ' + noteUsn + ' ' + tagUsn); - // Web.syncNotebookFinish(); - // 同步笔记本 - me.syncNotebook(notebookUsn, function(ok) { - if(ok) { - // Web.syncNoteFinish(); - // console.log('------------------') - // 同步笔记 - me.syncNote(noteUsn, function(ok) { - if(ok) { - // Web.syncTagFinish(); - // 同步标签 - me.syncTag(tagUsn, function(ok) { - if (ok) { - me.fullSyncStart = false; - // 更新上次同步时间 - me.updateLastSyncState(function() { - // send changes - // me.sendChanges(); - callback && callback(me._syncInfo, true); - }); - } - else { - me.fullSyncStart = false; - console.error('syncTag error....'); - callback && callback(me._syncInfo, false); - } - }); - } else { - me.fullSyncStart = false; - console.error('syncNote error.... 跳过tag'); - callback && callback(me._syncInfo, false); - } - }); - } else { - me.fullSyncStart = false; - console.error('syncNotebook error.... 跳过note,tag'); - callback && callback(me._syncInfo, false); + Api.getLastSyncState(function(serverState) { + if(!Common.isOk(serverState)) { + console.error(' get Server LastSyncState error!!'); + callback && callback(serverState, null); + return; } + + // Web.syncNotebookFinish(); + // 同步笔记本 + me.syncNotebook(notebookUsn, function(ok) { + if(ok) { + // Web.syncNoteFinish(); + // console.log('------------------') + // 同步笔记 + me.syncNote(noteUsn, function(ok) { + if(ok) { + // Web.syncTagFinish(); + // 同步标签 + me.syncTag(tagUsn, function(ok) { + if (ok) { + me.fullSyncStart = false; + // 更新上次同步时间 + me.updateLastSyncState(function() { + // send changes + // me.sendChanges(); + callback && callback(false, me._syncInfo); + }); + } + else { + me.fullSyncStart = false; + console.error('syncTag error....'); + callback && callback({}, me._syncInfo); + } + }); + } else { + me.fullSyncStart = false; + console.error('syncNote error.... 跳过tag'); + callback && callback({}, me._syncInfo); + } + }); + } else { + me.fullSyncStart = false; + console.error('syncNotebook error.... 跳过note,tag'); + callback && callback({}, me._syncInfo); + } + }); + }); }); @@ -782,6 +792,7 @@ var Sync = { me.setSyncFinished(); return; } + // 先从服务器上得到usn, 与本地的判断, 是否需要pull Api.getLastSyncState(function(serverState) { if(!Common.isOk(serverState)) { diff --git a/node_modules/web.js b/node_modules/web.js index a5e554e6..e0342dfb 100644 --- a/node_modules/web.js +++ b/node_modules/web.js @@ -15,6 +15,10 @@ var Web = { var me = this; me.Note && me.Note.unConnected(); }, + connected: function() { + var me = this; + me.Note && me.Note.connected(); + }, notLogin: function() { var me = this; me.Note && me.Note.notLogin(); diff --git a/public/js/app/note.js b/public/js/app/note.js index f00b05d4..a14fe0ec 100644 --- a/public/js/app/note.js +++ b/public/js/app/note.js @@ -847,21 +847,22 @@ Note.renderChangedNote = function(changedNote) { // 清空右侧note信息, 可能是共享的, // 此时需要清空只读的, 且切换到note edit模式下 Note.clearNoteInfo = function() { - Note.clearCurNoteId(); - Tag.input.clearTags(); - $("#noteTitle").val(""); - setEditorContent(""); + Note.clearCurNoteId(); + Tag.input.clearTags(); + $("#noteTitle").val(""); + setEditorContent(""); - // markdown editor - /* - $("#wmd-input").val(""); - $("#wmd-preview").html(""); - */ + // markdown editor + /* + $("#wmd-input").val(""); + $("#wmd-preview").html(""); + */ - // 只隐藏即可 - $("#noteRead").hide(); - } - // 清除noteList导航 + // 只隐藏即可 + $("#noteRead").hide(); +}; + +// 清除noteList导航 Note.clearNoteList = function() { Note.noteItemListO.html(""); // 清空 } @@ -1252,23 +1253,31 @@ Note.hideSyncProgress = function() { Note.unConnected = function() { var me = this; me._syncWarningE.show(); - SyncService.setSyncFinished(); + SyncService.setSyncFinished(true); me.hideSpin(); me._syncWarningE.data('reason', 'unConnected'); me._syncWarningE.attr('title', 'Network error'); }; +// 网络已经连接好了 +Note.connected = function() { + var me = this; + if (me._syncWarningE.data('reason') == 'unConnected') { + me._syncWarningE.data('reason', '-'); + me._syncWarningE.hide(); + } +}; Note.notLogin = function() { var me = this; me._syncWarningE.show(); me.hideSpin(); - SyncService.setSyncFinished(); + SyncService.setSyncFinished(true); me._syncWarningE.data('reason', 'notLogin'); me._syncWarningE.attr('title', getMsg('You need to sign in Leanote')); }; Note.needUpgradeAccount = function() { var me = this; me.hideSpin(); - SyncService.setSyncFinished(); + SyncService.setSyncFinished(true); me._syncWarningE.show(); me._syncWarningE.data('reason', 'NEED-UPGRADE-ACCOUNT'); me._syncWarningE.attr('title', getMsg('You need to upgrade Leanote account')); @@ -1284,7 +1293,7 @@ Note.fixNetOrAuthError = function() { } else if (reason == 'notLogin') { alert(getMsg('You need to sign in Leanote')); // 弹出登录框登录之, 重新弹出 - window.open('login.html?ref=needLogin'); + toLogin(); // 需要升级Leanote } else if (reason == 'NEED-UPGRADE-ACCOUNT') { diff --git a/public/js/app/page.js b/public/js/app/page.js index ba7377f8..88b1ad88 100644 --- a/public/js/app/page.js +++ b/public/js/app/page.js @@ -1216,8 +1216,8 @@ LeaAce = { function fullSync(callback) { log('full sync'); $('.loading-footer').show(); - SyncService.fullSync(function(ret, ok) { - callback && callback(ok); + SyncService.fullSync(function(err, ret) { + callback && callback(err, ret); }); } @@ -1525,9 +1525,29 @@ function initPage(initedCallback) { else if ('LastSyncUsn' in UserInfo && UserInfo['LastSyncUsn'] > 0) { _init(); } else { - fullSync(function(ok) { - if (!ok) { - Notify.show({ title: 'Info', body: getMsg('Sync error, retry to sync after 3 seconds') }); + fullSync(function(err, info) { + if (err) { + if (typeof err == 'object') { + if(err['Msg'] == 'NOTLOGIN') { + alert(getMsg('You need to sign in Leanote')); + toLogin(); + return; + } + if(err['Msg'] == 'NEED-UPGRADE-ACCOUNT') { + alert(getMsg('You need to upgrade Leanote account')); + openExternal('https://leanote.com/pricing#buy'); + setTimeout(function () { + toLogin(); + }, 1000); + return; + } + } + + if (isMac()) { + Notify.show({ title: 'Info', body: getMsg('Sync error, retry to sync after 3 seconds') }); + } else { + alert(getMsg('Sync error, retry to sync after 3 seconds')); + } setTimeout(function() { reloadApp(); }, 3000); diff --git a/public/js/app/tag.js b/public/js/app/tag.js index 75e88044..b075deae 100644 --- a/public/js/app/tag.js +++ b/public/js/app/tag.js @@ -220,9 +220,9 @@ TagInput.prototype = { // called by Note setTags: function(tags) { if(!Array.isArray(tags)) { - return; + tags = []; } - this.$tags.html(''); + this.clearTags(); for(var i = 0; i < tags.length; ++i) { this._addTag(tags[i]); } diff --git a/public/js/common.js b/public/js/common.js index 3863dc2b..c6354373 100644 --- a/public/js/common.js +++ b/public/js/common.js @@ -1524,7 +1524,7 @@ function toLogin() { if(isMac()) { ipc.send('openUrl', {html: 'login.html', width: 278, height: 370, show: true, frame: false, resizable: false }) } else { - ipc.send('openUrl', { width: 278, height: 400, show: true, frame: true, resizable: false }) + ipc.send('openUrl', {html: 'login.html', width: 278, height: 400, show: true, frame: true, resizable: false }) } // gui.getCurrentWindow().close(); }