Adopt EventEmitter class instead of injecting Signal methods
Introduce a new class, EventEmitter, which implements signal handling for pure JavaScript classes. EventEmitter still utilizes GJS' addSignalMethods internally. EventEmitter allows static typechecking to understand the structure of event-emitting JS classes and makes creating child classes simpler. The name 'EventEmitter' mirrors a common name for this pattern in Node and in JS libraries. Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2043>
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
/* exported MediaSection */
|
||||
const { Gio, GObject, Shell, St } = imports.gi;
|
||||
const Signals = imports.signals;
|
||||
const Signals = imports.misc.signals;
|
||||
|
||||
const Main = imports.ui.main;
|
||||
const MessageList = imports.ui.messageList;
|
||||
@ -86,14 +86,16 @@ class MediaMessage extends MessageList.Message {
|
||||
}
|
||||
});
|
||||
|
||||
var MprisPlayer = class MprisPlayer {
|
||||
var MprisPlayer = class MprisPlayer extends Signals.EventEmitter {
|
||||
constructor(busName) {
|
||||
super();
|
||||
|
||||
this._mprisProxy = new MprisProxy(Gio.DBus.session, busName,
|
||||
'/org/mpris/MediaPlayer2',
|
||||
this._onMprisProxyReady.bind(this));
|
||||
'/org/mpris/MediaPlayer2',
|
||||
this._onMprisProxyReady.bind(this));
|
||||
this._playerProxy = new MprisPlayerProxy(Gio.DBus.session, busName,
|
||||
'/org/mpris/MediaPlayer2',
|
||||
this._onPlayerProxyReady.bind(this));
|
||||
'/org/mpris/MediaPlayer2',
|
||||
this._onPlayerProxyReady.bind(this));
|
||||
|
||||
this._visible = false;
|
||||
this._trackArtists = [];
|
||||
@ -233,7 +235,6 @@ var MprisPlayer = class MprisPlayer {
|
||||
}
|
||||
}
|
||||
};
|
||||
Signals.addSignalMethods(MprisPlayer.prototype);
|
||||
|
||||
var MediaSection = GObject.registerClass(
|
||||
class MediaSection extends MessageList.MessageListSection {
|
||||
|
Reference in New Issue
Block a user