Closed rp1231 closed 10 months ago
Sorry but as mentioned in https://github.com/ruihe774/brightness-tray/issues/1#issuecomment-1826804866, currently I have no WMI monitor (e.g. laptop monitors) so I have no way to implement and debug WMI support. I'd like to implement it when I get a laptop someday. Any help is appreciated. BTW, this issue should be kept open.
I can help with the testing of the code if it's possible to develop in that way. You can create a branch for wmi and I can test the code?
@rp1231 You can have a try a45d66dea154efc5506034633a381f1894a17643
Thanks for the implementation. But currently it doesn't work properly. It initializes a slider for the internal monitor and reports the brightness properly (I tested at multiple brightness levels)
But I am not able to change the brightness of the slider, it just turns black like this:
This is a screenshot of the errors in the console window:
Let me know if anything else related to debugging is needed from my end.
@ruihe774 I changed the if statement to if true {
and it got rid of the Failed to load resource: net::ERR_CONNECTION_REFUSED
error in the console.
But the slider still isn't working.
I also ended up installing vue dev tools and found out that the
maybe that's causing the problem?
@rp1231 I mistakenly make error silent in some previous commit. Please try latest commit. ❤️
This is the console output:
This is the console output:
It is an error from Windows. I have no idea how it happens. 😿
Oh ok I see..... Would any of these crates help? https://crates.io/crates/wmi https://crates.io/crates/brightness-windows Mentioning it just in case.
Also posting the expanded error message in case it gives a clue:
Ok nevermind, After going through the code I realized that you're dealing with things at a much more advanced level. I just found these powershell commands that work for me to get the brightness and set the brightness. They use the same classes that you've used, so maybe they give you some sort of clue....
This is the powershell line that enables me to get the brightness:
Get-Ciminstance -Namespace root/WMI -ClassName WmiMonitorBrightness
You're also accessing the same class for retrieving the brightness property.....
This is the powershell script that enables me to set the brightness:
$monitor = Get-WmiObject -ns root/wmi -class WmiMonitorBrightnessMethods
$monitor.WmiSetBrightness(0,100)
But the timeout doesn't seem to work, only the brightness level gets set properly.
This is the article that I got these commands from: https://devblogs.microsoft.com/scripting/use-powershell-to-report-and-set-monitor-brightness/
I've looked through twinkle-tray's implementation. They first try invoking WMI in code (in "wmi-bridge"). If this fails, they will try using PowerShell commands. I think calling WMI through API and PowerShell should be literally same. Maybe there is security or permission problem? This needs investigation (when I get a laptop).
@ruihe774 I was able to get and set the brightness of the laptop display (and the external displays) using this crate: https://crates.io/crates/brightness Could you consider using this crate or looking through how they've implemented the wmi feature?
This is the code that I used to test it out:
use brightness::Brightness;
use futures::TryStreamExt;
async fn show_brightness() -> Result<(), brightness::Error> {
brightness::brightness_devices()
.try_for_each(|mut dev| async move {
let name = dev.device_name().await?;
let value = dev.get().await?;
println!("Brightness of device {} is {}%", name, value);
dev.set(50).await?;
Ok(())
})
.await
}
#[tokio::main]
async fn main() {
println!("Hello, world!");
if let Err(e) = show_brightness().await {
eprintln!("Error: {}", e);
}
}
@rp1231 I've copied some code from brightness
crate and you can have a try on ce0acad
@ruihe774 Yes it works now! Thanks
If a basic version of wmi for brightness is implemented, I can use this app as my daily driver.