Skip to content

Commit

Permalink
termux support (#66)
Browse files Browse the repository at this point in the history
- Uses a separate clipboard library on android (doesn't replace on other platforms)
- Fixes geode dir path getter (it tried to use macOS paths)
  • Loading branch information
Prevter committed Jun 27, 2024
1 parent b4b8544 commit 9ade13c
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 11 deletions.
103 changes: 98 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,14 @@ which = "6.0.1"
vec1 = { version = "1.12.1", features = ["serde"] }
crossterm_input = "0.5.0"
open = "5.1.4"
cli-clipboard = "0.4.0"
rand = "0.8.5"

[target.'cfg(target_os = "android")'.dependencies]
terminal-clipboard = "0.4.1"

[target.'cfg(not(target_os = "android"))'.dependencies]
cli-clipboard = "0.4.0"

[target.'cfg(windows)'.dependencies]
winreg = "0.52.0"
ansi_term = "0.12"
Expand Down
23 changes: 18 additions & 5 deletions src/index_auth.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(not(target_os = "android"))]
use cli_clipboard::ClipboardProvider;
use reqwest::header::USER_AGENT;
use serde::{Deserialize, Serialize};
Expand All @@ -20,6 +21,22 @@ struct LoginPoll {
uuid: String,
}

#[cfg(not(target_os = "android"))]
pub fn copy_token(token: &str) {
if let Ok(mut ctx) = cli_clipboard::ClipboardContext::new() {
if ctx.set_contents(token.to_string()).is_ok() {
done!("Token has been copied to your clipboard");
}
}
}

#[cfg(target_os = "android")]
pub fn copy_token(token: &str) {
if terminal_clipboard::set_string(token).is_ok() {
done!("Token has been copied to your clipboard");
}
}

pub fn login(config: &mut Config, token: Option<String>) {
if let Some(token) = token {
config.index_token = Some(token);
Expand Down Expand Up @@ -57,11 +74,7 @@ pub fn login(config: &mut Config, token: Option<String>) {
info!("You will need to complete the login process in your web browser");
info!("Go to: {} and enter the login code", &login_data.uri);
info!("Your login code is: {}", &login_data.code);
if let Ok(mut ctx) = cli_clipboard::ClipboardContext::new() {
if ctx.set_contents(login_data.code.to_string()).is_ok() {
info!("The code has been copied to your clipboard");
}
}
copy_token(&login_data.code);
open::that(&login_data.uri).nice_unwrap("Unable to open browser");

loop {
Expand Down
2 changes: 2 additions & 0 deletions src/util/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ impl Profile {
pub fn geode_dir(&self) -> PathBuf {
if self.platform == "win" {
self.gd_path.parent().unwrap().join("geode")
} else if self.platform == "android32" || self.platform == "android64" {
self.gd_path.join("game/geode")
} else {
self.gd_path.join("Contents/geode")
}
Expand Down

0 comments on commit 9ade13c

Please sign in to comment.