From d209661b91ed0dc6e11044bff2804d6a3bbbf8ab Mon Sep 17 00:00:00 2001 From: Guangcong Luo Date: Sat, 23 Jan 2016 06:24:43 -0500 Subject: [PATCH] Fix team saving in desktop client I'm not sure why this only recently started becoming a problem; I've been told this only recently became commonly reported in Help, but the code I've fixed seems to have been around for a long time. Maybe some recent change exacerbated it or something. Anyway, this should make team saving much more frequent, matching how team saving works in the browser. --- js/client-teambuilder.js | 20 ++++++++++---------- js/storage.js | 8 ++++++++ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/js/client-teambuilder.js b/js/client-teambuilder.js index 0a2b0d897..d618ec176 100644 --- a/js/client-teambuilder.js +++ b/js/client-teambuilder.js @@ -72,21 +72,17 @@ e.stopPropagation(); if (this[e.currentTarget.value]) this[e.currentTarget.value](e); }, - saveTeams: function () { - // save and return - Storage.saveTeams(); - app.user.trigger('saveteams'); - this.update(); - }, back: function () { if (this.exportMode) { - if (this.curTeam) this.curTeam.team = Storage.packTeam(this.curSetList); + if (this.curTeam) { + this.curTeam.team = Storage.packTeam(this.curSetList); + Storage.saveTeam(this.curTeam); + } this.exportMode = false; - Storage.saveTeams(); } else if (this.curSet) { app.clearGlobalListeners(); this.curSet = null; - Storage.saveTeams(); + Storage.saveTeam(this.curTeam); } else if (this.curTeam) { this.curTeam.team = Storage.packTeam(this.curSetList); this.curTeam.iconCache = ''; @@ -1140,7 +1136,11 @@ saveFlag: false, save: function () { this.saveFlag = true; - Storage.saveTeams(); + if (this.curTeam) { + Storage.saveTeam(this.curTeam); + } else { + Storage.saveTeams(); + } }, validate: function () { var format = this.curTeam.format; diff --git a/js/storage.js b/js/storage.js index 082fb89d1..6cb5c6565 100644 --- a/js/storage.js +++ b/js/storage.js @@ -1222,6 +1222,7 @@ Storage.initDirectory2 = function () { self.saveAllTeams = self.nwSaveAllTeams; self.deleteAllTeams = self.nwDeleteAllTeams; self.saveTeam = self.nwSaveTeam; + self.saveTeams = self.nwSaveTeams; self.deleteTeam = self.nwDeleteTeam; // logging @@ -1411,6 +1412,13 @@ Storage.nwSaveTeam = function (team) { fs.writeFile(this.dir + 'Teams/' + filename, Storage.exportTeam(team.team).replace(/\n/g, '\r\n')); }; +Storage.nwSaveTeams = function () { + // should never happen + try { + console.log("nwSaveTeams called: " + new Error().stack); + } catch (e) {} +}; + Storage.nwDeleteTeam = function (team) { if (team.filename) { var oldFilename = team.filename;