components/autorunManager: Use notification actions API

Stop using custom buttons for notification actions. The only reason to
use custom buttons was so that we could add icons next to the button
label, if we really need the icons next to the label we can add icons to
the notification API.
By using the actions API we can ensure that buttons always look the
same without additional work.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3173>
This commit is contained in:
Julian Sparber 2024-02-09 12:55:44 +01:00 committed by Florian Müllner
parent 050e4e9a6e
commit 6d6ac1372a
4 changed files with 14 additions and 82 deletions

View File

@ -21,7 +21,6 @@
@import 'widgets/ibus-popup';
// Notifications
@import 'widgets/notifications';
@import 'widgets/hotplug';
// Dialogs
@import 'widgets/dialogs';
// OSDs

View File

@ -1,10 +0,0 @@
// hotplug
.hotplug-notification-item {
@extend %bubble_button;
}
.hotplug-notification-item-icon {
icon-size: $medium_icon_size;
padding: 0 $base_margin;
}

View File

@ -17,7 +17,6 @@ theme_sources = files([
'gnome-shell-sass/widgets/_dash.scss',
'gnome-shell-sass/widgets/_dialogs.scss',
'gnome-shell-sass/widgets/_entries.scss',
'gnome-shell-sass/widgets/_hotplug.scss',
'gnome-shell-sass/widgets/_ibus-popup.scss',
'gnome-shell-sass/widgets/_keyboard.scss',
'gnome-shell-sass/widgets/_login-lock.scss',

View File

@ -1,9 +1,6 @@
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
import Clutter from 'gi://Clutter';
import Gio from 'gi://Gio';
import GObject from 'gi://GObject';
import St from 'gi://St';
import * as GnomeSession from '../../misc/gnomeSession.js';
import * as MessageTray from '../messageTray.js';
@ -190,7 +187,20 @@ class AutorunDispatcher {
return;
const source = MessageTray.getSystemSource();
const notification = new AutorunNotification(source, mount, apps);
const notification = new MessageTray.Notification(
source,
mount.get_name()
);
notification.connect('activate', () => {
const app = Gio.app_info_get_default_for_type('inode/directory', false);
startAppForMount(app, mount);
});
apps.forEach(app => {
notification.addAction(
_('Open with %s').format(app.get_name()),
() => startAppForMount(app, mount)
);
});
notification.connect('destroy', () => this._notifications.delete(mount));
this._notifications.set(mount, notification);
source.showNotification(notification);
@ -238,70 +248,4 @@ class AutorunDispatcher {
}
}
const AutorunNotification = GObject.registerClass(
class AutorunNotification extends MessageTray.Notification {
constructor(source, mount, apps) {
super(source, mount.get_name());
this.gicon = mount.get_icon();
this._mount = mount;
this._apps = apps;
}
createBanner() {
let banner = new MessageTray.NotificationBanner(this);
this._apps.forEach(app => {
let actor = this._buttonForApp(app);
if (actor)
banner.addButton(actor);
});
return banner;
}
_buttonForApp(app) {
let box = new St.BoxLayout({
x_expand: true,
x_align: Clutter.ActorAlign.START,
});
const icon = new St.Icon({
gicon: app.get_icon(),
style_class: 'hotplug-notification-item-icon',
});
box.add_child(icon);
let label = new St.Bin({
child: new St.Label({
text: _('Open with %s').format(app.get_name()),
y_align: Clutter.ActorAlign.CENTER,
}),
});
box.add_child(label);
const button = new St.Button({
child: box,
x_expand: true,
button_mask: St.ButtonMask.ONE,
style_class: 'hotplug-notification-item button',
});
button.connect('clicked', () => {
startAppForMount(app, this._mount);
this.destroy();
});
return button;
}
activate() {
super.activate();
let app = Gio.app_info_get_default_for_type('inode/directory', false);
startAppForMount(app, this._mount);
}
});
export {AutorunManager as Component};