Skip to content

Commit

Permalink
[wakelock] Minor cleanups (flutter-tizen#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
swift-kim authored Dec 8, 2021
1 parent 365d9fa commit 2be976c
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 40 deletions.
8 changes: 4 additions & 4 deletions packages/wakelock/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
## 1.0.0

* Initial release
* Initial release.

## 1.0.1

* Bump up `wakelock_platform_interface` to 0.3.0
* Update implementation according to the changed platform interface
* Bump up `wakelock` to 0.5.6 in example
* Bump up `wakelock_platform_interface` to 0.3.0.
* Update implementation according to the changed platform interface.
* Bump up `wakelock` to 0.5.6 in example.
4 changes: 2 additions & 2 deletions packages/wakelock/LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved.
Copyright (c) 2021, Samsung Electronics Co., Ltd. All rights reserved.
Copyright (c) 2021, creativecreatorormaybenot
All rights reserved.

Expand All @@ -27,4 +27,4 @@ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3 changes: 1 addition & 2 deletions packages/wakelock/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ To use the wakelock plugin in a Tizen application, the display privilege must be

```xml
<privileges>
<privilege>http://tizen.org/privilege/display</privilege>
<privilege>http://tizen.org/privilege/display</privilege>
</privileges>
```

2 changes: 0 additions & 2 deletions packages/wakelock/example/integration_test/wakelock_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @dart = 2.9

import 'package:flutter_test/flutter_test.dart';
import 'package:wakelock/wakelock.dart';
import 'package:integration_test/integration_test.dart';
Expand Down
5 changes: 4 additions & 1 deletion packages/wakelock/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ import 'package:flutter/material.dart';
import 'package:wakelock/wakelock.dart';

void main() {
runApp(WakelockExampleApp());
runApp(const WakelockExampleApp());
}

/// Example app widget demonstrating how to use the wakelock plugin.
///
/// The example implementation is located inside [OutlinedButton.onPressed]
/// callback functions and a [FutureBuilder].
class WakelockExampleApp extends StatefulWidget {
/// Creates the [WakelockExampleApp] widget.
const WakelockExampleApp({Key? key}) : super(key: key);

@override
_WakelockExampleAppState createState() => _WakelockExampleAppState();
}
Expand Down
2 changes: 0 additions & 2 deletions packages/wakelock/example/test_driver/integration_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @dart = 2.9

import 'package:integration_test/integration_test_driver.dart';

Future<void> main() => integrationDriver();
2 changes: 1 addition & 1 deletion packages/wakelock/example/tizen/Runner.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Tizen.NET.Sdk/1.1.5">
<Project Sdk="Tizen.NET.Sdk/1.1.7">

<PropertyGroup>
<OutputType>Exe</OutputType>
Expand Down
5 changes: 2 additions & 3 deletions packages/wakelock/example/tizen/tizen-manifest.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.example.wakelock_tizen_example" version="1.0.0" api-version="4.0" xmlns="http://tizen.org/ns/packages">
<profile name="common"/>
<ui-application appid="com.example.wakelock_tizen_example" exec="Runner.dll" type="dotnet" multiple="false" taskmanage="true" nodisplay="false" api-version="4" launch_mode="single">
<profile name="wearable"/>
<ui-application appid="com.example.wakelock_tizen_example" exec="Runner.dll" type="dotnet" multiple="false" taskmanage="true" nodisplay="false" api-version="4">
<label>wakelock_tizen_example</label>
<icon>ic_launcher.png</icon>
<metadata key="http://tizen.org/metadata/prefer_dotnet_aot" value="true"/>
<metadata key="http://tizen.org/metadata/direct-launch" value="yes"/>
</ui-application>
<feature name="http://tizen.org/feature/screen.size.all"/>
<privileges>
Expand Down
2 changes: 0 additions & 2 deletions packages/wakelock/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,3 @@ dev_dependencies:
environment:
sdk: ">=2.12.0 <3.0.0"
flutter: ">=2.0.0"


40 changes: 19 additions & 21 deletions packages/wakelock/tizen/src/wakelock_tizen_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ class IsEnabledMessage {
return flutter::EncodableValue(wrapped);
}

static flutter::EncodableValue decode(flutter::EncodableValue message) {
auto &map = std::get<flutter::EncodableMap>(message);
IsEnabledMessage isEnabledMessage;
isEnabledMessage.enabled =
std::get<bool>(map[flutter::EncodableValue("enabled")]);
return flutter::CustomEncodableValue(isEnabledMessage);
static flutter::EncodableValue decode(flutter::EncodableValue value) {
auto &map = std::get<flutter::EncodableMap>(value);
IsEnabledMessage message;
message.enabled = std::get<bool>(map[flutter::EncodableValue("enabled")]);
return flutter::CustomEncodableValue(message);
}

bool enabled;
Expand All @@ -36,12 +35,11 @@ class ToggleMessage {
return flutter::EncodableValue(wrapped);
}

static flutter::EncodableValue decode(flutter::EncodableValue message) {
auto &map = std::get<flutter::EncodableMap>(message);
ToggleMessage toggleMessage;
toggleMessage.enable =
std::get<bool>(map[flutter::EncodableValue("enable")]);
return flutter::CustomEncodableValue(toggleMessage);
static flutter::EncodableValue decode(flutter::EncodableValue value) {
auto &map = std::get<flutter::EncodableMap>(value);
ToggleMessage message;
message.enable = std::get<bool>(map[flutter::EncodableValue("enable")]);
return flutter::CustomEncodableValue(message);
}

bool enable;
Expand Down Expand Up @@ -115,11 +113,11 @@ class WakelockTizenPlugin : public flutter::Plugin {
LOG_DEBUG("Fetching wakelock status: %s",
plugin_pointer->wakelocked_ ? "enabled" : "disabled");

IsEnabledMessage isEnabledMessage;
isEnabledMessage.enabled = plugin_pointer->wakelocked_;
IsEnabledMessage is_enabled_message;
is_enabled_message.enabled = plugin_pointer->wakelocked_;
flutter::EncodableMap wrapped = {
{flutter::EncodableValue("result"),
flutter::CustomEncodableValue(isEnabledMessage)}};
flutter::CustomEncodableValue(is_enabled_message)}};
reply(flutter::EncodableValue(wrapped));
});

Expand All @@ -136,9 +134,9 @@ class WakelockTizenPlugin : public flutter::Plugin {
const auto &custom_type =
std::get<flutter::CustomEncodableValue>(args);
if (custom_type.type() == typeid(ToggleMessage)) {
const ToggleMessage &toggleMessage =
const ToggleMessage &toggle_message =
std::any_cast<ToggleMessage>(custom_type);
enable = toggleMessage.enable;
enable = toggle_message.enable;
argument_parsed = true;
}
}
Expand All @@ -150,15 +148,15 @@ class WakelockTizenPlugin : public flutter::Plugin {
return;
}

flutter::EncodableMap resultMap = {
flutter::EncodableMap result_map = {
{flutter::EncodableValue("result"), flutter::EncodableValue()}};
flutter::EncodableValue wrapped = flutter::EncodableValue(resultMap);
flutter::EncodableValue wrapped = flutter::EncodableValue(result_map);
LOG_DEBUG("Toggling wakelock status to %s",
enable ? "enable" : "disable");
if (enable != plugin_pointer->wakelocked_) {
const int WAKELOCK_PERMANENT = 0;
const int kTimeoutPermanent = 0;
int ret = enable ? device_power_request_lock(POWER_LOCK_DISPLAY,
WAKELOCK_PERMANENT)
kTimeoutPermanent)
: device_power_release_lock(POWER_LOCK_DISPLAY);
if (ret == DEVICE_ERROR_NONE) {
plugin_pointer->wakelocked_ = enable;
Expand Down

0 comments on commit 2be976c

Please sign in to comment.