Skip to content

Commit bb759e0

Browse files
committed
refactor: improve commit info section management and update display logic
1 parent a14e710 commit bb759e0

1 file changed

Lines changed: 44 additions & 37 deletions

File tree

extension.js

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -139,33 +139,48 @@ const Indicator = GObject.registerClass(
139139
};
140140
}
141141

142-
_createCommitInfoSection(dates, counts) {
143-
const commitSection = new PopupMenu.PopupMenuSection();
142+
_updateCommitInfoSection(dates, counts) {
143+
if (!this._commitSection) {
144+
this._commitSection = new PopupMenu.PopupMenuSection();
145+
this.menu.addMenuItem(this._commitSection, 0);
146+
147+
this._commitItems = [];
148+
149+
for (let i = 0; i < 7; i++) {
150+
const textItem = new St.Label({
151+
text: '',
152+
style_class: 'commit-text-item',
153+
x_align: Clutter.ActorAlign.START,
154+
y_align: Clutter.ActorAlign.CENTER
155+
});
156+
157+
const itemBin = new St.BoxLayout({
158+
style_class: 'popup-menu-item',
159+
reactive: false,
160+
can_focus: false,
161+
track_hover: false,
162+
style: 'padding-top: 2px; padding-bottom: 2px;'
163+
});
164+
165+
itemBin.add_child(textItem);
166+
this._commitSection.box.add_child(itemBin);
167+
this._commitItems.push({ bin: itemBin, label: textItem });
168+
}
169+
170+
if (!this._separator) {
171+
this._separator = new PopupMenu.PopupSeparatorMenuItem();
172+
this.menu.addMenuItem(this._separator, 1);
173+
}
174+
}
144175

145176
dates.forEach((date, index) => {
146177
const count = counts[index];
147178
const { label } = this._formatDateWithCommits(date, count);
148179

149-
const textItem = new St.Label({
150-
text: label,
151-
style_class: 'commit-text-item',
152-
x_align: Clutter.ActorAlign.START,
153-
y_align: Clutter.ActorAlign.CENTER
154-
});
155-
156-
const itemBin = new St.BoxLayout({
157-
style_class: 'popup-menu-item',
158-
reactive: false,
159-
can_focus: false,
160-
track_hover: false,
161-
style: 'padding-top: 2px; padding-bottom: 2px;'
162-
});
163-
164-
itemBin.add_child(textItem);
165-
commitSection.box.add_child(itemBin);
180+
if (this._commitItems[index]) {
181+
this._commitItems[index].label.text = label;
182+
}
166183
});
167-
168-
return commitSection;
169184
}
170185

171186
_updateBoxAppearance(box, count, date) {
@@ -182,15 +197,6 @@ const Indicator = GObject.registerClass(
182197
}
183198
}
184199

185-
_addSeparator() {
186-
if (this._separator) {
187-
this._separator.destroy();
188-
}
189-
190-
this._separator = new PopupMenu.PopupSeparatorMenuItem();
191-
this.menu.addMenuItem(this._separator, 1);
192-
}
193-
194200
async _updateContributionDisplay() {
195201
try {
196202
const { githubUsername: username, githubToken: token } = this._preferences;
@@ -206,13 +212,7 @@ const Indicator = GObject.registerClass(
206212
if (counts && counts.length === 7) {
207213
const dates = this._getDatesForLastWeek();
208214

209-
this._clearCommitInfoItems();
210-
211-
const commitSection = this._createCommitInfoSection(dates, counts);
212-
this.menu.addMenuItem(commitSection, 0);
213-
this._commitSection = commitSection;
214-
215-
this._addSeparator();
215+
this._updateCommitInfoSection(dates, counts);
216216

217217
counts.forEach((count, index) => {
218218
if (this._boxes[index]) {
@@ -278,6 +278,10 @@ const Indicator = GObject.registerClass(
278278
}
279279

280280
destroy() {
281+
this._boxes.forEach(box => {
282+
box.remove_all_transitions();
283+
});
284+
281285
if (this._refreshTimeoutId) {
282286
GLib.Source.remove(this._refreshTimeoutId);
283287
this._refreshTimeoutId = null;
@@ -289,6 +293,9 @@ const Indicator = GObject.registerClass(
289293
}
290294

291295
this._clearCommitInfoItems();
296+
this._boxes = null;
297+
this._cache = null;
298+
this._commitItems = null;
292299

293300
super.destroy();
294301
}

0 commit comments

Comments
 (0)