1
0
mirror of https://github.com/0O0o0oOoO00/Alas.git synced 2026-05-14 13:09:25 +08:00

add: add instance watcher support

This commit is contained in:
0O0o0oOoO00
2025-09-13 14:41:52 +08:00
parent 8d7f718285
commit 17482d44e1
2 changed files with 202 additions and 0 deletions

View File

@@ -1525,3 +1525,119 @@ def app():
)
return app
from module.instance_watcher import InstanceWatcher
class AlasGUI(AlasGUI):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.instance_watcher = InstanceWatcher.get_instance()
def on_start_on(self):
self.instance_watcher.remove_instance(self.alas.config_name)
self.alas.stop()
def on_start_off(self):
self.alas.start(None, updater.event)
self.instance_watcher.try_add_instance(self.alas.config_name)
@use_scope("content", clear=True)
def alas_overview(self) -> None:
self.init_menu(name="Overview")
self.set_title(t(f"Gui.MenuAlas.Overview"))
put_scope("overview", [put_scope("schedulers"), put_scope("logs")])
with use_scope("schedulers"):
put_scope(
"scheduler-bar",
[
put_text(t("Gui.Overview.Scheduler")).style(
"font-size: 1.25rem; margin: auto .5rem auto;"
),
put_scope("scheduler_btn"),
],
)
put_scope(
"running",
[
put_text(t("Gui.Overview.Running")),
put_html('<hr class="hr-group">'),
put_scope("running_tasks"),
],
)
put_scope(
"pending",
[
put_text(t("Gui.Overview.Pending")),
put_html('<hr class="hr-group">'),
put_scope("pending_tasks"),
],
)
put_scope(
"waiting",
[
put_text(t("Gui.Overview.Waiting")),
put_html('<hr class="hr-group">'),
put_scope("waiting_tasks"),
],
)
switch_scheduler = BinarySwitchButton(
label_on=t("Gui.Button.Stop"),
label_off=t("Gui.Button.Start"),
onclick_on=self.on_start_on,
onclick_off=self.on_start_off,
get_state=lambda: self.alas.alive,
color_on="off",
color_off="on",
scope="scheduler_btn",
)
log = RichLog("log")
with use_scope("logs"):
put_scope(
"log-bar",
[
put_text(t("Gui.Overview.Log")).style(
"font-size: 1.25rem; margin: auto .5rem auto;"
),
put_scope(
"log-bar-btns",
[
put_scope("log_scroll_btn"),
],
),
],
)
put_scope("log", [put_html("")])
log.console.width = log.get_width()
switch_log_scroll = BinarySwitchButton(
label_on=t("Gui.Button.ScrollON"),
label_off=t("Gui.Button.ScrollOFF"),
onclick_on=lambda: log.set_scroll(False),
onclick_off=lambda: log.set_scroll(True),
get_state=lambda: log.keep_bottom,
color_on="on",
color_off="off",
scope="log_scroll_btn",
)
self.task_handler.add(switch_scheduler.g(), 1, True)
self.task_handler.add(switch_log_scroll.g(), 1, True)
self.task_handler.add(self.alas_update_overview_task, 10, True)
self.task_handler.add(log.put_log(self.alas), 0.25, True)
old_app = app
def app():
ret = old_app()
InstanceWatcher.get_instance().start()
return ret