Skip to content

Commit

Permalink
Better integrate studio-display-control
Browse files Browse the repository at this point in the history
  • Loading branch information
xanderfrangos committed May 26, 2024
1 parent 929180b commit 6c8501a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
49 changes: 43 additions & 6 deletions src/Monitors.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ process.on('message', async (data) => {
settings = data.settings

// Overrides
if (settings?.disableAppleStudio) appleStudioUnavailable = true;
if (settings?.disableWMIC) wmicUnavailable = true;
if (settings?.disableWMI) wmiFailed = true;
if (settings?.disableWin32) win32Failed = true;
Expand Down Expand Up @@ -74,6 +75,7 @@ process.on('message', async (data) => {
lastDDCCIList,
lastWMI,
lastWin32,
monitorsAppleStudio,
monitorReports,
monitorReportsRaw,
lastRefresh,
Expand All @@ -91,6 +93,7 @@ let skipTest = (process.argv.indexOf("--skiptest=true") >= 0)

let monitors = false
let monitorNames = []
let monitorsAppleStudio = {}
let monitorsWin32 = {}
let monitorReports = {}
let monitorReportsRaw = {}
Expand Down Expand Up @@ -172,8 +175,17 @@ refreshMonitors = async (fullRefresh = false, ddcciType = "default", alwaysSendU
console.log("\x1b[41m" + "getBrightnessWMI() failed!" + "\x1b[0m", e)
}
}

await getStudioDisplay(monitors);

// Apple Studio displays
if (!appleStudioUnavailable) {
try {
startTime = process.hrtime.bigint()
monitorsAppleStudio = await getStudioDisplay(monitors);
console.log(`getStudioDisplay() Total: ${(startTime - process.hrtime.bigint()) / BigInt(-1000000)}ms`)
} catch (e) {
console.log("\x1b[41m" + "getStudioDisplay() failed!" + "\x1b[0m", e)
}
}

// Hide internal
if (settings?.hideClosedLid) {
Expand Down Expand Up @@ -244,7 +256,19 @@ getAllMonitors = async (ddcciMethod = "default") => {
console.log("getMonitorsWin32() skipped due to previous failure.")
}

await getStudioDisplay(foundMonitors);
// List Apple Studio displays
if (!appleStudioUnavailable) {
try {
startTime = process.hrtime.bigint()
monitorsAppleStudio = await getStudioDisplay(foundMonitors);
console.log(`getStudioDisplay() Total: ${(startTime - process.hrtime.bigint()) / BigInt(-1000000)}ms`)
} catch (e) {
console.log("\x1b[41m" + "getStudioDisplay() failed!" + "\x1b[0m", e)
}
} else {
console.log("getStudioDisplay() skipped due to previous failure.")
}


// DDC/CI Brightness + Features
try {
Expand Down Expand Up @@ -371,23 +395,36 @@ function determineDDCCIMethod() {
return ddcciMethod
}

let appleStudioUnavailable = false
getStudioDisplay = async (monitors) => {
try {
const sdctl = require("studio-display-control")
const displays = {}
let count = 0
for (const display of sdctl.getDisplays()) {
const serial = await display.getSerialNumber();
const hwid = [
"\\\\?\\DISPLAY",
"APPAE3A",
`APLSTD-${serial}-NUM${count}`
]
updateDisplay(monitors, serial, {
name: "Apple Studio Display",
type: "studio-display",
key: serial,
id: serial,
key: hwid[2],
id: `\\\\?\\${hwid[0]}#${hwid[1]}#${hwid[2]}`,
hwid,
serial,
brightness: await display.getBrightness()
});
displays[hwid[2]] = display
count++
}
return displays
} catch (e) {
console.log("\x1b[41m" + "getStudioDisplay(): failed to access Studio Display" + "\x1b[0m", e)
}
return {}
}

setStudioDisplayBrightness = async (serial, brightness) => {
Expand Down Expand Up @@ -785,7 +822,7 @@ function setBrightness(brightness, id) {
if(monitor) {
monitor.brightness = brightness
if (monitor.type == "studio-display") {
setStudioDisplayBrightness(id, brightness)
setStudioDisplayBrightness(monitor.serial, brightness)
} else {
setVCP(monitor.hwid.join("#"), monitor.brightnessType, brightness)
}
Expand Down
1 change: 1 addition & 0 deletions src/components/SettingsWindow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,7 @@ export default class SettingsWindow extends PureComponent {
<div className="sectionTitle">{T.t("SETTINGS_GENERAL_TROUBLESHOOTING")}</div>

<SettingsOption title={T.t("SETTINGS_GENERAL_DIS_MONITOR_FEATURES_TITLE")} description={T.h("SETTINGS_GENERAL_DIS_MONITOR_FEATURES_DESC", '<a href="javascript:window.openURL(\'troubleshooting-features\')">' + T.t("SETTINGS_GENERAL_ANALYTICS_LINK") + '</a>')} expandable={true}>
<SettingsChild title={"Apple Studio Displays"} input={this.renderToggle("disableAppleStudio", true, "right", true)} />
<SettingsChild title={"WMIC"} input={this.renderToggle("disableWMIC", true, "right", true)} />
<SettingsChild title={"WMI-Bridge"} input={this.renderToggle("disableWMI", true, "right", true)} />
<SettingsChild title={"Win32-DisplayConfig"} input={this.renderToggle("disableWin32", true, "right", true)} />
Expand Down
1 change: 1 addition & 0 deletions src/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ const defaultSettings = {
checkVCPWaitMS: 20,
overrideTaskbarPosition: false,
overrideTaskbarGap: false,
disableAppleStudio: false,
disableWMIC: false,
disableWMI: false,
disableWin32: false,
Expand Down

0 comments on commit 6c8501a

Please sign in to comment.