Skip to content

Commit

Permalink
Remove engine dependency of LifecycleChannel
Browse files Browse the repository at this point in the history
  • Loading branch information
swift-kim committed Jun 19, 2021
1 parent f1add55 commit a45473d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 22 deletions.
1 change: 1 addition & 0 deletions shell/platform/tizen/channels/key_event_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <map>

#include "flutter/shell/platform/common/json_message_codec.h"
#include "flutter/shell/platform/tizen/tizen_log.h"

static constexpr char kChannelName[] = "flutter/keyevent";
Expand Down
1 change: 0 additions & 1 deletion shell/platform/tizen/channels/key_event_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#include "flutter/shell/platform/common/client_wrapper/include/flutter/basic_message_channel.h"
#include "flutter/shell/platform/common/client_wrapper/include/flutter/binary_messenger.h"
#include "flutter/shell/platform/common/json_message_codec.h"
#include "rapidjson/document.h"

class KeyEventChannel {
Expand Down
31 changes: 15 additions & 16 deletions shell/platform/tizen/channels/lifecycle_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "lifecycle_channel.h"

#include "flutter/shell/platform/common/client_wrapper/include/flutter/standard_message_codec.h"
#include "flutter/shell/platform/tizen/flutter_tizen_engine.h"
#include "flutter/shell/platform/tizen/tizen_log.h"

Expand All @@ -13,33 +14,31 @@ static constexpr char kResumed[] = "AppLifecycleState.resumed";
static constexpr char kPaused[] = "AppLifecycleState.paused";
static constexpr char kDetached[] = "AppLifecycleState.detached";

LifecycleChannel::LifecycleChannel(FlutterTizenEngine* engine)
: engine_(engine) {}
LifecycleChannel::LifecycleChannel(flutter::BinaryMessenger* messenger)
: channel_(std::make_unique<
flutter::BasicMessageChannel<flutter::EncodableValue>>(
messenger,
kChannelName,
&flutter::StandardMessageCodec::GetInstance())) {}

LifecycleChannel::~LifecycleChannel() {}

void LifecycleChannel::SendLifecycleMessage(const char message[]) {
engine_->SendPlatformMessage(kChannelName,
reinterpret_cast<const uint8_t*>(message),
strlen(message), nullptr, nullptr);
}

void LifecycleChannel::AppIsInactive() {
FT_LOGI("send app lifecycle state inactive.");
SendLifecycleMessage(kInactive);
FT_LOGI("Sending %s message.", kInactive);
channel_->Send(flutter::EncodableValue(kInactive));
}

void LifecycleChannel::AppIsResumed() {
FT_LOGI("send app lifecycle state resumed.");
SendLifecycleMessage(kResumed);
FT_LOGI("Sending %s message.", kResumed);
channel_->Send(flutter::EncodableValue(kResumed));
}

void LifecycleChannel::AppIsPaused() {
FT_LOGI("send app lifecycle state paused.");
SendLifecycleMessage(kPaused);
FT_LOGI("Sending %s message.", kPaused);
channel_->Send(flutter::EncodableValue(kPaused));
}

void LifecycleChannel::AppIsDetached() {
FT_LOGI("send app lifecycle state detached.");
SendLifecycleMessage(kDetached);
FT_LOGI("Sending %s message.", kDetached);
channel_->Send(flutter::EncodableValue(kDetached));
}
9 changes: 5 additions & 4 deletions shell/platform/tizen/channels/lifecycle_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@
#ifndef EMBEDDER_LIFECYCLE_CHANNEL_H_
#define EMBEDDER_LIFECYCLE_CHANNEL_H_

class FlutterTizenEngine;
#include "flutter/shell/platform/common/client_wrapper/include/flutter/basic_message_channel.h"
#include "flutter/shell/platform/common/client_wrapper/include/flutter/binary_messenger.h"

class LifecycleChannel {
public:
explicit LifecycleChannel(FlutterTizenEngine* engine);
explicit LifecycleChannel(flutter::BinaryMessenger* messenger);
virtual ~LifecycleChannel();

void AppIsInactive();
void AppIsResumed();
void AppIsPaused();
void AppIsDetached();
void SendLifecycleMessage(const char message[]);

private:
FlutterTizenEngine* engine_{nullptr};
std::unique_ptr<flutter::BasicMessageChannel<flutter::EncodableValue>>
channel_;
};

#endif // EMBEDDER_LIFECYCLE_CHANNEL_H_
3 changes: 2 additions & 1 deletion shell/platform/tizen/flutter_tizen_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ bool FlutterTizenEngine::RunEngine(
internal_plugin_registrar_->messenger());
localization_channel = std::make_unique<LocalizationChannel>(this);
localization_channel->SendLocales();
lifecycle_channel = std::make_unique<LifecycleChannel>(this);
lifecycle_channel = std::make_unique<LifecycleChannel>(
internal_plugin_registrar_->messenger());

if (IsHeaded()) {
texture_registrar_ = std::make_unique<FlutterTizenTextureRegistrar>(this);
Expand Down

0 comments on commit a45473d

Please sign in to comment.