fix: tokio runtime, Enter-to-login, and server URL handling
Three bugs fixed: - No tokio reactor: glib::spawn_future_local does not provide a tokio context, so reqwest/hyper panicked at runtime. Introduce src/runtime.rs with a multi-thread tokio Runtime (init() called from main before the GTK app starts). runtime::spawn() posts the async result back to GTK via a tokio oneshot channel awaited by glib::spawn_future_local, which only polls a flag (no I/O). runtime::spawn_bg() is used for fire-and-forget background calls. - Enter key didn't submit login: connect_apply on AdwEntryRow only fires when show-apply-button is true. Switch to connect_entry_activated which fires on Return in all three login rows. - Wrong API URL: the app constructed /accounts/ClientLogin directly off the server host, yielding a 404. Add normalize_base_url() in api.rs that appends /api/greader.php when the URL doesn't already contain it, so users can enter just https://rss.example.com.
This commit is contained in:
parent
d157f3f244
commit
5dee5cc52b
6 changed files with 161 additions and 67 deletions
16
src/api.rs
16
src/api.rs
|
|
@ -42,14 +42,26 @@ struct Summary {
|
|||
|
||||
use crate::model::Article;
|
||||
|
||||
fn normalize_base_url(server_url: &str) -> String {
|
||||
let base = server_url.trim_end_matches('/');
|
||||
// If the user entered just a host (or host/path) without the FreshRSS
|
||||
// API suffix, append it automatically.
|
||||
if base.ends_with("/api/greader.php") {
|
||||
base.to_string()
|
||||
} else {
|
||||
format!("{base}/api/greader.php")
|
||||
}
|
||||
}
|
||||
|
||||
impl Api {
|
||||
pub async fn login(
|
||||
server_url: &str,
|
||||
username: &str,
|
||||
password: &str,
|
||||
) -> Result<Self, String> {
|
||||
let base = normalize_base_url(server_url);
|
||||
let client = Client::new();
|
||||
let url = format!("{}/accounts/ClientLogin", server_url.trim_end_matches('/'));
|
||||
let url = format!("{base}/accounts/ClientLogin");
|
||||
let resp = client
|
||||
.post(&url)
|
||||
.form(&[("Email", username), ("Passwd", password)])
|
||||
|
|
@ -72,7 +84,7 @@ impl Api {
|
|||
|
||||
Ok(Self {
|
||||
client,
|
||||
server_url: server_url.trim_end_matches('/').to_string(),
|
||||
server_url: base,
|
||||
auth_token,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue