From 7f900a167e0077c354fb26ab6d34ae06591a67c5 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Wed, 9 Mar 2022 01:30:42 -0300 Subject: [PATCH] fix(tray): force item title string to be null-terminated (#340) --- .changes/fix-tray-item-title.md | 5 +++++ src/platform_impl/windows/menu.rs | 4 ++++ 2 files changed, 9 insertions(+) create mode 100644 .changes/fix-tray-item-title.md diff --git a/.changes/fix-tray-item-title.md b/.changes/fix-tray-item-title.md new file mode 100644 index 000000000..e15dda1a5 --- /dev/null +++ b/.changes/fix-tray-item-title.md @@ -0,0 +1,5 @@ +--- +"tao": patch +--- + +Fixes system tray item titles on Windows by forcing the string to be null-terminated. diff --git a/src/platform_impl/windows/menu.rs b/src/platform_impl/windows/menu.rs index 4f3213bb3..141ed7859 100644 --- a/src/platform_impl/windows/menu.rs +++ b/src/platform_impl/windows/menu.rs @@ -194,6 +194,10 @@ impl Menu { anno_title.push('\t'); format_hotkey(accelerators, &mut anno_title); } + // NOTE(amrbashir): The title must be a null-terminated string. Otherwise, it will display some gibberish characters at the end. + if !anno_title.ends_with("\0") { + anno_title.push_str("\0"); + } AppendMenuW(self.hmenu, flags, menu_id.0 as _, anno_title);