-
-
Notifications
You must be signed in to change notification settings - Fork 46
Implement favorite paired devices (#72) #74
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
base: master
Are you sure you want to change the base?
Conversation
|
I need some assistance @pythops: where should we store the state, the favorited devices? Should it write itself into the users config? |
|
@sermuns, you can use |
|
Thanks, I will try that! |
Clearing cache shouldn't rather result in user's favourites disappearing. |
|
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.
|
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 I think I need to create a little in-memory state to "cache" the reading from disk, or am I overthinking this? |
| if !favorite_addrs_file.exists() { | ||
| return false; | ||
| } | ||
| let contents = tokio::fs::read_to_string(favorite_addrs_file).await; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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."); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
@sermuns |
No description provided.