Skip to content

Commit

Permalink
Show app screen by re-launch in nativeqt app
Browse files Browse the repository at this point in the history
:Release Notes:
  Show app screen by re-launch in nativeqt app

:Detailed Notes:
  - When receiving re-launch, the app is not shown full screen.
  - Call showFullScreen() to make the app is shown.
  • Loading branch information
nickyzero committed Jun 17, 2021
1 parent b6f105f commit 86098ee
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
12 changes: 9 additions & 3 deletions native-apps/built-in/com.example.app.nativeqt/ServiceRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ static std::string convertJsonToString(const pbnjson::JValue json)
return pbnjson::JGenerator::serialize(json, pbnjson::JSchemaFragment("{}"));
}

ServiceRequest::ServiceRequest(std::string appId)
ServiceRequest::ServiceRequest(std::string appId, QWindow &window)
: m_mainLoop(g_main_loop_new(nullptr, false))
, m_serviceHandle(nullptr)
{
m_appId = appId;
m_window = &window;
m_serviceHandle = acquireHandle();
}

Expand Down Expand Up @@ -83,7 +84,7 @@ void ServiceRequest::clearHandle()
}
}

static bool registerAppCallback(LSHandle* sh, LSMessage* msg, void* ctx)
static bool registerAppCallback(LSHandle* sh, LSMessage* msg, void* context)
{
PmLogInfo(getPmLogContext(), "REGISTER_CALLBACK", 1, PMLOGJSON("payload", LSMessageGetPayload(msg)), " ");

Expand All @@ -100,6 +101,11 @@ static bool registerAppCallback(LSHandle* sh, LSMessage* msg, void* ctx)
}
else if (event == "relaunch")
{
//relaunch screen
if (context != nullptr)
{
((ServiceRequest*)context)->m_window->showFullScreen();
}
//handle "relaunch" event
if (response.hasKey("parameters"))
{
Expand Down Expand Up @@ -136,7 +142,7 @@ void ServiceRequest::registerApp()
"luna://com.webos.service.applicationmanager/registerApp",
"{}",
registerAppCallback,
NULL,
this,
NULL,
&lserror))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <luna-service2/lunaservice.h>
#include <pbnjson.hpp>
#include <PmLog.h>
#include <QtGui/QWindow>

static PmLogContext getPmLogContext()
{
Expand All @@ -36,10 +37,11 @@ static PmLogContext getPmLogContext()
class ServiceRequest
{
public:
ServiceRequest(std::string appId);
ServiceRequest(std::string appId, QWindow &window);
virtual ~ServiceRequest();
LSHandle* getHandle() const { return m_serviceHandle; }
void registerApp();
QWindow* m_window;

protected:
LSHandle* acquireHandle();
Expand Down
2 changes: 1 addition & 1 deletion native-apps/built-in/com.example.app.nativeqt/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ int main(int argc, char **argv)
window.resize(screenGeometry.width(), screenGeometry.height());
window.show();

ServiceRequest s_request("com.example.app.nativeqt");
ServiceRequest s_request("com.example.app.nativeqt", window);
s_request.registerApp();

QGuiApplication::platformNativeInterface()->setWindowProperty(window.handle(), "appId", "com.example.app.nativeqt");
Expand Down

0 comments on commit 86098ee

Please sign in to comment.