Skip to content

Commit 6d5086a

Browse files
committed
fix(aw-sync): use passed hostname directly instead of client.hostname
- Created push_with_hostname() function that accepts hostname parameter - Updated JNI functions to use push_with_hostname() with passed hostname - This ensures sync directory uses actual device name from Android - Fixes issue where 'localhost' was used despite passing device name The hostname is now passed directly from Android through JNI to the sync functions, bypassing the client's hostname entirely.
1 parent 9b32e31 commit 6d5086a

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

aw-sync/src/android.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use jni::sys::jstring;
44
use aw_client_rust::blocking::AwClient;
55
use serde_json::json;
66

7-
use crate::{pull, pull_all, push};
7+
use crate::{pull, pull_all, push_with_hostname};
88

99
/// Helper function to convert Rust string to Java string
1010
fn rust_string_to_jstring(env: &JNIEnv, s: String) -> jstring {
@@ -128,7 +128,7 @@ pub extern "C" fn Java_net_activitywatch_android_SyncInterface_syncPush(
128128

129129
let result: Result<String, String> = (|| {
130130
let client = get_client(port)?;
131-
push(&client)
131+
push_with_hostname(&client, &hostname_str)
132132
.map_err(|e| format!("Sync push failed: {}", e))?;
133133
Ok(json!({
134134
"success": true,
@@ -178,7 +178,7 @@ pub extern "C" fn Java_net_activitywatch_android_SyncInterface_syncBoth(
178178
pull_all(&client)
179179
.map_err(|e| format!("Pull phase failed: {}", e))?;
180180

181-
push(&client)
181+
push_with_hostname(&client, &hostname_str)
182182
.map_err(|e| format!("Push phase failed: {}", e))?;
183183

184184
Ok(json!({

aw-sync/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub use sync::sync_run;
1111
pub use sync::SyncSpec;
1212

1313
mod sync_wrapper;
14-
pub use sync_wrapper::push;
14+
pub use sync_wrapper::{push, push_with_hostname};
1515
pub use sync_wrapper::{pull, pull_all};
1616

1717
mod accessmethod;

aw-sync/src/sync_wrapper.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,13 @@ pub fn pull(host: &str, client: &AwClient) -> Result<(), Box<dyn Error>> {
5757
}
5858

5959
pub fn push(client: &AwClient) -> Result<(), Box<dyn Error>> {
60+
push_with_hostname(client, &client.hostname)
61+
}
62+
63+
pub fn push_with_hostname(client: &AwClient, hostname: &str) -> Result<(), Box<dyn Error>> {
6064
let sync_dir = crate::dirs::get_sync_dir()
6165
.map_err(|_| "Could not get sync dir")?
62-
.join(&client.hostname);
66+
.join(hostname);
6367

6468
let sync_spec = SyncSpec {
6569
path: sync_dir,

0 commit comments

Comments
 (0)