Skip to content

Commit 7fe7cee

Browse files
authored
fix: load custom fonts on restart (#1499)
- fix: load custom fonts on restart - fix: input placement on extension tab sidebar
1 parent 4aefa74 commit 7fe7cee

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

src/lib/fonts.js

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import MesloLGSNFRegular from "../res/fonts/MesloLGSNFRegular.ttf";
77
import robotoMono from "../res/fonts/RobotoMono.ttf";
88

99
const fonts = new Map();
10+
const customFontNames = new Set();
11+
const CUSTOM_FONTS_KEY = "custom_fonts";
1012

1113
add(
1214
"Fira Code",
@@ -121,10 +123,47 @@ add(
121123
}`,
122124
);
123125

126+
// Load custom fonts on module initialization
127+
loadCustomFonts();
128+
124129
function add(name, css) {
125130
fonts.set(name, css);
126131
}
127132

133+
function addCustom(name, css) {
134+
fonts.set(name, css);
135+
customFontNames.add(name);
136+
saveCustomFonts();
137+
}
138+
139+
function saveCustomFonts() {
140+
const customFonts = {};
141+
142+
for (const name of customFontNames) {
143+
const css = fonts.get(name);
144+
if (css) {
145+
customFonts[name] = css;
146+
}
147+
}
148+
149+
localStorage.setItem(CUSTOM_FONTS_KEY, JSON.stringify(customFonts));
150+
}
151+
152+
function loadCustomFonts() {
153+
try {
154+
const customFonts = localStorage.getItem(CUSTOM_FONTS_KEY);
155+
if (customFonts) {
156+
const parsed = JSON.parse(customFonts);
157+
for (const [name, css] of Object.entries(parsed)) {
158+
fonts.set(name, css);
159+
customFontNames.add(name);
160+
}
161+
}
162+
} catch (error) {
163+
console.error("Failed to load custom fonts:", error);
164+
}
165+
}
166+
128167
function get(name) {
129168
return fonts.get(name);
130169
}
@@ -134,7 +173,12 @@ function getNames() {
134173
}
135174

136175
function remove(name) {
137-
return fonts.delete(name);
176+
const result = fonts.delete(name);
177+
if (result) {
178+
customFontNames.delete(name);
179+
saveCustomFonts();
180+
}
181+
return result;
138182
}
139183

140184
function has(name) {
@@ -224,6 +268,7 @@ async function loadFont(name) {
224268

225269
export default {
226270
add,
271+
addCustom,
227272
get,
228273
getNames,
229274
remove,

src/pages/fontManager/fontManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export default function fontManager() {
155155
if (editedCSS === null) return; // User cancelled
156156

157157
// Add the font
158-
fonts.add(fontName, editedCSS);
158+
fonts.addCustom(fontName, editedCSS);
159159
renderFonts();
160160
toast(`Font "${fontName}" added successfully`);
161161
} catch (error) {

src/sidebarApps/extensions/style.scss

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
display: flex;
77
flex-direction: column;
88
border-bottom: 1px solid var(--border-color);
9+
box-sizing: border-box;
910

1011
.title {
1112
font-weight: 600;
@@ -43,14 +44,15 @@
4344
}
4445

4546
input[type="search"] {
46-
width: 100%;
47-
padding: 0.5rem;
47+
width: 100% !important;
48+
padding: 0.5rem !important;
4849
border: 1px solid var(--border-color);
4950
border-radius: 6px;
5051
background: var(--secondary-color);
5152
color: var(--primary-text-color);
5253
font-size: 0.875rem;
5354
transition: all 0.2s ease;
55+
margin: 0 !important;
5456

5557
&:focus {
5658
outline: none;

0 commit comments

Comments
 (0)