Fetch appstore listing as soon as possible

This commit is contained in:
Johannes Zellner
2021-09-23 00:33:40 +02:00
parent 74045b7de1
commit 195c5ab21a
2 changed files with 44 additions and 34 deletions

View File

@@ -372,6 +372,7 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout
this._configListener = [];
this._readyListener = [];
this._reconnectListener = [];
this._fetchingAppstoreAppsListener = [];
this._userInfo = {
id: null,
username: null,
@@ -2825,23 +2826,40 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout
});
};
Client.prototype._onAppstoreApps = function (callback) {
if (!this._fetchingAppstoreApps) {console.log('not fetching'); callback(); }
else this._fetchingAppstoreAppsListener.push(callback);
};
Client.prototype.getAppstoreApps = function (callback) {
var that = this;
if (that._fetchingAppstoreApps) return this.getAppstoreAppsFast(callback);
that._fetchingAppstoreApps = true;
get('/api/v1/appstore/apps', null, function (error, data, status) {
that._fetchingAppstoreApps = false;
if (error) return callback(error);
if (status !== 200) return callback(new ClientError(status, data));
angular.copy(data.apps, that._appstoreAppCache);
that._fetchingAppstoreAppsListener.forEach(function (callback) { callback(); });
that._fetchingAppstoreAppsListener = [];
return callback(null, that._appstoreAppCache);
});
};
Client.prototype.getAppstoreAppsFast = function (callback) {
if (this._appstoreAppCache.length !== 0) return callback(null, this._appstoreAppCache);
var that = this;
this.getAppstoreApps(callback);
if (this._appstoreAppCache.length !== 0) return callback(null, this._appstoreAppCache);
if (!that._fetchingAppstoreApps) return this.getAppstoreApps(callback);
this._onAppstoreApps(function () { that.getAppstoreAppsFast(callback) });
};
Client.prototype.getSubscription = function (callback) {