Skip to content

Commit

Permalink
Added usePreviousResults option to JS bindings for ddcci
Browse files Browse the repository at this point in the history
  • Loading branch information
xanderfrangos committed Jan 4, 2024
1 parent b6506e3 commit 59526cd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/Monitors.js
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ testDDCCIMethods = async () => {
getDDCCI()

let startTime = process.hrtime.bigint()
const accurateResults = ddcci.getAllMonitors("accurate")
const accurateResults = ddcci.getAllMonitors("accurate", false)
const accurateIDs = []
const accurateFeatures = []
for(const monitor of accurateResults) {
Expand All @@ -1007,7 +1007,7 @@ testDDCCIMethods = async () => {
ddcci._clearDisplayCache()

startTime = process.hrtime.bigint()
const fastResults = ddcci.getAllMonitors("fast")
const fastResults = ddcci.getAllMonitors("fast", false)
const fastIDs = []
const fastFeatures = []
for(const monitor of fastResults) {
Expand Down
14 changes: 7 additions & 7 deletions src/modules/node-ddcci/ddcci.cc
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ populateHandlesMapLegacy()
}

void
populateHandlesMapNormal(std::string validationMethod, bool useExisting)
populateHandlesMapNormal(std::string validationMethod, bool usePreviousResults)
{
std::map<std::string, HANDLE> newHandles;
std::map<std::string, PhysicalMonitor> newPhysicalHandles;
Expand Down Expand Up @@ -469,7 +469,7 @@ populateHandlesMapNormal(std::string validationMethod, bool useExisting)
}

// Check if monitor was previously tested and supported
if(useExisting) {
if(usePreviousResults) {
for (auto const& previousDisplay : physicalMonitorHandles) {
if(previousDisplay.second.fullName == newMonitor.fullName && previousDisplay.second.deviceID == newMonitor.deviceID && previousDisplay.second.ddcciSupported) {
newMonitor.result = previousDisplay.second.result;
Expand Down Expand Up @@ -516,15 +516,15 @@ populateHandlesMapNormal(std::string validationMethod, bool useExisting)
}

void
populateHandlesMap(std::string validationMethod)
populateHandlesMap(std::string validationMethod, bool usePreviousResults)
{
if (validationMethod == "legacy")
return populateHandlesMapLegacy();

if (validationMethod == "accurate" || validationMethod == "no-validation")
return populateHandlesMapNormal(validationMethod, true);
return populateHandlesMapNormal(validationMethod, usePreviousResults);

return populateHandlesMapNormal("fast", true);
return populateHandlesMapNormal("fast", usePreviousResults);
}

std::string
Expand Down Expand Up @@ -558,12 +558,12 @@ refresh(const Napi::CallbackInfo& info)
if (info.Length() < 1) {
throw Napi::TypeError::New(env, "Not enough arguments");
}
if (!info[0].IsString()) {
if (!info[0].IsString() || !info[1].IsBoolean()) {
throw Napi::TypeError::New(env, "Invalid arguments");
}

try {
populateHandlesMap(info[0].As<Napi::String>().Utf8Value());
populateHandlesMap(info[0].As<Napi::String>().Utf8Value(), info[1].As<Napi::Boolean>().ToBoolean());
} catch (std::runtime_error& e) {
throw Napi::Error::New(env, e.what());
}
Expand Down
10 changes: 5 additions & 5 deletions src/modules/node-ddcci/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ module.exports = {
, _getAllMonitors: ddcci.getAllMonitors
, _clearDisplayCache: ddcci.clearDisplayCache
, _setLogLevel: ddcci.setLogLevel
, _refresh: (method = "accurate") => ddcci.refresh(method)
, getMonitorList: (method = "accurate") => {
ddcci.refresh(method);
, _refresh: (method = "accurate", usePreviousResults = true) => ddcci.refresh(method, usePreviousResults)
, getMonitorList: (method = "accurate", usePreviousResults = true) => {
ddcci.refresh(method, usePreviousResults);
return ddcci.getMonitorList();
}
, getAllMonitors: (method = "accurate") => {
ddcci.refresh(method);
, getAllMonitors: (method = "accurate", usePreviousResults = true) => {
ddcci.refresh(method, usePreviousResults);
const monitors = ddcci.getAllMonitors();
for(const monitor of monitors) {
if(monitor.result && monitor.result != "ok" && monitor.result != "invalid") {
Expand Down

0 comments on commit 59526cd

Please sign in to comment.