// WXT provided cross-browser compatible API. import { browser } from "wxt/browser"; import { importFile, exportFile } from "@/assets/js/lib/SettingsFileManager"; import { isSettings } from "@/assets/js/lib/SettingsGuard"; import { safeAsync } from "@/assets/js/lib/safeAsync"; import { escapeHTML } from "@/assets/js/lib/escapeHTML"; import { findInvalidPattern, getRegExpError } from "@/assets/js/lib/regexp"; import { detectOs } from "@/assets/js/lib/detectOs"; import { detectBrowser } from "@/assets/js/lib/detectBrowser"; import { Information } from "@/assets/js/constants/app"; import { BROWSER_CHROME } from "@/assets/js/constants/browser"; import { OS_WIN, OS_LINUX, OS_MAC } from "@/assets/js/constants/os"; import { MOUSE_BUTTON_LEFT, MOUSE_BUTTON_RIGHT } from "@/assets/js/constants/mouseButton"; import { KEY_CODE_NONE, KEY_CODE_SHIFT, KEY_CODE_CTRL, KEY_CODE_ALT, KEY_CODE_META, KEY_CODE_DEFAULT_Z, ALPHA_KEYCODE_START, ALPHA_CHARCODE_LOWERCASE_START, ALPHA_KEY_COUNT } from "@/assets/js/constants/keyboard"; import { COUNTER_FONT_SIZE_DEFAULT, COUNTER_FONT_SIZE_MIN, COUNTER_FONT_SIZE_MAX, COUNTER_FONT_WEIGHT_DEFAULT, COUNTER_FONT_WEIGHT_MIN, COUNTER_FONT_WEIGHT_MAX, OPTIONS_TOOLTIP_LEFT_OFFSET_PX } from "@/assets/js/constants/ui"; import type { OsType } from "@/assets/js/types/OS"; import type { OptionsSchema } from "@/assets/js/types/Options"; import type { ActionOptionValue, ActionSetting, Settings } from "@/assets/js/types/Settings"; // jQuery import $ from "jquery"; import "@/assets/js/lib/colorpicker/jquery.colorpicker.js"; import "@/assets/js/lib/colorpicker/jquery.colorpicker.css"; import "./style.css"; /** * Static UI definition schema for the options page. * * Defines the structure of the options UI — available triggers, action types, * and option fields (labels, types, defaults, and descriptions). * This is a compile-time constant embedded in the source code and is * **not** a user settings value. * * @see {@link OptionsSchema} * @see {@link currentSettings} for the mutable user settings loaded from storage. */ const optionsSchema: OptionsSchema = { "triggers": [ { "name": "Left" }, { "name": "Middle" }, { "name": "Right" } ], "actions": { "win": { "name": "Opened in a New Window", "options": [ "fontsizeofcounter", "fontweightofcounter", "samebgcolorasbox", "smart", "ignore", "block", "reverse", "delay", "unfocus" ] }, "tabs": { "name": "Opened as New Tabs", "options": [ "fontsizeofcounter", "fontweightofcounter", "samebgcolorasbox", "smart", "ignore", "block", "reverse", "delay", "close", "end" ] }, "bm": { "name": "Bookmarked", "options": [ "fontsizeofcounter", "fontweightofcounter", "samebgcolorasbox", "smart", "ignore", "block", "reverse", "bookmarks" ] }, "copy": { "name": "Copied to clipboard", "options": [ "fontsizeofcounter", "fontweightofcounter", "samebgcolorasbox", "smart", "ignore", "block", "reverse", "copy" ] } }, "options": { "fontsizeofcounter": { "name": "counter font size", "type": "number", "data": [ COUNTER_FONT_SIZE_DEFAULT, COUNTER_FONT_SIZE_MIN, COUNTER_FONT_SIZE_MAX ], // [ default, min , max ] "extra": `font size of the counter (default: ${COUNTER_FONT_SIZE_DEFAULT}, range: ${COUNTER_FONT_SIZE_MIN}-${COUNTER_FONT_SIZE_MAX})` }, "fontweightofcounter": { "name": "counter font weight", "type": "number", "data": [ COUNTER_FONT_WEIGHT_DEFAULT, COUNTER_FONT_WEIGHT_MIN, COUNTER_FONT_WEIGHT_MAX ], // [ default, min , max ] "extra": `font weight of the counter (default: ${COUNTER_FONT_WEIGHT_DEFAULT}, range: ${COUNTER_FONT_WEIGHT_MIN}-${COUNTER_FONT_WEIGHT_MAX}, thin: 100, normal: 400, bold: 700)` }, "samebgcolorasbox": { "name": "bgcolor of the counter the same as the box", "type": "checkbox", "extra": "select whether to make the background color of the counter the same as the box color" }, "smart": { "name": "smart select", "type": "selection", "data": [ "on", "off" ], "extra": "with smart select turned on linkclump tries to select only the important links" }, "ignore": { "name": "filter links", "type": "selection-textbox", "data": [ "exclude links with words", "include links with words" ], "extra": "filter links that include/exclude these words; separate words with a comma ," }, "bookmarks": { "name": "select bookmarks", "type": "selection", "data": [ "Main", "Other bookmarks" ], "extra": "select the bookmarks you want to add, Main or Other bookmarks" }, "copy": { "name": "copy format", "type": "selection", "data": [ "URLS with titles", "URLS only", "URLS only space separated", "titles only", "as link HTML", "as list link HTML", "as Markdown" ], "extra": "format of the links saved to the clipboard" }, "delay": { "name": "delay in opening", "type": "textbox", "extra": "number of seconds between the opening of each link" }, "close": { "name": "close tab time", "type": "textbox", "extra": "number of seconds before closing opened tab (0 means the tab wouldn't close)" }, "block": { "name": "block repeat links in selection", "type": "checkbox", "extra": "select to block repeat links in selection" }, "reverse": { "name": "reverse order", "type": "checkbox", "extra": "select to process links in reverse order" }, "end": { "name": "open tabs at the end", "type": "checkbox", "extra": "select to have links opened at the end of all other tabs" }, "unfocus": { "name": "do not focus on new window", "type": "checkbox", "extra": "select to stop the new window from coming to the front" } } }; const colors: string[] = [ "458B74", "838B8B", "CCCCCC", "0000FF", "8A2BE2", "D2691E", "6495ED", "DC143C", "006400", "9400D3", "1E90FF", "228B22", "00FF00", "ADFF2F", "FF69B4", "4B0082", "F0E68C", "8B814C", "87CEFA", "32CD32", "000080", "FFA500", "FF4500", "DA70D6", "8B475D", "8B668B", "FF0000", "2E8B57", "8E388E", "FFFF00" ]; let currentSettings: Settings | null = null; const div_history: Record = {}; let keys: Record; let os: OsType; window.addEventListener("load", main); function main() { initValue(); initEvent(); } function initValue() { os = detectOs(); keys = displayKeys(MOUSE_BUTTON_LEFT); } function initEvent() { const isFirstTime = (window.location.href).indexOf("init=true") > -1; // temp check to not load if in test mode if (document.getElementById("guide2") === null) { return; } // until migrate to the Svelte UI, we need to update the store link for Firefox users. // This is because the link to the Browser Extension Store (Google Chrome / Firefox) is hardcoded in the HTML, and we want to ensure that it points to the correct store based on the user's browser. if (detectBrowser() !== BROWSER_CHROME) { const storeLink = document.getElementById("faq-store-link"); if (storeLink) { const { url } = Information.stores.firefox; storeLink.setAttribute("href", url); storeLink.setAttribute("title", url); } } document.getElementById("guide3")?.addEventListener("click", tour3); document.getElementById("guide2")?.addEventListener("click", tour2); document.getElementById("guide1")?.addEventListener("click", tour1); document.getElementById("add")?.addEventListener("click", load_new_action); document.getElementById("form_block")?.addEventListener("keyup", save_block); document.getElementById("form_key")?.addEventListener("change", check_selection); document.getElementById("cancel")?.addEventListener("click", close_form); document.getElementById("save")?.addEventListener("click", save_action); // TODO: Verification needed @2024/12/17 document.getElementById("import-setting")?.addEventListener("click", import_setting); document.getElementById("export-setting")?.addEventListener("click", export_setting); setup_form(); browser.runtime.sendMessage( { message: "init", debug: true } ).then((response: Settings) => { currentSettings = response; if (!currentSettings) { console.error("Failed to load settings: response is null or undefined."); return; } for (const i in currentSettings.actions) { const action = currentSettings.actions[i]; if (!action) { continue; } $("#settings").append(setup_action(action, i)); } setup_text(keys); $("#form_block").val((currentSettings.blocked || []).join("\n")); check_block(currentSettings.blocked || [], "Ignored:"); if (isFirstTime) { tour1(); } else { tour2(); } }).catch((error) => { console.error("Failed to initialize settings in options page:", error); }); } function close_form(event?: Event | JQuery.TriggeredEvent) { $("#form-background").fadeOut(); event?.preventDefault(); } function tour1() { setup_text(keys); $("#page2").fadeOut(0); $("#page1").fadeIn(); $("#test_area").focus(); } function tour2() { $("#page1").fadeOut(0); $("#page2").fadeIn(); } function tour3() { const store = detectBrowser() === BROWSER_CHROME ? Information.stores.chrome : Information.stores.firefox; safeAsync("openStoreReview", () => browser.tabs.create({ url: store.reviews, active: true }), "options"); } /** * * @param {string | null} id */ function load_action(id: string | null) { // into form if (id === null) { displayKeys(MOUSE_BUTTON_LEFT); displayOptions("tabs"); $("#form_id").val(""); $("#form_mouse").val(MOUSE_BUTTON_LEFT); // default to left mouse button $("#form_key").val(KEY_CODE_DEFAULT_Z); // and z key $(".colorpicker-trigger").css("background-color", `#${colors[Math.floor(Math.random() * colors.length)]}`); } else { const actionSetting = currentSettings?.actions[id]; if (!actionSetting) { return; } $("#form_id").val(id); $("#form_mouse").val(actionSetting.mouse); displayKeys(actionSetting.mouse); $("#form_key").val(actionSetting.key); $(".colorpicker-trigger").css("background-color", actionSetting.color); $(`#form_${actionSetting.action}`).attr("checked", "checked"); displayOptions(actionSetting.action); for (const i in actionSetting.options) { const optDef = optionsSchema.options[i]; if (!optDef) { continue; } const optVal = actionSetting.options[i]; switch (optDef.type) { case "number": case "selection": case "textbox": $(`#form_option_${i}`).val(String(optVal ?? "")); break; case "checkbox": $(`#form_option_${i}`).prop("checked", Boolean(optVal)); break; case "selection-textbox": if (Array.isArray(optVal) && optVal.length > 1) { const selection = optVal[0]; let text = ""; for (let k = 1; k < optVal.length; k++) { text += `${optVal[k]},`; } $(`#form_option_selection_${i}`).val(String(selection ?? "")); $(`#form_option_text_${i}`).val(text); } break; } } } // hide warning and let it show later if required $(".warning").hide(); $("#form_error").hide(); // place the form at the top of the window+10 $(".form").css("margin-top", ($(window).scrollTop() ?? 0) + 10); // fade in the form and set the background to cover the whole page $("#form-background").fadeIn(); $("#form-background").css("height", $(document).height() ?? 0); check_selection(); } /** * * @param {string} id * @param {JQuery} div */ function delete_action(id: string, div: JQuery) { if (!currentSettings) { return; } div.fadeOut("swing", function () { if (!currentSettings) { return; } const del = $("
Action has been deleted
"); const undo = $("undo").click({ "i": id, "param": currentSettings.actions[id] }, function (event) { if (!currentSettings) { return false; } const hist = div_history[event.data.i]; if (hist && event.data.param) { hist.replaceWith(setup_action(event.data.param, event.data.i)); } if (event.data.param) { currentSettings.actions[event.data.i] = event.data.param; } delete (div_history[event.data.i]); save_settings(); return false; } ); del.append(undo); $(this).replaceWith(del).fadeIn("swing"); div_history[id] = del; delete (currentSettings.actions[id]); save_settings(); }); } function setup_action(actionSetting: ActionSetting, id: string): JQuery { const setting = $(`
`); const actionDef = optionsSchema.actions[actionSetting.action]; const actionName = actionDef ? actionDef.name : actionSetting.action; const h3 = $("

").text(actionName); const triggerDef = optionsSchema.triggers[actionSetting.mouse]; const triggerName = triggerDef ? triggerDef.name : String(actionSetting.mouse); const activate = $("

").text("Activate by "); const keyName = actionSetting.key > 0 ? keys[actionSetting.key] : undefined; if (keyName) { activate.append(document.createTextNode('"')); activate.append($("").text(keyName)); activate.append(document.createTextNode('" key and ')); } activate.append(document.createTextNode('"')); activate.append($("").text(triggerName)); activate.append(document.createTextNode('" mouse button.')); setting.append(h3); setting.append(activate); const list = $("

    "); for (const j in actionSetting.options) { const op = optionsSchema.options[j]; if (!op) { continue; } const optVal = actionSetting.options[j]; let text = `${op.name}: `; switch (op.type) { case "number": { text += String(optVal ?? ""); break; } case "selection": { const idx = Number(optVal ?? 0); const dataVal = op.data ? op.data[idx] : ""; text += String(dataVal ?? ""); break; } case "textbox": { // TODO: not sure if actionSetting.options[j] returns a string or int if (optVal === "" || String(optVal) === "0") { continue; } text += String(optVal); break; } case "checkbox": { text += String(optVal); break; } case "selection-textbox": { if (!Array.isArray(optVal) || optVal.length < 2) { continue; } const selection = Number(optVal[0]); let words = ""; for (let i = 1; i < optVal.length; i++) { words += optVal[i]; if (i < optVal.length - 1) { words += ", "; } } const selText = op.data ? op.data[selection] : ""; text += `${selText ?? ""}; ${words}`; break; } } list.append($("
  • ").text(text)); } const colorItem = $("
  • ").text("selection box color: "); const colorSpan = $("").css("background-color", actionSetting.color); colorItem.append(colorSpan); list.append(colorItem); setting.append(list); const edit = $("").click({ "i": id }, function (event) { load_action(event.data.i); return false; } ); const del = $("").click({ "i": id }, function (event) { delete_action(event.data.i, $(this).parent()); return false; } ); setting.append(del); setting.append(edit); return setting; } function setup_form() { const mouse = $("#form_mouse"); for (let i = 0; i < optionsSchema.triggers.length; i++) { const trg = optionsSchema.triggers[i]; if (trg) { mouse.append(``); } } mouse.change(function () { const select = this as HTMLSelectElement; displayKeys(Number(select.value)); check_selection(); }); const color = $("#form_color"); for (const i in colors) { color.append(``); } color.colorpicker({ size: 30, hide: false }); const action = $("#form_action"); for (const i in optionsSchema.actions) { const actDef = optionsSchema.actions[i]; if (!actDef) { continue; } const act = $(`${actDef.name}
    `); act.click(function (event) { const target = event.currentTarget as HTMLInputElement; displayOptions(target.value); }); action.append(act); } $('input[value="tabs"]').attr("checked", "checked"); } function setup_text(keys: Record) { if (!currentSettings) { return; } let actionSetting: ActionSetting | undefined; for (const i in currentSettings.actions) { actionSetting = currentSettings.actions[i]; break; } if (actionSetting === undefined) { $("#guide_instruction").hide(); $("#guide_no_actions").show(); return; } $("#guide_no_actions").hide(); $("#guide_instruction").show(); const trigger = optionsSchema.triggers[actionSetting.mouse]; const actionDef = optionsSchema.actions[actionSetting.action]; if (trigger) { $("#mouse_name").text(trigger.name); } if (actionDef) { $("#action_name").text(actionDef.name); } const selectedKeyName = actionSetting.key > 0 ? keys[actionSetting.key] : undefined; if (selectedKeyName) { $("#key_name").html(`the ${escapeHTML(selectedKeyName)} key and`); } else { $("#key_name").html(""); } } function check_selection() { const m = $("#form_mouse").val(); const k = $("#form_key").val(); const id = $("#form_id").val(); const keyWarning = $("#key_warning"); keyWarning.empty(); if (k === "0") { keyWarning.append("WARNING: Not using a key could cause unexpected behavior on some websites"); if ($(".warning2").is(":hidden")) { $(".warning2").stop(true, true).fadeIn(); } } else { if (!$(".warning2").is(":hidden")) { $(".warning2").stop(true, true).fadeOut(); } } // Trackpad Palm Rejection / AAP Notice for Letter Keys (A-Z) const trackpadNotice = $("#trackpad_notice"); const keyNum = Number(k); const isLetterKey = keyNum >= ALPHA_KEYCODE_START && keyNum < ALPHA_KEYCODE_START + ALPHA_KEY_COUNT; if (isLetterKey && (os === OS_WIN || os === OS_LINUX)) { const modifierList = os === OS_WIN ? "Ctrl, Shift, or Alt" : "Ctrl or Shift"; const osName = os === OS_WIN ? "Windows" : "Linux"; trackpadNotice.text(`Note: On ${osName} laptops, pressing a letter key may temporarily disable the built-in trackpad. Use ${modifierList} instead if using a trackpad.`); if (trackpadNotice.is(":hidden")) { trackpadNotice.stop(true, true).slideDown(); } } else { if (!trackpadNotice.is(":hidden")) { trackpadNotice.stop(true, true).slideUp(); } } if (!currentSettings) { return; } for (const i in currentSettings.actions) { const act = currentSettings.actions[i]; if (!act) { continue; } // not sure if mouse/key are strings or ints if (i !== id && Number(act.mouse) === Number(m) && Number(act.key) === Number(k)) { if ($(".warning").is(":hidden")) { $(".warning").stop(true, true).fadeIn(); } return; } } if (!$(".warning").is(":hidden")) { $(".warning").stop(true, true).fadeOut(); } } function displayOptions(action: string) { const options = $("#form_options"); options.empty(); const actionDef = optionsSchema.actions[action]; if (!actionDef) { return; } for (const optKey of actionDef.options) { const op = optionsSchema.options[optKey]; if (!op) { continue; } const title = $(``); const p = $("

    "); p.append(title); switch (op.type) { case "number": { const def = op.data ? op.data[0] : 0; const min = op.data ? op.data[1] : 0; const max = op.data ? op.data[2] : 100; p.append(``); break; } case "selection": { const selector = $(``); break; } case "checkbox": { p.append(``); break; } case "selection-textbox": { const selector = $(``); break; } } const label = p.find("label").eq(0); label.mouseover({ "extra": op.extra }, function (event) { const extra = $("#form_extra"); extra.html(event.data.extra); extra.css("top", $(this).position().top); extra.css("left", $(this).position().left + OPTIONS_TOOLTIP_LEFT_OFFSET_PX); extra.show(); }).mouseout(function () { $("#form_extra").hide(); }); options.append(p); } } export function displayKeys(mouseButton: number, osOverride?: OsType): Record { const currentOs = osOverride ?? os; const key = $("#form_key"); key.empty(); const keys: Record = []; keys[KEY_CODE_SHIFT] = "shift"; keys[KEY_CODE_CTRL] = "ctrl"; if (currentOs !== OS_LINUX) { keys[KEY_CODE_ALT] = "alt"; } if (currentOs === OS_MAC) { keys[KEY_CODE_META] = "cmd"; } // if not left or windows then allow no key // NOTE mouseButton is sometimes a string, sometimes an int const mb = (typeof mouseButton === "string") ? Number.parseInt(mouseButton, 10) : mouseButton; if (mb !== MOUSE_BUTTON_RIGHT || currentOs === OS_WIN) { keys[KEY_CODE_NONE] = ""; } // add on alpha characters for (let i = 0; i < ALPHA_KEY_COUNT; i++) { keys[ALPHA_KEYCODE_START + i] = String.fromCharCode(ALPHA_CHARCODE_LOWERCASE_START + i); } for (const i in keys) { key.append(``); } // set selected value to z key.val(KEY_CODE_DEFAULT_Z); return keys; } function load_new_action(event: Event | JQuery.TriggeredEvent) { load_action(null); event.preventDefault(); } function save_action(event: Event | JQuery.TriggeredEvent) { if (!currentSettings) { return; } let id = String($("#form_id").val() ?? ""); const mouseVal = Number($("#form_mouse").val() ?? 0); const keyVal = Number($("#form_key").val() ?? 0); const colorVal = $(".colorpicker-trigger").css("background-color") || ""; const actionVal = String($("input[name=action]:radio:checked").val() ?? "tabs"); const actionOptions: Record = {}; const actionSetting: ActionSetting = { mouse: mouseVal, key: keyVal, color: colorVal, action: actionVal, options: actionOptions }; const actionDef = optionsSchema.actions[actionSetting.action]; if (actionDef) { for (const name of actionDef.options) { const op = optionsSchema.options[name]; if (!op) { continue; } if (op.type === "checkbox") { actionOptions[name] = $(`#form_option_${name}`).is(":checked"); } else if (name === "ignore") { const rawText = String($(`#form_option_text_${name}`).val() ?? ""); const ignore: (number | string)[] = rawText.replace(/^ */, "").replace(/, */g, ",").toLowerCase().split(","); // if the last entry is empty then just remove from array if (ignore.length > 0 && ignore[ignore.length - 1] === "") { ignore.pop(); } // the words are used as regular expressions, so refuse to save invalid ones const words = ignore.map(String); const invalidWord = findInvalidPattern(words); const combinedError = invalidWord === null && words.length > 0 ? getRegExpError(words.join("|")) : null; if (invalidWord !== null || combinedError !== null) { const detail = invalidWord !== null ? `"${invalidWord.pattern}" is not a valid regular expression: ${invalidWord.message}` : `the words cannot be combined into one regular expression: ${combinedError}`; $("#form_error").text(`Not saved: in "filter links", ${detail}`).show(); return; } const selVal = Number($(`#form_option_selection_${name}`).val() ?? 0); ignore.unshift(selVal); actionOptions[name] = ignore; } else if (name === "delay" || name === "close" || name === "copy") { let value = parseFloat(String($(`#form_option_${name}`).val() ?? "0")); if (isNaN(value)) { value = 0; } actionOptions[name] = value; } else if (op.type === "number") { let value = parseFloat(String($(`#form_option_${name}`).val() ?? "0")); const def = op.data ? Number(op.data[0]) : 0; const min = op.data ? Number(op.data[1]) : 0; const max = op.data ? Number(op.data[2]) : 100; if (!value || isNaN(value)) { value = def; } if (value < min || max < value) { value = def; } actionOptions[name] = value; } else { actionOptions[name] = String($(`#form_option_${name}`).val() ?? ""); } } } if (id === "" || !currentSettings.actions[id]) { const newDate = new Date(); id = String(newDate.getTime()); currentSettings.actions[id] = actionSetting; $("#settings").append(setup_action(actionSetting, id)); } else { currentSettings.actions[id] = actionSetting; const update = setup_action(actionSetting, id); $(`#action_${id}`).replaceWith(update); } save_settings(); close_form(event); } function save_settings() { if (!currentSettings) { return; } safeAsync( "saveSettings", () => browser.runtime.sendMessage({ message: "update", settings: currentSettings }), "options" ); } /** * Shows (or hides) the message about invalid regular expressions below the blocklist. * * @param {readonly string[]} sites - Lines of the blocklist. * @param {string} prefix - Text that starts the message, e.g. what happens to the list. * @returns {boolean} True if every pattern is valid. */ function check_block(sites: readonly string[], prefix: string): boolean { const invalid = findInvalidPattern(sites); if (invalid === null) { $("#block_error").hide().text(""); return true; } $("#block_error").text(`${prefix} "${invalid.pattern}" is not a valid regular expression: ${invalid.message}`).show(); return false; } /** * Splits raw blocklist input into trimmed, non-empty pattern lines. * * @param {string} rawSites - Multiline string from textarea. * @returns {string[]} Array of non-empty, trimmed pattern strings. */ export function parseBlocklist(rawSites: string): string[] { return rawSites .split("\n") .map((line) => line.trim()) .filter((line) => line.length > 0); } function save_block() { if (!currentSettings) { return; } const rawSites = String($("#form_block").val() ?? ""); const sites = parseBlocklist(rawSites); // every line is used as a regular expression; keep the previously saved list while an // invalid pattern is being typed if (!check_block(sites, "Not saved:")) { return; } if (Array.isArray(sites)) { currentSettings.blocked = sites; save_settings(); } } async function import_setting() { try { const result = await importFile(); // If the user cancels the file selection, result will be null if (result === null) { return; } if (isSettings(result)) { currentSettings = result; const obj = currentSettings.actions; $("#settings").empty(); for (const key in obj) { const act = obj[key]; if (!act) { continue; } $("#settings").append(setup_action(act, key)); } setup_text(keys); save_settings(); } else { console.error("Failed to import settings:", result); } } catch (error) { console.error("Failed to read settings file:", error); } } function export_setting() { if (currentSettings) { try { exportFile(currentSettings); } catch (error) { console.error("Failed to export settings file:", error); } } }