I am trying to build a GNOME extension for my personal use on my Ubuntu system. The purpose of this extension is to switch between LAMP versions.
const Indicator = GObject.registerClass(
class Indicator extends PanelMenu.Button {
_init() {
super._init(0.0, _('PHP Switcher'));
this.add_child(new St.Icon({
icon_name: 'face-smile-symbolic',
style_class: 'system-status-icon',
}));
let item = new PopupMenu.PopupMenuItem(_('Switch to PHP 7.4'));
item.connect('activate', () => {
GLib.spawn_command_line_sync('sudo /opt/lampp/lampp stop && sudo rm /opt/lampp && sudo ln -s 7.4 /opt/lampp && sudo /opt/lampp/lampp start');
});
let item2 = new PopupMenu.PopupMenuItem(_('Switch to PHP 8.1'));
item2.connect('activate', () => {
GLib.spawn_command_line_sync('sudo /opt/lampp/lampp stop && sudo rm /opt/lampp && sudo ln -s 8.1 /opt/lampp && sudo /opt/lampp/lampp start');
});
this.menu.addMenuItem(item);
this.menu.addMenuItem(item2);
}
});
when i try click switch to php 7.4 and 8.1 its not work
Does anyone know why this isn't working?


Based on an image to text analysis of the input, we see the following commands being issued:
Now this is being run in a shell extension. These don't have a terminal associated with them, and thus won't have a place to type in a password.
In general for things that are in this situation, you should use something other than
sudo, such aspkexec, and make the entire set of commands into onepkexeccommand line like:This will cause the prompt for the sudo password, and then run the set of commands.
So, for the full command line, as asked about in the subsequent comment:
Please note: testing this was really tedious as I could not get gnome to reload my extension without restarting my entire session.