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:
|
// Notification:
|
||||||
// @source: the notification's Source
|
// @source: the notification's Source
|
||||||
// @title: the title
|
// @title: the title
|
||||||
@ -391,8 +410,7 @@ export const Notification = GObject.registerClass({
|
|||||||
this.forFeedback = false;
|
this.forFeedback = false;
|
||||||
this.bannerBodyText = null;
|
this.bannerBodyText = null;
|
||||||
this.bannerBodyMarkup = false;
|
this.bannerBodyMarkup = false;
|
||||||
this._soundName = null;
|
this.sound = null;
|
||||||
this._soundFile = null;
|
|
||||||
this._soundPlayed = false;
|
this._soundPlayed = false;
|
||||||
this.actions = [];
|
this.actions = [];
|
||||||
this.setResident(false);
|
this.setResident(false);
|
||||||
@ -419,8 +437,7 @@ export const Notification = GObject.registerClass({
|
|||||||
bannerMarkup: false,
|
bannerMarkup: false,
|
||||||
clear: false,
|
clear: false,
|
||||||
datetime: null,
|
datetime: null,
|
||||||
soundName: null,
|
sound: null,
|
||||||
soundFile: null,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.title = title;
|
this.title = title;
|
||||||
@ -438,10 +455,8 @@ export const Notification = GObject.registerClass({
|
|||||||
if (params.clear)
|
if (params.clear)
|
||||||
this.actions = [];
|
this.actions = [];
|
||||||
|
|
||||||
if (this._soundName !== params.soundName ||
|
if (this.sound !== params.sound) {
|
||||||
this._soundFile !== params.soundFile) {
|
this.sound = params.sound;
|
||||||
this._soundName = params.soundName;
|
|
||||||
this._soundFile = params.soundFile;
|
|
||||||
this._soundPlayed = false;
|
this._soundPlayed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -495,11 +510,7 @@ export const Notification = GObject.registerClass({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let player = global.display.get_sound_player();
|
this.sound?.play(this.title);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow customizing the banner UI:
|
// Allow customizing the banner UI:
|
||||||
|
@ -204,8 +204,7 @@ class FdoNotificationDaemon {
|
|||||||
gicon,
|
gicon,
|
||||||
bannerMarkup: true,
|
bannerMarkup: true,
|
||||||
clear: true,
|
clear: true,
|
||||||
soundFile,
|
sound: new MessageTray.Sound(soundFile, hints['sound-name']),
|
||||||
soundName: hints['sound-name'],
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let hasDefaultAction = false;
|
let hasDefaultAction = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user