VNOX-Client/src/ui/slint/connect.slint

144 lines
10 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { Theme, ActionButton } from "theme.slint";
export struct BookmarkItem { name: string, address: string }
export component ConnectScreen inherits Rectangle {
in-out property <[BookmarkItem]> bookmarks;
in-out property <string> address-input;
in-out property <string> status-text;
in-out property <bool> connecting;
in-out property <bool> auto-reconnect;
in-out property <string> node-name;
callback address-edited(string);
callback auto-reconnect-changed(bool);
callback connect(string);
callback disconnect();
callback remove-bookmark(string);
callback add-bookmark(string);
callback open-settings();
// 0 none, 1 first use, 2 certificate fingerprint changed, 3 server identity changed
in property <int> trust-kind: 0;
in property <string> trust-address;
in property <string> trust-received;
in property <string> trust-expected;
callback trust-accept();
callback trust-forget();
callback trust-dismiss();
background: Theme.bg-base;
VerticalLayout {
padding: 32px; spacing: 22px;
HorizontalLayout {
Image { source: @image-url("assets/vnox-mark.svg"); width: 32px; height: 32px; image-fit: contain; }
Text { text: "Vnox"; color: Theme.text-primary; font-size: Math.max(11px, Theme.font-size * 1.1875); font-weight: 700; }
Rectangle { horizontal-stretch: 1; }
ActionButton { text: @tr("Settings"); quiet: true; clicked => { root.open-settings(); } }
}
Rectangle { vertical-stretch: 1; }
HorizontalLayout {
Rectangle { horizontal-stretch: 1; }
Rectangle {
width: 540px;
height: card.preferred-height;
background: Theme.bg-surface; border-radius: 14px;
card := VerticalLayout {
padding: 28px; spacing: 15px; alignment: start;
Text { text: @tr("Connect to a server"); color: Theme.text-primary; font-size: Math.max(11px, Theme.font-size * 1.5); font-weight: 600; }
Text { text: @tr("Enter your server address or choose a saved server."); color: Theme.text-secondary; font-size: Math.max(11px, Theme.font-size * 0.8125); wrap: word-wrap; }
Text { text: @tr("Server address"); color: Theme.text-secondary; font-size: Math.max(11px, Theme.font-size * 0.75); }
HorizontalLayout {
spacing: 9px;
Rectangle {
height: 40px; background: Theme.bg-interactive; border-radius: 7px;
border-width: 1px; border-color: Theme.border;
HorizontalLayout {
padding: 10px;
TextInput {
text <=> root.address-input;
single-line: true; color: Theme.text-primary; font-size: Math.max(11px, Theme.font-size * 0.875);
edited => { root.address-edited(self.text); }
accepted => { if !root.connecting { root.connect(root.address-input); } }
}
}
}
if !root.connecting : ActionButton { text: @tr("Connect"); height: 40px; clicked => { root.connect(root.address-input); } }
if root.connecting : ActionButton { text: @tr("Cancel"); height: 40px; clicked => { root.disconnect(); } }
}
HorizontalLayout {
height: 30px;
ActionButton { text: root.auto-reconnect ? "✓" : "○"; width: 30px; height: 30px; quiet: true; clicked => { root.auto-reconnect = !root.auto-reconnect; root.auto-reconnect-changed(root.auto-reconnect); } }
Text { text: @tr("Reconnect automatically"); color: Theme.text-secondary; font-size: Math.max(11px, Theme.font-size * 0.75); vertical-alignment: center; }
Rectangle { horizontal-stretch: 1; }
}
if root.connecting : Text { text: @tr("Connecting…"); color: Theme.accent; font-size: Math.max(11px, Theme.font-size * 0.8125); }
if root.status-text != "" : Text { text: root.status-text; color: Theme.text-secondary; font-size: Math.max(11px, Theme.font-size * 0.8125); wrap: word-wrap; }
Rectangle { height: 1px; background: Theme.border; }
HorizontalLayout {
Text { text: @tr("Saved servers"); color: Theme.text-primary; font-size: Math.max(11px, Theme.font-size * 0.875); font-weight: 600; }
Rectangle { horizontal-stretch: 1; }
ActionButton { text: @tr("+ Save address"); quiet: true; clicked => { root.add-bookmark(root.address-input); } }
}
if root.bookmarks.length == 0 : Text { text: @tr("No saved servers yet."); color: Theme.text-muted; font-size: Math.max(11px, Theme.font-size * 0.75); }
for server in root.bookmarks: HorizontalLayout {
height: 48px; spacing: 8px;
VerticalLayout {
spacing: 2px; horizontal-stretch: 1;
Text { text: server.name; color: Theme.text-primary; font-size: Math.max(11px, Theme.font-size * 0.875); overflow: elide; }
Text { text: server.address; color: Theme.text-muted; font-size: Math.max(11px, Theme.font-size * 0.6875); overflow: elide; }
}
ActionButton { text: @tr("Join"); quiet: true; clicked => { if !root.connecting { root.connect(server.address); } } }
ActionButton { text: "×"; width: 28px; quiet: true; clicked => { root.remove-bookmark(server.address); } }
}
}
}
Rectangle { horizontal-stretch: 1; }
}
Rectangle { vertical-stretch: 1; }
Text { text: @tr("Your server. Your community."); color: Theme.text-disabled; font-size: Math.max(11px, Theme.font-size * 0.75); horizontal-alignment: center; }
}
if root.trust-kind != 0 : Rectangle {
background: #000000a0;
TouchArea { }
HorizontalLayout {
Rectangle { horizontal-stretch: 1; }
VerticalLayout {
Rectangle { vertical-stretch: 1; }
Rectangle {
width: 560px;
height: trust-card.preferred-height;
background: Theme.bg-surface; border-radius: 14px;
border-width: 1px; border-color: root.trust-kind == 1 ? Theme.border : Theme.danger;
trust-card := VerticalLayout {
padding: 26px; spacing: 12px; alignment: start;
Text {
text: root.trust-kind == 1 ? @tr("Trust this server?") : root.trust-kind == 2 ? @tr("Server fingerprint changed") : @tr("Server identity changed");
color: root.trust-kind == 1 ? Theme.text-primary : Theme.danger;
font-size: Math.max(11px, Theme.font-size * 1.375); font-weight: 600; wrap: word-wrap;
}
Text {
text: root.trust-kind == 1
? @tr("This is the first connection to this server. Its certificate is not issued by a public authority, so Vnox cannot verify it automatically. Compare the fingerprint with the one published by the server owner and trust it only if they match.")
: root.trust-kind == 2
? @tr("The certificate of this server is different from the one you trusted before. This can mean an attack on your connection, or the owner reinstalled the server. The connection was blocked and nothing was sent. Ask the owner whether the change is expected.")
: @tr("The server proved a different identity key than the one you trusted before. The connection was blocked and nothing was sent. Ask the owner whether the change is expected.");
color: Theme.text-secondary; font-size: Math.max(11px, Theme.font-size * 0.8125); wrap: word-wrap;
}
Text { text: @tr("Server address"); color: Theme.text-muted; font-size: Math.max(11px, Theme.font-size * 0.75); }
Text { text: root.trust-address; color: Theme.text-primary; font-size: Math.max(11px, Theme.font-size * 0.875); wrap: word-wrap; }
if root.trust-kind != 1 : Text { text: @tr("Previously trusted fingerprint"); color: Theme.text-muted; font-size: Math.max(11px, Theme.font-size * 0.75); }
if root.trust-kind != 1 : Text { text: root.trust-expected; color: Theme.text-primary; font-size: Math.max(11px, Theme.font-size * 0.75); wrap: word-wrap; }
Text { text: root.trust-kind == 1 ? @tr("Fingerprint (SHA-256)") : @tr("Received fingerprint"); color: Theme.text-muted; font-size: Math.max(11px, Theme.font-size * 0.75); }
Text { text: root.trust-received; color: root.trust-kind == 1 ? Theme.accent : Theme.danger; font-size: Math.max(11px, Theme.font-size * 0.75); wrap: word-wrap; }
HorizontalLayout {
spacing: 9px; alignment: end;
if root.trust-kind != 1 : ActionButton { text: @tr("Forget this server"); danger: true; clicked => { root.trust-forget(); } }
ActionButton { text: root.trust-kind == 1 ? @tr("Cancel") : @tr("Close"); clicked => { root.trust-dismiss(); } }
if root.trust-kind == 1 : ActionButton { text: @tr("Trust and connect"); active: true; clicked => { root.trust-accept(); } }
}
}
}
Rectangle { vertical-stretch: 1; }
}
Rectangle { horizontal-stretch: 1; }
}
}
}