Skip to content

Commit

Permalink
_parseSupportedProfiles:
Browse files Browse the repository at this point in the history
Added a method _parseSupportedProfiles to handle the non-JSON formatted output from supergfxctl -s.
This method cleans up the string and splits it into an array of supported profiles.
Error Handling and Default Fallback:

Ensured proper error handling and default fallback to all available profiles in case of parsing errors or command execution failures.
With these changes, the extension will correctly display only the supported modes based on the output of the supergfxctl -s command.
  • Loading branch information
chikobara committed Jun 20, 2024
1 parent e0bff07 commit 1b7f80c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ const GpuProfilesToggle = GObject.registerClass(
try {
let [ok, stdout, stderr] = proc.communicate_utf8_finish(res);
if (ok) {
const supportedProfiles = JSON.parse(stdout.trim());
const supportedProfiles = this._parseSupportedProfiles(
stdout.trim()
);
this._addProfileToggles(supportedProfiles);
this._fetchCurrentProfile();
} else {
Expand All @@ -92,6 +94,15 @@ const GpuProfilesToggle = GObject.registerClass(
}
}

_parseSupportedProfiles(output) {
try {
return output.replace(/[\[\]\s]/g, "").split(",");
} catch (e) {
console.error(`Error parsing supported profiles: ${e.message}`);
return Object.keys(GPU_PROFILE_PARAMS);
}
}

_fetchCurrentProfile() {
try {
let proc = Gio.Subprocess.new(
Expand Down

0 comments on commit 1b7f80c

Please sign in to comment.