Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression from v1.0.0 #39

Open
Rudxain opened this issue Sep 16, 2024 · 7 comments
Open

Regression from v1.0.0 #39

Rudxain opened this issue Sep 16, 2024 · 7 comments

Comments

@Rudxain
Copy link

Rudxain commented Sep 16, 2024

Universal-Debloater-Alliance/universal-android-debloater-next-generation#627

src/main.rs:

fn main() {
    println!("{:?}", dark_light::detect());
}

Cargo.toml:

[package]
name = "tmp"
version = "0.1.0"
edition = "2021"
[dependencies]
dark-light = "=1.1.1"
# `cargo run`: "Light"
[dependencies]
dark-light = "=1.0.0"
# `cargo run`: "Dark" (correct)

The 2 variations of dependencies from Cargo.toml where tested on separate directories, for better isolation (no need for cargo update) and to avoid recompilation of recursive deps (although I tried to recycle target/)

@maplant
Copy link

maplant commented Sep 17, 2024

I experience this as well, dark-light version 1.1.1 returns an incorrect theme for detect
I'm on Fedora 40, Gnome 46 on X11

@jacksongoode
Copy link

Can you narrow down if it was from 1.1.0 to 1.1.1 or 1.0.0 to 1.1.0. It could be the zbus bump which caused this.

@maplant
Copy link

maplant commented Oct 2, 2024

Can you narrow down if it was from 1.1.0 to 1.1.1 or 1.0.0 to 1.1.0. It could be the zbus bump which caused this.

It was 1.1.0 that introduced this issue

@klassenserver7b
Copy link

klassenserver7b commented Oct 20, 2024

Yes, it is zbus bump because zbus 0.4 introduced `body.deserialize::(). The current 1.1.0 code uses:

let theme = reply.body().deserialize::<u32>();

But the body of the message is structured like this: Structure { fields: [Value(Value(U32(1)))], signature: Signature("(v)") }
You can check this yourself by parsing the reply like that:

        let body = reply.body();
        let theme: zbus::zvariant::Structure = body.deserialize().unwrap();
        println!("theme: {:?}", theme);

(I use OpenSUSE Leap 15.6, KDE Plasma 5.27.11, BreezeDark, xdg-desktop-portal 1.18.2, X11)

@klassenserver7b
Copy link

klassenserver7b commented Oct 20, 2024

Therefore i would recommend to use ReadOne to get rid of the first Value() in Value(Value(U32))

After that is is required to downcast the Value(U32) to U32.
This would be working code:

    fn get_freedesktop_color_scheme() -> Option<Mode> {
    let conn = Connection::session();
    if conn.is_err() {
        return None;
    }
    let reply = conn.unwrap().call_method(
        Some("org.freedesktop.portal.Desktop"),
        "/org/freedesktop/portal/desktop",
        Some("org.freedesktop.portal.Settings"),
        "ReadOne",
        &("org.freedesktop.appearance", "color-scheme"),
    );
    if let Ok(reply) = &reply {
        
        let body = reply.body();
        let value = body.deserialize::<Value>();
        if value.is_err() {
            return None;
        }
        
        let theme = value.unwrap().downcast::<u32>();
        if theme.is_err() {
            return None;
        }

        match theme.unwrap() {
            1 => Some(Mode::Dark),
            2 => Some(Mode::Light),
            _ => None,
        }
    } else {
        None
    }
}

@klassenserver7b
Copy link

klassenserver7b commented Oct 20, 2024

You could also keep Read as dbus method. With that you would have to do the downcasting twice

        let body = reply.body();
        let val_val = body.deserialize::<Value>();
        if val_val.is_err() {
            return None;
        }

        let val = val_val.unwrap().downcast::<Value>();
        if val.is_err() {
            return None;
        }
        
        let theme = val.unwrap().downcast::<u32>();
        if theme.is_err() {
            return None;
        }

Obviously are thos err checks not needed it that amount and can be simplified but it showns the changes in zbus

@klassenserver7b
Copy link

Oh, i saw its fixed on main by using ashpd.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants