Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,31 @@ function windows(brightness,callback){

// powercfg -q gives information about power settings, but can only give accurate brightness info for laptops or other portable windows devices

exec('powercfg -q', function(error,stdout,stderr){
if(!error){
var regExp = /([a-z\-0-9]+)\s\D+$/
var splitOutput = stdout.split('\r\n');
GUID = regExp.exec(splitOutput[0])[1];
// Get the current power scheme GUID
exec("powercfg /getactivescheme", function (error, stdout, stderr) {
if (error) throw error;

for(var i = 0;i<splitOutput.length;i++){
if(splitOutput[i].match(/\(Display\)$/)){
const match = stdout.match(/GUID:\s*([a-f0-9\-]+)/i);
if (!match) throw new Error("Failed to retrieve the power scheme GUID");
GUID = match[1];

//The subgroup is derived from the output named display
// Get the SUB_VIDEO subgroup GUID
exec("powercfg -aliases | findstr /i SUB_VIDEO", function (error, stdout, stderr) {
if (error) throw error;

subgroup = regExp.exec(splitOutput[i])[1];
}
else if(splitOutput[i].match(/\(Display\sbrightness\)$/)){
const matchSub = stdout.match(/([a-f0-9\-]+)\s+SUB_VIDEO/i);
if (!matchSub) throw new Error("Failed to retrieve the SUB_VIDEO GUID");
subgroup = matchSub[1];

//The powerSetting is derived from the output named Display
// Get the GUID of VIDEONORMALLEVEL
exec("powercfg -aliases | findstr /i VIDEONORMALLEVEL", function (error, stdout, stderr) {
if (error) throw error;

powerSetting = regExp.exec(splitOutput[i])[1];
}
}
const matchPower = stdout.match(
/([a-f0-9\-]+)\s+VIDEONORMALLEVEL/i
);
if (!matchPower) throw new Error("Failed to retrieve the VIDEONORMALLEVEL GUID");
powerSetting = matchPower[1];

//console.log(GUID,subgroup,powerSetting);

Expand All @@ -84,11 +89,9 @@ function windows(brightness,callback){
});
});

}
else{
throw error;
}
});
});
});
});
}

function changeBrightness(brightness,callback){
Expand Down