From e917b7ce0f1dca31683534e1980477b0b88da0de Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Wed, 26 Feb 2014 15:13:21 -0500 Subject: [PATCH] background: refactor file loading This commit moves the code around a bit such that the caller gets allocated up front and then a file load is either found or created to attach the caller to. Functionally, the code is the same, it's just now factored in a way that will make it easier to fix a bug with cancellation later. https://bugzilla.gnome.org/show_bug.cgi?id=722149 --- js/ui/background.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/js/ui/background.js b/js/ui/background.js index 3fe279dd5..396309a43 100644 --- a/js/ui/background.js +++ b/js/ui/background.js @@ -132,6 +132,10 @@ const BackgroundCache = new Lang.Class({ this._removeContent(this._images, content); }, + _attachCallerToFileLoad: function(caller, fileLoad) { + fileLoad.callers.push(caller); + }, + _loadImageContent: function(params) { params = Params.parse(params, { monitorIndex: 0, style: null, @@ -140,21 +144,24 @@ const BackgroundCache = new Lang.Class({ cancellable: null, onFinished: null }); + let caller = { monitorIndex: params.monitorIndex, + effects: params.effects, + onFinished: params.onFinished }; + for (let i = 0; i < this._pendingFileLoads.length; i++) { - if (this._pendingFileLoads[i].filename == params.filename && - this._pendingFileLoads[i].style == params.style) { - this._pendingFileLoads[i].callers.push({ monitorIndex: params.monitorIndex, - effects: params.effects, - onFinished: params.onFinished }); + let fileLoad = this._pendingFileLoads[i]; + + if (fileLoad.filename == params.filename && + fileLoad.style == params.style) { + this._attachCallerToFileLoad(caller, fileLoad); return; } } - this._pendingFileLoads.push({ filename: params.filename, - style: params.style, - callers: [{ monitorIndex: params.monitorIndex, - effects: params.effects, - onFinished: params.onFinished }] }); + let fileLoad = { filename: params.filename, + style: params.style, + callers: [] }; + this._attachCallerToFileLoad(caller, fileLoad); let content = new Meta.Background({ meta_screen: global.screen });