简体   繁体   English

在 Gnome Shell 中设置通知图标 >= 3.16(自定义扩展)

[英]Set Notification Icon in Gnome Shell >= 3.16 (Custom Extension)

I've forked a Gnome Shell Extension, as I want to modify it to fit my personal preferences.我已经分叉了一个 Gnome Shell 扩展,因为我想修改它以适合我的个人喜好。 I want to send a notification each time an event occurs.我想在每次发生事件时发送通知。 Sending the notification itself is fairly easy with Main.notify(summary, text) .使用Main.notify(summary, text)发送通知本身相当容易。 However, I just can't find out how to set a custom icon.但是,我就是不知道如何设置自定义图标。 [EDIT: The following is wrong. [编辑:以下是错误的。 I looked up bad code] According to the github repo of gnome-shell I can define an icon via an optional parameter: Main.notify(summary, text, params) , where params will be checked in MessageTray.js l.367:我查找了错误代码]根据 gnome-shell 的 github 存储库,我可以通过可选参数定义一个图标: Main.notify(summary, text, params) ,其中params将在MessageTray.js l.367:检查MessageTray.js l.367:

 params = Params.parse(params, { gicon: null, secondaryGIcon: null, bannerMarkup: false, clear: false, soundName: null, soundFile: null }); if (params.gicon || params.clear) this.gicon = params.gicon;

So I tried to use the following command:所以我尝试使用以下命令:

 Main.notify(summary, text, {gicon: myicon});

But the {gicon: myicon} part is ignored completely and the default icon is used :-/.但是{gicon: myicon}部分被完全忽略并使用默认图标:-/。 I'm new to Javascript and GNOME programming, so pls don't hate me :-)我是 Javascript 和 GNOME 编程的新手,所以请不要讨厌我 :-)

Is using Main.notify() recommended generally, or is it deprecated?一般推荐使用Main.notify()还是不推荐使用?

Cheers, Maphardam干杯,马法丹

I think that Main.notify() is generally recommended, as it is used in some of the "official" extensions.我认为Main.notify()通常是推荐的,因为它用于一些“官方”扩展。

However, Main.notify() only takes two parameters (msg, details) and thus you cannot use this function to set a custom icon.但是, Main.notify()只接受两个参数(msg, details) ,因此您不能使用此函数来设置自定义图标。 You can however copy the source of Main.notify() and adapt it to your own needs.但是,您可以复制Main.notify()的源代码并根据自己的需要进行调整。 Inside the following function the source of the notification is set to a newly created source with a custom icon.在以下函数中,通知source设置为新创建的带有自定义图标的源。

function notify(msg, details, icon) {
    let source = new MessageTray.Source("MyApp Information", icon);
    Main.messageTray.add(source);
    let notification = new MessageTray.Notification(source, msg, details);
    notification.setTransient(true);
    source.notify(notification);
}

For example you could call it with notify("MyApp", "Test", 'folder-symbolic');例如,您可以使用notify("MyApp", "Test", 'folder-symbolic');调用它notify("MyApp", "Test", 'folder-symbolic'); . .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM