Fix: Set max window title size to 300 to prevent crashing. (#977)
This commit is contained in:
@@ -92,13 +92,21 @@ export const getTitle = (
|
|||||||
* If the title exceeds the maximum size, it appends an ellipsis ('...') to the truncated title.
|
* If the title exceeds the maximum size, it appends an ellipsis ('...') to the truncated title.
|
||||||
*
|
*
|
||||||
* @param title The title string to truncate.
|
* @param title The title string to truncate.
|
||||||
* @param max_size The maximum size of the truncated title.
|
* @param maxSize The maximum size of the truncated title.
|
||||||
*
|
*
|
||||||
* @returns The truncated title as a string. If the title is within the maximum size, returns the original title.
|
* @returns The truncated title as a string. If the title is within the maximum size, returns the original title.
|
||||||
*/
|
*/
|
||||||
export const truncateTitle = (title: string, max_size: number): string => {
|
export const truncateTitle = (title: string | null, maxSize: number): string => {
|
||||||
if (max_size > 0 && title.length > max_size) {
|
if (title === null) {
|
||||||
return title.substring(0, max_size).trim() + '...';
|
return '--';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const MAX_LABEL_SIZE = 300;
|
||||||
|
const effectiveSize = maxSize <= 0 ? MAX_LABEL_SIZE : Math.min(maxSize, MAX_LABEL_SIZE);
|
||||||
|
|
||||||
|
if (title.length <= effectiveSize) {
|
||||||
return title;
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
return title.substring(0, effectiveSize).trim() + '...';
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -381,6 +381,7 @@ export const BarSettings = (): JSX.Element => {
|
|||||||
title="Truncation Size"
|
title="Truncation Size"
|
||||||
type="number"
|
type="number"
|
||||||
min={10}
|
min={10}
|
||||||
|
max={300}
|
||||||
/>
|
/>
|
||||||
<Option
|
<Option
|
||||||
opt={options.theme.bar.buttons.windowtitle.spacing}
|
opt={options.theme.bar.buttons.windowtitle.spacing}
|
||||||
|
|||||||
Reference in New Issue
Block a user