Skip to content

Commit 11898ee

Browse files
authored
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
1 parent 5f6f02b commit 11898ee

File tree

1 file changed

+27
-22
lines changed
  • api-samples/fontSettings/fontSettings Advanced

1 file changed

+27
-22
lines changed

api-samples/fontSettings/fontSettings Advanced/options.js

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -617,13 +617,14 @@ advancedFonts.importSettings = function () {
617617
if (selectedFile.type === 'application/json') {
618618
const reader = new FileReader();
619619

620-
reader.onload = function (e) {
620+
reader.onload = async function (e) {
621621
const jsonContent = e.target.result;
622622

623623
try {
624624
const parsedConfig = JSON.parse(jsonContent);
625625

626-
advancedFonts.applyImportedSettings(parsedConfig);
626+
await advancedFonts.applyImportedSettings(parsedConfig);
627+
window.location.reload();
627628
} catch (error) {
628629
console.error('Error parsing JSON:', error);
629630
}
@@ -682,30 +683,34 @@ advancedFonts.applyImportedSettings = async function (config) {
682683
}
683684
if (isNumeric('defaultFontSize', config)) {
684685
await chrome.fontSettings.setDefaultFontSize({
685-
pixelSize: config.minimumFontSize
686+
pixelSize: config.defaultFontSize
686687
});
687688
}
688689

689690
if (Array.isArray(config.configuredFonts)) {
690-
config.configuredFonts.forEach(({ script, scriptData }) => {
691-
if (Array.isArray(scriptData)) {
692-
scriptData.forEach(async ({ fontId, genericFamily }) => {
693-
if (isString(fontId, genericFamily, script)) {
694-
try {
695-
await chrome.fontSettings.setFont({
696-
fontId,
697-
genericFamily,
698-
script
699-
});
700-
} catch (e) {
701-
console.warn(
702-
`Unable to set ${script},${fonId},${genericFamily}: ${e}`
703-
);
704-
}
705-
}
706-
});
707-
}
708-
});
691+
await Promise.all(
692+
config.configuredFonts.map(async ({ script, scriptData }) => {
693+
if (Array.isArray(scriptData)) {
694+
await Promise.all(
695+
scriptData.map(async ({ fontId, genericFamily }) => {
696+
if (isString(fontId, genericFamily, script)) {
697+
try {
698+
await chrome.fontSettings.setFont({
699+
fontId,
700+
genericFamily,
701+
script
702+
});
703+
} catch (e) {
704+
console.warn(
705+
`Unable to set ${script},${fonId},${genericFamily}: ${e}`
706+
);
707+
}
708+
}
709+
})
710+
);
711+
}
712+
})
713+
);
709714
} else if (typeof config.configuredFonts !== 'undefined') {
710715
console.error(
711716
`Invalid value for configuredFonts. It needs to be an array, recieved ${typeof config[

0 commit comments

Comments
 (0)