add 'back' and 'home' buttons
Summary: Ref T2746 Reviewers: #testers, kuba-orlik Reviewed By: #testers, kuba-orlik Subscribers: kuba-orlik Maniphest Tasks: T2746 Differential Revision: https://hub.sealcode.org/D1393
This commit is contained in:
parent
6a0f11f7e1
commit
2e0ea198f1
@ -16,7 +16,7 @@ async function spawnPromise(program, args) {
|
||||
//maybe check output of child processe and send errors in some way
|
||||
server.on("connection", (socket) => {
|
||||
socket.on("data", async (dataBuf) => {
|
||||
data = dataBuf.toString();
|
||||
data = dataBuf.toString();
|
||||
if (data === "screenshot") {
|
||||
socket.write("start");
|
||||
await spawnPromise("bash", ["/conf/screenshot.sh"]);
|
||||
@ -29,7 +29,16 @@ server.on("connection", (socket) => {
|
||||
dataSplit[1],
|
||||
dataSplit[2],
|
||||
]);
|
||||
}
|
||||
} else if (data === "back") {
|
||||
await spawnPromise("bash", [
|
||||
"/conf/back.sh",
|
||||
]);
|
||||
} else if (data === "home") {
|
||||
await spawnPromise("bash", [
|
||||
"/conf/home.sh",
|
||||
]);
|
||||
}
|
||||
|
||||
});
|
||||
socket.on("close", (_) => {
|
||||
socket.end();
|
||||
|
1
android/conf/back.sh
Normal file
1
android/conf/back.sh
Normal file
@ -0,0 +1 @@
|
||||
/opt/android-sdk-linux/platform-tools/adb shell input keyevent 4
|
1
android/conf/home.sh
Normal file
1
android/conf/home.sh
Normal file
@ -0,0 +1 @@
|
||||
/opt/android-sdk-linux/platform-tools/adb shell input keyevent 3
|
@ -20,11 +20,36 @@
|
||||
.screen{
|
||||
display: inline-block
|
||||
}
|
||||
|
||||
.screen-buttons{
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
margin-top: 5px;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.screen-buttons button{
|
||||
font-size: 1.1rem;
|
||||
padding: 10px 20px;
|
||||
width: 100%;
|
||||
cursor: pointer;
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
.screen-buttons button:hover{
|
||||
background-color: aqua;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<img id="screen" src="" class="screen"/>
|
||||
<section class="screen-section">
|
||||
<img id="screen" alt="android screen" src="" class="screen"/>
|
||||
<div class="screen-buttons">
|
||||
<button class="screen-buttons-home">home</button>
|
||||
<button class="screen-buttons-back">back</button>
|
||||
</div>
|
||||
</section>
|
||||
<p
|
||||
id="clicks-log"
|
||||
class="log-section"
|
||||
@ -37,6 +62,9 @@
|
||||
<script>
|
||||
var screen = document.getElementById("screen");
|
||||
var clicksLog = document.getElementById("clicks-log");
|
||||
const homeButton = document.querySelector(".screen-buttons-home");
|
||||
const backButton = document.querySelector(".screen-buttons-back");
|
||||
|
||||
let lastTouch = new Date().getTime();
|
||||
|
||||
const calculateElapsedTime = (last) => {
|
||||
@ -56,6 +84,24 @@
|
||||
clicksLog.appendChild(clickInfo);
|
||||
}
|
||||
|
||||
const registerClick = ({path, logText}) =>{
|
||||
const clicksLog = document.getElementById("clicks-log");
|
||||
const span = document.createElement("span");
|
||||
|
||||
waitToLog(logText);
|
||||
|
||||
fetch(path, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
homeButton.addEventListener("click", () => registerClick({path: "home", logText: "await homeButton();"}));
|
||||
|
||||
backButton.addEventListener("click", () => registerClick({path: "back", logText: "await backButton();"}));
|
||||
|
||||
async function displayImage() {
|
||||
try {
|
||||
const response = await fetch("screen");
|
||||
@ -67,25 +113,18 @@
|
||||
}
|
||||
|
||||
async function handleTouchEvent(event) {
|
||||
var phoneX = event.offsetX;
|
||||
var phoneY = event.offsetY;
|
||||
if (
|
||||
phoneX <= 320 &&
|
||||
phoneX >= 0 &&
|
||||
phoneY <= 640 &&
|
||||
phoneY >= 0
|
||||
) {
|
||||
waitToLog(`await click(${phoneX}, ${phoneY});`);
|
||||
const phoneX = event.offsetX;
|
||||
const phoneY = event.offsetY;
|
||||
|
||||
await fetch("touch", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
},
|
||||
body: `x=${phoneX}&y=${phoneY}`,
|
||||
});
|
||||
|
||||
}
|
||||
waitToLog(`await click(${phoneX}, ${phoneY});`);
|
||||
|
||||
await fetch("touch", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
},
|
||||
body: `x=${phoneX}&y=${phoneY}`,
|
||||
});
|
||||
}
|
||||
|
||||
async function sleep(time) {
|
||||
|
@ -111,4 +111,14 @@ app.get("/", async function (req, res) {
|
||||
res.send(fileData);
|
||||
});
|
||||
|
||||
app.post("/back", function (req, res) {
|
||||
socket_client.write(`back`);
|
||||
res.sendStatus(200);
|
||||
});
|
||||
|
||||
app.post("/home", function (req, res) {
|
||||
socket_client.write(`home`);
|
||||
res.sendStatus(200);
|
||||
});
|
||||
|
||||
app.listen(8080, () => console.log("Listening in port 8080"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user