diff --git a/modules/ui.py b/modules/ui.py index b31059012..b5581a069 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -1918,24 +1918,38 @@ def create_ui(): def reload_javascript(): - with open(os.path.join(script_path, "script.js"), "r", encoding="utf8") as jsfile: - javascript = f'' - scripts_list = modules.scripts.list_scripts("javascript", ".js") - + js_files = [] for basedir, filename, path in scripts_list: - with open(path, "r", encoding="utf8") as jsfile: - javascript += f"\n" + path = path[len(script_path) + 1:] + js_files.append(path) + inline = [f"{localization.localization_js(shared.opts.localization)};"] if cmd_opts.theme is not None: - javascript += f"\n\n" + inline.append(f"set_theme('{cmd_opts.theme}');", ) - javascript += f"\n" + t = int(time.time()) + head = [ + f""" + + """.strip() + ] + inline_code = "\n".join(inline) + head.append(f""" + + """.strip()) + for file in js_files: + head.append(f""" + + """.strip()) def template_response(*args, **kwargs): res = shared.GradioTemplateResponseOriginal(*args, **kwargs) + head_inject = "\n".join(head) res.body = res.body.replace( - b'', f'{javascript}'.encode("utf8")) + b'', f'{head_inject}'.encode("utf8")) res.init_headers() return res