Skip to content

Commit

Permalink
Fixed bugs in menu slider
Browse files Browse the repository at this point in the history
Fixed bugs in button label relating to the artist
The player proxy now polls the player till there is a length after it is initialized
  • Loading branch information
sakithb committed Jan 5, 2024
1 parent d6e64a3 commit df44315
Show file tree
Hide file tree
Showing 7 changed files with 212 additions and 125 deletions.
2 changes: 1 addition & 1 deletion assets/locale/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-01-04 20:18+0530\n"
"POT-Creation-Date: 2024-01-05 16:39+0530\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down
48 changes: 25 additions & 23 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,25 @@ export default class MediaControls extends Extension {
debugLog("Enabled");
}

public disable() {
this.playerProxies = null;

this.destroySettings();

this.watchIfaceInfo = null;
this.mprisIfaceInfo = null;
this.mprisPlayerIfaceInfo = null;
this.propertiesIfaceInfo = null;
this.watchProxy = null;

this.removePanelButton();
this.updateMediaNotificationVisiblity(true);

Main.wm.removeKeybinding("mediacontrols-show-popup-menu");

debugLog("Disabled");
}

public getPlayers() {
const players: PlayerProxy[] = [];

Expand Down Expand Up @@ -381,13 +400,15 @@ export default class MediaControls extends Extension {
const isPlayerBlacklisted = this.isPlayerBlacklisted(playerProxy.identity, playerProxy.desktopEntry);

if (isPlayerBlacklisted) {
debugLog("Player is blacklisted:", busName);
return;
}

playerProxy.onChanged("IsInvalid", this.setActivePlayer.bind(this));
playerProxy.onChanged("IsPinned", this.setActivePlayer.bind(this));
playerProxy.onChanged("PlaybackStatus", this.setActivePlayer.bind(this));
playerProxy.onChanged("IsInvalid", () => {
this.setActivePlayer();
this.panelBtn?.updateWidgets(WidgetFlags.MENU_PLAYERS);
});

this.playerProxies.set(busName, playerProxy);
this.panelBtn?.updateWidgets(WidgetFlags.MENU_PLAYERS);
Expand All @@ -402,8 +423,6 @@ export default class MediaControls extends Extension {
}

private setActivePlayer() {
debugLog("Setting active player");

if (this.playerProxies.size === 0) {
if (this.panelBtn != null) {
this.removePanelButton();
Expand All @@ -424,9 +443,9 @@ export default class MediaControls extends Extension {
break;
}

if (this.panelBtn == null && chosenPlayer == null) {
if (chosenPlayer == null) {
chosenPlayer = playerProxy;
} else if (this.panelBtn?.isSamePlayer(playerProxy) && chosenPlayer == null) {
} else if (this.panelBtn?.isSamePlayer(playerProxy)) {
chosenPlayer = playerProxy;
} else if (playerProxy.playbackStatus === PlaybackStatus.PLAYING) {
chosenPlayer = playerProxy;
Expand Down Expand Up @@ -522,21 +541,4 @@ export default class MediaControls extends Extension {
this.cacheArt = null;
this.blacklistedPlayers = null;
}

public disable() {
this.watchProxy = null;
this.watchIfaceInfo = null;
this.mprisIfaceInfo = null;
this.mprisPlayerIfaceInfo = null;
this.propertiesIfaceInfo = null;
this.playerProxies = null;

this.removePanelButton();
this.updateMediaNotificationVisiblity(true);
this.destroySettings();

Main.wm.removeKeybinding("mediacontrols-show-popup-menu");

debugLog("Disabled");
}
}
124 changes: 65 additions & 59 deletions src/helpers/MenuSlider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,135 +14,141 @@ class MenuSlider extends St.BoxLayout {
private durationLabel: St.Label;

private dragPaused: boolean;
private disabled: boolean;

constructor(initLocation: number, initLength: number, initPaused: boolean) {
constructor() {
super({ vertical: true });

initLocation = initLocation / 1000;
initLength = initLength / 1000;

const initialValue = initLocation / initLength;
const elapsedText = msToHHMMSS(initLocation);
const durationText = msToHHMMSS(initLength);

this.slider = new Slider.Slider(initialValue);
this.slider = new Slider.Slider(0);
this.textBox = new St.BoxLayout();

this.elapsedLabel = new St.Label({
text: elapsedText,
text: "00:00",
xExpand: true,
xAlign: Clutter.ActorAlign.START,
});

this.durationLabel = new St.Label({
text: durationText,
text: "00:00",
xExpand: true,
xAlign: Clutter.ActorAlign.END,
});

const sliderInterval = new Clutter.Interval({
valueType: GObject.TYPE_DOUBLE,
initial: 0,
final: 1,
});

this.transition = new Clutter.PropertyTransition({
propertyName: "value",
progressMode: Clutter.AnimationMode.LINEAR,
interval: sliderInterval,
duration: initLength,
repeatCount: 1,
});

this.transition.connect("marker-reached", (_, name: string) => {
this.elapsedLabel.text = name;
});

this.slider.connect("drag-begin", () => {
if (this.transition.is_playing()) {
if (this.transition.is_playing() && this.disabled === false) {
this.transition.pause();
this.dragPaused = true;
}

return Clutter.EVENT_PROPAGATE;
});

this.slider.connect("drag-end", () => {
const ms = this.slider.value * this.transition.duration;
this.emit("seeked", Math.floor(ms * 1000));

if (this.dragPaused) {
this.transition.advance(ms);
this.transition.start();
this.dragPaused = false;
}

this.emit("seeked", Math.floor(ms * 1000));
return Clutter.EVENT_PROPAGATE;
});

this.slider.connect("scroll-event", () => {
return Clutter.EVENT_STOP;
});

this.updateMarkers();
this.slider.add_transition("progress", this.transition);

this.transition.skip(initLocation);
this.transition = new Clutter.PropertyTransition({
propertyName: "value",
progressMode: Clutter.AnimationMode.LINEAR,
repeatCount: 1,
interval: new Clutter.Interval({
valueType: GObject.TYPE_DOUBLE,
initial: 0,
final: 1,
}),
});

if (initPaused) {
this.pauseTransition();
}
this.transition.connect("marker-reached", (_, name: string) => {
this.elapsedLabel.text = name;
});

this.textBox.add_child(this.elapsedLabel);
this.textBox.add_child(this.durationLabel);
this.add_child(this.textBox);
this.add_child(this.slider);
}

private updateMarkers() {
const noOfSecs = Math.floor(this.transition.duration / 1000);
const markers = this.transition.list_markers(-1);

for (const marker of markers) {
this.transition.remove_marker(marker);
}
this.slider.add_transition("progress", this.transition);
this.setDisabled(true);
}

for (let i = 0; i <= noOfSecs; i++) {
const ms = i * 1000;
const elapsedText = msToHHMMSS(ms);
this.transition.add_marker_at_time(elapsedText, ms);
}
public updateSlider(position: number, length: number) {
this.setLength(length);
this.setPosition(position);
}

public setPosition(position: number) {
position = position / 1000;

this.transition.advance(position);
this.slider.value = position / this.transition.duration;
this.elapsedLabel.text = msToHHMMSS(position);
this.slider.value = position / this.transition.duration;
this.transition.advance(position);
}

public setLength(length: number) {
length = length / 1000;

this.transition.set_duration(length);
this.durationLabel.text = msToHHMMSS(length);
this.slider.value = 0;
this.transition.set_duration(length);
this.transition.rewind();

this.updateMarkers();
}

public pauseTransition() {
this.transition.pause();
if (this.disabled === false) {
this.transition.pause();
}
}

public resumeTransition() {
this.transition.start();
if (this.disabled === false) {
this.transition.start();
}
}

public setDisabled(disabled: boolean) {
this.slider.reactive = !disabled;
this.disabled = disabled;
this.slider.reactive = disabled === false;
this.elapsedLabel.text = disabled ? "00:00" : this.elapsedLabel.text;
this.durationLabel.text = disabled ? "00:00" : this.durationLabel.text;
this.transition.set_duration(disabled ? 0 : this.transition.duration);
this.updateMarkers();
this.opacity = disabled ? 127 : 255;

if (disabled) {
this.transition.set_duration(1);
this.transition.stop();
this.slider.value = 0;
} else {
this.updateMarkers();
}
}

private updateMarkers() {
const noOfSecs = Math.floor(this.transition.duration / 1000);
const markers = this.transition.list_markers(-1);

for (const marker of markers) {
this.transition.remove_marker(marker);
}

for (let i = 0; i <= noOfSecs; i++) {
const ms = i * 1000;
const elapsedText = msToHHMMSS(ms);
this.transition.add_marker_at_time(elapsedText, ms);
}
}
}

Expand Down
Loading

0 comments on commit df44315

Please sign in to comment.