super-stt-app/src/ui/views/models/add_sheet.rs
Line | Count | Source |
1 | | // SPDX-License-Identifier: GPL-3.0-only |
2 | | use cosmic::iced::{Alignment, Length}; |
3 | | use cosmic::iced_widget::{column, row}; |
4 | | use cosmic::widget::{self, button, text}; |
5 | | use cosmic::{Apply, Element}; |
6 | | |
7 | | use crate::core::app::AppModel; |
8 | | use crate::ui::icons; |
9 | | use crate::ui::messages::{Message, ModelsPageMessage}; |
10 | | |
11 | | use super::surface::muted_text_color; |
12 | | |
13 | | /// Right-side "Add a backend" sheet, rendered as a COSMIC context drawer. It |
14 | | /// holds the two manual install paths that used to crowd the top of the |
15 | | /// Download tab — install from a Git repository URL, or import a local |
16 | | /// directory. The drawer is scoped to the Models page and dismisses itself on |
17 | | /// navigation or daemon disconnect (enforced in `AppModel::context_drawer`). |
18 | 0 | pub fn add_backend_sheet(app: &AppModel) -> Element<'_, Message> { |
19 | 0 | let spacing = cosmic::theme::spacing(); |
20 | 0 | let muted = muted_text_color(); |
21 | | |
22 | | // From a repository: URL input + Install, with the unverified-source note. |
23 | 0 | let can_install = !app.registry.custom_repo_input.trim().is_empty(); |
24 | 0 | let install_btn = if can_install { |
25 | 0 | button::suggested("Install").on_press(Message::ModelsPage( |
26 | 0 | ModelsPageMessage::InstallBackendFromRepoUrl(app.registry.custom_repo_input.clone()), |
27 | 0 | )) |
28 | | } else { |
29 | 0 | button::suggested("Install") |
30 | | }; |
31 | 0 | let repo_section = column![ |
32 | 0 | text::title4("From a repository"), |
33 | 0 | text::body( |
34 | | "Paste a Git repository URL. Super STT resolves the latest release, \ |
35 | | verifies its manifest, and installs it." |
36 | | ) |
37 | 0 | .class(cosmic::theme::Text::Color(muted)), |
38 | 0 | row![ |
39 | 0 | widget::text_input( |
40 | | "https://github.com/owner/backend", |
41 | 0 | &app.registry.custom_repo_input |
42 | | ) |
43 | 0 | .on_input(|x| Message::ModelsPage(ModelsPageMessage::RegistryCustomRepoInputChanged(x))) |
44 | 0 | .width(Length::Fill), |
45 | 0 | install_btn, |
46 | | ] |
47 | 0 | .spacing(spacing.space_xs) |
48 | 0 | .align_y(Alignment::Center), |
49 | 0 | row![ |
50 | 0 | icons::phosphor_warning(icons::WARNING, 15.0), |
51 | 0 | text::caption("Unverified source — only HTTPS protects this download."), |
52 | | ] |
53 | 0 | .spacing(spacing.space_xs) |
54 | 0 | .align_y(Alignment::Center), |
55 | | ] |
56 | 0 | .spacing(spacing.space_s) |
57 | 0 | .apply(widget::container) |
58 | 0 | .class(cosmic::theme::Container::List) |
59 | 0 | .padding(spacing.space_m) |
60 | 0 | .width(Length::Fill); |
61 | | |
62 | | // From a folder: import a local backend directory. |
63 | 0 | let dir_section = column![ |
64 | 0 | text::title4("From a folder"), |
65 | 0 | text::body("Point Super STT at a local directory that contains a backend.toml manifest.") |
66 | 0 | .class(cosmic::theme::Text::Color(muted)), |
67 | 0 | button::standard("Choose folder\u{2026}") |
68 | 0 | .on_press(Message::ModelsPage(ModelsPageMessage::ImportBackendFromDir)), |
69 | | ] |
70 | 0 | .spacing(spacing.space_s) |
71 | 0 | .apply(widget::container) |
72 | 0 | .class(cosmic::theme::Container::List) |
73 | 0 | .padding(spacing.space_m) |
74 | 0 | .width(Length::Fill); |
75 | | |
76 | 0 | column![repo_section, dir_section] |
77 | 0 | .spacing(spacing.space_m) |
78 | 0 | .width(Length::Fill) |
79 | 0 | .into() |
80 | 0 | } |