1 local InputDialog
= require("ui/widget/inputdialog")
2 local Persist
= require("persist")
3 local DataStorage
= require("datastorage")
4 local UIManager
= require("ui/uimanager")
5 local KeyValuePage
= require("ui/widget/keyvaluepage")
6 local _
= require("gettext")
7 local T
= require("ffi/util").template
9 local gemini_dir
= DataStorage
:getDataDir() .. "/gemini"
10 local scheme_proxies_persist
= Persist
:new
{ path
= gemini_dir
.. "/scheme_proxies.lua" }
12 local SchemeProxies
= {
13 scheme_proxies
= scheme_proxies_persist
:load() or { gopher
= {}, ["http(s)"] = {} },
16 function SchemeProxies
:get(scheme
)
17 local proxy
= self
.scheme_proxies
[scheme
]
18 if proxy
and proxy
.host
then
21 if scheme
== "http" or scheme
== "https" then
22 return self
:get("http(s)")
26 function SchemeProxies
:supportedSchemes()
27 local schemes
= { "gemini", "about", "titan" }
28 for scheme
,proxy
in pairs(self
.scheme_proxies
) do
29 if proxy
and proxy
.host
then
30 if scheme
== "http(s)" then
31 table.insert(schemes
, "http")
32 table.insert(schemes
, "https")
34 table.insert(schemes
, scheme
)
41 local function basicInputDialog(title
, cb
, input
, is_secret
)
43 input_dialog
= InputDialog
:new
{
46 text_type
= is_secret
and "password",
54 UIManager
:close(input_dialog
)
67 function SchemeProxies
:edit()
70 for scheme
,proxy
in pairs(self
.scheme_proxies
) do
71 table.insert(kv_pairs
, { scheme
, proxy
.host
or "", callback
= function()
73 input_dialog
= basicInputDialog(
74 T(_("Set proxy server for %1 URLs"), scheme
),
76 local host
= input_dialog
:getInputText()
80 self
.scheme_proxies
[scheme
].host
= host
81 scheme_proxies_persist
:save(self
.scheme_proxies
)
82 UIManager
:close(input_dialog
)
87 UIManager
:show(input_dialog
)
88 input_dialog
:onShowKeyboard()
91 table.insert(kv_pairs
, { _("[New]"), _("Select to add new scheme"), callback
= function()
93 input_dialog
= basicInputDialog(_("Add new scheme to proxy"), function()
94 local scheme
= input_dialog
:getInputText()
95 UIManager
:close(input_dialog
)
97 self
.scheme_proxies
[scheme
] = {}
102 UIManager
:show(input_dialog
)
103 input_dialog
:onShowKeyboard()
105 menu
= KeyValuePage
:new
{
106 title
= _("Scheme proxies"),