diff options
| author | EnricoGuccii <partyka.003@proton.me> | 2026-01-10 22:12:49 +0100 |
|---|---|---|
| committer | EnricoGuccii <partyka.003@proton.me> | 2026-01-10 22:12:49 +0100 |
| commit | c2f5fbe7fb93ce420caf23c5c0e06144cf953bb8 (patch) | |
| tree | c876d1edcc7873b122082c5ae7b3c218cd347226 /src/netmonitor/front/options_tab.py | |
| parent | 6a4d020146d6ed55c204e02ee90313a9f03a03b2 (diff) | |
yy
Diffstat (limited to 'src/netmonitor/front/options_tab.py')
| -rw-r--r-- | src/netmonitor/front/options_tab.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/netmonitor/front/options_tab.py b/src/netmonitor/front/options_tab.py new file mode 100644 index 0000000..6cbd448 --- /dev/null +++ b/src/netmonitor/front/options_tab.py @@ -0,0 +1,44 @@ +from textual.app import ComposeResult +from textual.containers import Container, Horizontal +from textual.widgets import Button, Input, Label +from textual import on + +from ..back.notification_service import notification_service + +class OptionsTab(Container): + def __init__(self, scanner_manager, detector_manager, *args, **kwargs): + super().__init__(*args, **kwargs) + self.scanner_manager = scanner_manager + self.detector_manager = detector_manager + + def compose(self) -> ComposeResult: + notify_section = Container(id="notify-section", classes="section-card") + notify_section.border_title = "Notification config" + with notify_section: + yield Label("Discord Webhook URL:") + yield Input(placeholder="https://discord.com/api/webhooks/...", id="input-webhook-url") + + with Horizontal(classes="modal-footer"): + yield Button("Save config", id="save-config", variant="success") + yield Button("notification test", id="test-notif", variant="primary") + + def on_mount(self): + self.query_one("#input-webhook-url", Input).value = notification_service.webhook_url + + @on(Button.Pressed, "#save-config") + def save_configuration(self): + url = self.query_one("#input-webhook-url", Input).value.strip() + + if notification_service.save_config(url): + self.app.notify("Config saved", severity="information") + else: + self.app.notify("Error during saving", severity="error") + + @on(Button.Pressed, "#test-notif") + def test_notification(self): + success = notification_service.send_message("**Test NetMonitor**\n") + + if success: + self.app.notify("good", severity="information") + else: + self.app.notify("bad", severity="error") |