Skip to content

Commit e44f05e

Browse files
committed
🎨 Improve status bar color parsing on mobile siyuan-note/siyuan#18073
1 parent 828cad9 commit e44f05e

1 file changed

Lines changed: 5 additions & 15 deletions

File tree

entry/src/main/ets/pages/JSHarmony.ets

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -380,24 +380,14 @@ export struct JSHarmony {
380380
private parseColor(color: string): string {
381381
try {
382382
color = color.trim();
383-
if (color.toLowerCase().includes("rgb")) {
384-
const splitStr = color.substring(color.indexOf('(') + 1, color.indexOf(')'));
385-
const splitString = splitStr.split(",");
386-
const colorValues = splitString.map(value => parseInt(value.trim(), 10));
387-
return `rgb(${colorValues[0]}, ${colorValues[1]}, ${colorValues[2]})`;
383+
if (color.length !== 9 || color.charAt(0) !== '#') {
384+
throw new Error("invalid color format");
388385
}
389-
if (color.length < 7) {
390-
// Convert 3-digit hex colors to 6-digit
391-
color = color.replace(new RegExp("#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])"), "#$1$1$2$2$3$3");
392-
}
393-
if (color.length === 9 && color.charAt(0) === '#') {
394-
// Convert #RRGGBBAA to #AARRGGBB
395-
color = "#" + color.substring(7, 9) + color.substring(1, 7);
396-
}
397-
return color;
386+
// Convert #RRGGBBAA to #AARRGGBB
387+
return "#" + color.substring(7, 9) + color.substring(1, 7);
398388
} catch (e) {
399389
hilog.error(0x0000, "siyuan", "parse color [" + color + "] failed", e);
400-
return "#ffffff";
390+
return "#ffffffff";
401391
}
402392
}
403393

0 commit comments

Comments
 (0)