feat(ui): UI 支持向局域网开放
This commit is contained in:
parent
68dbc487e8
commit
9b37bcf541
|
@ -461,16 +461,22 @@ class MiscConfig(ConfigBaseModel):
|
|||
check_update: Literal['never', 'startup'] = 'startup'
|
||||
"""
|
||||
检查更新时机。
|
||||
|
||||
|
||||
* never: 从不检查更新。
|
||||
* startup: 启动时检查更新。
|
||||
"""
|
||||
auto_install_update: bool = True
|
||||
"""
|
||||
是否自动安装更新。
|
||||
|
||||
|
||||
若启用,则每次自动检查更新时若有新版本会自动安装,否则只是会提示。
|
||||
"""
|
||||
expose_to_lan: bool = False
|
||||
"""
|
||||
是否允许局域网访问 Web 界面。
|
||||
|
||||
启用后,局域网内的其他设备可以通过本机 IP 地址访问 Web 界面。
|
||||
"""
|
||||
|
||||
class BaseConfig(ConfigBaseModel):
|
||||
purchase: PurchaseConfig = PurchaseConfig()
|
||||
|
|
|
@ -92,8 +92,8 @@ ConfigKey = Literal[
|
|||
'trace_recommend_card_detection',
|
||||
|
||||
# misc
|
||||
'check_update', 'auto_install_update',
|
||||
|
||||
'check_update', 'auto_install_update', 'expose_to_lan',
|
||||
|
||||
'_selected_backend_index'
|
||||
|
||||
]
|
||||
|
@ -1513,14 +1513,22 @@ class KotoneBotUI:
|
|||
info=MiscConfig.model_fields['auto_install_update'].description,
|
||||
interactive=True
|
||||
)
|
||||
|
||||
expose_to_lan = gr.Checkbox(
|
||||
label="允许局域网访问",
|
||||
value=self.current_config.options.misc.expose_to_lan,
|
||||
info=MiscConfig.model_fields['expose_to_lan'].description,
|
||||
interactive=True
|
||||
)
|
||||
|
||||
def set_config(config: BaseConfig, data: dict[ConfigKey, Any]) -> None:
|
||||
config.misc.check_update = data['check_update']
|
||||
config.misc.auto_install_update = data['auto_install_update']
|
||||
config.misc.expose_to_lan = data['expose_to_lan']
|
||||
|
||||
return set_config, {
|
||||
'check_update': check_update,
|
||||
'auto_install_update': auto_install_update
|
||||
'auto_install_update': auto_install_update,
|
||||
'expose_to_lan': expose_to_lan
|
||||
}
|
||||
|
||||
def _create_settings_tab(self) -> None:
|
||||
|
@ -1907,7 +1915,9 @@ def main(kaa: Kaa | None = None) -> None:
|
|||
kaa = kaa or Kaa('./config.json')
|
||||
ui = KotoneBotUI(kaa)
|
||||
app = ui.create_ui()
|
||||
app.launch(inbrowser=True, show_error=True)
|
||||
|
||||
server_name = "0.0.0.0" if ui.current_config.options.misc.expose_to_lan else "127.0.0.1"
|
||||
app.launch(inbrowser=True, show_error=True, server_name=server_name)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
Loading…
Reference in New Issue