Merge pull request #295 from dumingqiao/master

fixed: TypeError: this.container.get_parent() is null in gnome 48.
This commit is contained in:
Vasilii
2025-05-15 09:51:48 +03:00
committed by GitHub

View File

@@ -175,6 +175,11 @@ class FreonMenuButton extends PanelMenu.Button {
// readd to update queue // readd to update queue
return true; return true;
}); });
GLib.timeout_add(GLib.PRIORITY_DEFAULT, 500, () => {
this._positionInPanelChanged();
return false; // 只执行一次
});
} }
_createHotItem(s, showIcon, gicon){ _createHotItem(s, showIcon, gicon){
@@ -208,31 +213,47 @@ class FreonMenuButton extends PanelMenu.Button {
this._querySensors(); this._querySensors();
} }
_positionInPanelChanged(){ _positionInPanelChanged() {
this.container.get_parent().remove_child(this.container); try {
if (!this.container || !this.container.get_parent()) {
console.debug('Container not ready yet, skipping position change');
return;
}
// small HACK with private boxes :) if (!Main.panel._leftBox || !Main.panel._centerBox || !Main.panel._rightBox) {
let boxes = { console.debug('Panel boxes not available yet');
left: Main.panel._leftBox, return;
center: Main.panel._centerBox, }
right: Main.panel._rightBox
};
let i = this._settings.get_int('panel-box-index'); this.container.get_parent().remove_child(this.container);
let p = this._settings.get_int('position-in-panel');
console.debug(p) // small HACK with private boxes :)
let boxes = {
left: Main.panel._leftBox,
center: Main.panel._centerBox,
right: Main.panel._rightBox
};
switch (p) { let i = this._settings.get_int('panel-box-index');
case 0: let p = this._settings.get_int('position-in-panel');
boxes['left'].insert_child_at_index(this.container, i); break;
case 1: console.debug('Position in panel:', p);
boxes['center'].insert_child_at_index(this.container, i); break;
case 2: switch (p) {
default: case 0:
boxes['right'].insert_child_at_index(this.container, i); break; boxes['left'].insert_child_at_index(this.container, i);
break;
case 1:
boxes['center'].insert_child_at_index(this.container, i);
break;
case 2:
default:
boxes['right'].insert_child_at_index(this.container, i);
break;
}
} catch (error) {
console.error('Error while changing panel position:', error);
} }
//boxes[p].insert_child_at_index(this.container, i);
} }
_showIconOnPanelChanged(){ _showIconOnPanelChanged(){
@@ -1042,8 +1063,11 @@ export default class extends Extension {
enable() { enable() {
this._freonMenu = new FreonMenuButton(this.uuid, this.path, this.getSettings()); this._freonMenu = new FreonMenuButton(this.uuid, this.path, this.getSettings());
Main.panel.addToStatusArea('freonMenu', this._freonMenu); try {
this._freonMenu._positionInPanelChanged(); Main.panel.addToStatusArea('freonMenu', this._freonMenu);
} catch (error) {
console.error('Error adding Freon to status area:', error);
}
} }
disable() { disable() {