Skip to content

Conversation

@USTHzhanglu
Copy link

if device info Description have a long info, the tray menu will very long.
so we need limit description.
besides, we need show bus-id, if user use same device
more infore
#13

@JPHutchins
Copy link
Contributor

Thanks! Do take a minute to make sure that the linters pass.

let menu_item = self
let menu_item;

if description.len() > 16 {
Copy link
Contributor

@JPHutchins JPHutchins Jul 4, 2025

Choose a reason for hiding this comment

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

It seems that this should be more like ~32. As is, it has the potential to make the name longer while conveying less information.

Copy link
Owner

Choose a reason for hiding this comment

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

Agreed on increasing the length to 32, I feel like 16 would be too short to convey any useful information.

Copy link
Author

Choose a reason for hiding this comment

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

A better way maybe use menu_item to config.
if agree with it, i will cost some time to achieve it .( i have no exp with nwg, so i need read code to understand)

Copy link
Owner

Choose a reason for hiding this comment

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

Why not just increase the number to 32? Is it more complicated than that?


if description.len() > 16 {
let mut short_description = description.clone();
short_description.truncate(16);
Copy link
Owner

Choose a reason for hiding this comment

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

You can avoid the if-else here right away and just always call truncate on the string, since truncate does nothing if the string is already shorter, (see rust doc about truncate). This should simplify the code and reduce nesting a bit, making everything cleaner.

Copy link
Author

Choose a reason for hiding this comment

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

if len less 16, maybe we needn't show bus id. so i use if-else. now i not have a batter code to active it, does you have some suggestions?

Copy link
Owner

Choose a reason for hiding this comment

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

Oh I see now why you did it like this. Fine by me, keep it as is.

@nickbeth nickbeth linked an issue Jul 13, 2025 that may be closed by this pull request
Comment on lines 174 to 184
// if len > 32, truncate and add bus id
if description.len() > 32 { // @todo use settings replace magic number
description.truncate(32);
let bus_id = device
.bus_id
.clone()
.unwrap_or_else(|| "Unknown Bus".to_string());
description.push_str(&format!("..(Bus:{})", bus_id));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is not the desired behavior. If the goal is to establish a max string length, truncating if necessary, and adding unique ID (bus ID), then the length of that metadata must be taken into account. The present implementation can result in a longer string with less information.

The truncation point is not the same as the desired max string length. The truncation point must be max_length - length(id_string).

  • description is greater than max length
  • format the ID string (... BUS-ID)
  • truncate and concat at description[max_length - length(id_string)]

This will prevent the fix from being longer than the problem.

Copy link
Author

Choose a reason for hiding this comment

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

agree with you

Copy link
Owner

@nickbeth nickbeth left a comment

Choose a reason for hiding this comment

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

LGTM, I'll briefly test it and merge if all goes smoothly. Thanks!

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.

tray menu too long

3 participants