summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/options/options.js12
-rw-r--r--src/popup/popup.js16
2 files changed, 28 insertions, 0 deletions
diff --git a/src/options/options.js b/src/options/options.js
index b4fc349..09d0a5f 100644
--- a/src/options/options.js
+++ b/src/options/options.js
@@ -102,6 +102,11 @@ function fillModels(models, selected) {
$model.append(option);
showStatus('保存済みモデルがOllama上に見つかりません。', true);
}
+ if (!selected && models.length > 0) {
+ // No model saved yet: explicitly select the first one so the UI value
+ // matches what will be saved (see popup fillModels note).
+ $model.selectedIndex = 0;
+ }
}
async function loadModels(selected) {
@@ -158,6 +163,13 @@ async function loadSettings() {
const settings = result.settings || defaultSettings();
applySettings(settings);
await loadModels(settings.model);
+ // If no model was saved yet and the list just loaded, sync the
+ // auto-selected first model into storage so it matches the UI.
+ if (!settings.model && $model.value) {
+ await browser.storage.local.set({
+ settings: sanitizeSettings({ ...settings, model: $model.value })
+ });
+ }
}
function readForm() {
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