これは、gnome-shell 拡張機能がどのように機能するかについての (私の側の) 基本的な誤解に違いありません。ドキュメントを見つけるのに苦労しましたが、残念ながら、少しまばらなようです。
通常FFMを使用しているため、フォーカスモードをFFMからパネル内のアイコンをクリックしてフォーカスするように切り替える簡単な拡張機能を書きたいのですが、一部のプログラムが壊れています。そのため、基本的なものから始めてgnome-shell-extension-tool --create-extension
、次のように変更しました。
const St = imports.gi.St;
const Main = imports.ui.main;
const Tweener = imports.ui.tweener;
let text, button, icon;
var toggle;
function _hideHello() {
Main.uiGroup.remove_actor(text);
text = null;
}
function _showHello(what) {
if (!text) {
text = new St.Label({ style_class: 'helloworld-label', text: what });
Main.uiGroup.add_actor(text);
}
text.opacity = 255;
let monitor = Main.layoutManager.primaryMonitor;
text.set_position(Math.floor(monitor.width / 2 - text.width / 2),
Math.floor(monitor.height / 2 - text.height / 2));
Tweener.addTween(text,
{ opacity: 0,
time: 2,
transition: 'easeOutQuad',
onComplete: _hideHello });
}
function _switch() {
if (toggle == 0) {
toggle = 1;
_showHello("Setting toggle to " + toggle);
}
if (toggle == 1) {
toggle = 0;
_showHello("Setting toggle to " + toggle);
}
}
function init() {
button = new St.Bin({ style_class: 'panel-button',
reactive: true,
can_focus: true,
x_fill: true,
y_fill: false,
track_hover: true });
icon = new St.Icon({ icon_name: 'system-run-symbolic',
style_class: 'system-status-icon' });
button.set_child(icon);
toggle = 0;
button.connect('button-press-event', _switch);
}
function enable() {
Main.panel._rightBox.insert_child_at_index(button, 0);
}
function disable() {
Main.panel._rightBox.remove_child(button);
}
ボタンを押すたびにtoggle
0 から 1 に、またはその逆に切り替えることができるという (おそらくナイーブな) 考えでした。
代わりに、ボタンをクリックするたびに、同じ「トグルを 1 に設定しています」というメッセージが表示されます。
誰が何が起こっているのか説明できますか? ありがとう。