summaryrefslogtreecommitdiff
path: root/src/popup
diff options
context:
space:
mode:
authortanaka takashi <isazaka@gmail.com>2026-09-01 20:57:29 +0900
committertanaka takashi <isazaka@gmail.com>2026-09-01 20:57:29 +0900
commit5ba53d7b64b181134b9c594fd9881ec626eae791 (patch)
tree7feba23bf8071119c3b081e7259dd40b6c8aee97 /src/popup
parent305c7479a589e7877074588b6467321f0a49cbdf (diff)
fix: model select showed a value that was never saved
Root cause of "設定値が不正です (モデルが設定されていません)" despite the settings UI showing a selected model: - fillModels(models, selected="") never set option.selected when no model was saved yet. The browser then auto-selects the first option visually, so the UI displayed e.g. "glm-5.3:cloud" while storage.model remained empty. Translation therefore failed with the no-model error until the user pressed Save, which materialized the UI value into storage. Fixes - popup.js/options.js fillModels: when no model is saved and the list is non-empty, explicitly select the first model so the UI value always matches what will be used - popup.js: after the model list loads, persist the auto-selected model if storage still has none - options.js loadSettings: same sync after loadModels, so opening the options page also heals the empty-model state Results: 73 passed, 0 failed. dist rebuilt.
Diffstat (limited to 'src/popup')
-rw-r--r--src/popup/popup.js16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/popup/popup.js b/src/popup/popup.js
index 612d0fd..eb213f5 100644
--- a/src/popup/popup.js
+++ b/src/popup/popup.js
@@ -46,6 +46,13 @@ function fillModels(models, selected) {
option.selected = true;
$model.append(option);
}
+ if (!selected && models.length > 0) {
+ // No model saved yet: explicitly select the first one so the UI value
+ // matches what will be used. Otherwise the browser auto-selects the
+ // first option visually while storage still has an empty model,
+ // which made translation fail until the user pressed Save.
+ $model.selectedIndex = 0;
+ }
}
function showStatus(message, isError) {
@@ -128,4 +135,13 @@ $openOptions.addEventListener('click', () => {
void (async () => {
await loadSettings();
await loadModels();
+ // If the model list loaded and no model is saved yet, persist the
+ // auto-selected first model so the stored settings match the UI.
+ if (knownModels.length > 0) {
+ const result = await browser.storage.local.get({ settings: null });
+ const stored = sanitizeSettings(result.settings || defaultSettings());
+ if (!stored.model) {
+ await persist({ model: $model.value });
+ }
+ }
})(); \ No newline at end of file