diff --git a/main.js b/main.js index eef8d9e..1991180 100644 --- a/main.js +++ b/main.js @@ -97,11 +97,20 @@ module.exports = class RibbonClasp extends Plugin { this.mergeNewItems(ribbon); } + // a drag saves, and the dom change it makes wakes the observer up, which can + // save again before the first one has finished writing. queue them instead. + save() { + this.writing = Promise.resolve(this.writing) + .catch(() => {}) + .then(() => this.saveData(this.settings)); + return this.writing; + } + recordOrder(ribbon) { const ids = ribbon.items.map((item) => item.id); if (this.sameOrder(ids, this.settings.order)) return; this.settings.order = ids; - this.saveData(this.settings); + this.save(); } // only append icons we haven't seen before instead of overwriting the @@ -113,7 +122,7 @@ module.exports = class RibbonClasp extends Plugin { const newIds = ribbon.items.map((item) => item.id).filter((id) => !known.has(id)); if (newIds.length === 0) return; this.settings.order = [...this.settings.order, ...newIds]; - this.saveData(this.settings); + this.save(); } sameOrder(a, b) {