Skip to content

Commit

Permalink
Merge branch 'refs/heads/develop' into feature/humans_perceive_bright…
Browse files Browse the repository at this point in the history
…ness
  • Loading branch information
aaassseee committed Dec 13, 2024
2 parents 9d67067 + 6513548 commit 9540005
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 45 deletions.
8 changes: 8 additions & 0 deletions screen_brightness/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 2.0.1

* [Windows] fix call HandleWindowProc will lead to crash [#38](https://github.com/aaassseee/screen_brightness/issues/38)

## 2.0.0+2

* update README.md

## 2.0.0+1

* update README.md
Expand Down
5 changes: 5 additions & 0 deletions screen_brightness/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ Add the following lines in your pubspec.yaml file
latest_version:\
[![pub package](https://img.shields.io/pub/v/screen_brightness.svg)](https://pub.dartlang.org/packages/screen_brightness)
To adjust the system brightness on Android, add the following permission in your `AndroidManifest.xml` file
```xml
<uses-permission android:name="android.permission.WRITE_SETTINGS" tools:ignore="ProtectedPermissions"/>
```

### API
#### System brightness
```dart
Expand Down
4 changes: 2 additions & 2 deletions screen_brightness/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: screen_brightness
description: A Plugin for controlling screen brightness with application life cycle reset implemented
version: 2.0.0+1
version: 2.0.1
homepage: https://github.com/aaassseee/screen_brightness
repository: https://github.com/aaassseee/screen_brightness/tree/master/screen_brightness
issue_tracker: https://github.com/aaassseee/screen_brightness/issues
Expand All @@ -21,7 +21,7 @@ dependencies:
screen_brightness_android: ">=2.0.0 <3.0.0"
screen_brightness_ios: ">=2.0.0 <3.0.0"
screen_brightness_macos: ">=2.0.0 <3.0.0"
screen_brightness_windows: ">=2.0.0 <3.0.0"
screen_brightness_windows: ">=2.0.1 <3.0.0"

dev_dependencies:
flutter_test:
Expand Down
4 changes: 4 additions & 0 deletions screen_brightness_windows/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.1

* fix call HandleWindowProc will lead to crash [#38](https://github.com/aaassseee/screen_brightness/issues/38)

## 2.0.0

* support changing system brightness [#31](https://github.com/aaassseee/screen_brightness/issues/31) [#32](https://github.com/aaassseee/screen_brightness/issues/32)
Expand Down
2 changes: 1 addition & 1 deletion screen_brightness_windows/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: screen_brightness_windows
description: The Windows federated plugin implementation of the screen_brightness.
version: 2.0.0
version: 2.0.1
homepage: https://github.com/aaassseee/screen_brightness
repository: https://github.com/aaassseee/screen_brightness/tree/master/screen_brightness_windows
issue_tracker: https://github.com/aaassseee/screen_brightness/issues
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ namespace screen_brightness
&flutter::StandardMethodCodec::GetInstance());
method_channel->SetMethodCallHandler
([plugin_pointer = plugin.get()](const auto& call, auto result)
{
plugin_pointer->HandleMethodCall(call, std::move(result));
});
{
plugin_pointer->HandleMethodCall(call, std::move(result));
});

const auto system_screen_brightness_changed_event_channel =
std::make_unique<flutter::EventChannel<flutter::EncodableValue>>(
Expand Down Expand Up @@ -156,11 +156,11 @@ namespace screen_brightness

void ScreenBrightnessWindowsPlugin::HandleGetSystemScreenBrightnessMethodCall(const std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) const
{
if (system_screen_brightness_ == -1)
{
result->Error("-11", "Could not found system screen brightness value");
return;
}
if (system_screen_brightness_ == -1)
{
result->Error("-11", "Could not found system screen brightness value");
return;
}

result->Success(GetScreenBrightnessPercentage(system_screen_brightness_));
}
Expand All @@ -184,8 +184,8 @@ namespace screen_brightness
const long brightness_value = GetScreenBrightnessValueByPercentage(brightness);
try
{
system_screen_brightness_ = brightness_value;
HandleSystemScreenBrightnessChanged(brightness_value);
system_screen_brightness_ = brightness_value;
HandleSystemScreenBrightnessChanged(brightness_value);
if (application_screen_brightness_ == -1)
{
SetScreenBrightness(brightness_value);
Expand Down Expand Up @@ -227,7 +227,7 @@ namespace screen_brightness

try
{
long application_screen_brightness = -1;
long application_screen_brightness = -1;
GetScreenBrightness(minimum_screen_brightness_, application_screen_brightness, maximum_screen_brightness_);
result->Success(GetScreenBrightnessPercentage(application_screen_brightness));
}
Expand Down Expand Up @@ -349,28 +349,21 @@ namespace screen_brightness
switch (wParam)
{
case SIZE_MINIMIZED:
if (!is_auto_reset_)
{
if (!is_auto_reset_)
{
return std::nullopt;
}
}

OnApplicationPause();
break;

case SIZE_MAXIMIZED:
case SIZE_RESTORED:
if (!is_auto_reset_)
{
return std::nullopt;
}

GetScreenBrightness(minimum_screen_brightness_, system_screen_brightness_, maximum_screen_brightness_);
HandleSystemScreenBrightnessChanged(system_screen_brightness_);
if (application_screen_brightness_ == -1)
{
HandleApplicationScreenBrightnessChanged(system_screen_brightness_);
return std::nullopt;
}

OnApplicationResume();
break;
}
Expand All @@ -389,28 +382,21 @@ namespace screen_brightness

bool is_activate = bool(wParam);
if (is_activate)
{
GetScreenBrightness(minimum_screen_brightness_, system_screen_brightness_, maximum_screen_brightness_);
HandleSystemScreenBrightnessChanged(system_screen_brightness_);
if (application_screen_brightness_ == -1)
{
HandleApplicationScreenBrightnessChanged(system_screen_brightness_);
}

{
OnApplicationResume();
break;
}
else
{
break;
}
else
{
OnApplicationPause();
}
}
break;
}

// allow another plugin to process message
return std::nullopt;
}

void ScreenBrightnessWindowsPlugin::GetScreenBrightness(long& minimum_screen_brightness, long& screen_brightness, long& maximum_screen_brightness)
{
DWORD physical_monitor_array_size = 0;
Expand Down Expand Up @@ -506,16 +492,32 @@ namespace screen_brightness
return;
}

SetScreenBrightness(system_screen_brightness_);
try {
SetScreenBrightness(system_screen_brightness_);
}
catch (const std::exception& exception)
{
std::cout << exception.what() << std::endl;
}
}

void ScreenBrightnessWindowsPlugin::OnApplicationResume() {
if (application_screen_brightness_ == -1)
try
{
return;
}
GetScreenBrightness(minimum_screen_brightness_, system_screen_brightness_, maximum_screen_brightness_);
HandleSystemScreenBrightnessChanged(system_screen_brightness_);
if (application_screen_brightness_ == -1)
{
HandleApplicationScreenBrightnessChanged(system_screen_brightness_);
return;
}

SetScreenBrightness(application_screen_brightness_);
SetScreenBrightness(application_screen_brightness_);
}
catch (const std::exception& exception)
{
std::cout << exception.what() << std::endl;
}
}
}

Expand Down

0 comments on commit 9540005

Please sign in to comment.