messageTray: Add object holding sound for a notification
A notification can have two ways to specify a sound, via a name of a sound in the sound theme and/or a file. Therefore introduce an object that can hold both properties and creates an abstraction over the different source. This reduces the number of properties for a notification, which will make it simpler to port it to GObject properties. Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3173>
This commit is contained in:
parent
f8567bb1a7
commit
e4c44fd1ed
@ -314,6 +314,25 @@ export const NotificationApplicationPolicy = GObject.registerClass({
|
||||
}
|
||||
});
|
||||
|
||||
export const Sound = GObject.registerClass(
|
||||
class Sound extends GObject.Object {
|
||||
constructor(file, themedName) {
|
||||
super();
|
||||
|
||||
this._soundFile = file;
|
||||
this._soundName = themedName;
|
||||
}
|
||||
|
||||
play() {
|
||||
const player = global.display.get_sound_player();
|
||||
|
||||
if (this._soundName)
|
||||
player.play_from_theme(this._soundName, _('Notification sound'), null);
|
||||
else if (this._soundFile)
|
||||
player.play_from_file(this._soundFile, _('Notification sound'), null);
|
||||
}
|
||||
});
|
||||
|
||||
// Notification:
|
||||
// @source: the notification's Source
|
||||
// @title: the title
|
||||
@ -391,8 +410,7 @@ export const Notification = GObject.registerClass({
|
||||
this.forFeedback = false;
|
||||
this.bannerBodyText = null;
|
||||
this.bannerBodyMarkup = false;
|
||||
this._soundName = null;
|
||||
this._soundFile = null;
|
||||
this.sound = null;
|
||||
this._soundPlayed = false;
|
||||
this.actions = [];
|
||||
this.setResident(false);
|
||||
@ -419,8 +437,7 @@ export const Notification = GObject.registerClass({
|
||||
bannerMarkup: false,
|
||||
clear: false,
|
||||
datetime: null,
|
||||
soundName: null,
|
||||
soundFile: null,
|
||||
sound: null,
|
||||
});
|
||||
|
||||
this.title = title;
|
||||
@ -438,10 +455,8 @@ export const Notification = GObject.registerClass({
|
||||
if (params.clear)
|
||||
this.actions = [];
|
||||
|
||||
if (this._soundName !== params.soundName ||
|
||||
this._soundFile !== params.soundFile) {
|
||||
this._soundName = params.soundName;
|
||||
this._soundFile = params.soundFile;
|
||||
if (this.sound !== params.sound) {
|
||||
this.sound = params.sound;
|
||||
this._soundPlayed = false;
|
||||
}
|
||||
|
||||
@ -495,11 +510,7 @@ export const Notification = GObject.registerClass({
|
||||
return;
|
||||
}
|
||||
|
||||
let player = global.display.get_sound_player();
|
||||
if (this._soundName)
|
||||
player.play_from_theme(this._soundName, this.title, null);
|
||||
else if (this._soundFile)
|
||||
player.play_from_file(this._soundFile, this.title, null);
|
||||
this.sound?.play(this.title);
|
||||
}
|
||||
|
||||
// Allow customizing the banner UI:
|
||||
|
@ -204,8 +204,7 @@ class FdoNotificationDaemon {
|
||||
gicon,
|
||||
bannerMarkup: true,
|
||||
clear: true,
|
||||
soundFile,
|
||||
soundName: hints['sound-name'],
|
||||
sound: new MessageTray.Sound(soundFile, hints['sound-name']),
|
||||
});
|
||||
|
||||
let hasDefaultAction = false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user