notification: Pass policy in the Source contructor

Commit 932ccac1 changed Source to use a regular constructor
instead of `_init()`.

Unfortunately that results in ordering issues for subclasses
that override `_createPolicy()`, if that method needs to access
any properties that are set in the constructor (as `this` is
only available after chaining up to the parent).

We can fix that by simply setting the policy from the constructor,
instead of relying on some overriden method being called.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3170>
This commit is contained in:
Florian Müllner
2024-02-06 18:16:29 +01:00
committed by Marge Bot
parent 810391f41e
commit 3fc7ed4088
4 changed files with 53 additions and 81 deletions

View File

@ -56,15 +56,14 @@ export class WindowAttentionHandler {
const WindowAttentionSource = GObject.registerClass(
class WindowAttentionSource extends MessageTray.Source {
_init(app, window) {
this._window = window;
this._app = app;
super._init({
title: this._app.get_name(),
icon: this._app.get_icon(),
constructor(app, window) {
super({
title: app.get_name(),
icon: app.get_icon(),
policy: MessageTray.NotificationPolicy.newForApp(app),
});
this._window = window;
this._window.connectObject(
'notify::demands-attention', this._sync.bind(this),
'notify::urgent', this._sync.bind(this),
@ -78,15 +77,6 @@ class WindowAttentionSource extends MessageTray.Source {
this.destroy();
}
_createPolicy() {
if (this._app && this._app.get_app_info()) {
let id = this._app.get_id().replace(/\.desktop$/, '');
return new MessageTray.NotificationApplicationPolicy(id);
} else {
return new MessageTray.NotificationGenericPolicy();
}
}
destroy(params) {
this._window.disconnectObject(this);