Fix issue in advanced fontSettings sample (#1523)

We were using the wrong key when importing settings from a file.
Additionally, added a reload to fix an issue where the UI was not
updated when new settings were imported.

Fixes #1519
This commit is contained in:
Oliver Dunk
2025-08-05 18:33:39 +01:00
committed by GitHub
parent 5f6f02b924
commit 11898ee8eb

View File

@@ -617,13 +617,14 @@ advancedFonts.importSettings = function () {
if (selectedFile.type === 'application/json') {
const reader = new FileReader();
reader.onload = function (e) {
reader.onload = async function (e) {
const jsonContent = e.target.result;
try {
const parsedConfig = JSON.parse(jsonContent);
advancedFonts.applyImportedSettings(parsedConfig);
await advancedFonts.applyImportedSettings(parsedConfig);
window.location.reload();
} catch (error) {
console.error('Error parsing JSON:', error);
}
@@ -682,30 +683,34 @@ advancedFonts.applyImportedSettings = async function (config) {
}
if (isNumeric('defaultFontSize', config)) {
await chrome.fontSettings.setDefaultFontSize({
pixelSize: config.minimumFontSize
pixelSize: config.defaultFontSize
});
}
if (Array.isArray(config.configuredFonts)) {
config.configuredFonts.forEach(({ script, scriptData }) => {
if (Array.isArray(scriptData)) {
scriptData.forEach(async ({ fontId, genericFamily }) => {
if (isString(fontId, genericFamily, script)) {
try {
await chrome.fontSettings.setFont({
fontId,
genericFamily,
script
});
} catch (e) {
console.warn(
`Unable to set ${script},${fonId},${genericFamily}: ${e}`
);
}
}
});
}
});
await Promise.all(
config.configuredFonts.map(async ({ script, scriptData }) => {
if (Array.isArray(scriptData)) {
await Promise.all(
scriptData.map(async ({ fontId, genericFamily }) => {
if (isString(fontId, genericFamily, script)) {
try {
await chrome.fontSettings.setFont({
fontId,
genericFamily,
script
});
} catch (e) {
console.warn(
`Unable to set ${script},${fonId},${genericFamily}: ${e}`
);
}
}
})
);
}
})
);
} else if (typeof config.configuredFonts !== 'undefined') {
console.error(
`Invalid value for configuredFonts. It needs to be an array, recieved ${typeof config[