forked from omer-faruq/assistant.koplugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassistant_settings.lua
More file actions
789 lines (747 loc) · 31.9 KB
/
Copy pathassistant_settings.lua
File metadata and controls
789 lines (747 loc) · 31.9 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
--[[--
This widget displays a setting dialog.
]]
local Trapper = require("ui/trapper")
local NetworkMgr = require("ui/network/manager")
local koutil = require("util")
local Blitbuffer = require("ffi/blitbuffer")
local CenterContainer = require("ui/widget/container/centercontainer")
local CheckButton = require("ui/widget/checkbutton")
local FrameContainer = require("ui/widget/container/framecontainer")
local Geom = require("ui/geometry")
local HorizontalGroup = require("ui/widget/horizontalgroup")
local HorizontalSpan = require("ui/widget/horizontalspan")
local InfoMessage = require("ui/widget/infomessage")
local Font = require("ui/font")
local InputDialog = require("ui/widget/inputdialog")
local LineWidget = require("ui/widget/linewidget")
local MovableContainer = require("ui/widget/container/movablecontainer")
local RadioButtonTable = require("ui/widget/radiobuttontable")
local TextBoxWidget = require("ui/widget/textboxwidget")
local SpinWidget = require("ui/widget/spinwidget")
local Notification = require("ui/widget/notification")
local Size = require("ui/size")
local UIManager = require("ui/uimanager")
local VerticalGroup = require("ui/widget/verticalgroup")
local VerticalSpan = require("ui/widget/verticalspan")
local ConfirmBox = require("ui/widget/confirmbox")
local _ = require("assistant_gettext")
local T = require("ffi/util").template
local Device = require("device")
local Screen = Device.screen
local ffiutil = require("ffi/util")
local meta = require("_meta")
local logger = require("logger")
local koutil = require("util")
local ToolExecutor = require("assistant_tool_executor")
local ExtTools = require("assistant_exttools")
local Updater = require("assistant_updater")
local ASUtils = require("assistant_utils")
local Registry = require("assistant_provider_registry")
local SearchRegistry = require("assistant_search_registry")
local Notebook = require("assistant_notebook")
-- Custom Widget: auto fill the empty field
local MultiInputDialog = require("ui/widget/multiinputdialog")
local CopyMultiInputDialog = MultiInputDialog:extend{}
function CopyMultiInputDialog:onSwitchFocus(inputbox)
MultiInputDialog.onSwitchFocus(self, inputbox)
local vidx = inputbox.idx == 1 and 2 or 1
local vval = self.input_fields[vidx]:getText()
-- copy value from the other field
if vval ~= "" and inputbox:getText() == "" then
inputbox:addChars(vval)
end
end
function CopyMultiInputDialog:init() -- fix the MultiInputDialog cannot move
MultiInputDialog.init(self)
local keyboard_height = self.keyboard_visible and self._input_widget:getKeyboardDimen().h or 0
self[1] = CenterContainer:new{
dimen = Geom:new{
w = Screen:getWidth(),
h = Screen:getHeight() - keyboard_height,
},
ignore_if_over = "height",
MovableContainer:new{ self.dialog_frame, },
}
end
function CopyMultiInputDialog:onTap(arg, ges) -- fix: tap outside to close
if ges.pos:notIntersectWith(self.dialog_frame.dimen) then
UIManager:close(self)
return true
end
return false
end
local function LanguageSetting(assistant, close_callback)
local langsetting
local chkbtn_is_rtl
langsetting = CopyMultiInputDialog:new{
description_margin = Size.margin.tiny,
description_padding = Size.padding.tiny,
title = _("AI Response Language Setting"),
fields = {
{
description = _("AI Response Language"),
text = assistant.settings:readSetting("response_language") or "",
hint = T(_("Leave blank to use: %1"), assistant.ui_language),
},
{
description = _("Dictionary Language"),
text = assistant.settings:readSetting("dict_language") or "",
hint = T(_("Leave blank to use: %1"), assistant.ui_language),
},
},
buttons = {
{
{
text = _("Cancel"),
id = "close",
callback = function()
UIManager:close(langsetting)
end
},
{
text = _("Clear"),
callback = function()
for i, f in ipairs(langsetting.input_fields) do
f:setText("")
end
if chkbtn_is_rtl then
chkbtn_is_rtl.checked = assistant.ui_language_is_rtl
chkbtn_is_rtl:init()
end
UIManager:setDirty(langsetting, function()
return "ui", langsetting.dialog_frame.dimen
end)
end
},
{
id = "save",
text = _("Save"),
callback = function()
local fields = langsetting:getFields()
for i, key in ipairs({"response_language", "dict_language"}) do
if fields[i] == "" then
assistant.settings:delSetting(key)
else
assistant.settings:saveSetting(key, fields[i])
end
end
if chkbtn_is_rtl then
local checked = chkbtn_is_rtl.checked
if checked ~= (assistant.settings:readSetting("response_is_rtl") or false) then
assistant.settings:saveSetting("response_is_rtl", checked)
end
end
assistant.updated = true
UIManager:close(langsetting)
if close_callback then
close_callback()
end
end
},
},
},
}
chkbtn_is_rtl = CheckButton:new{
text = _("RTL written Language"),
face = Font:getFace("xx_smallinfofont"),
checked = assistant.settings:readSetting("response_is_rtl") or assistant.ui_language_is_rtl,
parent = langsetting,
}
langsetting:addWidget(FrameContainer:new{
padding = Size.padding.default,
margin = Size.margin.small,
bordersize = 0,
chkbtn_is_rtl
})
if assistant.settings:has("dict_language") or
assistant.settings:has("response_language") then
-- show a notice when fields filled
langsetting:addWidget(FrameContainer:new{
padding = Size.padding.default,
margin = Size.margin.small,
bordersize = 0,
TextBoxWidget:new{
text = T(_("Leave these fields blank to use the UI language: %1"), assistant.ui_language),
face = Font:getFace("x_smallinfofont"),
width = math.floor(langsetting.width * 0.95),
}
})
end
UIManager:show(langsetting)
return langsetting
end
local SettingsDialog = InputDialog:extend{
title = _("Providers and Models"),
-- inited variables
assistant = nil, -- reference to the main assistant object
CONFIGURATION = nil,
settings = nil,
-- widgets
buttons = nil,
radio_buttons = nil,
}
function SettingsDialog:init()
self.title_bar_left_icon = "notice-info"
self.title_bar_left_icon_tap_callback = function ()
self.assistant:showAboutDialog()
end
-- action buttons
self.buttons = {{
{
id = "close",
text = _("Close"),
callback = function() UIManager:close(self) end
},
{
id = "select_model",
text = _("Browse Models"),
enabled_func = function ()
return self.assistant.querier.handler.can_fetch_models
end,
callback = function() self:onBrowseModel() end,
hold_callback = function ()
UIManager:show(InfoMessage:new{
alignment = "center",
text = _("Browse available models from the current provider")
})
end
},
{
id = "edit_provider",
text = _("Edit"),
enabled_func = function()
local cur = self.assistant.querier.provider_name
if not cur then return false end
local ps = koutil.tableGetValue(self.CONFIGURATION, "provider_settings", cur)
return Registry.is_editable(ps)
end,
callback = function() self:onEditProvider() end,
},
{
id = "delete_provider",
text = _("Delete"),
enabled_func = function()
local cur = self.assistant.querier.provider_name
if not cur then return false end
local ps = koutil.tableGetValue(self.CONFIGURATION, "provider_settings", cur)
return Registry.is_deletable(ps)
end,
callback = function() self:onDeleteProvider() end,
},
}}
table.insert(self.buttons[1], 3, {
id = "add_provider",
text = _("Add"),
callback = function()
UIManager:close(self)
UIManager:nextTick(function()
self.assistant:showAddProviderMenu()
end)
end,
})
-- init radio buttons for selecting AI Model provider
self.radio_buttons = {} -- init radio buttons table
local MAX_FOR_SINGLE_COLUMN = 12
-- 2 columns if more than MAX_FOR_SINGLE_COLUMN providers, otherwise 1 column
local columns = koutil.tableSize(self.CONFIGURATION.provider_settings) > MAX_FOR_SINGLE_COLUMN and 2 or 1
local buttonrow = {}
for key, tab in ffiutil.orderedPairs(self.CONFIGURATION.provider_settings) do
if self.assistant.querier:is_valid_provider(key, tab) then
if not (koutil.tableGetValue(tab, "visible") == false) then -- skip `visible = false` providers
if #buttonrow < columns then
local seleted_model = self.settings:readSetting("selected_model_" .. key)
local model_name = seleted_model or koutil.tableGetValue(tab, "model")
local display_name = koutil.tableGetValue(tab, "display_name") or key
local button_text = string.format("%s (%s)", display_name, model_name)
table.insert(buttonrow, {
text = button_text,
provider = key, -- note: this `provider` field belongs to the RadioButton, not our AI Model provider.
checked = (key == self.assistant.querier.provider_name),
})
end
if #buttonrow == columns then
table.insert(self.radio_buttons, buttonrow)
buttonrow = {}
end
end
end
end
if #buttonrow > 0 then -- edge case: if there are remaining buttons in the last row
table.insert(self.radio_buttons, buttonrow)
buttonrow = {}
end
-- init title and buttons in base class
InputDialog.init(self)
-- adds a close button to the top right
self.title_bar.close_callback = function() UIManager:close(self) end
self.title_bar:init()
self.element_width = math.floor(self.width * 0.9)
self.radio_button_table = RadioButtonTable:new{
radio_buttons = self.radio_buttons,
width = self.element_width,
face = Font:getFace("cfont", 18),
zero_sep = true,
sep_width = 0,
focused = true,
scroll = false,
parent = self,
button_select_callback = function(btn)
self.settings:saveSetting("provider", btn.provider)
self.assistant.updated = true
self.assistant.querier:load_model(btn.provider)
self:updateSelectModelButton()
end
}
self.layout = {self.layout[#self.layout]} -- keep bottom buttons
self:mergeLayoutInVertical(self.radio_button_table, #self.layout) -- before bottom buttons
-- main dialog widget layout table
self.vgroup = VerticalGroup:new{
align = "left",
self.title_bar, -- -- Title Bar
CenterContainer:new{ -- -- Provider radio buttons
dimen = Geom:new{
w = self.width,
h = self.radio_button_table:getSize().h,
},
self.radio_button_table,
},
CenterContainer:new{ -- -- Button at the bottom
dimen = Geom:new{
w = self.title_bar:getSize().w,
h = self.button_table:getSize().h,
},
self.button_table,
}
}
self.dialog_frame = FrameContainer:new{
radius = Size.radius.window,
bordersize = Size.border.window,
padding = 0,
margin = 0,
background = Blitbuffer.COLOR_WHITE,
self.vgroup,
}
self.movable = MovableContainer:new{
self.dialog_frame,
}
self[1] = CenterContainer:new{
dimen = Geom:new{
w = Screen:getWidth(),
h = Screen:getHeight(),
},
self.movable,
}
self:refocusWidget()
end
function SettingsDialog:updateSelectModelButton()
local btn = self.button_table:getButtonById("select_model")
if btn then
if self.assistant.querier.handler.can_fetch_models then
btn:enable()
else
btn:disable()
end
UIManager:setDirty(self, "ui")
end
end
function SettingsDialog:onBrowseModel()
UIManager:close(self)
-- final check
if not self.assistant.querier.handler.can_fetch_models then
return
end
NetworkMgr:runWhenOnline(function()
Trapper:wrap(function()
local showModelPicker = require("assistant_model_picker").showModelPicker
showModelPicker(self.assistant, self.close_callback)
end)
end)
end
function SettingsDialog:onDeleteProvider()
local provider_name = self.assistant.querier.provider_name
local ps = koutil.tableGetValue(self.CONFIGURATION, "provider_settings", provider_name)
if not Registry.is_deletable(ps) then return end
local display_name = koutil.tableGetValue(ps, "display_name") or provider_name
UIManager:show(ConfirmBox:new{
text = T(_("Delete provider %1?"), display_name),
ok_text = _("Delete"),
ok_callback = function()
local ui_data = self.assistant._ui_provider_data
Registry.delete(ui_data, provider_name)
Registry.save(self.settings, ui_data)
self.assistant.updated = true
-- Remove the provider from the in-memory merged config
if self.assistant.CONFIGURATION and self.assistant.CONFIGURATION.provider_settings then
self.assistant.CONFIGURATION.provider_settings[provider_name] = nil
end
-- Fallback: reselect a valid provider
local new_provider = self.assistant:getModelProvider()
if new_provider then
self.assistant.querier:load_model(new_provider)
end
-- Close and reopen settings
UIManager:close(self)
if self.assistant._settings_dialog then
UIManager:close(self.assistant._settings_dialog)
self.assistant._settings_dialog = nil
end
UIManager:scheduleIn(0.15, function()
self.assistant:showSettings()
end)
end,
})
end
function SettingsDialog:onEditProvider()
local provider_name = self.assistant.querier.provider_name
local ps = koutil.tableGetValue(self.CONFIGURATION, "provider_settings", provider_name)
if not Registry.is_editable(ps) then return end
UIManager:close(self)
UIManager:nextTick(function()
self.assistant:_showAddProviderDialog(nil, nil, nil, nil, provider_name)
end)
end
function SettingsDialog:onCloseWidget()
InputDialog.onCloseWidget(self)
if self.close_callback then
self.close_callback()
end
self.assistant._settings_dialog = nil
end
SettingsDialog.genWebSearchSubMenuItem = function(assistant, key)
return {
text = ToolExecutor.ToolToText(key),
radio = true,
checked_func = function ()
return assistant.settings:readSetting("use_websearch", "none") == key
end,
callback = function ()
local old_key = assistant.settings:readSetting("use_websearch", "none")
assistant.settings:saveSetting("use_websearch", key)
assistant.updated = true
-- Only rebuild highlight-menu buttons when crossing the None/Non-None
-- boundary: the 🌐 icon visibility depends solely on whether web
-- search is enabled at all, not on which specific tool is selected.
if (old_key == "none") ~= (key == "none") then
assistant:_rebuildShowOnMainButtons()
end
end,
enabled_func = function ()
if key == "none" then
return true
elseif key == "builtin" then
return koutil.tableGetValue(assistant, "querier", "handler", "has_builtin_websearch")
elseif ToolExecutor.IsExtSearch(key) then
return
(koutil.tableGetValue(assistant.CONFIGURATION, "provider_settings", key, "api_key") ~= nil) or
(koutil.tableGetValue(assistant.CONFIGURATION, "provider_settings", key, "base_url") ~= nil)
end
return false --
end,
hold_callback = function ()
if key == "builtin" then
local info = _("Builtin Tools Works ONLY with these models:\n- Gemini-2.5/3\n- OpenAI/gpt-4o-search\n")
UIManager:show(InfoMessage:new{ face = Font:getFace("smallinfofont"),
text = info
})
end
if ToolExecutor.IsExtSearch(key) then
Trapper:wrap(function()
local API = ExtTools[key]
local ok, info = API:AccoutInfo()
UIManager:show(InfoMessage:new{ face = Font:getFace("smallinfofont"),
text = info
})
if not ok then
logger.warn("info err", info)
end
end)
end
end
}
end
SettingsDialog.genMenuSettings = function(assistant)
local sub_item_table = {
{
text_func = function ()
return _("AI Language: ") ..
(assistant.settings:readSetting("response_language") or assistant.ui_language)
end,
callback = function (touchmenu_instance)
LanguageSetting(assistant, function ()
touchmenu_instance:updateItems()
end)
end,
keep_menu_open = true,
},
{
text_func = function ()
return T(_("AI Text Size: %1"), assistant.settings:readSetting("response_font_size") or 20)
end,
callback = function (touchmenu_instance)
local widget = SpinWidget:new{
title_text = _("AI Response Text Font Size"),
value = assistant.settings:readSetting("response_font_size") or 20,
value_min = 12, value_max = 30, default_value = 20,
callback = function(spin)
assistant.settings:saveSetting("response_font_size", spin.value)
assistant.updated = true
end,
close_callback = function ()
touchmenu_instance:updateItems()
end
}
UIManager:show(widget)
end,
keep_menu_open = true,
},
{
text = _("Response Settings"),
sub_item_table = {
{
text = _("Enable Stream Response"),
checked_func = function () return assistant.settings:readSetting("use_stream_mode", true) end,
callback = function ()
assistant.settings:toggle("use_stream_mode")
assistant.updated = true
end
},
{
text = _("Stream Text Auto Scroll"),
enabled_func = function () return assistant.settings:readSetting("use_stream_mode") end,
checked_func = function () return assistant.settings:readSetting("stream_mode_auto_scroll", true) end,
callback = function()
assistant.settings:toggle("stream_mode_auto_scroll")
assistant.updated = true
end
},
{
text = _("Large Streaming Window"),
enabled_func = function () return assistant.settings:readSetting("use_stream_mode") end,
checked_func = function () return assistant.settings:readSetting("large_stream_dialog", true) end,
callback = function()
assistant.settings:toggle("large_stream_dialog")
assistant.updated = true
end,
separator = true,
},
{
text = _("Show Reasoning Text"),
checked_func = function () return assistant.settings:readSetting("show_reasoning", false) end,
callback = function ()
assistant.settings:toggle("show_reasoning")
assistant.updated = true
end,
hold_callback = function ()
UIManager:show(InfoMessage:new{
text = _("Show deeply thought process (reasoning) from the AI response if exists.")
})
end
},
{
text = _("Show Follow-up Questions"),
checked_func = function () return assistant.settings:readSetting("auto_prompt_suggest", false) end,
callback = function()
assistant.settings:toggle("auto_prompt_suggest")
assistant.updated = true
end,
hold_callback = function ()
UIManager:show(InfoMessage:new{
text = _("Show follow up questions related to the response content.")
})
end
},
}
},
{
text = _("Notebook Settings"),
sub_item_table = {
{
text = _("Auto-save conversations to notebook"),
checked_func = function () return assistant.settings:readSetting("auto_save_to_notebook", false) end,
callback = function()
assistant.settings:toggle("auto_save_to_notebook")
assistant.updated = true
end
},
{
text = _("Multiple notebooks"),
checked_func = function ()
return assistant.settings:readSetting("use_multiple_general_notebooks", false)
end,
callback = function()
assistant.settings:toggle("use_multiple_general_notebooks")
assistant.updated = true
end,
hold_callback = function ()
UIManager:show(InfoMessage:new{
text = _("Choose which notebook your notes are saved to.")
})
end
},
{
text_func = function ()
local folder = Notebook.getFolder(assistant, false)
if folder then
return T(_("Notebooks folder: %1"), folder)
end
return _("Notebooks folder")
end,
callback = function (touchmenu_instance)
Notebook.showFolderPicker(assistant, {
on_select = function ()
touchmenu_instance:updateItems()
end,
})
end,
keep_menu_open = true,
},
},
},
{
-- @translators: functional overriding
text = _("KOReader Tweaks"),
sub_item_table = {
{
-- @translators: 'Translate' is a built-in function
text = _("Use AI Assistant for 'Translate'"),
checked_func = function () return assistant.settings:readSetting("ai_translate_override", false) end,
callback = function()
assistant.settings:toggle("ai_translate_override")
assistant.updated = true
UIManager:nextTick(function ()
assistant:syncTranslateOverride()
end)
end
},
{
text = _("Auto-recap on opening long-unread books"),
checked_func = function () return assistant.settings:readSetting("enable_auto_recap", false) end,
callback = function()
assistant.settings:toggle("enable_auto_recap")
assistant.updated = true
if not assistant.settings:readSetting("enable_auto_recap") then
-- if disable, remove the action from dispatcher
require("dispatcher"):removeAction("ai_recap")
return
end
Notification:notify(_("AI Recap will be enabled the next time a long-unread book is opened."), Notification.SOURCE_ALWAYS_SHOW)
end
},
{
text = _("Show Dictionary(AI) in Dictionary Popup"),
checked_func = function () return assistant.settings:readSetting("dict_popup_show_dictionary", true) end,
callback = function()
assistant.settings:toggle("dict_popup_show_dictionary")
assistant.updated = true
end
},
{
text = _("Show Wikipedia(AI) in Dictionary Popup"),
checked_func = function () return assistant.settings:readSetting("dict_popup_show_wikipedia", true) end,
callback = function()
assistant.settings:toggle("dict_popup_show_wikipedia")
assistant.updated = true
end
},
{
text = _("Show Term X-Ray(AI) in Dictionary Popup"),
checked_func = function () return assistant.settings:readSetting("dict_popup_show_term_xray", false) end,
callback = function()
assistant.settings:toggle("dict_popup_show_term_xray")
assistant.updated = true
end
},
{
text = _("Show Custom Prompts in Dictionary Popup"),
checked_func = function () return assistant.settings:readSetting("dict_popup_show_custom_prompts", false) end,
callback = function()
assistant.settings:toggle("dict_popup_show_custom_prompts")
assistant.updated = true
end
},
}
},
{
text = _("Copy entered question to the clipboard"),
checked_func = function () return assistant.settings:readSetting("auto_copy_asked_question", true) end,
callback = function()
assistant.settings:toggle("auto_copy_asked_question")
assistant.updated = true
end
},
{
text = _("Use book text for x-ray and recap"),
checked_func = function () return assistant.settings:readSetting("use_book_text_for_analysis", false) end,
callback = function()
assistant.settings:toggle("use_book_text_for_analysis")
assistant.updated = true
end
},
{
text = _("OTA Update"),
callback = function(touchmenu_instance)
local ota_github_base = koutil.tableGetValue(assistant.CONFIGURATION, "features", "ota_github_base")
or "https://github.com"
local ota_github_repo = koutil.tableGetValue(assistant.CONFIGURATION, "features", "ota_github_repo")
or "omer-faruq/assistant.koplugin"
local version_input
version_input = InputDialog:new{
title = T("%1 - %2 %3", _("OTA Update"), meta.fullname, meta.version),
input = "main",
input_hint = _("branch or tag name"),
description = ASUtils.bold_format(
T(_("Enter a branch or tag name to update the plugin from the source repository.\n\n<b>Github URL:</b> %1\n<b>Source Repo:</b> %2\n\nDefault: \"main\" (latest development branch)\nExamples: \"main\", \"v1.12\", \"v1.11\"\n\n<b>The configuration.lua will be preserved.</b>"),
ota_github_base, ota_github_repo)
),
buttons = {
-- The cancellation button should be kept on the left
-- and the button executing the action on the right.
{
{
text = _("Cancel"),
callback = function()
UIManager:close(version_input)
end,
},
{
text = _("Update"),
callback = function()
NetworkMgr:runWhenOnline(function()
local version = version_input:getInputText()
if version == "" then version = "main" end
UIManager:close(version_input)
touchmenu_instance:closeMenu()
Updater.otaUpgrade(assistant, version)
end)
end,
},
},
},
}
UIManager:show(version_input)
end,
keep_menu_open = true,
},
{
text = _("Purge the settings"),
callback = function()
UIManager:show(ConfirmBox:new{
text = _([[Purge assistant.koplugin settings?
This restores the plugin to its factory defaults. Only settings will be removed;
File configuration.lua will be preserved.]]),
ok_text = _("Purge"),
ok_callback = function()
assistant.settings:reset({})
assistant.settings:flush()
UIManager:askForRestart()
end
})
end
},
}
table.insert(sub_item_table, 1, Registry.getAddProviderMenuItem(assistant))
table.insert(sub_item_table, 2, SearchRegistry.getAddWebSearchMenuItem(assistant))
return sub_item_table
end
return SettingsDialog