wayBetter for X
This commit is contained in:
commit
2f1e35ba20
720 changed files with 147465 additions and 0 deletions
45
apps/desktop/src-tauri/src/profiles.rs
Normal file
45
apps/desktop/src-tauri/src/profiles.rs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
//! Account profiles (wayBetter host) with X's account rules: each X tab runs in one profile, every
|
||||
//! non-default profile has its own WebView data directory, and the X login inside a profile is read
|
||||
//! from X's own account button and validated with `site::SITE.accounts`.
|
||||
|
||||
pub use crate::site::valid_handle;
|
||||
pub use waybetter_host::profiles::{
|
||||
data_dir, orphan_dirs, store_identifier, valid_profile_id, AccountSeen, Profile, ProfileSettings, DEFAULT_PROFILE,
|
||||
PROFILES_DIR,
|
||||
};
|
||||
|
||||
/// The X account signed in inside a profile (`@handle` without the `@`, name, pbs.twimg.com avatar).
|
||||
pub type XAccount = waybetter_host::profiles::Account;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::site::SITE;
|
||||
|
||||
fn account(handle: &str, avatar: &str) -> XAccount {
|
||||
XAccount { handle: handle.into(), name: "Fishies".into(), avatar: Some(avatar.into()), signed_in: false }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn x_logins_are_validated_with_x_rules() {
|
||||
let mut settings = ProfileSettings::default();
|
||||
for bad in ["", "has space", "waytoolonghandle_", "a/b", "a.b"] {
|
||||
assert!(!settings.observe("default", AccountSeen::SignedIn(account(bad, "https://pbs.twimg.com/a.jpg")), &SITE.accounts), "{bad:?}");
|
||||
}
|
||||
assert!(settings.observe("default", AccountSeen::SignedIn(account("@play_fishies", "https://evil.test/x.png")), &SITE.accounts));
|
||||
let seen = settings.profiles[0].account.clone().unwrap();
|
||||
assert_eq!((seen.handle.as_str(), seen.avatar, seen.signed_in), ("play_fishies", None, true));
|
||||
assert!(settings.observe("default", AccountSeen::SignedIn(account("play_fishies", "https://pbs.twimg.com/profile_images/1/a_x96.jpg")), &SITE.accounts));
|
||||
assert!(settings.profiles[0].account.as_ref().unwrap().avatar.is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn profile_json_shape_is_unchanged() {
|
||||
// profiles.json written by earlier builds must keep loading.
|
||||
let raw = r##"{"profiles":[{"id":"default","name":"Main","color":"#1d9bf0","account":{"handle":"a","name":"A","avatar":"https://pbs.twimg.com/x.jpg","signedIn":true}}],"active":"default"}"##;
|
||||
let settings: ProfileSettings = serde_json::from_str(raw).unwrap();
|
||||
let settings = settings.validated(&SITE.accounts).unwrap();
|
||||
assert_eq!(serde_json::to_string(&settings).unwrap(), raw);
|
||||
assert_eq!(ProfileSettings::default().profiles[0].color, "#1d9bf0");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue