diff options
author | Andrew Dolgov <[email protected]> | 2019-03-14 08:14:36 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2019-03-14 08:14:36 +0300 |
commit | 59f2d1318a159463a9f8fa563d11fd124afe5f64 (patch) | |
tree | a69ce09710c419ffae09fd2e25fc9206eb0dd341 | |
parent | 01c548289368d27d17b4250a9ae43a4e79e9549c (diff) |
fix syncclient.set not doing anything
-rwxr-xr-x | reader.js | 49 |
1 files changed, 33 insertions, 16 deletions
@@ -32,24 +32,36 @@ function Model() { return rv; }, set: function(page) { - if (!self.syncAccount() || !self.fileName()) - return; + return new Promise((resolve, reject) => { + if (!self.syncAccount() || !self.fileName()) { + resolve(null); + return; + } + + const owner = this._sha1_compat(self.syncAccount()); + const hash = this._sha1_compat(self.fileName()); + + console.log('syncClient, set', owner, hash, page); - const owner = this._sha1_compat(self.syncAccount()); - const hash = this._sha1_compat(self.fileName()); + $.post(TCRSYNC_SERVER, {op: "set", version: 2, owner: owner, hash: hash, position: page}).then((resp) => { + console.log('tcrsync_set', resp); - console.log('syncClient, set', owner, hash, page) + resolve(page); + }); + }); }, get: function() { - if (!self.syncAccount() || !self.fileName()) - return; + return new Promise((resolve, reject) => { + if (!self.syncAccount() || !self.fileName()) { + resolve(-1); + return; + } - const owner = this._sha1_compat(self.syncAccount()); - const hash = this._sha1_compat(self.fileName()); + const owner = this._sha1_compat(self.syncAccount()); + const hash = this._sha1_compat(self.fileName()); - console.log('syncClient, get', owner, hash); + console.log('syncClient, get', owner, hash); - return new Promise((resolve, reject) => { $.post(TCRSYNC_SERVER, {op: "get", version: 2, owner: owner, hash: hash}).then((resp) => { console.log('tcrsync_get', resp); @@ -259,6 +271,8 @@ function Model() { case "F-FLIP": m.checked = self.flipColumns(); break; + case "F-SYNC": + m.enabled = self.syncAccount() != ""; } } }); @@ -350,12 +364,15 @@ $(document).ready(function () { ipcRenderer.on("sync-to-last", (event, args) => { model.syncClient.get().then((page) => { - if (confirm("You are currently on page %p. Furthest read page stored on the server is %r. Open it instead?" - .replace("%p", model.currentPageDisp()) - .replace("%r", page + 1))) { - - model.currentPage(page); + if (page > model.currentPage()) { + if (confirm("You are currently on page %p. Furthest read page stored on the server is %r. Open it instead?" + .replace("%p", model.currentPageDisp()) + .replace("%r", page + 1))) { + model.currentPage(page); + } + } else { + alert("No information stored or you are on the furthest read page."); } }); }); |