Skip to content

Commit 6b38d84

Browse files
committed
wip
1 parent 6d7332c commit 6b38d84

File tree

3 files changed

+114
-56
lines changed

3 files changed

+114
-56
lines changed

README.md

Lines changed: 38 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -233,59 +233,41 @@ See the changes on the PGN Viewer demo page: http://localhost:8091/
233233

234234
### Mobile
235235

236-
#### On your Android phone:
237-
238-
1. Connect your phone on the same wifi network as your host machine
239-
2. Make sure your phone is in developer mode
240-
3. Enable wireless debugging
241-
4.
242-
243-
#### On your host machine:
244-
245-
1. Configure lila to run with your host's IP address or hostname instead of localhost
246-
```bash
247-
./lila-docker hostname
248-
```
249-
2. Ensure phone and can access lila using that host
250-
```
251-
http://[your private IP]:8080 # instead of http://localhost:8080
252-
```
253-
3. Run:
254-
```bash
255-
adb kill-server
256-
adb tcpip 5555
257-
```
258-
4. You should see the phone in the devices list:
259-
```bash
260-
adb devices
261-
```
262-
263-
#### On the container:
264-
265-
1. Get a shell on the container:
266-
267-
```bash
268-
docker compose exec -it mobile bash
269-
```
270-
271-
2. Connect to your phone:
272-
273-
```bash
274-
# get the ip address from your phone's wifi settings
275-
adb connect 192.168.1.xxx
276-
# you should see the phone in the devices list
277-
adb devices
278-
```
279-
280-
3. Install the app dependencies:
281-
282-
```bash
283-
flutter pub get
284-
dart run build_runner build
285-
```
286-
287-
4. Run the app:
288-
```bash
289-
flutter run --dart-define=LICHESS_HOST=$LICHESS_URL --dart-define=LICHESS_WS_HOST=$LICHESS_URL
290-
```
291-
- The `$LICHESS_URL` environment variable will already be set on the container.
236+
1. On your host machine:
237+
1. Configure lila to run with your host's IP address or hostname instead of localhost
238+
```bash
239+
./lila-docker hostname
240+
```
241+
1. Configure the mobile settings
242+
```bash
243+
./lila-docker mobile setup
244+
```
245+
1. Enter the IP address, port, and pairing code from the steps below
246+
1. On your Android phone:
247+
1. Connect your phone to the same wifi network as your host machine
248+
1. Ensure your phone and can access lila in your browser app using the host value you set above
249+
```
250+
http://[your-selection]:8080
251+
```
252+
1. Enable Developer Mode
253+
1. In Developer Options
254+
1. enable wireless debugging
255+
2. Tap into the wireless debugging settings
256+
1. Use the "IP address & Port" value in the prompt on your host
257+
2. Tap "Pair device with pairing code"
258+
1. Enter the pairing port and code in the prompt on your host
259+
1. On your host machine:
260+
1. Get a shell on the container:
261+
```bash
262+
docker compose exec -it mobile bash
263+
```
264+
2. Install the app dependencies:
265+
```bash
266+
flutter pub get
267+
dart run build_runner build
268+
```
269+
3. Run the app:
270+
```bash
271+
flutter run --dart-define=LICHESS_HOST=$LICHESS_URL --dart-define=LICHESS_WS_HOST=$LICHESS_URL
272+
```
273+
- No substitutions necessary. The `$LICHESS_URL` environment variable will already be set on the container.

command/src/main.rs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ struct Config {
2222
su_password: Option<String>,
2323
password: Option<String>,
2424
hostname: Option<String>,
25+
phone_ip: Option<String>,
26+
connection_port: Option<u16>,
27+
pairing_port: Option<u16>,
28+
pairing_code: Option<u32>,
2529
}
2630

2731
impl Config {
@@ -64,6 +68,22 @@ impl Config {
6468
new_config_values.insert("LILA_HOSTNAME".to_string(), hostname.to_string());
6569
}
6670

71+
if let Some(phone_ip) = &self.phone_ip {
72+
new_config_values.insert("PHONE_IP".to_string(), phone_ip.to_string());
73+
}
74+
75+
if let Some(connection_port) = &self.connection_port {
76+
new_config_values.insert("CONNECTION_PORT".to_string(), connection_port.to_string());
77+
}
78+
79+
if let Some(pairing_port) = &self.pairing_port {
80+
new_config_values.insert("PAIRING_PORT".to_string(), pairing_port.to_string());
81+
}
82+
83+
if let Some(pairing_code) = &self.pairing_code {
84+
new_config_values.insert("PAIRING_CODE".to_string(), pairing_code.to_string());
85+
}
86+
6787
config_values.extend(new_config_values);
6888

6989
std::fs::write(
@@ -134,6 +154,7 @@ fn main() -> std::io::Result<()> {
134154
match args[1].as_str() {
135155
"setup" => setup(),
136156
"hostname" => hostname(),
157+
"mobile" => mobile_setup(),
137158
"gitpod-welcome" => {
138159
gitpod_welcome();
139160
Ok(())
@@ -182,6 +203,10 @@ fn setup() -> std::io::Result<()> {
182203
su_password: Some(su_password),
183204
password: Some(password),
184205
hostname: None,
206+
phone_ip: None,
207+
connection_port: None,
208+
pairing_port: None,
209+
pairing_code: None,
185210
}
186211
.to_env();
187212

@@ -412,12 +437,53 @@ fn hostname() -> std::io::Result<()> {
412437
su_password: None,
413438
password: None,
414439
hostname: Some(hostname),
440+
phone_ip: None,
441+
connection_port: None,
442+
pairing_port: None,
443+
pairing_code: None,
444+
}
445+
.to_env();
446+
447+
Ok(())
448+
}
449+
450+
fn mobile_setup() -> std::io::Result<()> {
451+
let phone_ip: String = input("Your phone's private IP address")
452+
.placeholder("192.168.x.x or 10.x.x.x")
453+
.interact()?;
454+
let connection_port: u16 = input("Wireless debugging port")
455+
.validate(|input: &String| validate_string_length(input, 5))
456+
.interact()?;
457+
let pairing_port: u16 = input("Pairing port")
458+
.validate(|input: &String| validate_string_length(input, 5))
459+
.interact()?;
460+
let pairing_code: u32 = input("Pairing code")
461+
.validate(|input: &String| validate_string_length(input, 6))
462+
.interact()?;
463+
464+
Config {
465+
profiles: None,
466+
setup_database: None,
467+
su_password: None,
468+
password: None,
469+
hostname: None,
470+
phone_ip: Some(phone_ip),
471+
connection_port: Some(connection_port),
472+
pairing_port: Some(pairing_port),
473+
pairing_code: Some(pairing_code),
415474
}
416475
.to_env();
417476

418477
Ok(())
419478
}
420479

480+
fn validate_string_length(input: &String, length: usize) -> Result<(), String> {
481+
match input.len() {
482+
len if len == length => Ok(()),
483+
_ => Err(format!("Value should be {length} digits in length")),
484+
}
485+
}
486+
421487
fn gitpod_welcome() {
422488
println!("{}", "################".green());
423489
println!(

lila-docker

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ run_hostname() {
9696
fi
9797
}
9898

99+
run_mobile() {
100+
rust_cmd mobile
101+
export $(cat .env | xargs)
102+
docker compose exec mobile adb pair $PHONE_IP:$PAIRING_PORT $PAIRING_CODE
103+
docker compose exec mobile adb connect $PHONE_IP:$CONNECTION_PORT
104+
}
105+
99106
rust_cmd() {
100107
if command -v rustup &> /dev/null; then
101108
# if the host has Rust installed, use it directly
@@ -142,6 +149,9 @@ case $1 in
142149
hostname)
143150
run_hostname
144151
;;
152+
mobile)
153+
run_mobile "${@:2}"
154+
;;
145155
*)
146156
show_help
147157
exit 1

0 commit comments

Comments
 (0)