mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-08-03 14:18:45 +00:00
update:server删除由server自己负责
This commit is contained in:
parent
5ef8d9bcab
commit
b0c228df02
4 changed files with 18 additions and 34 deletions
|
@ -10,9 +10,7 @@
|
||||||
|
|
||||||
#define DEVICE_SERVER_PATH "/data/local/tmp/scrcpy-server.jar"
|
#define DEVICE_SERVER_PATH "/data/local/tmp/scrcpy-server.jar"
|
||||||
#define DEVICE_NAME_FIELD_LENGTH 64
|
#define DEVICE_NAME_FIELD_LENGTH 64
|
||||||
//#define SOCKET_NAME "qtscrcpy" //jar需要同步修改
|
#define SOCKET_NAME "qtscrcpy"
|
||||||
#define SOCKET_NAME "scrcpy"
|
|
||||||
|
|
||||||
|
|
||||||
Server::Server(QObject *parent) : QObject(parent)
|
Server::Server(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
|
@ -29,9 +27,6 @@ Server::Server(QObject *parent) : QObject(parent)
|
||||||
// we don't need the server socket anymore
|
// we don't need the server socket anymore
|
||||||
// just m_deviceSocket is ok
|
// just m_deviceSocket is ok
|
||||||
m_serverSocket.close();
|
m_serverSocket.close();
|
||||||
// the server is started, we can clean up the jar from the temporary folder
|
|
||||||
removeServer();
|
|
||||||
m_serverCopiedToDevice = false;
|
|
||||||
// we don't need the adb tunnel anymore
|
// we don't need the adb tunnel anymore
|
||||||
disableTunnelReverse();
|
disableTunnelReverse();
|
||||||
m_tunnelEnabled = false;
|
m_tunnelEnabled = false;
|
||||||
|
@ -70,21 +65,6 @@ bool Server::pushServer()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Server::removeServer()
|
|
||||||
{
|
|
||||||
AdbProcess* adb = new AdbProcess();
|
|
||||||
if (!adb) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
connect(adb, &AdbProcess::adbProcessResult, this, [this](AdbProcess::ADB_EXEC_RESULT processResult){
|
|
||||||
if (AdbProcess::AER_SUCCESS_START != processResult) {
|
|
||||||
sender()->deleteLater();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
adb->removePath(m_serial, DEVICE_SERVER_PATH);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Server::enableTunnelReverse()
|
bool Server::enableTunnelReverse()
|
||||||
{
|
{
|
||||||
if (m_workProcess.isRuning()) {
|
if (m_workProcess.isRuning()) {
|
||||||
|
@ -218,9 +198,6 @@ bool Server::connectTo()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
// the server is started, we can clean up the jar from the temporary folder
|
|
||||||
removeServer();
|
|
||||||
m_serverCopiedToDevice = false;
|
|
||||||
// we don't need the adb tunnel anymore
|
// we don't need the adb tunnel anymore
|
||||||
disableTunnelForward();
|
disableTunnelForward();
|
||||||
m_tunnelEnabled = false;
|
m_tunnelEnabled = false;
|
||||||
|
@ -263,10 +240,6 @@ void Server::stop()
|
||||||
m_tunnelForward = false;
|
m_tunnelForward = false;
|
||||||
m_tunnelEnabled = false;
|
m_tunnelEnabled = false;
|
||||||
}
|
}
|
||||||
if (m_serverCopiedToDevice) {
|
|
||||||
removeServer();
|
|
||||||
m_serverCopiedToDevice = false;
|
|
||||||
}
|
|
||||||
m_serverSocket.close();
|
m_serverSocket.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -363,7 +336,6 @@ void Server::onWorkProcessResult(AdbProcess::ADB_EXEC_RESULT processResult)
|
||||||
switch (m_serverStartStep) {
|
switch (m_serverStartStep) {
|
||||||
case SSS_PUSH:
|
case SSS_PUSH:
|
||||||
if (AdbProcess::AER_SUCCESS_EXEC == processResult) {
|
if (AdbProcess::AER_SUCCESS_EXEC == processResult) {
|
||||||
m_serverCopiedToDevice = true;
|
|
||||||
#if 1
|
#if 1
|
||||||
m_serverStartStep = SSS_ENABLE_TUNNEL_REVERSE;
|
m_serverStartStep = SSS_ENABLE_TUNNEL_REVERSE;
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -66,7 +66,6 @@ private:
|
||||||
quint16 m_localPort = 0;
|
quint16 m_localPort = 0;
|
||||||
bool m_tunnelEnabled = false;
|
bool m_tunnelEnabled = false;
|
||||||
bool m_tunnelForward = false; // use "adb forward" instead of "adb reverse"
|
bool m_tunnelForward = false; // use "adb forward" instead of "adb reverse"
|
||||||
bool m_serverCopiedToDevice = false;
|
|
||||||
quint16 m_maxSize = 0;
|
quint16 m_maxSize = 0;
|
||||||
quint32 m_bitRate = 0;
|
quint32 m_bitRate = 0;
|
||||||
QString m_crop = "";
|
QString m_crop = "";
|
||||||
|
|
|
@ -14,7 +14,7 @@ public final class DesktopConnection implements Closeable {
|
||||||
|
|
||||||
private static final int DEVICE_NAME_FIELD_LENGTH = 64;
|
private static final int DEVICE_NAME_FIELD_LENGTH = 64;
|
||||||
|
|
||||||
private static final String SOCKET_NAME = "scrcpy";
|
private static final String SOCKET_NAME = "qtscrcpy";
|
||||||
|
|
||||||
private final LocalSocket socket;
|
private final LocalSocket socket;
|
||||||
private final InputStream inputStream;
|
private final InputStream inputStream;
|
||||||
|
|
|
@ -2,10 +2,14 @@ package com.genymobile.scrcpy;
|
||||||
|
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public final class Server {
|
public final class Server {
|
||||||
|
|
||||||
|
private static final String SERVER_PATH = "/data/local/tmp/scrcpy-server.jar";
|
||||||
|
|
||||||
private Server() {
|
private Server() {
|
||||||
// not instantiable
|
// not instantiable
|
||||||
}
|
}
|
||||||
|
@ -82,6 +86,14 @@ public final class Server {
|
||||||
return new Rect(x, y, x + width, y + height);
|
return new Rect(x, y, x + width, y + height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void unlinkSelf() {
|
||||||
|
try {
|
||||||
|
new File(SERVER_PATH).delete();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Ln.e("Cannot unlink server", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String... args) throws Exception {
|
public static void main(String... args) throws Exception {
|
||||||
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
|
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -90,6 +102,7 @@ public final class Server {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
unlinkSelf();
|
||||||
Options options = createOptions(args);
|
Options options = createOptions(args);
|
||||||
scrcpy(options);
|
scrcpy(options);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue