Skip to content

Conversation

@sermuns
Copy link

@sermuns sermuns commented Sep 18, 2025

No description provided.

@sermuns
Copy link
Author

sermuns commented Sep 18, 2025

I need some assistance @pythops: where should we store the state, the favorited devices? Should it write itself into the users config?

@pythops
Copy link
Owner

pythops commented Sep 18, 2025

@sermuns, you can use ~/.cache directory for that.
bluetui has dirs crate as dependency already, and you can get the cache directory easily
https://docs.rs/dirs/6.0.0/dirs/fn.cache_dir.html

@sermuns
Copy link
Author

sermuns commented Sep 18, 2025

Thanks, I will try that!

@Jorenar
Copy link
Contributor

Jorenar commented Oct 16, 2025

@sermuns, you can use ~/.cache directory for that.

Clearing cache shouldn't rather result in user's favourites disappearing.
It should rather go to $XDG_DATA_HOME (~/.local/share).

@pythops
Copy link
Owner

pythops commented Oct 20, 2025

I agree with @Jorenar on this one

- We should stop reading from disk everytime.
- Only visually changes order. This MUST BE FIXED.
- Need to add keybind to hint in footer.
@sermuns
Copy link
Author

sermuns commented Oct 25, 2025

I have now had some time to try to implement this.

ec432f9 works, but I am not proud of this approach since it performs way too much I/O, reading from disk everytime the App::refresh is invoked.

I think I need to create a little in-memory state to "cache" the reading from disk, or am I overthinking this?

@sermuns sermuns marked this pull request as ready for review October 28, 2025 20:03
if !favorite_addrs_file.exists() {
return false;
}
let contents = tokio::fs::read_to_string(favorite_addrs_file).await;
Copy link

@eHammarstrom eHammarstrom Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this read cached or do we read the file every time we ask if the addr is a favorite?
Perhaps it is a good idea to store a map of the favorites (addr: Address, favorite: bool) that we serialize and deserialize on startup and favorite state modification?

Then you could have the member method is_favorite which only queries the map/store of the favorite state, giving a similar API as to is_trusted and is_connected

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not cached, and it called everytime the App:tick is called.. so this is EXTREMELY bad and practically constantly reading from disk.

I think your idea is good. I will try to implement!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think getting some input from @pythops as well would be a good idea before running with it :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not good idea to have an io for every tick

}

pub async fn get_if_favorite(addr: Address) -> bool {
let state_dir = dirs::state_dir().expect("Could not find state directory.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if user's favorites aren't important enough to warrant placement in $XDG_DATA_HOME?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might be right. According to Gentoo's Wiki, $XDG_STATE_HOME is more for data that isn't important/portable enough.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the program should not exit because we can not find favorite directory or we can not read from it.


pub async fn get_if_favorite(addr: Address) -> bool {
let state_dir = dirs::state_dir().expect("Could not find state directory.");
let favorite_addrs_file = state_dir.join(crate_name!()).join("favorite_addrs.txt");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just favorites.txt?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My code taste is to make names as specific as possible. The file contains MAC adresses of favorite devices, so that's why I named it that.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree with @Jorenar
also, same as the comment above, the program should not quit if the read operation is not successful for any reason.

@pythops
Copy link
Owner

pythops commented Nov 2, 2025

@sermuns
maybe we should sync about it so we agree on the implementation.
@eHammarstrom @Jorenar you are welcome to join if you want to.
I have my Discord server https://discord.gg/mfSRc9Jann, so we can take the discussion there

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

Successfully merging this pull request may close these issues.

4 participants