-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.html
More file actions
1263 lines (1078 loc) · 56.2 KB
/
settings.html
File metadata and controls
1263 lines (1078 loc) · 56.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>gengo 設定</title>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Bootstrap Icons -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css" rel="stylesheet">
<!-- i18next -->
<script src="https://unpkg.com/i18next/dist/umd/i18next.min.js"></script>
<script src="https://unpkg.com/i18next-http-backend/i18nextHttpBackend.min.js"></script>
<script src="i18n.js"></script>
<style>
body {
margin: 0;
padding: 0;
background: #f8f9fa;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
}
.full-container {
margin: 0;
padding: 0;
width: 100%;
height: 100vh;
box-sizing: border-box;
background: #f8f9fa;
overflow-y: auto;
}
/* スクロールバーのスタイリング(Webkit系ブラウザ用) */
.full-container::-webkit-scrollbar {
width: 8px;
}
.full-container::-webkit-scrollbar-track {
background: transparent;
}
.full-container::-webkit-scrollbar-thumb {
background: #cbd5e0;
border-radius: 4px;
}
.full-container::-webkit-scrollbar-thumb:hover {
background: #a0aec0;
}
/* ヘッダー */
.settings-header {
background: #ffffff;
color: #2d3748;
padding: 24px 32px;
border-bottom: 1px solid #e2e8f0;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
position: sticky;
top: 0;
z-index: 100;
}
.settings-header h5 {
margin: 0;
font-size: 1.5rem;
font-weight: 600;
}
.settings-header h5 i {
color: #667eea;
}
.settings-header .btn-light {
background: #f7fafc;
border: 1px solid #e2e8f0;
color: #4a5568;
transition: all 0.2s;
}
.settings-header .btn-light:hover {
background: #edf2f7;
color: #2d3748;
}
/* コンテンツエリア */
.settings-content {
padding: 32px;
max-width: 1000px;
margin: 0 auto;
}
/* セクション */
.settings-section {
background: white;
border-radius: 12px;
padding: 24px;
margin-bottom: 24px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
transition: box-shadow 0.2s;
}
.settings-section:hover {
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}
.settings-section h6 {
font-size: 1.1rem;
font-weight: 600;
color: #2d3748;
margin-bottom: 20px;
padding-bottom: 12px;
border-bottom: 2px solid #e2e8f0;
}
.settings-section h6 i {
color: #667eea;
margin-right: 8px;
}
/* フォーム要素 */
.form-label {
font-weight: 500;
color: #4a5568;
margin-bottom: 8px;
}
.form-control,
.form-select {
border-radius: 8px;
border: 1px solid #e2e8f0;
padding: 10px 14px;
transition: border-color 0.2s, box-shadow 0.2s;
}
.form-control:focus,
.form-select:focus {
border-color: #667eea;
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}
.form-text {
font-size: 0.875rem;
color: #718096;
}
/* プロンプトリスト */
.list-group-item {
border: 1px solid #e2e8f0;
border-radius: 8px !important;
margin-bottom: 12px;
padding: 20px;
background: #f7fafc;
transition: all 0.2s;
}
.list-group-item:hover {
background: white;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}
.preset-prompt-textarea {
font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
font-size: 0.9rem;
resize: vertical;
}
.preset-shortcut-input {
font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
font-weight: 600;
}
/* ボタン */
.btn {
border-radius: 8px;
padding: 10px 20px;
font-weight: 500;
transition: all 0.2s;
}
.btn-primary {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border: none;
}
.btn-primary:hover {
transform: translateY(-1px);
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}
.btn-outline-primary {
border-color: #667eea;
color: #667eea;
}
.btn-outline-primary:hover {
background: #667eea;
border-color: #667eea;
}
.btn-outline-danger:hover {
transform: scale(1.05);
}
.btn-success {
background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
border: none;
}
.btn-success:hover {
transform: translateY(-1px);
box-shadow: 0 4px 12px rgba(72, 187, 120, 0.4);
}
/* バッジ */
.badge {
padding: 6px 12px;
border-radius: 6px;
font-weight: 600;
font-size: 0.85rem;
}
/* アラート */
.alert {
border-radius: 8px;
border: none;
}
/* ボタングループ(下部) */
.button-group {
background: white;
padding: 20px 32px;
box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.08);
position: sticky;
bottom: 0;
z-index: 100;
}
.button-group .btn {
min-width: 120px;
}
/* プレースホルダー */
::placeholder {
color: #a0aec0;
opacity: 1;
}
/* チェックボックス */
.form-check-input:checked {
background-color: #667eea;
border-color: #667eea;
}
.form-check-input:focus {
border-color: #667eea;
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}
/* 追加ボタン */
#addPresetPromptBtn {
border: 2px dashed #cbd5e0;
background: transparent;
color: #667eea;
width: 100%;
padding: 12px;
transition: all 0.2s;
}
#addPresetPromptBtn:hover {
border-color: #667eea;
background: rgba(102, 126, 234, 0.05);
}
/* 削除ボタン */
.delete-preset-btn {
width: 36px;
height: 36px;
padding: 0;
display: flex;
align-items: center;
justify-content: center;
}
/* テストボタン */
#testLLMConnection {
display: flex;
align-items: center;
gap: 8px;
}
/* 接続テスト結果 */
#llmTestResult {
border-radius: 8px;
padding: 12px;
}
/* レスポンシブ調整 */
@media (max-width: 768px) {
.settings-content {
padding: 16px;
}
.settings-section {
padding: 16px;
}
.button-group {
padding: 16px;
}
}
</style>
</head>
<body>
<div class="full-container">
<!-- ヘッダー -->
<div class="settings-header">
<div class="d-flex justify-content-between align-items-center">
<h5 id="settings-title">
<i class="bi bi-gear-fill"></i> <span id="settingsTitle">設定</span>
</h5>
<button type="button" class="btn btn-light btn-sm" id="closeBtn">
<i class="bi bi-x-lg"></i>
</button>
</div>
</div>
<!-- コンテンツ -->
<div class="settings-content">
<!-- UI言語設定 -->
<div class="settings-section">
<h6>
<i class="bi bi-globe"></i> <span id="ui-language-title">UI言語</span>
</h6>
<div class="row">
<div class="col-md-6">
<label for="uiLanguage" class="form-label" id="ui-language-label">UI言語</label>
<select class="form-select" id="uiLanguage">
<option value="ja">日本語</option>
<option value="en">English</option>
</select>
</div>
</div>
</div>
<!-- プロンプト設定 -->
<div class="settings-section">
<h6 id="prompt-section-title">
<i class="bi bi-chat-left-text"></i> プロンプト設定
</h6>
<!-- 事前プロンプトリスト -->
<div class="mb-4">
<div class="d-flex justify-content-between align-items-center mb-3">
<label class="form-label mb-0" id="preset-prompts-label">事前プロンプト(最大5個)</label>
</div>
<small class="text-muted d-block mb-3" id="preset-prompts-description">
各事前プロンプトにショートカットキーを設定できます。
</small>
<!-- 事前プロンプトリストコンテナ -->
<div id="presetPromptsList" class="mb-3">
<!-- JavaScriptで動的に生成 -->
</div>
<button type="button" class="btn btn-outline-primary" id="addPresetPromptBtn">
<i class="bi bi-plus-circle"></i> <span id="add-preset-btn-text">事前プロンプトを追加</span>
</button>
</div>
<!-- オンデマンドプロンプト設定 -->
<div class="mb-3 mt-4 pt-4" style="border-top: 1px solid #e2e8f0;">
<label class="form-label" id="ondemand-prompt-label">
<i class="bi bi-lightning-fill text-warning"></i> オンデマンドプロンプト
</label>
<div class="mb-2">
<label class="form-label small" id="ondemand-shortcut-label">ショートカットキー</label>
<input type="text" class="form-control" id="onDemandShortcutKey" placeholder="例: Ctrl+Shift+1">
<small class="form-text text-muted" id="ondemand-shortcut-help">
使用可能なキー: Ctrl, Alt, Shift, Command (Mac), 英数字, F1-F12など
</small>
</div>
<small class="text-muted d-block" id="ondemand-prompt-description">
ショートカット実行時にプロンプト入力画面が表示されます。
</small>
</div>
</div>
<!-- LLMエンジン設定 -->
<div class="settings-section">
<h6 id="llm-settings-title">
<i class="bi bi-cpu"></i> LLMエンジン設定
</h6>
<!-- LLMプロバイダー選択 -->
<div class="mb-3">
<label for="llmProvider" class="form-label" id="llm-provider-label">LLMプロバイダー</label>
<select class="form-select" id="llmProvider">
<option value="local" id="llm-provider-local-option">ローカルLLM</option>
<option value="remote" id="llm-provider-remote-option">リモートLLM</option>
</select>
</div>
<!-- エンドポイントURL(共通) -->
<div class="mb-3">
<label for="llmEndpoint" class="form-label" id="llm-endpoint-label">APIエンドポイント</label>
<input type="text" class="form-control" id="llmEndpoint" placeholder="http://127.0.0.1:1234">
<small class="text-muted" id="llm-endpoint-description">
ベースURL(例: http://127.0.0.1:1234 または https://api.openai.com/v1)。プロバイダーに応じて必要なAPIパスは自動で追加されます
</small>
</div>
<!-- リモート接続用設定 -->
<div id="remoteSettings" style="display: none;">
<div class="mb-3">
<label for="apiKey" class="form-label" id="api-key-label">APIキー</label>
<input type="password" class="form-control" id="apiKey" placeholder="your-api-key-here">
<small class="text-muted" id="api-key-description">
リモートLLMサービスのAPIキー(ローカルに保存されます)
</small>
</div>
<div class="mb-3">
<label for="modelName" class="form-label" id="model-name-label">モデル名</label>
<input type="text" class="form-control" id="modelName" placeholder="gpt-4o-mini">
<small class="text-muted" id="model-name-description">
使用するモデル名(例: gpt-4o-mini, gpt-4, claude-3-5-sonnet-20241022)
</small>
</div>
</div>
<!-- ローカル接続用設定 -->
<div id="localSettings">
<div class="mb-3">
<label for="localModelInstanceId" class="form-label" id="local-model-label">ロード済みモデル</label>
<div class="d-flex gap-2">
<select class="form-select" id="localModelInstanceId">
<option value="" id="local-model-placeholder">ロード済みモデルを取得してください</option>
</select>
<button type="button" class="btn btn-outline-secondary" id="refreshLocalModels">
<i class="bi bi-arrow-repeat"></i>
</button>
</div>
<small class="text-muted" id="local-model-description">
LM Studioでロード済みのモデルを使用します。複数ある場合はここで選択できます。
</small>
<div class="mt-2" id="localModelStatus"></div>
</div>
</div>
<!-- 最大トークン数設定 -->
<div class="mb-3">
<label for="maxTokens" class="form-label" id="max-tokens-label">最大トークン数</label>
<input type="number" class="form-control" id="maxTokens" placeholder="4096" min="256" max="32768"
step="256">
<small class="text-muted" id="max-tokens-description">
LLMの応答に使用する最大トークン数(デフォルト: 4096)
</small>
</div>
<!-- LLM接続テストボタン -->
<div class="mb-3">
<button type="button" class="btn btn-outline-primary" id="testLLMConnection">
<i class="bi bi-wifi"></i> <span id="test-connection-text">接続テスト</span>
</button>
<div id="llmTestResult" class="mt-2"></div>
</div>
</div>
<!-- その他の設定 -->
<div class="settings-section">
<h6 id="other-settings-title">
<i class="bi bi-toggles"></i> その他の設定
</h6>
<div class="form-check">
<input class="form-check-input" type="checkbox" id="autoApplyAndClose">
<label class="form-check-label" for="autoApplyAndClose" id="auto-apply-and-close-label">
AI処理完了後に自動で結果を適用してウィンドウを閉じる
</label>
</div>
</div>
</div>
<!-- ボタングループ(下部固定) -->
<div class="button-group">
<div class="d-flex justify-content-between align-items-center">
<button type="button" class="btn btn-outline-danger" id="resetBtn">
<i class="bi bi-arrow-clockwise"></i> リセット
</button>
<div class="d-flex gap-2">
<button type="button" class="btn btn-secondary" id="cancelBtn">
<i class="bi bi-x-circle"></i> キャンセル
</button>
<button type="button" class="btn btn-success" id="saveBtn">
<i class="bi bi-check-circle"></i> 保存
</button>
</div>
</div>
</div>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
<!-- Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<script>
// プラットフォーム判定
const isMac = navigator.platform.toUpperCase().indexOf('MAC') >= 0;
const cmdKeyName = isMac ? 'Command' : 'Ctrl';
const shortcutExample = isMac ? 'Command+1, Command+Shift+A' : 'Ctrl+1, Ctrl+Shift+A';
// グローバル変数:翻訳テキスト
let translations = {
shortcutKeyLabel: 'ショートカットキー',
shortcutKeyHelp: `使用可能なキー: Ctrl, Alt, Shift, ${cmdKeyName} ${isMac ? '(Mac)' : ''}, 英数字, F1-F12など`.trim(),
promptLabel: 'プロンプト'
};
// 初期化
document.addEventListener('DOMContentLoaded', async () => {
// 翻訳を読み込み
await loadTranslations();
// 設定を読み込み
await loadSettings();
// イベントリスナー設定
document.getElementById('closeBtn').addEventListener('click', closeWindow);
document.getElementById('cancelBtn').addEventListener('click', closeWindow);
document.getElementById('saveBtn').addEventListener('click', saveSettings);
document.getElementById('resetBtn').addEventListener('click', resetSettings);
// UI言語変更イベント
document.getElementById('uiLanguage').addEventListener('change', async (e) => {
await changeUILanguage(e.target.value);
});
// 事前プロンプト追加ボタンイベント
document.getElementById('addPresetPromptBtn').addEventListener('click', addPresetPrompt);
// LLMプロバイダー変更イベント
document.getElementById('llmProvider').addEventListener('change', handleProviderChange);
document.getElementById('refreshLocalModels').addEventListener('click', async () => {
await loadLocalModels();
});
document.getElementById('llmEndpoint').addEventListener('blur', async () => {
if (document.getElementById('llmProvider').value === 'local') {
await loadLocalModels();
}
});
// LLM接続テストイベント
document.getElementById('testLLMConnection').addEventListener('click', testLLMConnection);
});
// 翻訳を読み込み
async function loadTranslations() {
try {
const currentLang = await window.electronAPI.getCurrentLanguage();
document.getElementById('uiLanguage').value = currentLang;
await updateUITexts();
await populateLanguageOptions();
} catch (error) {
console.error('翻訳読み込みエラー:', error);
}
}
// UI言語を変更
async function changeUILanguage(language) {
try {
const currentLang = await window.electronAPI.getCurrentLanguage();
// 言語が実際に変更された場合のみダイアログを表示
if (language !== currentLang) {
// 再起動ダイアログのメッセージを取得
const title = await window.electronAPI.getTranslation('settings.ui_language.restart_dialog.title');
const message = await window.electronAPI.getTranslation('settings.ui_language.restart_dialog.message');
// ダイアログで確認
if (confirm(`${title}\n\n${message}`)) {
// まず言語設定を保存
await window.electronAPI.changeLanguage(language);
// アプリケーションを再起動
await window.electronAPI.restartApp();
} else {
// キャンセルされた場合は元の言語に戻す
document.getElementById('uiLanguage').value = currentLang;
}
} else {
// 同じ言語の場合はUIを更新するだけ
await updateUITexts();
await populateLanguageOptions();
}
} catch (error) {
console.error('言語変更エラー:', error);
}
}
// UIテキストを更新
async function updateUITexts() {
try {
// ヘッダー
document.getElementById('settings-title').innerHTML =
'<i class="bi bi-gear"></i> ' + await window.electronAPI.getTranslation('settings.title');
// UI言語セクション
document.getElementById('ui-language-title').textContent =
await window.electronAPI.getTranslation('settings.ui_language.title') || 'UI言語';
document.getElementById('ui-language-label').textContent =
await window.electronAPI.getTranslation('settings.ui_language.label') || 'UI言語';
// プロンプト設定セクション
document.getElementById('prompt-section-title').innerHTML =
'<i class="bi bi-chat-left-text"></i> ' + await window.electronAPI.getTranslation('settings.prompt.title');
document.getElementById('preset-prompts-label').textContent =
await window.electronAPI.getTranslation('settings.prompt.preset_prompts_label') || '事前プロンプト(最大5個)';
document.getElementById('preset-prompts-description').textContent =
await window.electronAPI.getTranslation('settings.prompt.preset_prompts_description') || '各事前プロンプトにショートカットキーを設定できます。';
document.getElementById('addPresetPromptBtn').innerHTML =
'<i class="bi bi-plus-circle"></i> ' + (await window.electronAPI.getTranslation('settings.prompt.add_preset_button') || '事前プロンプトを追加');
// 翻訳テキストをグローバル変数に保存(動的生成で使用)
translations.shortcutKeyLabel = await window.electronAPI.getTranslation('settings.prompt.shortcut_key_label') || 'ショートカットキー';
translations.shortcutKeyHelp = await window.electronAPI.getTranslation('settings.prompt.shortcut_key_help') || '使用可能なキー: Ctrl, Alt, Shift, Command (Mac), 英数字, F1-F12など';
translations.promptLabel = await window.electronAPI.getTranslation('settings.prompt.prompt_label') || 'プロンプト';
// オンデマンドプロンプトセクション
document.getElementById('ondemand-prompt-label').textContent =
await window.electronAPI.getTranslation('settings.prompt.ondemand_label') || 'オンデマンドプロンプト';
document.getElementById('ondemand-shortcut-label').textContent =
await window.electronAPI.getTranslation('settings.prompt.shortcut_key_label') || 'ショートカットキー';
document.getElementById('ondemand-shortcut-help').textContent =
await window.electronAPI.getTranslation('settings.prompt.shortcut_key_help') || '使用可能なキー: Ctrl, Alt, Shift, Command (Mac), 英数字, F1-F12など';
document.getElementById('ondemand-prompt-description').textContent =
await window.electronAPI.getTranslation('settings.prompt.ondemand_description') || '選択したテキストに対して、毎回異なるプロンプトを入力できます。';
// LLMエンドポイント設定セクション
document.getElementById('llm-settings-title').innerHTML =
'<i class="bi bi-cpu"></i> ' + await window.electronAPI.getTranslation('settings.llm.title');
// LLMプロバイダー関連
document.getElementById('llm-provider-label').textContent =
await window.electronAPI.getTranslation('settings.llm.provider');
document.getElementById('llm-provider-local-option').textContent =
await window.electronAPI.getTranslation('settings.llm.provider_local');
document.getElementById('llm-provider-remote-option').textContent =
await window.electronAPI.getTranslation('settings.llm.provider_remote');
// エンドポイント関連
document.getElementById('llm-endpoint-label').textContent =
await window.electronAPI.getTranslation('settings.llm.endpoint');
document.getElementById('llm-endpoint-description').textContent =
await window.electronAPI.getTranslation('settings.llm.endpoint_description');
// APIキー関連
document.getElementById('api-key-label').textContent =
await window.electronAPI.getTranslation('settings.llm.api_key');
document.getElementById('api-key-description').textContent =
await window.electronAPI.getTranslation('settings.llm.api_key_description');
// モデル名関連
document.getElementById('model-name-label').textContent =
await window.electronAPI.getTranslation('settings.llm.model_name');
document.getElementById('model-name-description').textContent =
await window.electronAPI.getTranslation('settings.llm.model_name_description');
// ローカルモデル選択関連
document.getElementById('local-model-label').textContent =
await window.electronAPI.getTranslation('settings.llm.local_model') || 'ロード済みモデル';
document.getElementById('local-model-description').textContent =
await window.electronAPI.getTranslation('settings.llm.local_model_description') || 'LM Studioでロード済みのモデルを使用します。';
document.getElementById('local-model-placeholder').textContent =
await window.electronAPI.getTranslation('settings.llm.local_model_placeholder') || 'ロード済みモデルを取得してください';
document.getElementById('refreshLocalModels').innerHTML =
`<i class="bi bi-arrow-repeat"></i> ${await window.electronAPI.getTranslation('settings.llm.local_model_refresh') || '更新'}`;
// 最大トークン数関連
document.getElementById('max-tokens-label').textContent =
await window.electronAPI.getTranslation('settings.llm.max_tokens');
document.getElementById('max-tokens-description').textContent =
await window.electronAPI.getTranslation('settings.llm.max_tokens_description');
// 接続テスト
document.getElementById('test-connection-text').textContent =
await window.electronAPI.getTranslation('settings.llm.test_connection');
// その他設定セクション
document.getElementById('other-settings-title').innerHTML =
'<i class="bi bi-toggles"></i> ' + await window.electronAPI.getTranslation('settings.other.title');
document.getElementById('auto-apply-and-close-label').textContent =
await window.electronAPI.getTranslation('settings.other.auto_apply_and_close');
// ボタン
document.getElementById('saveBtn').innerHTML =
'<i class="bi bi-check"></i> ' + await window.electronAPI.getTranslation('settings.buttons.save');
document.getElementById('cancelBtn').textContent =
await window.electronAPI.getTranslation('settings.buttons.cancel');
document.getElementById('resetBtn').innerHTML =
'<i class="bi bi-arrow-clockwise"></i> ' + await window.electronAPI.getTranslation('settings.buttons.reset');
} catch (error) {
console.error('UIテキスト更新エラー:', error);
}
}
// 言語選択肢を動的に作成
async function populateLanguageOptions() {
try {
const languages = [
'ja', 'en', 'zh', 'ko', 'fr', 'de', 'es', 'it', 'pt', 'ru'
];
const language1Select = document.getElementById('language1');
const language2Select = document.getElementById('language2');
// 既存の選択肢をクリア
language1Select.innerHTML = '';
language2Select.innerHTML = '';
// 各言語の選択肢を作成
for (const langCode of languages) {
const langName = await window.electronAPI.getTranslation(`languages.${langCode}`);
console.log(`言語コード: ${langCode}, 取得した言語名: ${langName}`);
// Language1用のオプション
const option1 = document.createElement('option');
option1.value = langCode;
option1.textContent = langName;
language1Select.appendChild(option1);
// Language2用のオプション
const option2 = document.createElement('option');
option2.value = langCode;
option2.textContent = langName;
language2Select.appendChild(option2);
}
// 作成されたオプションを確認
console.log('Language1 オプション一覧:');
for (const option of language1Select.options) {
console.log(` value: ${option.value}, text: ${option.textContent}`);
}
console.log('Language2 オプション一覧:');
for (const option of language2Select.options) {
console.log(` value: ${option.value}, text: ${option.textContent}`);
}
} catch (error) {
console.error('言語選択肢作成エラー:', error);
}
}
// 設定読み込み
async function loadSettings() {
try {
const settings = await window.electronAPI.getSettings();
// 最初に言語選択肢を作成
await populateLanguageOptions();
// UI言語設定を含める
if (settings.language) {
document.getElementById('uiLanguage').value = settings.language || 'ja';
}
// 事前プロンプトリストを描画
renderPresetPrompts(settings.presetPrompts || []);
// オンデマンドプロンプトショートカットを設定
document.getElementById('onDemandShortcutKey').value = settings.onDemandShortcutKey || 'Ctrl+Shift+1';
// LLM設定
document.getElementById('llmProvider').value = settings.llmProvider || 'local';
document.getElementById('llmEndpoint').value = settings.llmEndpoint || 'http://127.0.0.1:1234';
if (settings.apiKey) {
document.getElementById('apiKey').value = settings.apiKey;
}
if (settings.modelName) {
document.getElementById('modelName').value = settings.modelName;
}
// 最大トークン数設定
document.getElementById('maxTokens').value = settings.maxTokens || 4096;
// プロバイダー設定に応じてUI表示を切り替え
await handleProviderChange();
if (settings.llmProvider === 'local') {
await loadLocalModels(settings.localModelInstanceId || '');
}
// 統合された自動適用・閉じる設定
document.getElementById('autoApplyAndClose').checked = settings.autoApplyAndClose || false;
} catch (error) {
console.error('設定読み込みエラー:', error);
}
}
// 事前プロンプトリストを描画
function renderPresetPrompts(presetPrompts) {
const container = document.getElementById('presetPromptsList');
container.innerHTML = '';
presetPrompts.forEach((preset, index) => {
const item = createPresetPromptItem(preset, index);
container.appendChild(item);
});
// 追加ボタンの表示/非表示を制御
const addBtn = document.getElementById('addPresetPromptBtn');
if (presetPrompts.length >= 5) {
addBtn.style.display = 'none';
} else {
addBtn.style.display = 'inline-block';
}
}
// 事前プロンプトアイテムを作成
function createPresetPromptItem(preset, index) {
const item = document.createElement('div');
item.className = 'list-group-item';
item.innerHTML = `
<div class="d-flex justify-content-between align-items-start mb-2">
<div class="flex-grow-1">
<div class="d-flex align-items-center gap-2 mb-2">
<strong>事前プロンプト ${index + 1}</strong>
</div>
<div class="mb-2">
<label class="form-label small">${translations.shortcutKeyLabel}</label>
<input type="text" class="form-control form-control-sm preset-shortcut-input"
data-index="${index}" value="${preset.shortcutKey}"
placeholder="例: ${shortcutExample}">
<small class="form-text text-muted">
${translations.shortcutKeyHelp}
</small>
</div>
<div>
<label class="form-label small">${translations.promptLabel}</label>
<textarea class="form-control preset-prompt-textarea" rows="3" data-index="${index}">${preset.prompt}</textarea>
</div>
</div>
${index > 0 ? `
<button type="button" class="btn btn-outline-danger btn-sm ms-2 delete-preset-btn" data-index="${index}">
<i class="bi bi-trash"></i>
</button>
` : ''}
</div>
`;
// 削除ボタンのイベントリスナー
const deleteBtn = item.querySelector('.delete-preset-btn');
if (deleteBtn) {
deleteBtn.addEventListener('click', () => deletePresetPrompt(index));
}
return item;
}
// 事前プロンプトを追加
async function addPresetPrompt() {
try {
const settings = await window.electronAPI.getSettings();
const presetPrompts = settings.presetPrompts || [];
if (presetPrompts.length >= 5) {
alert('事前プロンプトは最大5個までです。');
return;
}
// 次の空いているショートカットキーを見つける
const usedNumbers = presetPrompts.map(p => {
const match = p.shortcutKey.match(/Ctrl\+(\d)/);
return match ? parseInt(match[1]) : 0;
});
let nextNumber = 1;
for (let i = 1; i <= 5; i++) {
if (!usedNumbers.includes(i)) {
nextNumber = i;
break;
}
}
// 新しいプロンプトを追加
presetPrompts.push({
shortcutKey: `Ctrl+${nextNumber}`,
prompt: '',
enabled: true
});
renderPresetPrompts(presetPrompts);
} catch (error) {
console.error('プロンプト追加エラー:', error);
}
}
// 事前プロンプトを削除
async function deletePresetPrompt(index) {
if (!confirm('このプロンプトを削除しますか?')) {
return;
}
try {
const settings = await window.electronAPI.getSettings();
const presetPrompts = settings.presetPrompts || [];
// 配列から削除
presetPrompts.splice(index, 1);
renderPresetPrompts(presetPrompts);
} catch (error) {
console.error('プロンプト削除エラー:', error);
}
}
// 設定保存
async function saveSettings() {
try {
// 事前プロンプトを収集
const presetPrompts = [];
const textareas = document.querySelectorAll('.preset-prompt-textarea');
const shortcutInputs = document.querySelectorAll('.preset-shortcut-input');
// ショートカットキーの重複チェック用
const usedShortcuts = new Set();
textareas.forEach((textarea, index) => {
const shortcutInput = shortcutInputs[index];
const shortcutKey = shortcutInput ? shortcutInput.value.trim() : `Ctrl+${index + 1}`;
const prompt = textarea.value;
// ショートカットキーが空でないかチェック
if (!shortcutKey) {
throw new Error(`事前プロンプト ${index + 1} のショートカットキーを入力してください。`);
}
// 重複チェック
if (usedShortcuts.has(shortcutKey)) {
throw new Error(`ショートカットキー "${shortcutKey}" が重複しています。`);
}
usedShortcuts.add(shortcutKey);
presetPrompts.push({
shortcutKey: shortcutKey,
prompt: prompt,
enabled: true
});
});
// 最低1個の事前プロンプトは必須
if (presetPrompts.length === 0) {
alert('最低1個の事前プロンプトが必要です。');
return;
}
// オンデマンドプロンプトのショートカットキー
const onDemandShortcutKey = document.getElementById('onDemandShortcutKey').value.trim();
if (!onDemandShortcutKey) {
throw new Error('オンデマンドプロンプトのショートカットキーを入力してください。');
}
// オンデマンドショートカットが事前プロンプトと重複していないかチェック
if (usedShortcuts.has(onDemandShortcutKey)) {
throw new Error(`オンデマンドプロンプトのショートカットキー "${onDemandShortcutKey}" が事前プロンプトと重複しています。`);
}
const settings = {
autoApplyAndClose: document.getElementById('autoApplyAndClose').checked,
language: document.getElementById('uiLanguage').value,
presetPrompts: presetPrompts,
onDemandShortcutKey: onDemandShortcutKey,
llmProvider: document.getElementById('llmProvider').value,
llmEndpoint: document.getElementById('llmEndpoint').value,
apiKey: document.getElementById('apiKey').value,
modelName: document.getElementById('modelName').value,
localModelInstanceId: document.getElementById('localModelInstanceId').value,
maxTokens: parseInt(document.getElementById('maxTokens').value) || 4096
};
if (settings.llmProvider === 'local' && !settings.localModelInstanceId) {
const noModelMessage = await window.electronAPI.getTranslation('settings.llm.local_model_required')
|| 'ローカルLLMではロード済みモデルの選択が必要です。';
throw new Error(noModelMessage);
}
await window.electronAPI.saveSettings(settings);
// 保存完了メッセージ
const successMessage = await window.electronAPI.getTranslation('settings.messages.save_success');