Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fitztrev committed Nov 26, 2023
1 parent 6d7332c commit 6b38d84
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 56 deletions.
94 changes: 38 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,59 +233,41 @@ See the changes on the PGN Viewer demo page: http://localhost:8091/

### Mobile

#### On your Android phone:

1. Connect your phone on the same wifi network as your host machine
2. Make sure your phone is in developer mode
3. Enable wireless debugging
4.

#### On your host machine:

1. Configure lila to run with your host's IP address or hostname instead of localhost
```bash
./lila-docker hostname
```
2. Ensure phone and can access lila using that host
```
http://[your private IP]:8080 # instead of http://localhost:8080
```
3. Run:
```bash
adb kill-server
adb tcpip 5555
```
4. You should see the phone in the devices list:
```bash
adb devices
```
#### On the container:
1. Get a shell on the container:
```bash
docker compose exec -it mobile bash
```
2. Connect to your phone:
```bash
# get the ip address from your phone's wifi settings
adb connect 192.168.1.xxx
# you should see the phone in the devices list
adb devices
```
3. Install the app dependencies:
```bash
flutter pub get
dart run build_runner build
```
4. Run the app:
```bash
flutter run --dart-define=LICHESS_HOST=$LICHESS_URL --dart-define=LICHESS_WS_HOST=$LICHESS_URL
```
- The `$LICHESS_URL` environment variable will already be set on the container.
1. On your host machine:
1. Configure lila to run with your host's IP address or hostname instead of localhost
```bash
./lila-docker hostname
```
1. Configure the mobile settings
```bash
./lila-docker mobile setup
```
1. Enter the IP address, port, and pairing code from the steps below
1. On your Android phone:
1. Connect your phone to the same wifi network as your host machine
1. Ensure your phone and can access lila in your browser app using the host value you set above
```
http://[your-selection]:8080
```
1. Enable Developer Mode
1. In Developer Options
1. enable wireless debugging
2. Tap into the wireless debugging settings
1. Use the "IP address & Port" value in the prompt on your host
2. Tap "Pair device with pairing code"
1. Enter the pairing port and code in the prompt on your host
1. On your host machine:
1. Get a shell on the container:
```bash
docker compose exec -it mobile bash
```
2. Install the app dependencies:
```bash
flutter pub get
dart run build_runner build
```
3. Run the app:
```bash
flutter run --dart-define=LICHESS_HOST=$LICHESS_URL --dart-define=LICHESS_WS_HOST=$LICHESS_URL
```
- No substitutions necessary. The `$LICHESS_URL` environment variable will already be set on the container.
66 changes: 66 additions & 0 deletions command/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ struct Config {
su_password: Option<String>,
password: Option<String>,
hostname: Option<String>,
phone_ip: Option<String>,
connection_port: Option<u16>,
pairing_port: Option<u16>,
pairing_code: Option<u32>,
}

impl Config {
Expand Down Expand Up @@ -64,6 +68,22 @@ impl Config {
new_config_values.insert("LILA_HOSTNAME".to_string(), hostname.to_string());
}

if let Some(phone_ip) = &self.phone_ip {
new_config_values.insert("PHONE_IP".to_string(), phone_ip.to_string());
}

if let Some(connection_port) = &self.connection_port {
new_config_values.insert("CONNECTION_PORT".to_string(), connection_port.to_string());
}

if let Some(pairing_port) = &self.pairing_port {
new_config_values.insert("PAIRING_PORT".to_string(), pairing_port.to_string());
}

if let Some(pairing_code) = &self.pairing_code {
new_config_values.insert("PAIRING_CODE".to_string(), pairing_code.to_string());
}

config_values.extend(new_config_values);

std::fs::write(
Expand Down Expand Up @@ -134,6 +154,7 @@ fn main() -> std::io::Result<()> {
match args[1].as_str() {
"setup" => setup(),
"hostname" => hostname(),
"mobile" => mobile_setup(),
"gitpod-welcome" => {
gitpod_welcome();
Ok(())
Expand Down Expand Up @@ -182,6 +203,10 @@ fn setup() -> std::io::Result<()> {
su_password: Some(su_password),
password: Some(password),
hostname: None,
phone_ip: None,
connection_port: None,
pairing_port: None,
pairing_code: None,
}
.to_env();

Expand Down Expand Up @@ -412,12 +437,53 @@ fn hostname() -> std::io::Result<()> {
su_password: None,
password: None,
hostname: Some(hostname),
phone_ip: None,
connection_port: None,
pairing_port: None,
pairing_code: None,
}
.to_env();

Ok(())
}

fn mobile_setup() -> std::io::Result<()> {
let phone_ip: String = input("Your phone's private IP address")
.placeholder("192.168.x.x or 10.x.x.x")
.interact()?;
let connection_port: u16 = input("Wireless debugging port")
.validate(|input: &String| validate_string_length(input, 5))
.interact()?;
let pairing_port: u16 = input("Pairing port")
.validate(|input: &String| validate_string_length(input, 5))
.interact()?;
let pairing_code: u32 = input("Pairing code")
.validate(|input: &String| validate_string_length(input, 6))
.interact()?;

Config {
profiles: None,
setup_database: None,
su_password: None,
password: None,
hostname: None,
phone_ip: Some(phone_ip),
connection_port: Some(connection_port),
pairing_port: Some(pairing_port),
pairing_code: Some(pairing_code),
}
.to_env();

Ok(())
}

fn validate_string_length(input: &String, length: usize) -> Result<(), String> {
match input.len() {
len if len == length => Ok(()),
_ => Err(format!("Value should be {length} digits in length")),
}
}

fn gitpod_welcome() {
println!("{}", "################".green());
println!(
Expand Down
10 changes: 10 additions & 0 deletions lila-docker
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ run_hostname() {
fi
}

run_mobile() {
rust_cmd mobile
export $(cat .env | xargs)
docker compose exec mobile adb pair $PHONE_IP:$PAIRING_PORT $PAIRING_CODE
docker compose exec mobile adb connect $PHONE_IP:$CONNECTION_PORT
}

rust_cmd() {
if command -v rustup &> /dev/null; then
# if the host has Rust installed, use it directly
Expand Down Expand Up @@ -142,6 +149,9 @@ case $1 in
hostname)
run_hostname
;;
mobile)
run_mobile "${@:2}"
;;
*)
show_help
exit 1
Expand Down

0 comments on commit 6b38d84

Please sign in to comment.