Skip to content

Commit 1f63f4a

Browse files
committed
Better adb pairing ui, update most of the ui from SAF to ADB
1 parent b149dc1 commit 1f63f4a

10 files changed

Lines changed: 253 additions & 99 deletions

File tree

QuestAppVersionSwitcher/Adb/AdbServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public void Start()
119119
{
120120
if (!IsRunning)
121121
{
122-
StartServer("connect 127.0.0.1");
122+
StartServer("server nodaemon");
123123
}
124124
}
125125

QuestAppVersionSwitcher/Adb/ExitInfo.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,10 @@ public class ExitInfo
1111
public int ExitCode { get; set; }
1212
public string Output { get; set; }
1313
public string Error { get; set; }
14+
15+
public override string ToString()
16+
{
17+
return $"Exit code: {ExitCode}\nOutput: {Output}\nError: {Error}";
18+
}
1419
}
1520
}

QuestAppVersionSwitcher/Adb/QAVSAdbInteractor.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,12 @@ public static void Initialize()
5757
}
5858
}
5959

60-
public static void TryConnect()
60+
public static bool TryConnect()
6161
{
6262
Logger.Log("Trying to enable wireless adb");
6363
try
6464
{
65+
AdbWrapper.KillServer();
6566
var port = AdbWrapper.EnableAdbWiFi(true);
6667

6768
// If the port is above 0 we were successful.
@@ -70,6 +71,7 @@ public static void TryConnect()
7071
Logger.Log("Found adb port in log, connecting: " + port, "ADB Wrapper");
7172
// Connect to the loopback IP on the detected port.
7273
var device = AdbWrapper.Connect("127.0.0.1", port);
74+
return true;
7375
}
7476
else
7577
{
@@ -79,7 +81,13 @@ public static void TryConnect()
7981
{
8082
Logger.Log("Failed to enable wireless adb: " + e.Message);
8183
}
82-
84+
85+
return false;
86+
}
87+
88+
public static void Connect()
89+
{
90+
8391
}
8492
}
8593
}
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
<html>
2+
<head>
3+
<meta charset="UTF-8">
4+
<title>QAVS - Setup</title>
5+
<link rel="stylesheet" type="text/css" href="newstyle.css">
6+
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,400italic,700,700italic' rel='stylesheet' type='text/css'>
7+
</head>
8+
<body>
9+
10+
<div class="content" id="checking">
11+
<h1>Checking adb</h1>
12+
<h3>Please wait a bit. This may take a few seconds</h3>
13+
<div class="loaderContainer center">
14+
<div class="loaderBarRight"></div>
15+
<div class="loaderBarLeft"></div>
16+
<div class="loaderBarTop"></div>
17+
<div class="loaderBarBottom"></div>
18+
<div class="loaderSpinningCircle"></div>
19+
<div class="loaderMiddleCircle"></div>
20+
<div class="loaderCircleHole"></div>
21+
<div class="loaderSquare"></div>
22+
</div>
23+
</div>
24+
<div class="content hidden" id="connected">
25+
<h1>Quest connected!</h1>
26+
<p>Your quest is connected via adb. You can return now</p>
27+
<button onclick="AdbConnected()">Continue</button>
28+
</div>
29+
<div class="content hidden" id="pair">
30+
<h1>Pairing</h1>
31+
<p>Your quest is not connected via adb yet. Input the port and code shown in the wireless adb pairing page.</p>
32+
<input type="number" placeholder="port" id="port">
33+
<input type="number" placeholder="code" id="code">
34+
<button onclick="pair()">Pair</button>
35+
</div>
36+
<div class="content hidden" id="remember">
37+
<h1>Connect</h1>
38+
<p>QAVS has successfully paired with your Quest. We will now connect QAVS with your Quest. For that, input the wireless port from the adb wireless settings page.</p>
39+
40+
<input type="number" placeholder="wireless port" id="adbport">
41+
<button onclick="connect()">Connect</button>
42+
</div>
43+
<div class="content hidden" id="connecting">
44+
<h1>Connecting, please wait a bit</h1>
45+
46+
<div class="loaderContainer center">
47+
<div class="loaderBarRight"></div>
48+
<div class="loaderBarLeft"></div>
49+
<div class="loaderBarTop"></div>
50+
<div class="loaderBarBottom"></div>
51+
<div class="loaderSpinningCircle"></div>
52+
<div class="loaderMiddleCircle"></div>
53+
<div class="loaderCircleHole"></div>
54+
<div class="loaderSquare"></div>
55+
</div>
56+
</div>
57+
<div class="content hidden" id="persistent">
58+
<h1>Making connecting persistent, please wait a bit</h1>
59+
<div class="loaderContainer center">
60+
<div class="loaderBarRight"></div>
61+
<div class="loaderBarLeft"></div>
62+
<div class="loaderBarTop"></div>
63+
<div class="loaderBarBottom"></div>
64+
<div class="loaderSpinningCircle"></div>
65+
<div class="loaderMiddleCircle"></div>
66+
<div class="loaderCircleHole"></div>
67+
<div class="loaderSquare"></div>
68+
</div>
69+
</div>
70+
<a href="/pair">Advanced ui</a>
71+
<script>
72+
FirstOpen()
73+
// get after query string
74+
var urlParams = new URLSearchParams(window.location.search);
75+
var after = urlParams.get('after')
76+
77+
function AdbConnected() {
78+
location = decodeURIComponent(after || "/");
79+
}
80+
81+
function connect() {
82+
OpenTab("connecting")
83+
fetch("/api/adb/connect", {
84+
method: "POST",
85+
body: JSON.stringify({port: document.getElementById('adbport').value})
86+
})
87+
.then(response => response.json())
88+
.then(data => {
89+
if (data.success) {
90+
OpenTab("persistent")
91+
persistent()
92+
} else {
93+
alert("Failed to connect. Please try again. If it doesn't work, try to restart the headset then try again.")
94+
}
95+
})
96+
}
97+
98+
function FirstOpen() {
99+
// Check if device is connected already
100+
fetch(`/api/adb/devices`)
101+
.then(response => response.json())
102+
.then(data => {
103+
if (data.length > 0) {
104+
// Found devices
105+
OpenTab("connected")
106+
} else {
107+
OpenTab("pair")
108+
}
109+
})
110+
}
111+
function wireless() {
112+
fetch(`/api/adb/togglewireless`, {
113+
method: "POST"
114+
})
115+
}
116+
function persistent() {
117+
fetch(`/api/adb/makepersistent`, {
118+
method: "POST"
119+
}).then(res => res.json()).then(data => {
120+
if(data.success) {
121+
OpenTab("connected")
122+
} else {
123+
alert("Failed to make persistent. Please try again. If it doesn't work, try to restart the headset then try again.")
124+
}
125+
})
126+
}
127+
128+
function port() {
129+
fetch("/api/adb/port")
130+
.then(response => response.text())
131+
.then(data => {
132+
alert(data)
133+
})
134+
}
135+
function settings() {
136+
fetch(`/api/adb/opensettings`, {
137+
method: "POST"
138+
})
139+
}
140+
141+
function pair() {
142+
var port = document.getElementById('port').value;
143+
var code = document.getElementById('code').value;
144+
fetch(`/api/adb/pair`, {
145+
method: "POST",
146+
body: JSON.stringify({port: port, code: code})
147+
})
148+
.then(response => response.json())
149+
.then(data => {
150+
if (data.success) {
151+
OpenTab("remember")
152+
} else {
153+
alert("Failed to pair. Please try again. If it doesn't work, try to restart the headset then try again.")
154+
}
155+
})
156+
}
157+
158+
function send() {
159+
var command = document.getElementById('command').value;
160+
fetch(`/api/adb/command`, {
161+
method: 'POST',
162+
body: JSON.stringify({command: command})
163+
})
164+
.then(response => response.text())
165+
.then(data => {
166+
document.getElementById('response').value = data;
167+
})
168+
}
169+
170+
171+
function OpenTab(section) {
172+
Array.prototype.forEach.call(document.getElementsByClassName("content"), e => {
173+
e.className = "content" + (e.id == section ? "" : " hidden")
174+
})
175+
}
176+
</script>
177+
</body>
178+
</html>

QuestAppVersionSwitcher/Assets/html/flows/beat_saber_modding.html

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ <h1>Install Game</h1>
6161
</div>
6262
<div class="content hidden" id="saf">
6363
<h1>Access needed</h1>
64-
<p>To mod your game correctly you need to grant access to your Beat Saber install. To do this press <code>Use this folder</code> at the bottom of both prompts which will appear after you press <code>Grant access</code> below.</p>
65-
<button onclick="SAFRequest()">Grant access</button>
64+
<p>To mod your game correctly you need to grant access to your Beat Saber install. To do this follow the provided instructions after pressing <code>Grant access</code> below</p>
65+
<button onclick="ADBRequest()">Grant access</button>
6666
</div>
6767
<div class="content hidden" id="afterrestore">
6868
<h1>Game modded!</h1>
@@ -361,9 +361,8 @@ <h2>Upload logs</h2>
361361
})
362362
}
363363

364-
function SAFRequest() {
365-
fetch("/api/grantaccess?package=com.beatgames.beatsaber", {method: "POST"})
366-
OpenTab(nextTab)
364+
function ADBRequest() {
365+
location = start + `/adb?after=${encodeURIComponent(`/flows/beat_saber_modding?tab=${nextTab}`)}`
367366
}
368367

369368

QuestAppVersionSwitcher/Assets/html/index.html

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,6 @@ <h2>Downloads</h2>
344344
<div class="button" id="changeApp">Change app</div>
345345
<div class="buttonLabel">Change the app you want to manage</div>
346346
</div>
347-
<div class="buttonContainer" id="requestAppData">
348-
<div class="button" id="requestAppPermission">Request Android directory permission</div>
349-
<div class="buttonLabel">Requests permissions to access Android/data and Android/obb</div>
350-
</div>
351347
<div class="buttonContainer" id="requestAppManage">
352348
<div class="button" id="requestManageStorageAppPermission">Allow manage storage permission for selected app</div>
353349
<div class="buttonLabel">Opens settings to allow manage storage for the selected app</div>
@@ -643,7 +639,7 @@ <h3>Credits</h3>
643639
<br>
644640
This will give QuestAppVersionSwitcher access to the games folder so it can install mods and restore app data and obbs.
645641
<br>
646-
Press <code>Use this folder</code> on both prompts you'll get after you press <code>Grant access</code>
642+
Follow the provided instructions after pressing grant access then restore this backup again.
647643
<div id="step4.1box" class="textBox"></div>
648644
<div class="buttonSelectionContainer">
649645
<div class="buttonContainer">
@@ -711,7 +707,7 @@ <h3>Credits</h3>
711707
<div class="contentHeader headerMargin">
712708
Access needed
713709
</div>
714-
To create and restore backups, QuestAppVersionSwitcher needs access to Android data and obb folder. To grant access press <code>Grant access</code> below follow the provided instructions.
710+
To create and restore backups, QuestAppVersionSwitcher needs to be paired with your Quest. To do this press <code>Grant access</code> below follow the provided instructions.
715711
<div id="step12box" class="textBox"></div>
716712
<div class="buttonSelectionContainer">
717713
<div class="buttonContainer">
@@ -723,7 +719,7 @@ <h3>Credits</h3>
723719
<div class="contentHeader headerMargin">
724720
Access needed
725721
</div>
726-
To create and restore backups, QuestAppVersionSwitcher needs access to Android data and obb folder. To grant access press <code>Grant access</code> below and press <code>Use this folder</code> on <b>both</b> prompts you'll get.
722+
To create and restore backups, QuestAppVersionSwitcher needs to be paired with your Quest. To do this press <code>Grant access</code> below follow the provided instructions.
727723
<div id="step15box" class="textBox"></div>
728724
<div class="buttonSelectionContainer">
729725
<div class="buttonContainer">

QuestAppVersionSwitcher/Assets/html/pair.html

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ <h2>Pairing</h2>
1212
<input type="number" placeholder="code" id="code">
1313
<button onclick="pair()">Pair</button>
1414
<button onclick="persistent()">Maker persistent (after pairing)</button>
15-
<button onclick="port()">Get adb port from logcat (requires persistence)</button>
16-
<button onclick="wireless()">Toggle wireless (requires persistence)</button>
15+
<button onclick="port()">Get adb port from logcat (requires persistence)</button>
16+
<button onclick="wireless()">Toggle wireless (requires persistence)</button>
17+
<h2>Commands</h2>
1718
<input type="text" placeholder="command" id="command">
18-
<h2>Commands</h2>
1919
<button onclick="send()">Send command</button>
20-
<textarea id="response"></textarea>
20+
<textarea id="response" readonly></textarea>
2121
<h2>Quick guide</h2>
2222
Open settings -> system info -> build number -> tap 7 times -> go back -> developer options -> enable wireless adb and open menu -> pair with the code and port you see on the headset-> run a commands like <code>ls /sdcard/</code> to see if it worked.
2323
<br>
@@ -59,7 +59,7 @@ <h2>Quick guide</h2>
5959
alert(data)
6060
})
6161
}
62-
62+
6363
function send() {
6464
var command = document.getElementById('command').value;
6565
fetch(`/api/adb/command`, {
@@ -71,7 +71,6 @@ <h2>Quick guide</h2>
7171
document.getElementById('response').value = data;
7272
})
7373
}
74-
7574
</script>
7675
</body>
7776
</html>

QuestAppVersionSwitcher/Assets/html/script.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,7 @@ function AfterAPKInstall() {
13571357
// 4: restore app data
13581358
// 5: done'd
13591359
if(j.isPatchedApk) {
1360-
if(j.moddedJson && j.moddedJson.modloaderName == "QuestLoader") {
1360+
if(j.moddedJson && j.moddedJson.modloaderName == "QuestLoader" && !a.gotAccess) {
13611361
GotoStep("4.1") // QuestLoader needs access to Android/data
13621362
} else {
13631363
GotoStep("4.2") // No need to ask for access
@@ -1459,22 +1459,18 @@ document.getElementById("deleteAllMods").onclick = () => {
14591459
}
14601460

14611461
document.getElementById("grantAccess2").onclick = () => {
1462-
location = "/pair"
1462+
location = "/adb"
14631463
}
14641464

14651465
document.getElementById("grantAccess3").onclick = () => {
1466-
location = "/pair?after=step16"
1466+
location = `/adb?after=${encodeURIComponent(start + `/?step16=true`)}`
14671467
}
14681468

14691469
document.getElementById("requestManageStorageAppPermission").onclick = () => {
14701470
fetch("/api/grantmanagestorageappaccess?package=" + config.currentApp, {method: "POST"}).then(res => {
14711471
})
14721472
}
14731473

1474-
document.getElementById("requestAppPermission").onclick = () => {
1475-
fetch("/api/grantaccess?package=" + config.currentApp, {method: "POST"})
1476-
}
1477-
14781474
document.getElementById("restoreappdata").onclick = () => {
14791475
fetch("/api/android/ispackageinstalled?package=" + config.currentApp).then(res => {
14801476
res.json().then(j => {

QuestAppVersionSwitcher/QuestAppVersionSwitcher.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@
165165
<Compile Include="WebServer.cs" />
166166
</ItemGroup>
167167
<ItemGroup>
168+
<AndroidAsset Include="Assets\html\adb.html" />
168169
<AndroidAsset Include="Assets\html\diff\diff.html" />
169170
<AndroidAsset Include="Assets\html\flows\beat_saber_modding.html" />
170171
<AndroidAsset Include="Assets\html\hiddenApps.json" />

0 commit comments

Comments
 (0)