mpris: Move widgets to messageList.js
Widgets for other type of messages (notifications) are already in `messageList.js` therefore move widgets for mpris also there. Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3429>
This commit is contained in:
parent
c102d8c5ba
commit
0c6f896d4b
@ -7,7 +7,6 @@ import St from 'gi://St';
|
|||||||
|
|
||||||
import * as Main from './main.js';
|
import * as Main from './main.js';
|
||||||
import * as MessageList from './messageList.js';
|
import * as MessageList from './messageList.js';
|
||||||
import * as Mpris from './mpris.js';
|
|
||||||
import * as PopupMenu from './popupMenu.js';
|
import * as PopupMenu from './popupMenu.js';
|
||||||
import {ensureActorVisibleInScrollView} from '../misc/animationUtils.js';
|
import {ensureActorVisibleInScrollView} from '../misc/animationUtils.js';
|
||||||
|
|
||||||
@ -877,7 +876,7 @@ class CalendarMessageList extends St.Widget {
|
|||||||
this);
|
this);
|
||||||
this._scrollView.child = this._sectionList;
|
this._scrollView.child = this._sectionList;
|
||||||
|
|
||||||
this._mediaSection = new Mpris.MediaSection();
|
this._mediaSection = new MessageList.MediaSection();
|
||||||
this._addSection(this._mediaSection);
|
this._addSection(this._mediaSection);
|
||||||
|
|
||||||
this._notificationSection = new MessageList.NotificationSection();
|
this._notificationSection = new MessageList.NotificationSection();
|
||||||
|
@ -10,6 +10,7 @@ import St from 'gi://St';
|
|||||||
|
|
||||||
import * as Main from './main.js';
|
import * as Main from './main.js';
|
||||||
import * as MessageTray from './messageTray.js';
|
import * as MessageTray from './messageTray.js';
|
||||||
|
import * as Mpris from './mpris.js';
|
||||||
|
|
||||||
import * as Util from '../misc/util.js';
|
import * as Util from '../misc/util.js';
|
||||||
import {formatTimeSpan} from '../misc/dateUtils.js';
|
import {formatTimeSpan} from '../misc/dateUtils.js';
|
||||||
@ -741,6 +742,68 @@ class NotificationMessage extends Message {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const MediaMessage = GObject.registerClass(
|
||||||
|
class MediaMessage extends Message {
|
||||||
|
constructor(player) {
|
||||||
|
super(player.source);
|
||||||
|
|
||||||
|
this._player = player;
|
||||||
|
this.add_style_class_name('media-message');
|
||||||
|
|
||||||
|
this._prevButton = this.addMediaControl('media-skip-backward-symbolic',
|
||||||
|
() => {
|
||||||
|
this._player.previous();
|
||||||
|
});
|
||||||
|
|
||||||
|
this._playPauseButton = this.addMediaControl('',
|
||||||
|
() => {
|
||||||
|
this._player.playPause();
|
||||||
|
});
|
||||||
|
|
||||||
|
this._nextButton = this.addMediaControl('media-skip-forward-symbolic',
|
||||||
|
() => {
|
||||||
|
this._player.next();
|
||||||
|
});
|
||||||
|
|
||||||
|
this._player.connectObject('changed', this._update.bind(this), this);
|
||||||
|
this._update();
|
||||||
|
}
|
||||||
|
|
||||||
|
vfunc_clicked() {
|
||||||
|
this._player.raise();
|
||||||
|
Main.panel.closeCalendar();
|
||||||
|
}
|
||||||
|
|
||||||
|
_updateNavButton(button, sensitive) {
|
||||||
|
button.reactive = sensitive;
|
||||||
|
}
|
||||||
|
|
||||||
|
_update() {
|
||||||
|
let icon;
|
||||||
|
if (this._player.trackCoverUrl) {
|
||||||
|
const file = Gio.File.new_for_uri(this._player.trackCoverUrl);
|
||||||
|
icon = new Gio.FileIcon({file});
|
||||||
|
} else {
|
||||||
|
icon = new Gio.ThemedIcon({name: 'audio-x-generic-symbolic'});
|
||||||
|
}
|
||||||
|
|
||||||
|
this.set({
|
||||||
|
title: this._player.trackTitle,
|
||||||
|
body: this._player.trackArtists.join(', '),
|
||||||
|
icon,
|
||||||
|
});
|
||||||
|
|
||||||
|
let isPlaying = this._player.status === 'Playing';
|
||||||
|
let iconName = isPlaying
|
||||||
|
? 'media-playback-pause-symbolic'
|
||||||
|
: 'media-playback-start-symbolic';
|
||||||
|
this._playPauseButton.child.icon_name = iconName;
|
||||||
|
|
||||||
|
this._updateNavButton(this._prevButton, this._player.canGoPrevious);
|
||||||
|
this._updateNavButton(this._nextButton, this._player.canGoNext);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
export const MessageListSection = GObject.registerClass({
|
export const MessageListSection = GObject.registerClass({
|
||||||
Properties: {
|
Properties: {
|
||||||
'can-clear': GObject.ParamSpec.boolean(
|
'can-clear': GObject.ParamSpec.boolean(
|
||||||
@ -1013,3 +1076,43 @@ class NotificationSection extends MessageListSection {
|
|||||||
super.vfunc_map();
|
super.vfunc_map();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const MediaSection = GObject.registerClass(
|
||||||
|
class MediaSection extends MessageListSection {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this._players = new Map();
|
||||||
|
this._mediaSource = new Mpris.MprisSource();
|
||||||
|
|
||||||
|
this._mediaSource.connectObject(
|
||||||
|
'player-added', (_, player) => this._addPlayer(player),
|
||||||
|
'player-removed', (_, player) => this._removePlayer(player),
|
||||||
|
this);
|
||||||
|
|
||||||
|
this._mediaSource.players.forEach(player => {
|
||||||
|
this._addPlayer(player);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
_addPlayer(player) {
|
||||||
|
if (this._players.has(player))
|
||||||
|
throw new Error('Player was already added previously');
|
||||||
|
|
||||||
|
const message = new MediaMessage(player);
|
||||||
|
this._players.set(player, message);
|
||||||
|
this.addMessage(message, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
_removePlayer(player) {
|
||||||
|
const message = this._players.get(player);
|
||||||
|
|
||||||
|
if (message)
|
||||||
|
this.removeMessage(message, true);
|
||||||
|
|
||||||
|
this._players.delete(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
get allowed() {
|
||||||
|
return !Main.sessionMode.isGreeter;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
104
js/ui/mpris.js
104
js/ui/mpris.js
@ -2,7 +2,6 @@ import Gio from 'gi://Gio';
|
|||||||
import GObject from 'gi://GObject';
|
import GObject from 'gi://GObject';
|
||||||
import Shell from 'gi://Shell';
|
import Shell from 'gi://Shell';
|
||||||
|
|
||||||
import * as Main from './main.js';
|
|
||||||
import * as MessageList from './messageList.js';
|
import * as MessageList from './messageList.js';
|
||||||
|
|
||||||
import {loadInterfaceXML} from '../misc/fileUtils.js';
|
import {loadInterfaceXML} from '../misc/fileUtils.js';
|
||||||
@ -18,69 +17,6 @@ const MprisPlayerProxy = Gio.DBusProxy.makeProxyWrapper(MprisPlayerIface);
|
|||||||
|
|
||||||
const MPRIS_PLAYER_PREFIX = 'org.mpris.MediaPlayer2.';
|
const MPRIS_PLAYER_PREFIX = 'org.mpris.MediaPlayer2.';
|
||||||
|
|
||||||
const MediaMessage = GObject.registerClass(
|
|
||||||
class MediaMessage extends MessageList.Message {
|
|
||||||
constructor(player) {
|
|
||||||
super(player.source);
|
|
||||||
|
|
||||||
this._player = player;
|
|
||||||
this.add_style_class_name('media-message');
|
|
||||||
|
|
||||||
this._prevButton = this.addMediaControl('media-skip-backward-symbolic',
|
|
||||||
() => {
|
|
||||||
this._player.previous();
|
|
||||||
});
|
|
||||||
|
|
||||||
this._playPauseButton = this.addMediaControl('',
|
|
||||||
() => {
|
|
||||||
this._player.playPause();
|
|
||||||
});
|
|
||||||
|
|
||||||
this._nextButton = this.addMediaControl('media-skip-forward-symbolic',
|
|
||||||
() => {
|
|
||||||
this._player.next();
|
|
||||||
});
|
|
||||||
|
|
||||||
this._player.connectObject('changed', this._update.bind(this), this);
|
|
||||||
this._update();
|
|
||||||
}
|
|
||||||
|
|
||||||
vfunc_clicked() {
|
|
||||||
this._player.raise();
|
|
||||||
Main.panel.closeCalendar();
|
|
||||||
}
|
|
||||||
|
|
||||||
_updateNavButton(button, sensitive) {
|
|
||||||
button.reactive = sensitive;
|
|
||||||
}
|
|
||||||
|
|
||||||
_update() {
|
|
||||||
let icon;
|
|
||||||
if (this._player.trackCoverUrl) {
|
|
||||||
const file = Gio.File.new_for_uri(this._player.trackCoverUrl);
|
|
||||||
icon = new Gio.FileIcon({file});
|
|
||||||
} else {
|
|
||||||
icon = new Gio.ThemedIcon({name: 'audio-x-generic-symbolic'});
|
|
||||||
}
|
|
||||||
|
|
||||||
this.set({
|
|
||||||
title: this._player.trackTitle,
|
|
||||||
body: this._player.trackArtists.join(', '),
|
|
||||||
icon,
|
|
||||||
});
|
|
||||||
|
|
||||||
let isPlaying = this._player.status === 'Playing';
|
|
||||||
let iconName = isPlaying
|
|
||||||
? 'media-playback-pause-symbolic'
|
|
||||||
: 'media-playback-start-symbolic';
|
|
||||||
this._playPauseButton.child.icon_name = iconName;
|
|
||||||
|
|
||||||
this._updateNavButton(this._prevButton, this._player.canGoPrevious);
|
|
||||||
this._updateNavButton(this._nextButton, this._player.canGoNext);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
export const MprisPlayer = GObject.registerClass({
|
export const MprisPlayer = GObject.registerClass({
|
||||||
Properties: {
|
Properties: {
|
||||||
'can-play': GObject.ParamSpec.boolean(
|
'can-play': GObject.ParamSpec.boolean(
|
||||||
@ -316,43 +252,3 @@ export const MprisSource = GObject.registerClass({
|
|||||||
this._addPlayer(name);
|
this._addPlayer(name);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export const MediaSection = GObject.registerClass(
|
|
||||||
class MediaSection extends MessageList.MessageListSection {
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
this._players = new Map();
|
|
||||||
this._mediaSource = new MprisSource();
|
|
||||||
|
|
||||||
this._mediaSource.connectObject(
|
|
||||||
'player-added', (_, player) => this._addPlayer(player),
|
|
||||||
'player-removed', (_, player) => this._removePlayer(player),
|
|
||||||
this);
|
|
||||||
|
|
||||||
this._mediaSource.players.forEach(player => {
|
|
||||||
this._addPlayer(player);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
_addPlayer(player) {
|
|
||||||
if (this._players.has(player))
|
|
||||||
throw new Error('Player was already added previously');
|
|
||||||
|
|
||||||
const message = new MediaMessage(player);
|
|
||||||
this._players.set(player, message);
|
|
||||||
this.addMessage(message, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
_removePlayer(player) {
|
|
||||||
const message = this._players.get(player);
|
|
||||||
|
|
||||||
if (message)
|
|
||||||
this.removeMessage(message, true);
|
|
||||||
|
|
||||||
this._players.delete(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
get allowed() {
|
|
||||||
return !Main.sessionMode.isGreeter;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user