mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2026-06-17 06:01:12 +00:00
Simplify app quitting implementation a bit
This commit is contained in:
+46
-15
@@ -275,16 +275,6 @@ int Session::getDecoderCapabilities(StreamingPreferences::VideoDecoderSelection
|
||||
return caps;
|
||||
}
|
||||
|
||||
NvComputer *Session::getComputer() const
|
||||
{
|
||||
return m_Computer;
|
||||
}
|
||||
|
||||
bool Session::shouldQuitAppAfter() const
|
||||
{
|
||||
return m_Preferences->quitAppAfter;
|
||||
}
|
||||
|
||||
Session::Session(NvComputer* computer, NvApp& app, StreamingPreferences *preferences)
|
||||
: m_Preferences(preferences ? preferences : new StreamingPreferences(this)),
|
||||
m_Computer(computer),
|
||||
@@ -303,6 +293,14 @@ Session::Session(NvComputer* computer, NvApp& app, StreamingPreferences *prefere
|
||||
{
|
||||
}
|
||||
|
||||
Session::~Session()
|
||||
{
|
||||
// Acquire session semaphore to ensure all cleanup is done before the destructor returns
|
||||
// and the object is deallocated.
|
||||
s_ActiveSessionSemaphore.acquire();
|
||||
s_ActiveSessionSemaphore.release();
|
||||
}
|
||||
|
||||
void Session::initialize()
|
||||
{
|
||||
qInfo() << "Server GPU:" << m_Computer->gpuModel;
|
||||
@@ -561,15 +559,48 @@ bool Session::validateLaunch()
|
||||
|
||||
class DeferredSessionCleanupTask : public QRunnable
|
||||
{
|
||||
void run() override
|
||||
{
|
||||
// Finish cleanup of the connection state
|
||||
LiStopConnection();
|
||||
public:
|
||||
DeferredSessionCleanupTask(Session* session) :
|
||||
m_Session(session) {}
|
||||
|
||||
private:
|
||||
virtual ~DeferredSessionCleanupTask() override
|
||||
{
|
||||
// Allow another session to start now that we're cleaned up
|
||||
Session::s_ActiveSession = nullptr;
|
||||
Session::s_ActiveSessionSemaphore.release();
|
||||
}
|
||||
|
||||
void run() override
|
||||
{
|
||||
// Notify the UI
|
||||
if (!m_Session->m_Preferences->quitAppAfter) {
|
||||
emit m_Session->sessionFinished();
|
||||
}
|
||||
else {
|
||||
emit m_Session->quitStarting();
|
||||
}
|
||||
|
||||
// Finish cleanup of the connection state
|
||||
LiStopConnection();
|
||||
|
||||
// Perform a best-effort app quit
|
||||
if (m_Session->m_Preferences->quitAppAfter) {
|
||||
NvHTTP http(m_Session->m_Computer->activeAddress);
|
||||
|
||||
// Logging is already done inside NvHTTP
|
||||
try {
|
||||
http.quitApp();
|
||||
} catch (const GfeHttpResponseException&) {
|
||||
} catch (const QtNetworkReplyException&) {
|
||||
}
|
||||
|
||||
// Session is finished now
|
||||
emit m_Session->sessionFinished();
|
||||
}
|
||||
}
|
||||
|
||||
Session* m_Session;
|
||||
};
|
||||
|
||||
void Session::getWindowDimensions(int& x, int& y,
|
||||
@@ -1162,6 +1193,6 @@ DispatchDeferredCleanup:
|
||||
// Cleanup can take a while, so dispatch it to a worker thread.
|
||||
// When it is complete, it will release our s_ActiveSessionSemaphore
|
||||
// reference.
|
||||
QThreadPool::globalInstance()->start(new DeferredSessionCleanupTask());
|
||||
QThreadPool::globalInstance()->start(new DeferredSessionCleanupTask(this));
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ class Session : public QObject
|
||||
public:
|
||||
explicit Session(NvComputer* computer, NvApp& app, StreamingPreferences *preferences = nullptr);
|
||||
|
||||
virtual ~Session();
|
||||
|
||||
Q_INVOKABLE void exec(int displayOriginX, int displayOriginY);
|
||||
|
||||
static
|
||||
@@ -30,10 +32,6 @@ public:
|
||||
int getDecoderCapabilities(StreamingPreferences::VideoDecoderSelection vds,
|
||||
int videoFormat, int width, int height, int frameRate);
|
||||
|
||||
NvComputer* getComputer() const;
|
||||
|
||||
Q_INVOKABLE bool shouldQuitAppAfter() const;
|
||||
|
||||
signals:
|
||||
void stageStarting(QString stage);
|
||||
|
||||
@@ -45,6 +43,10 @@ signals:
|
||||
|
||||
void displayLaunchWarning(QString text);
|
||||
|
||||
void quitStarting();
|
||||
|
||||
void sessionFinished();
|
||||
|
||||
private:
|
||||
void initialize();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user