44
55#include " wakelock_plus_tizen_plugin.h"
66
7- #include < Ecore.h>
87#include < dlfcn.h>
98#include < flutter/method_channel.h>
109#include < flutter/plugin_registrar.h>
1110#include < flutter/standard_method_codec.h>
11+ #include < glib.h>
1212#include < tizen.h>
1313
1414#include < memory>
@@ -41,7 +41,12 @@ class WakelockPlusTizenPlugin : public flutter::Plugin {
4141
4242 WakelockPlusTizenPlugin () {}
4343
44- virtual ~WakelockPlusTizenPlugin () = default ;
44+ virtual ~WakelockPlusTizenPlugin () {
45+ if (timer_id_ != 0 ) {
46+ g_source_remove (timer_id_);
47+ timer_id_ = 0 ;
48+ }
49+ }
4550
4651 private:
4752 void HandleMethodCall (
@@ -58,20 +63,25 @@ class WakelockPlusTizenPlugin : public flutter::Plugin {
5863 if (std::holds_alternative<bool >(arguments)) {
5964 bool enable = std::get<bool >(arguments);
6065 if (enable) {
66+ if (!screensaver_reset_timeout_) {
67+ result->Error (" Not supported" ,
68+ " The screensaver API is not supported." );
69+ return ;
70+ }
6171 int ret = screensaver_reset_timeout_ ();
6272 if (ret != 0 ) {
6373 result->Error (std::to_string (ret), get_error_message (ret));
6474 return ;
6575 }
66- if (timer_ ) {
67- ecore_timer_del (timer_ );
76+ if (timer_id_ != 0 ) {
77+ g_source_remove (timer_id_ );
6878 }
69- timer_ = ecore_timer_add ( 30 , OnResetScreensaverTimeout, this );
79+ timer_id_ = g_timeout_add ( 30000 , OnResetScreensaverTimeout, this );
7080 is_enabled_ = true ;
7181 } else {
72- if (timer_ ) {
73- ecore_timer_del (timer_ );
74- timer_ = nullptr ;
82+ if (timer_id_ != 0 ) {
83+ g_source_remove (timer_id_ );
84+ timer_id_ = 0 ;
7585 }
7686 is_enabled_ = false ;
7787 }
@@ -114,24 +124,24 @@ class WakelockPlusTizenPlugin : public flutter::Plugin {
114124 }
115125 }
116126
117- static Eina_Bool OnResetScreensaverTimeout (void * data) {
127+ static gboolean OnResetScreensaverTimeout (gpointer data) {
118128 auto *plugin = static_cast <WakelockPlusTizenPlugin *>(data);
119129 if (!plugin->screensaver_reset_timeout_ ) {
120- return ECORE_CALLBACK_CANCEL ;
130+ return G_SOURCE_REMOVE ;
121131 }
122132 int ret = plugin->screensaver_reset_timeout_ ();
123133 if (ret != 0 ) {
124134 LOG_ERROR (" screensaver_reset_timeout failed: %s" , get_error_message (ret));
125- return ECORE_CALLBACK_CANCEL ;
135+ return G_SOURCE_REMOVE ;
126136 }
127137
128- return ECORE_CALLBACK_RENEW ;
138+ return G_SOURCE_CONTINUE ;
129139 }
130140
131141 bool is_initialized_screensaver_api_ = false ;
132142 void *screensaver_api_handle_ = nullptr ;
133- Ecore_Timer *timer_ = nullptr ;
134- FuncScreensaverResetTimeout screensaver_reset_timeout_;
143+ guint timer_id_ = 0 ;
144+ FuncScreensaverResetTimeout screensaver_reset_timeout_ = nullptr ;
135145 bool is_enabled_ = false ;
136146};
137147
0 commit comments