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
@ -29,7 +29,16 @@ server.on("connection", (socket) => {
|
|||||||
dataSplit[1],
|
dataSplit[1],
|
||||||
dataSplit[2],
|
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.on("close", (_) => {
|
||||||
socket.end();
|
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{
|
.screen{
|
||||||
display: inline-block
|
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>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<main>
|
<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
|
<p
|
||||||
id="clicks-log"
|
id="clicks-log"
|
||||||
class="log-section"
|
class="log-section"
|
||||||
@ -37,6 +62,9 @@
|
|||||||
<script>
|
<script>
|
||||||
var screen = document.getElementById("screen");
|
var screen = document.getElementById("screen");
|
||||||
var clicksLog = document.getElementById("clicks-log");
|
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();
|
let lastTouch = new Date().getTime();
|
||||||
|
|
||||||
const calculateElapsedTime = (last) => {
|
const calculateElapsedTime = (last) => {
|
||||||
@ -56,6 +84,24 @@
|
|||||||
clicksLog.appendChild(clickInfo);
|
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() {
|
async function displayImage() {
|
||||||
try {
|
try {
|
||||||
const response = await fetch("screen");
|
const response = await fetch("screen");
|
||||||
@ -67,25 +113,18 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function handleTouchEvent(event) {
|
async function handleTouchEvent(event) {
|
||||||
var phoneX = event.offsetX;
|
const phoneX = event.offsetX;
|
||||||
var phoneY = event.offsetY;
|
const phoneY = event.offsetY;
|
||||||
if (
|
|
||||||
phoneX <= 320 &&
|
|
||||||
phoneX >= 0 &&
|
|
||||||
phoneY <= 640 &&
|
|
||||||
phoneY >= 0
|
|
||||||
) {
|
|
||||||
waitToLog(`await click(${phoneX}, ${phoneY});`);
|
|
||||||
|
|
||||||
await fetch("touch", {
|
waitToLog(`await click(${phoneX}, ${phoneY});`);
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/x-www-form-urlencoded",
|
|
||||||
},
|
|
||||||
body: `x=${phoneX}&y=${phoneY}`,
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
await fetch("touch", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/x-www-form-urlencoded",
|
||||||
|
},
|
||||||
|
body: `x=${phoneX}&y=${phoneY}`,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sleep(time) {
|
async function sleep(time) {
|
||||||
|
@ -111,4 +111,14 @@ app.get("/", async function (req, res) {
|
|||||||
res.send(fileData);
|
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"));
|
app.listen(8080, () => console.log("Listening in port 8080"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user