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,16 @@ 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+ if (screensaver_api_handle_) {
50+ dlclose (screensaver_api_handle_);
51+ screensaver_api_handle_ = nullptr ;
52+ }
53+ }
4554
4655 private:
4756 void HandleMethodCall (
@@ -58,20 +67,25 @@ class WakelockPlusTizenPlugin : public flutter::Plugin {
5867 if (std::holds_alternative<bool >(arguments)) {
5968 bool enable = std::get<bool >(arguments);
6069 if (enable) {
70+ if (!screensaver_reset_timeout_) {
71+ result->Error (" Not supported" ,
72+ " The screensaver API is not supported." );
73+ return ;
74+ }
6175 int ret = screensaver_reset_timeout_ ();
6276 if (ret != 0 ) {
6377 result->Error (std::to_string (ret), get_error_message (ret));
6478 return ;
6579 }
66- if (timer_ ) {
67- ecore_timer_del (timer_ );
80+ if (timer_id_ != 0 ) {
81+ g_source_remove (timer_id_ );
6882 }
69- timer_ = ecore_timer_add ( 30 , OnResetScreensaverTimeout, this );
83+ timer_id_ = g_timeout_add ( 30000 , OnResetScreensaverTimeout, this );
7084 is_enabled_ = true ;
7185 } else {
72- if (timer_ ) {
73- ecore_timer_del (timer_ );
74- timer_ = nullptr ;
86+ if (timer_id_ != 0 ) {
87+ g_source_remove (timer_id_ );
88+ timer_id_ = 0 ;
7589 }
7690 is_enabled_ = false ;
7791 }
@@ -114,24 +128,26 @@ class WakelockPlusTizenPlugin : public flutter::Plugin {
114128 }
115129 }
116130
117- static Eina_Bool OnResetScreensaverTimeout (void * data) {
131+ static gboolean OnResetScreensaverTimeout (gpointer data) {
118132 auto *plugin = static_cast <WakelockPlusTizenPlugin *>(data);
119133 if (!plugin->screensaver_reset_timeout_ ) {
120- return ECORE_CALLBACK_CANCEL ;
134+ plugin->timer_id_ = 0 ;
135+ return G_SOURCE_REMOVE ;
121136 }
122137 int ret = plugin->screensaver_reset_timeout_ ();
123138 if (ret != 0 ) {
124139 LOG_ERROR (" screensaver_reset_timeout failed: %s" , get_error_message (ret));
125- return ECORE_CALLBACK_CANCEL ;
140+ plugin->timer_id_ = 0 ;
141+ return G_SOURCE_REMOVE ;
126142 }
127143
128- return ECORE_CALLBACK_RENEW ;
144+ return G_SOURCE_CONTINUE ;
129145 }
130146
131147 bool is_initialized_screensaver_api_ = false ;
132148 void *screensaver_api_handle_ = nullptr ;
133- Ecore_Timer *timer_ = nullptr ;
134- FuncScreensaverResetTimeout screensaver_reset_timeout_;
149+ guint timer_id_ = 0 ;
150+ FuncScreensaverResetTimeout screensaver_reset_timeout_ = nullptr ;
135151 bool is_enabled_ = false ;
136152};
137153
0 commit comments