Skip to content

Commit c69d344

Browse files
loading state for initial setup
1 parent 474937e commit c69d344

1 file changed

Lines changed: 14 additions & 23 deletions

File tree

  • steamGamesStarter@KopfdesDaemons/files/steamGamesStarter@KopfdesDaemons

steamGamesStarter@KopfdesDaemons/files/steamGamesStarter@KopfdesDaemons/desklet.js

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,18 @@ class SteamGamesStarterDesklet extends Desklet.Desklet {
3434
settings.bindProperty(Settings.BindingDirection.IN, "background-color", "backgroundColor", this._updateScrollViewStyle.bind(this));
3535

3636
this.setHeader(_("Steam Games Starter"));
37+
this._initUI();
3738
this._loadGamesAndSetupUI();
3839
}
3940

40-
async _loadGamesAndSetupUI() {
41-
if (!this.mainContainer) {
42-
this.mainContainer = new St.BoxLayout({ vertical: true, style_class: "main-container" });
43-
this.mainContainer.add_child(UiHelper.createHeader(this.metadata.path, this._loadGamesAndSetupUI.bind(this)));
44-
}
45-
if (this.scrollView) {
46-
this.mainContainer.remove_child(this.scrollView);
47-
this.scrollView.destroy();
48-
}
49-
this.scrollView = new St.ScrollView({ overlay_scrollbars: true, clip_to_allocation: true });
50-
this._updateScrollViewStyle();
41+
_initUI() {
42+
this.mainContainer = new St.BoxLayout({ vertical: true, style_class: "main-container" });
43+
this.mainContainer.add_child(UiHelper.createHeader(this.metadata.path, this._loadGamesAndSetupUI.bind(this)));
44+
this.setContent(this.mainContainer);
45+
}
5146

52-
this.scrollView.add_actor(UiHelper.createLoadingView());
53-
this.mainContainer.add_child(this.scrollView);
47+
async _loadGamesAndSetupUI() {
48+
this._setupLayout(true);
5449

5550
this.error = null;
5651
this.games = [];
@@ -60,17 +55,12 @@ class SteamGamesStarterDesklet extends Desklet.Desklet {
6055
} catch (e) {
6156
this.error = e;
6257
global.logError(`Error getting Steam games: ${e}`);
63-
} finally {
64-
this._setupLayout();
6558
}
66-
}
6759

68-
_setupLayout() {
69-
if (!this.mainContainer) {
70-
this.mainContainer = new St.BoxLayout({ vertical: true, style_class: "main-container" });
71-
this.mainContainer.add_child(UiHelper.createHeader(this.metadata.path, this._loadGamesAndSetupUI.bind(this)));
72-
}
60+
this._setupLayout();
61+
}
7362

63+
_setupLayout(loading = false) {
7464
const gamesToDisplay = this.games.slice(0, this.numberOfGames);
7565

7666
if (this.scrollView) {
@@ -81,7 +71,9 @@ class SteamGamesStarterDesklet extends Desklet.Desklet {
8171
this.scrollView = new St.ScrollView({ overlay_scrollbars: true, clip_to_allocation: true });
8272
this._updateScrollViewStyle();
8373

84-
if (this.error || gamesToDisplay.length === 0) {
74+
if (loading) {
75+
this.scrollView.add_actor(UiHelper.createLoadingView());
76+
} else if (this.error || gamesToDisplay.length === 0) {
8577
this.scrollView.add_actor(UiHelper.createErrorView(this.error, gamesToDisplay.length > 0, this.metadata.path));
8678
} else {
8779
const gamesContainer = new St.BoxLayout({ vertical: true, style_class: "games-container" });
@@ -93,7 +85,6 @@ class SteamGamesStarterDesklet extends Desklet.Desklet {
9385
}
9486

9587
this.mainContainer.add_child(this.scrollView);
96-
this.setContent(this.mainContainer);
9788
}
9889

9990
_updateScrollViewStyle() {

0 commit comments

Comments
 (0)