Skip to content

Commit bb84d52

Browse files
committed
chore(ui): limit string length of device and url
It can happen that device names (as FQDN) and the current tab URL (used in background SSO UI element) are very long, leading to UI glitches where the alignment between the right and left column is broken. We fix this by limiting the string length to a reasonable value and add a tooltip with the full string if it is overly long. Signed-off-by: Felix Moessbauer <[email protected]>
1 parent 080cb2d commit bb84d52

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

popup/menu.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* SPDX-FileCopyrightText: Copyright 2024 Siemens AG
44
*/
55

6+
/* max length of user-provided strings in UI */
7+
const UI_MAX_STRING_LEN = 30;
8+
69
let bg_port = chrome.runtime.connect({ name: "linux-entra-sso" });
710
/* communication with backend is in progress */
811
let inflight = false;
@@ -48,6 +51,21 @@ function setup_color_scheme() {
4851
document.documentElement.classList.add(scheme);
4952
}
5053

54+
/**
55+
* If string is short enough, just set the innerText property.
56+
* If not, set it to a cropped version and set the title to the
57+
* full one.
58+
*/
59+
function set_text_cropped(element, str) {
60+
if (str.length <= UI_MAX_STRING_LEN) {
61+
element.innerText = str;
62+
element.title = "";
63+
} else {
64+
element.innerText = str.slice(0, UI_MAX_STRING_LEN) + "…";
65+
element.title = str;
66+
}
67+
}
68+
5169
setup_color_scheme();
5270
bg_port.onMessage.addListener(async (m) => {
5371
if (m.event == "stateChanged") {
@@ -79,7 +97,10 @@ bg_port.onMessage.addListener(async (m) => {
7997
document.getElementById("version").innerText = vstr;
8098
}
8199
if (m.device) {
82-
document.getElementById("device-name").innerText = m.device.name;
100+
set_text_cropped(
101+
document.getElementById("device-name"),
102+
m.device.name,
103+
);
83104
document.getElementById("state-compliant-value").innerText = m
84105
.device.compliant
85106
? "compliant"
@@ -174,7 +195,7 @@ async function check_bg_sso_enabled() {
174195

175196
var tab_hostname = new URL(tab.url).hostname;
176197
current_filter = "https://" + tab_hostname + "/*";
177-
document.getElementById("current-url").innerText = tab_hostname;
198+
set_text_cropped(document.getElementById("current-url"), tab_hostname);
178199
const permissionsToCheck = {
179200
origins: [current_filter],
180201
};

0 commit comments

Comments
 (0)