Owner-corrected UX: the compact view keeps exactly TWO buttons — the
screen must serve fast. Upload moves from the advanced row to the
always-visible footer (with its uploaded-URL row un-gated so the link
shows in compact view too); level/search/refresh/auto-tail, the
diagnostics-bundle copy, open-file and clear stay behind [+]. Reverts
the open-expanded default from fe43c698.
cc
517 lines
23 KiB
Plaintext
517 lines
23 KiB
Plaintext
// In-app log viewer — the native replacement for the Tauri web console.
|
||
//
|
||
// Opened from Settings > Developer (or a hotkey). The Rust side owns a rolling
|
||
// ring of log records; it pushes an already-filtered + capped slice into
|
||
// LogViewerState.rows (with .total = ring size, .shown = after filter+cap) so
|
||
// this modal never holds the full history. All filtering/searching is delegated
|
||
// back to Rust via set-level / set-search — the level QbzSelect and the search
|
||
// field only emit; they never mutate the row model here.
|
||
//
|
||
// Layout mirrors QconnectDevModal: a dimmed full-window backdrop that closes on
|
||
// click, a centered card that swallows clicks, a header (title + shown/total +
|
||
// X), a controls row (level filter / search / refresh / auto-tail), a scrolling
|
||
// per-level-colored ListView body, and a footer button row (copy / bundle /
|
||
// upload / open file / clear). Mounted in AppShell in declaration order so its
|
||
// z-order is the mount order (ADR-009); conditional-mounted on .open (ADR-010).
|
||
|
||
import { Theme } from "../foundation/semantic-colors.slint";
|
||
import { Typography } from "../foundation/typography.slint";
|
||
import { Radius } from "../foundation/radius.slint";
|
||
import { LogViewerState, UiFocusState } from "../state.slint";
|
||
import { QbzIcon } from "../primitives/QbzIcon.slint";
|
||
import { QbzSelect } from "../primitives/QbzSelect.slint";
|
||
import { QbzToggle } from "../primitives/QbzToggle.slint";
|
||
import { ListView } from "std-widgets.slint";
|
||
|
||
// Small bordered icon+label control used by the controls row (Refresh) and the
|
||
// whole footer (Copy / Bundle / Upload / Open file / Clear). Auto-sizes to its
|
||
// label; `danger` recolors it for the destructive Clear action.
|
||
component IconTextButton inherits Rectangle {
|
||
in property <string> label;
|
||
in property <image> icon;
|
||
in property <bool> has-icon: true;
|
||
in property <bool> danger: false;
|
||
in property <bool> enabled: true;
|
||
callback clicked();
|
||
|
||
height: 32px;
|
||
border-radius: Radius.sm;
|
||
border-width: 1px;
|
||
border-color: Theme.border-subtle;
|
||
background: ta.has-hover && root.enabled ? Theme.surface-hover : Theme.surface-elevated;
|
||
opacity: root.enabled ? 1.0 : 0.4;
|
||
|
||
HorizontalLayout {
|
||
alignment: center;
|
||
padding-left: 12px;
|
||
padding-right: 12px;
|
||
spacing: 7px;
|
||
if root.has-icon: VerticalLayout {
|
||
alignment: center;
|
||
QbzIcon {
|
||
source: root.icon;
|
||
width: 14px;
|
||
height: 14px;
|
||
tint: root.danger ? Theme.danger : Theme.text-secondary;
|
||
}
|
||
}
|
||
Text {
|
||
text: root.label;
|
||
color: root.danger ? Theme.danger : Theme.text-secondary;
|
||
font-size: 13px;
|
||
font-weight: Typography.medium;
|
||
vertical-alignment: center;
|
||
}
|
||
}
|
||
|
||
ta := TouchArea {
|
||
mouse-cursor: root.enabled ? pointer : default;
|
||
clicked => {
|
||
if (root.enabled) {
|
||
root.clicked();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
export component LogViewerModal inherits Rectangle {
|
||
width: 100%;
|
||
height: 100%;
|
||
visible: LogViewerState.open;
|
||
// Advanced controls (level/search/refresh/auto-tail + bundle/open/clear)
|
||
// hide behind a discreet [+]: the default view must serve FAST — the log
|
||
// list plus exactly TWO buttons, Copy all and Upload (the whole point of
|
||
// reaching this through Settings > Share logs).
|
||
private property <bool> advanced-open: false;
|
||
|
||
if LogViewerState.open: Rectangle {
|
||
background: #000000bf;
|
||
// Snapshot the ring the MOMENT the viewer opens, so it always shows the
|
||
// current logs immediately — not an empty pane until Refresh/auto-tail.
|
||
init => {
|
||
LogViewerState.refresh();
|
||
}
|
||
TouchArea {
|
||
mouse-cursor: default;
|
||
clicked => {
|
||
LogViewerState.open = false;
|
||
}
|
||
}
|
||
|
||
Rectangle {
|
||
width: Math.min(root.width - 80px, 760px);
|
||
height: Math.min(root.height - 80px, 640px);
|
||
x: Math.round((parent.width - self.width) / 2 / 1px) * 1px;
|
||
y: Math.round((parent.height - self.height) / 2 / 1px) * 1px;
|
||
border-radius: Radius.md;
|
||
background: Theme.surface-card;
|
||
border-width: 1px;
|
||
border-color: Theme.border-subtle;
|
||
drop-shadow-blur: 32px;
|
||
drop-shadow-color: #00000080;
|
||
// Swallow clicks so they don't reach the closing backdrop.
|
||
TouchArea { }
|
||
|
||
VerticalLayout {
|
||
padding: 20px;
|
||
spacing: 14px;
|
||
|
||
// ---- Header: title + shown/total count + close X.
|
||
HorizontalLayout {
|
||
spacing: 10px;
|
||
Text {
|
||
text: @tr("Logs");
|
||
color: Theme.text-primary;
|
||
font-size: Typography.heading;
|
||
font-weight: Typography.semibold;
|
||
vertical-alignment: center;
|
||
}
|
||
VerticalLayout {
|
||
alignment: center;
|
||
horizontal-stretch: 1;
|
||
Text {
|
||
text: "\{LogViewerState.shown} / \{LogViewerState.total}";
|
||
color: Theme.text-muted;
|
||
font-size: Typography.legal;
|
||
vertical-alignment: center;
|
||
}
|
||
}
|
||
// Discreet [+] / [−] — reveals the advanced controls + actions.
|
||
adv-toggle := TouchArea {
|
||
width: 24px;
|
||
height: 24px;
|
||
mouse-cursor: pointer;
|
||
clicked => {
|
||
root.advanced-open = !root.advanced-open;
|
||
}
|
||
Text {
|
||
width: 100%;
|
||
height: 100%;
|
||
text: root.advanced-open ? "−" : "+";
|
||
color: adv-toggle.has-hover ? Theme.text-primary : Theme.text-muted;
|
||
font-size: 18px;
|
||
horizontal-alignment: center;
|
||
vertical-alignment: center;
|
||
}
|
||
}
|
||
close-x := TouchArea {
|
||
width: 28px;
|
||
height: 28px;
|
||
mouse-cursor: pointer;
|
||
clicked => {
|
||
LogViewerState.open = false;
|
||
}
|
||
QbzIcon {
|
||
source: @image-url("../assets/icons/x.svg");
|
||
width: 17px;
|
||
height: 17px;
|
||
x: Math.round((parent.width - self.width) / 2 / 1px) * 1px;
|
||
y: Math.round((parent.height - self.height) / 2 / 1px) * 1px;
|
||
tint: close-x.has-hover ? Theme.text-primary : Theme.text-muted;
|
||
}
|
||
}
|
||
}
|
||
|
||
// ---- Controls (advanced, behind [+]): level / search / refresh / auto-tail.
|
||
if root.advanced-open: HorizontalLayout {
|
||
height: 34px;
|
||
spacing: 10px;
|
||
|
||
// Level filter — index<->token mapping kept here so Rust only
|
||
// ever receives the canonical "all|error|warn|info|debug|trace".
|
||
VerticalLayout {
|
||
alignment: center;
|
||
QbzSelect {
|
||
menu-width: 132px;
|
||
options: [
|
||
@tr("All levels"),
|
||
@tr("Error"),
|
||
@tr("Warn"),
|
||
@tr("Info"),
|
||
@tr("Debug"),
|
||
@tr("Trace"),
|
||
];
|
||
current-index: LogViewerState.filter-level == "error" ? 1
|
||
: LogViewerState.filter-level == "warn" ? 2
|
||
: LogViewerState.filter-level == "info" ? 3
|
||
: LogViewerState.filter-level == "debug" ? 4
|
||
: LogViewerState.filter-level == "trace" ? 5
|
||
: 0;
|
||
selected(i) => {
|
||
LogViewerState.set-level(
|
||
i == 1 ? "error"
|
||
: i == 2 ? "warn"
|
||
: i == 3 ? "info"
|
||
: i == 4 ? "debug"
|
||
: i == 5 ? "trace"
|
||
: "all");
|
||
}
|
||
}
|
||
}
|
||
|
||
// Search box — emits set-search on every edit; Rust filters.
|
||
search-box := Rectangle {
|
||
horizontal-stretch: 1;
|
||
height: 34px;
|
||
border-radius: Radius.sm;
|
||
border-width: 1px;
|
||
border-color: search-input.has-focus ? Theme.focus-ring : Theme.border-subtle;
|
||
background: Theme.surface-elevated;
|
||
HorizontalLayout {
|
||
padding-left: 11px;
|
||
padding-right: 11px;
|
||
spacing: 8px;
|
||
VerticalLayout {
|
||
alignment: center;
|
||
QbzIcon {
|
||
source: @image-url("../assets/icons/search.svg");
|
||
width: 14px;
|
||
height: 14px;
|
||
tint: Theme.text-muted;
|
||
}
|
||
}
|
||
Rectangle {
|
||
horizontal-stretch: 1;
|
||
clip: true;
|
||
search-input := TextInput {
|
||
width: 100%;
|
||
height: 100%;
|
||
color: Theme.text-primary;
|
||
font-size: Typography.body;
|
||
vertical-alignment: center;
|
||
single-line: true;
|
||
text <=> LogViewerState.search;
|
||
changed has-focus => {
|
||
UiFocusState.text-input-focused = self.has-focus;
|
||
}
|
||
edited => {
|
||
LogViewerState.set-search(self.text);
|
||
}
|
||
}
|
||
Text {
|
||
visible: search-input.text == "";
|
||
width: 100%;
|
||
height: 100%;
|
||
text: @tr("Search logs…");
|
||
color: Theme.text-muted;
|
||
font-size: Typography.body;
|
||
vertical-alignment: center;
|
||
overflow: elide;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
VerticalLayout {
|
||
alignment: center;
|
||
IconTextButton {
|
||
label: @tr("Refresh");
|
||
icon: @image-url("../assets/icons/refresh-cw.svg");
|
||
clicked => {
|
||
LogViewerState.refresh();
|
||
}
|
||
}
|
||
}
|
||
|
||
// Auto-tail toggle (label + switch).
|
||
VerticalLayout {
|
||
alignment: center;
|
||
HorizontalLayout {
|
||
spacing: 8px;
|
||
Text {
|
||
text: @tr("Auto-tail");
|
||
color: Theme.text-secondary;
|
||
font-size: 13px;
|
||
vertical-alignment: center;
|
||
}
|
||
VerticalLayout {
|
||
alignment: center;
|
||
QbzToggle {
|
||
checked: LogViewerState.auto-tail;
|
||
toggled(v) => {
|
||
LogViewerState.toggle-auto-tail(v);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// ---- Column header (compact, muted).
|
||
HorizontalLayout {
|
||
padding-left: 12px;
|
||
padding-right: 12px;
|
||
spacing: 10px;
|
||
Text {
|
||
text: @tr("Time");
|
||
width: 80px;
|
||
color: Theme.text-muted;
|
||
font-size: Typography.legal;
|
||
font-weight: Typography.semibold;
|
||
}
|
||
Text {
|
||
text: @tr("Level");
|
||
width: 48px;
|
||
color: Theme.text-muted;
|
||
font-size: Typography.legal;
|
||
font-weight: Typography.semibold;
|
||
}
|
||
Text {
|
||
text: @tr("Target");
|
||
width: 140px;
|
||
color: Theme.text-muted;
|
||
font-size: Typography.legal;
|
||
font-weight: Typography.semibold;
|
||
}
|
||
Text {
|
||
text: @tr("Message");
|
||
horizontal-stretch: 1;
|
||
color: Theme.text-muted;
|
||
font-size: Typography.legal;
|
||
font-weight: Typography.semibold;
|
||
}
|
||
}
|
||
|
||
// ---- Body: per-level-colored, scrolling log rows.
|
||
Rectangle {
|
||
vertical-stretch: 1;
|
||
background: Theme.surface-main;
|
||
border-radius: Radius.sm;
|
||
border-width: 1px;
|
||
border-color: Theme.border-subtle;
|
||
clip: true;
|
||
|
||
ListView {
|
||
width: 100%;
|
||
height: 100%;
|
||
for row in LogViewerState.rows: Rectangle {
|
||
// Delegate height tracks the wrapped message so long
|
||
// lines aren't clipped (parent reads child preferred
|
||
// height — the supported, non-looping direction).
|
||
height: line.preferred-height;
|
||
line := HorizontalLayout {
|
||
padding-left: 12px;
|
||
padding-right: 12px;
|
||
padding-top: 3px;
|
||
padding-bottom: 3px;
|
||
spacing: 10px;
|
||
Text {
|
||
text: row.ts;
|
||
width: 80px;
|
||
color: Theme.text-muted;
|
||
font-size: 11px;
|
||
overflow: elide;
|
||
}
|
||
Text {
|
||
text: row.level;
|
||
width: 48px;
|
||
font-size: 11px;
|
||
font-weight: Typography.semibold;
|
||
color: row.level == "ERROR" ? #f44336
|
||
: row.level == "WARN" ? #e0a030
|
||
: (row.level == "DEBUG" || row.level == "TRACE") ? Theme.text-muted
|
||
: Theme.text-secondary;
|
||
}
|
||
Text {
|
||
text: row.target;
|
||
width: 140px;
|
||
color: Theme.text-muted;
|
||
font-size: 11px;
|
||
overflow: elide;
|
||
}
|
||
Text {
|
||
text: row.message;
|
||
horizontal-stretch: 1;
|
||
color: Theme.text-primary;
|
||
font-size: 11px;
|
||
wrap: word-wrap;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// Empty-state placeholder.
|
||
if LogViewerState.rows.length == 0: Text {
|
||
text: @tr("No log entries.");
|
||
color: Theme.text-muted;
|
||
font-size: Typography.body;
|
||
x: Math.round((parent.width - self.width) / 2 / 1px) * 1px;
|
||
y: Math.round((parent.height - self.height) / 2 / 1px) * 1px;
|
||
}
|
||
}
|
||
|
||
// ---- Uploaded URL — shown after upload, with a copy button.
|
||
// NOT gated on advanced: Upload lives in the footer now, so
|
||
// the resulting link must show in the compact view too.
|
||
if LogViewerState.uploaded-url != "": Rectangle {
|
||
height: 32px;
|
||
border-radius: Radius.sm;
|
||
border-width: 1px;
|
||
border-color: Theme.border-subtle;
|
||
background: Theme.surface-elevated;
|
||
HorizontalLayout {
|
||
padding-left: 11px;
|
||
padding-right: 4px;
|
||
spacing: 8px;
|
||
VerticalLayout {
|
||
alignment: center;
|
||
QbzIcon {
|
||
source: @image-url("../assets/icons/link.svg");
|
||
width: 14px;
|
||
height: 14px;
|
||
tint: Theme.accent;
|
||
}
|
||
}
|
||
Rectangle {
|
||
horizontal-stretch: 1;
|
||
clip: true;
|
||
url-input := TextInput {
|
||
width: 100%;
|
||
height: 100%;
|
||
read-only: true;
|
||
single-line: true;
|
||
color: Theme.text-secondary;
|
||
font-size: 12px;
|
||
vertical-alignment: center;
|
||
text: LogViewerState.uploaded-url;
|
||
changed has-focus => { UiFocusState.text-input-focused = self.has-focus; }
|
||
}
|
||
}
|
||
VerticalLayout {
|
||
alignment: center;
|
||
url-copy := TouchArea {
|
||
width: 26px;
|
||
height: 26px;
|
||
mouse-cursor: pointer;
|
||
clicked => {
|
||
LogViewerState.copy-url();
|
||
}
|
||
QbzIcon {
|
||
source: @image-url("../assets/icons/copy.svg");
|
||
width: 14px;
|
||
height: 14px;
|
||
x: Math.round((parent.width - self.width) / 2 / 1px) * 1px;
|
||
y: Math.round((parent.height - self.height) / 2 / 1px) * 1px;
|
||
tint: url-copy.has-hover ? Theme.text-primary : Theme.text-muted;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// ---- Advanced actions (behind [+]): bundle / open file / clear.
|
||
if root.advanced-open: HorizontalLayout {
|
||
spacing: 10px;
|
||
IconTextButton {
|
||
label: @tr("Copy diagnostics bundle");
|
||
icon: @image-url("../assets/icons/copy.svg");
|
||
clicked => {
|
||
LogViewerState.copy-bundle();
|
||
}
|
||
}
|
||
Rectangle { horizontal-stretch: 1; }
|
||
IconTextButton {
|
||
label: @tr("Open log file");
|
||
icon: @image-url("../assets/icons/external-link.svg");
|
||
clicked => {
|
||
LogViewerState.open-log-file();
|
||
}
|
||
}
|
||
IconTextButton {
|
||
label: @tr("Clear");
|
||
icon: @image-url("../assets/icons/trash-2.svg");
|
||
danger: true;
|
||
clicked => {
|
||
LogViewerState.clear();
|
||
}
|
||
}
|
||
}
|
||
|
||
// ---- Footer, always visible: Copy all + Upload — the two
|
||
// actions the modal exists for (share a log, fast).
|
||
HorizontalLayout {
|
||
spacing: 10px;
|
||
IconTextButton {
|
||
label: LogViewerState.copied ? @tr("Copied") : @tr("Copy all");
|
||
icon: LogViewerState.copied
|
||
? @image-url("../assets/icons/check.svg")
|
||
: @image-url("../assets/icons/copy.svg");
|
||
clicked => {
|
||
LogViewerState.copy-all();
|
||
}
|
||
}
|
||
IconTextButton {
|
||
label: LogViewerState.uploading ? @tr("Uploading…") : @tr("Upload (public)");
|
||
icon: @image-url("../assets/icons/cloud-upload.svg");
|
||
enabled: !LogViewerState.uploading;
|
||
clicked => {
|
||
LogViewerState.upload();
|
||
}
|
||
}
|
||
Rectangle { horizontal-stretch: 1; }
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|