问题描述
我有一些全局快捷方式来更新麦克风声音输入电平。因此,我创建了一个 gnome 扩展,在顶部栏中添加一个标签,显示当前麦克风声音百分比。
extension.js
中的代码是这样的:
const Microphone = new Lang.Class({
Name: 'Microphone',_init: function() {
this.active = null;
this.stream = null;
this.muted_changed_id = 0;
this.mixer_control = new Gvc.MixerControl({name: 'Some random name'});
this.mixer_control.open();
this.mixer_control.connect('default-source-changed',Lang.bind(this,this.refresh));
this.mixer_control.connect('stream-added',this.refresh));
this.mixer_control.connect('stream-removed',this.refresh));
this.stream = this.mixer_control.get_default_source();
},// ...
get level() {
return 100 * this.stream.get_volume() / this.mixer_control.get_vol_max_norm();
}
});
function enable() {
// ...
microphone = new Microphone();
let panel_button_label = new St.Label({
y_expand: true,y_align: Clutter.ActorAlign.CENTER
});
panel_button_label.text = microphone.level + '%';
Main.panel._rightBox.insert_child_at_index(panel_button_label,0);
}
function disable() {
// ...
Main.panel._rightBox.remove_child(panel_button_label);
panel_button_label.destroy();
panel_button_label = null;
}
但是,每次全局快捷方式更新麦克风级别时,我不知道如何更新 microphone.label
标签文本。截至目前,它始终显示为 0%。我查看了 journalctl
中的日志,没有警告或错误。
我在 How to handle keyboard events in gnome shell extensions? 上找到了 StackOverflow 链接,但是,我不希望将其链接到特定的键盘事件。相反,即使通过其他方式更改了麦克风级别,标签也应该更新。
我想我需要将它连接到信号或使用类似的东西,但是,我不知道该怎么做。我是 gnome 扩展的新手,所以详细的解释可能会有所帮助。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)