AzzamAlsharafi / ideapad-controls-gnome-extension

GNOME Shell extension for controling Lenovo IdeaPad laptops options.
GNU General Public License v3.0
27 stars 5 forks source link

Error in `enable()` when missing a sys option #3

Closed andyholmes closed 1 year ago

andyholmes commented 1 year ago

Great extension!

My IdeaPad is missing .../usb_charging, so the extension has an error at startup:

Gio.IOErrorEnum: Error opening file /sys/bus/platform/drivers/ideapad_acpi/VPC2004:00/usb_charging: No such file or directory

I guess an easy way to fix this is something like:

function addOptionsToMenu(menu) {
  let settings = ExtensionUtils.getSettings('org.gnome.shell.extensions.ideapad-controls');

  // Create a switch item for each option
  for (let i = 0; i < options.length; i++) {
    // Convert option title to schema key, i.e. "Camera Lock" becomes "camera-lock-option"
    const optionKey = options[i].toLowerCase().replace(" ", "-") + "-option";

    try {
        // should fail at this point
        let optionSwitch = new PopupMenu.PopupSwitchMenuItem(options[i], getOptionValue(i) === "1");

        // etc...
    } catch (e) {
        logError(e, `Failed to read option ${options[i]}`);

        // Error has occurred, so remove the item and decrement the position before the next iteration
        options.splice(i--, 1);
    }
  }
}
AzzamAlsharafi commented 1 year ago

Hello, can you try to install the extension manually and see if it works now?

andyholmes commented 1 year ago

Works great now, thanks!

AzzamAlsharafi commented 1 year ago

Thanks for the confirmation.