S020: welcome flow, task manager, about, clear data, site settings, source, devtools, error pages, dialogs, bars; row layout fix; PROGRESS, INDEX
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
parent
9edec66dee
commit
500c4f0ed4
24 changed files with 1138 additions and 470 deletions
|
|
@ -12,12 +12,12 @@ Apply the design system to the remaining internal pages and all dialogs, with de
|
|||
- each page file as you redo it
|
||||
|
||||
## Steps
|
||||
- [ ] History and bookmarks pages (lists, search, folders, empty states)
|
||||
- [ ] Downloads page and passwords/vault page (lock state, entries, empty state)
|
||||
- [ ] Apps, devtools and misc pages
|
||||
- [ ] Dialogs: alert/confirm/prompt, HTTP sign-in, select, colour, permissions, leave page — M3 dialog shape and motion
|
||||
- [ ] Smoke shots of every page and dialog, light/dark; check by eye; stores and basics smoke scripts still pass
|
||||
- [ ] PROGRESS entry, INDEX line, commit `S020: …` and push
|
||||
- [x] History and bookmarks pages (lists, search, folders, empty states)
|
||||
- [x] Downloads page and passwords/vault page (lock state, entries, empty state)
|
||||
- [x] Apps, devtools and misc pages
|
||||
- [x] Dialogs: alert/confirm/prompt, HTTP sign-in, select, colour, permissions, leave page — M3 dialog shape and motion
|
||||
- [x] Smoke shots of every page and dialog, light/dark; check by eye; stores and basics smoke scripts still pass
|
||||
- [x] PROGRESS entry, INDEX line, commit `S020: …` and push
|
||||
|
||||
## End criteria
|
||||
- Basics and stores smoke scripts green.
|
||||
|
|
|
|||
|
|
@ -30,5 +30,5 @@ Tracker: https://claude.ai/artifact/9AD7fPfwJ4ASFzVTJGKU4h
|
|||
- [x] [S017 — New tab page: elements](04%20UI%20redesign/S017-ntp-elements.md) · Opus medium
|
||||
- [x] [S018 — New tab page: backgrounds and Customize](04%20UI%20redesign/S018-ntp-backgrounds.md) · Opus medium
|
||||
- [x] [S019 — Settings pages redesign](04%20UI%20redesign/S019-ui-settings.md) · Opus medium
|
||||
- [ ] [S020 — Other pages and dialogs redesign](04%20UI%20redesign/S020-ui-pages.md) · Sonnet high
|
||||
- [x] [S020 — Other pages and dialogs redesign](04%20UI%20redesign/S020-ui-pages.md) · Sonnet high
|
||||
- [ ] [S021 — Phase 4 review with the user](04%20UI%20redesign/S021-phase4-review.md) · Sonnet medium · 🧑
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -4,21 +4,31 @@
|
|||
<meta charset="utf-8">
|
||||
<title>Connection not secure</title>
|
||||
<style>
|
||||
:root { color-scheme: light dark; font-family: system-ui, sans-serif; }
|
||||
body { max-width: 560px; margin: 12vh auto; padding: 0 24px; line-height: 1.5; }
|
||||
h1 { font-size: 1.5em; font-weight: 600; }
|
||||
#bytes { display: none; }
|
||||
button { font: inherit; padding: 6px 16px; margin-right: 8px; }
|
||||
:root { font-family: system-ui, sans-serif; --bg: #fdfbff; --text: #1a1b1f; --muted: #44474e; --card: #f1f0f4; --primary: #415f91; --on-primary: #ffffff; --tonal: #d6e3ff; --on-tonal: #001b3e; --error: #ffdad6; --on-error: #410002; --line: #c4c6d0; }
|
||||
@media (prefers-color-scheme: dark) { :root { --bg: #101114; --text: #e3e2e6; --muted: #c4c6d0; --card: #1d1e22; --primary: #aac7ff; --on-primary: #0a305f; --tonal: #284777; --on-tonal: #d6e3ff; --error: #93000a; --on-error: #ffdad6; --line: #44474e; } }
|
||||
html { background: var(--bg); color: var(--text); }
|
||||
body { max-width: 520px; margin: 14vh auto; padding: 0 24px; line-height: 1.5; text-align: center; background: var(--bg); color: var(--text); }
|
||||
.mark { width: 72px; height: 72px; margin: 0 auto 20px; border-radius: 50%; background: var(--error); color: var(--on-error); font-size: 34px; font-weight: 600; line-height: 72px; }
|
||||
h1 { font-size: 1.75em; font-weight: 600; margin: 0 0 8px; }
|
||||
p { margin: 8px 0; color: var(--muted); }
|
||||
p.url { word-break: break-all; color: var(--text); }
|
||||
code, pre { font-family: ui-monospace, monospace; word-break: break-all; }
|
||||
.detail { font-size: 0.85em; }
|
||||
.actions { margin-top: 28px; }
|
||||
button { font: inherit; font-weight: 600; height: 40px; padding: 0 24px; margin: 0 4px; border-radius: 20px; border: 1px solid var(--line); background: transparent; color: var(--primary); cursor: pointer; }
|
||||
button.main { border-color: transparent; background: var(--primary); color: var(--on-primary); }
|
||||
button:hover { filter: brightness(1.08); }
|
||||
details { margin-top: 20px; text-align: left; color: var(--muted); }
|
||||
details pre { white-space: pre-wrap; font-size: 12px; background: var(--card); padding: 12px; border-radius: 12px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="mark">!</div>
|
||||
<h1>Connection not secure</h1>
|
||||
<p>This site's certificate can't be trusted, so someone could be reading or changing what you send.
|
||||
It's safest to go back.</p>
|
||||
<p><small>Details: <code>${reason}</code></small></p>
|
||||
<button id="leave" onclick="history.back()">Go back</button>
|
||||
<button id="allow">Open anyway for now</button>
|
||||
<div id="bytes">${bytes}</div>
|
||||
<p>This site's certificate can't be trusted, so someone could be reading or changing what you send. It's safest to go back.</p>
|
||||
<p class="detail">Details: <code>${reason}</code></p>
|
||||
<div class="actions"><button class="main" id="leave" onclick="history.back()">Go back</button><button id="allow">Open anyway for now</button></div>
|
||||
<div id="bytes" style="display:none">${bytes}</div>
|
||||
<script>
|
||||
let bytes = document.getElementById('bytes').textContent;
|
||||
let button = document.getElementById('allow');
|
||||
|
|
|
|||
|
|
@ -4,18 +4,29 @@
|
|||
<meta charset="utf-8">
|
||||
<title>This page crashed</title>
|
||||
<style>
|
||||
:root { color-scheme: light dark; font-family: system-ui, sans-serif; }
|
||||
body { max-width: 640px; margin: 12vh auto; padding: 0 24px; line-height: 1.5; }
|
||||
h1 { font-size: 1.5em; font-weight: 600; }
|
||||
details pre { white-space: pre-wrap; font-size: 12px; }
|
||||
button { font: inherit; padding: 6px 16px; }
|
||||
:root { font-family: system-ui, sans-serif; --bg: #fdfbff; --text: #1a1b1f; --muted: #44474e; --card: #f1f0f4; --primary: #415f91; --on-primary: #ffffff; --tonal: #d6e3ff; --on-tonal: #001b3e; --error: #ffdad6; --on-error: #410002; --line: #c4c6d0; }
|
||||
@media (prefers-color-scheme: dark) { :root { --bg: #101114; --text: #e3e2e6; --muted: #c4c6d0; --card: #1d1e22; --primary: #aac7ff; --on-primary: #0a305f; --tonal: #284777; --on-tonal: #d6e3ff; --error: #93000a; --on-error: #ffdad6; --line: #44474e; } }
|
||||
html { background: var(--bg); color: var(--text); }
|
||||
body { max-width: 600px; margin: 14vh auto; padding: 0 24px; line-height: 1.5; text-align: center; background: var(--bg); color: var(--text); }
|
||||
.mark { width: 72px; height: 72px; margin: 0 auto 20px; border-radius: 50%; background: var(--error); color: var(--on-error); font-size: 34px; font-weight: 600; line-height: 72px; }
|
||||
h1 { font-size: 1.75em; font-weight: 600; margin: 0 0 8px; }
|
||||
p { margin: 8px 0; color: var(--muted); }
|
||||
p.url { word-break: break-all; color: var(--text); }
|
||||
code, pre { font-family: ui-monospace, monospace; word-break: break-all; }
|
||||
.detail { font-size: 0.85em; }
|
||||
.actions { margin-top: 28px; }
|
||||
button { font: inherit; font-weight: 600; height: 40px; padding: 0 24px; margin: 0 4px; border-radius: 20px; border: 1px solid var(--line); background: transparent; color: var(--primary); cursor: pointer; }
|
||||
button.main { border-color: transparent; background: var(--primary); color: var(--on-primary); }
|
||||
button:hover { filter: brightness(1.08); }
|
||||
details { margin-top: 20px; text-align: left; color: var(--muted); }
|
||||
details pre { white-space: pre-wrap; font-size: 12px; background: var(--card); padding: 12px; border-radius: 12px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="mark">!</div>
|
||||
<h1>This page crashed</h1>
|
||||
<p>Something on the page broke the engine. Reloading usually fixes it. The details are also written to pages.log
|
||||
in Nacre's data folder.</p>
|
||||
<p>Something on the page broke the engine. Reloading usually fixes it. The details are also written to pages.log in Nacre's data folder.</p>
|
||||
<!-- Reloading turns a POST into a GET; see whatwg/html#6600. -->
|
||||
<button onclick="location.reload()">Reload</button>
|
||||
<div class="actions"><button class="main" onclick="location.reload()">Reload</button></div>
|
||||
<details><summary>Details</summary><pre><plaintext>
|
||||
${details}
|
||||
|
|
|
|||
|
|
@ -4,21 +4,31 @@
|
|||
<meta charset="utf-8">
|
||||
<title>Couldn't open this page</title>
|
||||
<style>
|
||||
:root { color-scheme: light dark; font-family: system-ui, sans-serif; }
|
||||
body { max-width: 560px; margin: 12vh auto; padding: 0 24px; line-height: 1.5; }
|
||||
h1 { font-size: 1.5em; font-weight: 600; }
|
||||
code { word-break: break-all; }
|
||||
button { font: inherit; padding: 6px 16px; margin-right: 8px; }
|
||||
:root { font-family: system-ui, sans-serif; --bg: #fdfbff; --text: #1a1b1f; --muted: #44474e; --card: #f1f0f4; --primary: #415f91; --on-primary: #ffffff; --tonal: #d6e3ff; --on-tonal: #001b3e; --error: #ffdad6; --on-error: #410002; --line: #c4c6d0; }
|
||||
@media (prefers-color-scheme: dark) { :root { --bg: #101114; --text: #e3e2e6; --muted: #c4c6d0; --card: #1d1e22; --primary: #aac7ff; --on-primary: #0a305f; --tonal: #284777; --on-tonal: #d6e3ff; --error: #93000a; --on-error: #ffdad6; --line: #44474e; } }
|
||||
html { background: var(--bg); color: var(--text); }
|
||||
body { max-width: 520px; margin: 14vh auto; padding: 0 24px; line-height: 1.5; text-align: center; background: var(--bg); color: var(--text); }
|
||||
.mark { width: 72px; height: 72px; margin: 0 auto 20px; border-radius: 50%; background: var(--error); color: var(--on-error); font-size: 34px; font-weight: 600; line-height: 72px; }
|
||||
h1 { font-size: 1.75em; font-weight: 600; margin: 0 0 8px; }
|
||||
p { margin: 8px 0; color: var(--muted); }
|
||||
p.url { word-break: break-all; color: var(--text); }
|
||||
code, pre { font-family: ui-monospace, monospace; word-break: break-all; }
|
||||
.detail { font-size: 0.85em; }
|
||||
.actions { margin-top: 28px; }
|
||||
button { font: inherit; font-weight: 600; height: 40px; padding: 0 24px; margin: 0 4px; border-radius: 20px; border: 1px solid var(--line); background: transparent; color: var(--primary); cursor: pointer; }
|
||||
button.main { border-color: transparent; background: var(--primary); color: var(--on-primary); }
|
||||
button:hover { filter: brightness(1.08); }
|
||||
details { margin-top: 20px; text-align: left; color: var(--muted); }
|
||||
details pre { white-space: pre-wrap; font-size: 12px; background: var(--card); padding: 12px; border-radius: 12px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="mark">!</div>
|
||||
<h1>Couldn't open this page</h1>
|
||||
<p id="url"></p>
|
||||
<p>The server didn't answer or the connection broke. Check that the address is right and that you're online.
|
||||
If you use Nacre's VPN, it may still be connecting.</p>
|
||||
<p><small>Details: <code>${reason}</code></small></p>
|
||||
<button onclick="location.reload()">Try again</button>
|
||||
<button onclick="history.back()">Go back</button>
|
||||
<p class="url" id="url"></p>
|
||||
<p>The server didn't answer or the connection broke. Check that the address is right and that you're online. If you use Nacre's VPN, it may still be connecting.</p>
|
||||
<p class="detail">Details: <code>${reason}</code></p>
|
||||
<div class="actions"><button class="main" onclick="location.reload()">Try again</button><button onclick="history.back()">Go back</button></div>
|
||||
<script>document.getElementById('url').textContent = location.href;</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -223,6 +223,22 @@ then shows only sections with matches, rows highlighted; `nacre://settings/?sear
|
|||
scheme preview (mini browser in the live roles + key colours), palette swatches built per preset with the current
|
||||
mode/style/contrast (cached), custom colour = hex field + picker.
|
||||
|
||||
**Pages and dialogs** (S020). Page widgets in `widgets.rs`: `page_header(title, subtitle, actions)` (Headline title,
|
||||
actions right or under it below 640 pt, subtitle truncated), `search_pill(id, &mut text, hint)`, `empty_state(glyph,
|
||||
title, body, action)` and `status_state(glyph, title, body, error)` (round icon, plain words, button), `list_item(id,
|
||||
glyph, title, detail, trailing)` (one 56 pt row inside a `card`: round icon, title and detail cut with an ellipsis,
|
||||
whole row clickable, icon buttons at the end), `more_menu` (more button + `menus::menu_item` rows), `password_field`,
|
||||
`strength_meter`. Pages follow one shape: header, search pill, then `section` + `card` groups; every list has an empty
|
||||
state (what will appear and how) and a "nothing matches" state. `row` now lays the control beside the text on its first
|
||||
frame and moves it under the text only when it measured too wide (it used to start stacked, which stuck in narrow cards).
|
||||
Welcome (`pages/welcome.rs`): six steps in a 560 pt card over the new tab backdrop; indicator dots (current one a
|
||||
stretched pill, clickable), card height on a spring, step content fades and slides in (a new spring id per step),
|
||||
Enter continues, Escape skips, every choice is written to settings at once. Dialogs (`dialogs.rs::dialog_card`): scrim
|
||||
over the page rect, `surface_container_high` card radius `XL`, padding 24, one shadow, eases in; title Headline, body
|
||||
`on_surface_variant`, actions right with the main one last (Enter = main, Escape = cancel). Permission and find bars are
|
||||
56 pt `surface_container_high` bars with real buttons. Selftest: `key <name>`, `welcome <step>`. The web error pages
|
||||
(`assets/servo/{neterror,badcert,crash}.html`) use the same roles in CSS with a dark scheme.
|
||||
|
||||
**Shapes** (`ui::paint`): `cookie(painter, center, radius, lobes, rotation, fill, stroke)`,
|
||||
`cookie_image(painter, texture, center, radius, lobes, rotation)` (artwork in a cookie), `cookie_points`,
|
||||
`wavy_line(painter, x0, x1, y, amplitude, wavelength, phase, stroke)`, `wavy_progress(painter, rect, fraction,
|
||||
|
|
|
|||
|
|
@ -130,6 +130,24 @@ One entry per session, newest last, ≤ 15 lines: done, verified how, not done,
|
|||
- Not seen: page scrolled below the fold (no scroll command), hover/press in shots, colour picker popup, key capture;
|
||||
backgrounds/chrome smoke not rerun after moving chip/slider out of customize.rs (same code, it compiles).
|
||||
|
||||
## S020 — Other pages and dialogs redesign (2026-11-12)
|
||||
- Done: history, bookmarks (+ reading list), downloads, passwords (logins, addresses, cards, generator, check, master
|
||||
password, lock screen), apps (+ scripts and styles), devtools, task manager, about, clear data, site settings, source
|
||||
and the web error pages (neterror, badcert, crash HTML, dark and light) in the S015/S019 system, each with designed
|
||||
empty, no-match and error states. Welcome is the six-step setup flow (R1-08). All dialogs: alert/confirm/prompt, sign-in,
|
||||
select, colour, Bluetooth, leave page, autofill dropdowns, permission and find bars.
|
||||
- Widgets added (DESIGN.md "Pages and dialogs"): page_header, search_pill, empty_state, status_state, list_item,
|
||||
more_menu, password_field, strength_meter. Fixed `row` starting stacked in narrow containers. Added icons diamond,
|
||||
fingerprint, rocket_launch, lightbulb. Selftest `key`, `welcome`.
|
||||
- Shots (target-independent, run with SMOKE_VISIBLE=1): `tests/smoke/pages-ui.txt` (history, bookmarks, downloads,
|
||||
passwords, apps, site settings, clear data, about, tasks, devtools, source, welcome 1-6, light variants) and
|
||||
`tests/smoke/dialogs.txt` (alert, confirm, prompt, select, colour, find bar, light alert).
|
||||
- Verified: 51 unit tests; launch, settings, chrome, pages-ui, dialogs smoke exit 0.
|
||||
- Not seen: populated downloads and apps lists, password/address/card editors and lists (vault is empty in smoke),
|
||||
the select dropdown and permission/sign-in/leave-page dialogs (no script trigger), the HTML error pages after
|
||||
the change (only the old one), welcome Import with a detected browser, hover/press states, tiny windows. "Make Nacre
|
||||
your default browser" is not in the done step (no code for it yet).
|
||||
|
||||
## Later
|
||||
- Reader mode, split view, translate, real gamepad rumble (D-002: not planned for now).
|
||||
- Packaging and first release (D-001: plan when the user asks).
|
||||
|
|
|
|||
|
|
@ -33,5 +33,5 @@ State tags: `[open]`, `[fixed <commit>]`, `[wontfix: reason]`. Severity: high /
|
|||
- R1-05 [open] UI is "really basic"; the new-tab page isn't what the user was going for. Severity: medium. Phase 4 redesign; target in docs/UI-BRIEF.md.
|
||||
- R1-06 [open] Wants the feel of the old Python Nacre (`nacre` in ~/.local/bin: dark Material-style lists of nacre:// pages, outlined icons), improved with animations and an "unslop" look, very user friendly. Severity: medium. Input for the Phase 4 redesign.
|
||||
- R1-07 [open] Ad-block removal animation, like the "pie" ad blocker extension: before a blocked ad element (e.g. YouTube in-feed "Sponsored" cards, feed/sidebar ad slots) disappears, show a Material You overlay on it, a tonal shape (cookie/scalloped) with a check mark that pops in, then the element shrinks out and its height/width collapses smoothly so the surrounding content shifts into place (no jump, no blank gap). Applies to cosmetic removals and YouTube ad slots. Today `COSMETIC_JS` in `src/inject.rs` only fades and scales to 0.92 and then sets `display:none`, so content jumps. Respect the Motion setting and `animate_removal`; skip offscreen elements. Severity: medium. (user, during S019) → S012.
|
||||
- R1-08 [open] Welcome page: make nacre://welcome the multi-step setup flow from the user's recording (steps, motion and frames in docs/UI-BRIEF.md "Welcome page", `docs/ui-reference/welcome-*.jpg`), improved where possible. Severity: medium. (user, during S019) → S020.
|
||||
- R1-08 [fixed S020] Welcome page: make nacre://welcome the multi-step setup flow from the user's recording (steps, motion and frames in docs/UI-BRIEF.md "Welcome page", `docs/ui-reference/welcome-*.jpg`), improved where possible. Severity: medium. (user, during S019) → S020.
|
||||
- R1-09 [open] Address bar becomes a wavy progress bar while a page loads: the address pill turns into a Material 3 Expressive wavy (wiggly) progress line that maps the page's load progress; hovering it (or focusing it, or typing) morphs it back to the normal text field; when not loading it's the normal field. Every change between the two states is animated (spring morph, Motion setting respected). Build it as described here; the old browser's loading wave (a line under the pill) is NOT the target. Severity: medium. (user, during S020) → chrome follow-up after S020, before S021.
|
||||
|
|
|
|||
|
|
@ -19,8 +19,10 @@
|
|||
//! js <script> run JavaScript in the current tab; the result goes to the log
|
||||
//! click <x> <y> click in the page at CSS-ish pixel x,y (from the page's top left)
|
||||
//! pointer <x> <y> | off move the interface's pointer to x,y in the page area (new tab backgrounds follow it)
|
||||
//! key <name> press and release a key in the interface: enter, escape, tab, space or a letter
|
||||
//! tap <x> <y> click the interface (not the web page) at x,y in the window (logical px, as in a
|
||||
//! 1:1 screenshot): press, then release a frame later; for the chrome and Nacre's pages
|
||||
//! welcome <step> show step 0..5 of the welcome page
|
||||
//! customize [close] open (or close) the new tab page's Customize panel
|
||||
//! log <text> write a line to the log
|
||||
//! quit
|
||||
|
|
@ -291,6 +293,12 @@ impl App {
|
|||
}
|
||||
self.redraw(window);
|
||||
},
|
||||
"welcome" => {
|
||||
if let Some(win) = self.windows.get_mut(&window) {
|
||||
win.ui.pages.welcome_step = rest.trim().parse().unwrap_or(0);
|
||||
}
|
||||
self.redraw(window);
|
||||
},
|
||||
"customize" => {
|
||||
if let Some(win) = self.windows.get_mut(&window) {
|
||||
win.ui.pages.ntp_customize = rest != "close";
|
||||
|
|
@ -310,6 +318,23 @@ impl App {
|
|||
}
|
||||
self.redraw(window);
|
||||
},
|
||||
"key" => {
|
||||
// Press and release one key in the interface: Enter, Escape, Tab, Space, or a single letter.
|
||||
let key = match rest.trim().to_ascii_lowercase().as_str() {
|
||||
"enter" | "return" => Some(egui::Key::Enter),
|
||||
"escape" | "esc" => Some(egui::Key::Escape),
|
||||
"tab" => Some(egui::Key::Tab),
|
||||
"space" => Some(egui::Key::Space),
|
||||
other => egui::Key::from_name(other),
|
||||
};
|
||||
if let (Some(key), Some(win)) = (key, self.windows.get_mut(&window)) {
|
||||
let input = win.egui.egui_winit.egui_input_mut();
|
||||
for pressed in [true, false] {
|
||||
input.events.push(egui::Event::Key { key, physical_key: Some(key), pressed, repeat: false, modifiers: egui::Modifiers::NONE });
|
||||
}
|
||||
}
|
||||
self.redraw(window);
|
||||
},
|
||||
"tap" => {
|
||||
let mut parts = rest.split_whitespace().filter_map(|p| p.parse::<f32>().ok());
|
||||
if let (Some(x), Some(y), Some(win)) = (parts.next(), parts.next(), self.windows.get_mut(&window)) {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,71 @@
|
|||
//! Bars above the page (permission requests, save password, ...), the find bar, and dialogs in
|
||||
//! front of the page (alerts, sign-in, select lists, colour picker, autofill).
|
||||
|
||||
use egui::{Align2, RichText, Ui, Vec2};
|
||||
use egui::{Align2, Id, Rect, RichText, Sense, Ui, Vec2, pos2, vec2};
|
||||
|
||||
use super::Frame;
|
||||
use super::menus::{menu_item, surface};
|
||||
use super::widgets::{ButtonKind, button, chip, icon, icon_button, password_field, text_field};
|
||||
use super::{Frame, paint};
|
||||
use crate::actions::{Command, DialogResult, PromptAnswer};
|
||||
use crate::tabs::{Dialog, Prompt};
|
||||
use crate::util;
|
||||
use crate::theme::{self, Palette, Weight};
|
||||
use crate::ui::icons;
|
||||
use crate::util;
|
||||
|
||||
/// A modal dialog: the page dims behind a scrim, and a card of `surface_container_high` with large corners and one
|
||||
/// soft shadow eases in at the centre of the page. `body` draws title, text, fields and `dialog_actions`.
|
||||
fn dialog_card(ctx: &egui::Context, p: &Palette, page: Rect, id: Id, width: f32, body: &mut dyn FnMut(&mut Ui)) {
|
||||
// The card eases in from where it was last frame's start; a new dialog gets a new id so it starts fresh.
|
||||
let seen = ctx.data(|d| d.get_temp::<bool>(id.with("seen"))).unwrap_or(false);
|
||||
let t = if theme::tokens(ctx).motion <= 0.0 {
|
||||
1.0
|
||||
} else if seen {
|
||||
theme::spring(ctx, id.with("in"), 1.0, theme::EFFECT)
|
||||
} else {
|
||||
ctx.data_mut(|d| d.insert_temp(id.with("seen"), true));
|
||||
ctx.request_repaint();
|
||||
theme::spring(ctx, id.with("in"), 0.0, theme::EFFECT)
|
||||
}
|
||||
.clamp(0.0, 1.0);
|
||||
let scrim = ctx.layer_painter(egui::LayerId::new(egui::Order::Middle, id.with("scrim")));
|
||||
scrim.rect_filled(page, 0.0, p.scrim.gamma_multiply(0.32 * t));
|
||||
let radius = theme::radius(ctx, theme::XL);
|
||||
let width = width.min(page.width() - 2.0 * theme::GAP_L).max(240.0);
|
||||
egui::Area::new(id).fixed_pos(page.center() + vec2(0.0, (1.0 - t) * 16.0)).pivot(Align2::CENTER_CENTER).order(egui::Order::Foreground).show(ctx, |ui| {
|
||||
ui.set_opacity(t);
|
||||
egui::Frame::NONE
|
||||
.fill(p.surface_container_high)
|
||||
.corner_radius(theme::corner_radius(radius))
|
||||
.inner_margin(egui::Margin::same(24))
|
||||
.shadow(egui::Shadow { offset: [0, 6], blur: 24, spread: 0, color: egui::Color32::from_black_alpha(if p.dark { 150 } else { 70 }) })
|
||||
.show(ui, |ui| {
|
||||
ui.set_width(width - 48.0);
|
||||
body(ui);
|
||||
});
|
||||
});
|
||||
let _ = paint::shadow;
|
||||
}
|
||||
|
||||
fn dialog_title(ui: &mut Ui, text: &str) {
|
||||
let p = theme::palette(ui.ctx());
|
||||
ui.label(RichText::new(text).font(theme::font(theme::HEADLINE, Weight::Medium)).color(p.on_surface));
|
||||
ui.add_space(theme::GAP_M);
|
||||
}
|
||||
|
||||
fn dialog_text(ui: &mut Ui, text: &str) {
|
||||
let p = theme::palette(ui.ctx());
|
||||
ui.label(RichText::new(text).font(theme::font(theme::BODY, Weight::Regular)).color(p.on_surface_variant));
|
||||
}
|
||||
|
||||
/// The buttons at the bottom right, the main action last. Gets the row's layout (right to left): add the main
|
||||
/// action first.
|
||||
fn dialog_actions(ui: &mut Ui, contents: impl FnOnce(&mut Ui)) {
|
||||
ui.add_space(theme::GAP_XL);
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
ui.spacing_mut().item_spacing.x = theme::GAP_S;
|
||||
contents(ui);
|
||||
});
|
||||
}
|
||||
|
||||
pub fn prompt_bars(root: &mut Ui, f: &mut Frame) {
|
||||
let Some(tab) = f.tab() else { return };
|
||||
|
|
@ -26,66 +84,79 @@ pub fn prompt_bars(root: &mut Ui, f: &mut Frame) {
|
|||
Prompt::PopupBlocked { .. } => "A pop-up was blocked on this site".to_owned(),
|
||||
Prompt::Info { text } => text.clone(),
|
||||
};
|
||||
let kind = match prompt {
|
||||
Prompt::Permission { .. } | Prompt::ProtocolHandler { .. } => 0,
|
||||
Prompt::SaveLogin { .. } => 1,
|
||||
Prompt::HttpFallback { .. } => 2,
|
||||
Prompt::External { .. } => 3,
|
||||
Prompt::PopupBlocked { .. } => 4,
|
||||
Prompt::Info { .. } => 5,
|
||||
let (kind, glyph) = match prompt {
|
||||
Prompt::Permission { .. } | Prompt::ProtocolHandler { .. } => (0, icons::SHIELD),
|
||||
Prompt::SaveLogin { .. } => (1, icons::KEY),
|
||||
Prompt::HttpFallback { .. } => (2, icons::LOCK_OPEN),
|
||||
Prompt::External { .. } => (3, icons::OPEN_IN_NEW),
|
||||
Prompt::PopupBlocked { .. } => (4, icons::BLOCK),
|
||||
Prompt::Info { .. } => (5, icons::INFO),
|
||||
};
|
||||
let fill = f.palette().accent_soft;
|
||||
egui::Panel::top("prompt-bar").frame(egui::Frame::NONE.fill(fill).inner_margin(egui::Margin::symmetric(12, 6))).show(root, |ui| {
|
||||
let p = f.palette();
|
||||
let frame = egui::Frame::NONE.fill(p.surface_container_high).inner_margin(egui::Margin::symmetric(theme::GAP_L as i8, theme::GAP_S as i8));
|
||||
egui::Panel::top("prompt-bar").frame(frame).show(root, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(RichText::new(text).strong());
|
||||
ui.spacing_mut().item_spacing.x = theme::GAP_S;
|
||||
ui.set_min_height(theme::CONTROL);
|
||||
let (rect, _) = ui.allocate_exact_size(Vec2::splat(theme::ICON_LARGE), Sense::hover());
|
||||
icon(ui, rect.center(), glyph, theme::ICON, false, p.primary);
|
||||
ui.add_space(theme::GAP_XS);
|
||||
let mut answer = None;
|
||||
// Buttons first from the right; the text takes what is left and is cut with an ellipsis.
|
||||
let mut buttons = ui.new_child(egui::UiBuilder::new().max_rect(ui.max_rect()).layout(egui::Layout::right_to_left(egui::Align::Center)));
|
||||
buttons.spacing_mut().item_spacing.x = theme::GAP_S;
|
||||
if icon_button(&mut buttons, icons::CLOSE, "Not now").clicked() {
|
||||
answer = Some(PromptAnswer::Dismiss);
|
||||
}
|
||||
match kind {
|
||||
0 | 3 => {
|
||||
let remember_id = Id::new(("remember", tab_id));
|
||||
let mut remember = buttons.data_mut(|d| *d.get_temp_mut_or(remember_id, true));
|
||||
if button(&mut buttons, ButtonKind::Filled, None, "Allow").clicked() {
|
||||
answer = Some(PromptAnswer::Allow { remember });
|
||||
}
|
||||
if button(&mut buttons, ButtonKind::Tonal, None, "Block").clicked() {
|
||||
answer = Some(PromptAnswer::Deny { remember });
|
||||
}
|
||||
if chip(&mut buttons, if remember { Some(icons::CHECK) } else { None }, "Remember", remember).clicked() {
|
||||
remember = !remember;
|
||||
}
|
||||
buttons.data_mut(|d| d.insert_temp(remember_id, remember));
|
||||
},
|
||||
1 => {
|
||||
if button(&mut buttons, ButtonKind::Filled, None, "Save").clicked() {
|
||||
answer = Some(PromptAnswer::Yes);
|
||||
}
|
||||
if button(&mut buttons, ButtonKind::Tonal, None, "Never for this site").clicked() {
|
||||
answer = Some(PromptAnswer::Never);
|
||||
}
|
||||
},
|
||||
2 => {
|
||||
if button(&mut buttons, ButtonKind::Filled, None, "Open anyway").clicked() {
|
||||
answer = Some(PromptAnswer::Yes);
|
||||
}
|
||||
if button(&mut buttons, ButtonKind::Tonal, None, "Always for this site").clicked() {
|
||||
answer = Some(PromptAnswer::Allow { remember: true });
|
||||
}
|
||||
},
|
||||
4 => {
|
||||
if button(&mut buttons, ButtonKind::Tonal, None, "Always allow pop-ups here").clicked() {
|
||||
answer = Some(PromptAnswer::Allow { remember: true });
|
||||
}
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
let used = buttons.min_rect().width();
|
||||
let mut label = text;
|
||||
if more > 0 {
|
||||
ui.label(RichText::new(format!("(+{more} more)")).weak());
|
||||
label = format!("{label} (+{more} more)");
|
||||
}
|
||||
let width = (ui.available_width() - used - theme::GAP_L).max(80.0);
|
||||
let galley = super::menus::one_line(ui, &label, theme::font(theme::BODY, Weight::Medium), p.on_surface, width);
|
||||
ui.add(egui::Label::new(galley));
|
||||
if let Some(answer) = answer {
|
||||
f.send(Command::Prompt { tab: tab_id, answer });
|
||||
}
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
let mut answer = None;
|
||||
if ui.small_button(icons::CLOSE).on_hover_text("Not now").clicked() {
|
||||
answer = Some(PromptAnswer::Dismiss);
|
||||
}
|
||||
match kind {
|
||||
0 | 3 => {
|
||||
let remember_id = ui.id().with(("remember", tab_id));
|
||||
let mut remember = ui.data_mut(|d| *d.get_temp_mut_or(remember_id, true));
|
||||
if ui.button("Block").clicked() {
|
||||
answer = Some(PromptAnswer::Deny { remember });
|
||||
}
|
||||
if ui.button("Allow").clicked() {
|
||||
answer = Some(PromptAnswer::Allow { remember });
|
||||
}
|
||||
ui.checkbox(&mut remember, "Remember");
|
||||
ui.data_mut(|d| d.insert_temp(remember_id, remember));
|
||||
},
|
||||
1 => {
|
||||
if ui.button("Never for this site").clicked() {
|
||||
answer = Some(PromptAnswer::Never);
|
||||
}
|
||||
if ui.button("Save").clicked() {
|
||||
answer = Some(PromptAnswer::Yes);
|
||||
}
|
||||
},
|
||||
2 => {
|
||||
if ui.button("Always for this site").clicked() {
|
||||
answer = Some(PromptAnswer::Allow { remember: true });
|
||||
}
|
||||
if ui.button("Open anyway").clicked() {
|
||||
answer = Some(PromptAnswer::Yes);
|
||||
}
|
||||
},
|
||||
4 => {
|
||||
if ui.button("Always allow pop-ups here").clicked() {
|
||||
answer = Some(PromptAnswer::Allow { remember: true });
|
||||
}
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
if let Some(answer) = answer {
|
||||
f.send(Command::Prompt { tab: tab_id, answer });
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -96,10 +167,13 @@ pub fn find_bar(root: &mut Ui, f: &mut Frame) {
|
|||
return;
|
||||
}
|
||||
let mut find = tab.find.clone();
|
||||
egui::Panel::top("find-bar").show(root, |ui| {
|
||||
let p = f.palette();
|
||||
let frame = egui::Frame::NONE.fill(p.surface_container_high).inner_margin(egui::Margin::symmetric(theme::GAP_L as i8, theme::GAP_S as i8));
|
||||
egui::Panel::top("find-bar").frame(frame).show(root, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Find");
|
||||
let response = ui.add(egui::TextEdit::singleline(&mut find.text).desired_width(260.0).hint_text("Find in page"));
|
||||
ui.spacing_mut().item_spacing.x = theme::GAP_S;
|
||||
ui.set_min_height(theme::CONTROL);
|
||||
let response = text_field(ui, &mut find.text, "Find in page", 280.0);
|
||||
if find.focus {
|
||||
response.request_focus();
|
||||
find.focus = false;
|
||||
|
|
@ -117,18 +191,19 @@ pub fn find_bar(root: &mut Ui, f: &mut Frame) {
|
|||
f.send(Command::FindClose);
|
||||
}
|
||||
let label = if find.text.is_empty() { String::new() } else if find.count == 0 { "No matches".into() } else { format!("{} of {}", find.index, find.count) };
|
||||
ui.label(RichText::new(label).weak());
|
||||
if ui.small_button(icons::ARROW_UPWARD).on_hover_text("Previous (Shift+Enter)").clicked() {
|
||||
ui.label(RichText::new(label).font(theme::font(theme::SMALL, Weight::Medium)).color(if !find.text.is_empty() && find.count == 0 { p.error } else { p.on_surface_variant }));
|
||||
if icon_button(ui, icons::ARROW_UPWARD, "Previous (Shift+Enter)").clicked() {
|
||||
f.send(Command::Find { text: find.text.clone(), forward: false, case: find.case_sensitive });
|
||||
}
|
||||
if ui.small_button(icons::ARROW_DOWNWARD).on_hover_text("Next (Enter)").clicked() {
|
||||
if icon_button(ui, icons::ARROW_DOWNWARD, "Next (Enter)").clicked() {
|
||||
f.send(Command::Find { text: find.text.clone(), forward: true, case: find.case_sensitive });
|
||||
}
|
||||
if ui.checkbox(&mut find.case_sensitive, "Match case").changed() {
|
||||
if chip(ui, if find.case_sensitive { Some(icons::CHECK) } else { None }, "Match case", find.case_sensitive).clicked() {
|
||||
find.case_sensitive = !find.case_sensitive;
|
||||
f.send(Command::Find { text: find.text.clone(), forward: true, case: find.case_sensitive });
|
||||
}
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
if ui.small_button(icons::CLOSE).clicked() {
|
||||
if icon_button(ui, icons::CLOSE, "Close").clicked() {
|
||||
f.send(Command::FindClose);
|
||||
}
|
||||
});
|
||||
|
|
@ -149,43 +224,40 @@ pub fn page_dialogs(ctx: &egui::Context, f: &mut Frame) {
|
|||
let Some(dialog) = tab.dialog.take() else { return };
|
||||
let page = f.page_rect.unwrap_or_else(|| ctx.content_rect());
|
||||
let palette = f.palette();
|
||||
let center = page.center_top() + egui::vec2(0.0, 80.0);
|
||||
let card = |ctx: &egui::Context, id: &str, body: &mut dyn FnMut(&mut Ui)| {
|
||||
egui::Area::new(egui::Id::new((id, tab_id))).fixed_pos(center).pivot(Align2::CENTER_TOP).order(egui::Order::Foreground).show(ctx, |ui| {
|
||||
egui::Frame::popup(ui.style()).fill(palette.surface_high).inner_margin(egui::Margin::same(16)).show(ui, |ui| {
|
||||
ui.set_width(380.0);
|
||||
body(ui);
|
||||
});
|
||||
});
|
||||
// Each dialog gets a new id so it eases in from the start.
|
||||
let count: u32 = ctx.data(|d| d.get_temp(Id::new("dialog-count"))).unwrap_or(0);
|
||||
let card = |ctx: &egui::Context, id: &str, width: f32, body: &mut dyn FnMut(&mut Ui)| {
|
||||
dialog_card(ctx, &palette, page, Id::new((id, tab_id, count)), width, body);
|
||||
};
|
||||
let mut result: Option<DialogResult> = None;
|
||||
let mut extra: Vec<Command> = Vec::new();
|
||||
match &dialog {
|
||||
Dialog::Simple(simple, origin) => {
|
||||
let value_id = egui::Id::new(("prompt-value", tab_id));
|
||||
card(ctx, "simple-dialog", &mut |ui| {
|
||||
ui.label(RichText::new(format!("{} says", util::host_of_str(origin))).weak());
|
||||
ui.add_space(4.0);
|
||||
ui.label(util::ellipsize(simple.message(), 2000));
|
||||
ui.add_space(8.0);
|
||||
let value_id = Id::new(("prompt-value", tab_id));
|
||||
card(ctx, "simple-dialog", 400.0, &mut |ui| {
|
||||
let host = util::host_of_str(origin);
|
||||
dialog_title(ui, &if host.is_empty() { "This page says".to_owned() } else { format!("{host} says") });
|
||||
egui::ScrollArea::vertical().max_height(240.0).auto_shrink([true, true]).show(ui, |ui| dialog_text(ui, &util::ellipsize(simple.message(), 2000)));
|
||||
let mut value: Option<String> = None;
|
||||
if let servo::SimpleDialog::Prompt(prompt) = simple {
|
||||
ui.add_space(theme::GAP_L);
|
||||
let mut text = ui.data_mut(|d| d.get_temp::<String>(value_id)).unwrap_or_else(|| prompt.current_value().to_owned());
|
||||
let r = ui.add(egui::TextEdit::singleline(&mut text).desired_width(340.0));
|
||||
let r = text_field(ui, &mut text, "", ui.available_width());
|
||||
r.request_focus();
|
||||
ui.data_mut(|d| d.insert_temp(value_id, text.clone()));
|
||||
value = Some(text);
|
||||
}
|
||||
ui.horizontal(|ui| {
|
||||
if !matches!(simple, servo::SimpleDialog::Alert(_)) && ui.button("Cancel").clicked() {
|
||||
result = Some(DialogResult::Cancel);
|
||||
}
|
||||
if ui.button("OK").clicked() || ui.input(|i| i.key_pressed(egui::Key::Enter)) {
|
||||
let alert = matches!(simple, servo::SimpleDialog::Alert(_));
|
||||
dialog_actions(ui, |ui| {
|
||||
if button(ui, ButtonKind::Filled, None, "OK").clicked() || ui.input(|i| i.key_pressed(egui::Key::Enter)) {
|
||||
result = Some(DialogResult::Ok(value.clone()));
|
||||
}
|
||||
if !alert && button(ui, ButtonKind::Text, None, "Cancel").clicked() {
|
||||
result = Some(DialogResult::Cancel);
|
||||
}
|
||||
});
|
||||
if ui.input(|i| i.key_pressed(egui::Key::Escape)) {
|
||||
result = Some(if matches!(simple, servo::SimpleDialog::Alert(_)) { DialogResult::Ok(None) } else { DialogResult::Cancel });
|
||||
result = Some(if alert { DialogResult::Ok(None) } else { DialogResult::Cancel });
|
||||
}
|
||||
});
|
||||
if result.is_some() {
|
||||
|
|
@ -193,36 +265,46 @@ pub fn page_dialogs(ctx: &egui::Context, f: &mut Frame) {
|
|||
}
|
||||
},
|
||||
Dialog::Auth { request, username, password } => {
|
||||
let id = egui::Id::new(("auth", tab_id));
|
||||
card(ctx, "auth-dialog", &mut |ui| {
|
||||
let id = Id::new(("auth", tab_id));
|
||||
card(ctx, "auth-dialog", 400.0, &mut |ui| {
|
||||
let host = request.url().host_str().unwrap_or("").to_owned();
|
||||
ui.label(RichText::new(if request.for_proxy() { format!("The proxy {host} needs you to sign in") } else { format!("{host} needs you to sign in") }).strong());
|
||||
dialog_title(ui, "Sign in");
|
||||
dialog_text(ui, &if request.for_proxy() { format!("The proxy {host} asks for a user name and password.") } else { format!("{host} asks for a user name and password.") });
|
||||
ui.add_space(theme::GAP_L);
|
||||
let (mut u, mut p) = ui.data_mut(|d| d.get_temp::<(String, String)>(id)).unwrap_or((username.clone(), password.clone()));
|
||||
ui.add(egui::TextEdit::singleline(&mut u).hint_text("User name").desired_width(340.0));
|
||||
let pr = ui.add(egui::TextEdit::singleline(&mut p).hint_text("Password").password(true).desired_width(340.0));
|
||||
let width = ui.available_width();
|
||||
text_field(ui, &mut u, "User name", width);
|
||||
ui.add_space(theme::GAP_S);
|
||||
let pr = password_field(ui, &mut p, "Password", width);
|
||||
ui.data_mut(|d| d.insert_temp(id, (u.clone(), p.clone())));
|
||||
ui.horizontal(|ui| {
|
||||
if ui.button("Cancel").clicked() {
|
||||
result = Some(DialogResult::Cancel);
|
||||
}
|
||||
if ui.button("Sign in").clicked() || (pr.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter))) {
|
||||
dialog_actions(ui, |ui| {
|
||||
if button(ui, ButtonKind::Filled, None, "Sign in").clicked() || (pr.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter))) {
|
||||
result = Some(DialogResult::Auth { username: u.clone(), password: p.clone() });
|
||||
}
|
||||
if button(ui, ButtonKind::Text, None, "Cancel").clicked() {
|
||||
result = Some(DialogResult::Cancel);
|
||||
}
|
||||
});
|
||||
if ui.input(|i| i.key_pressed(egui::Key::Escape)) {
|
||||
result = Some(DialogResult::Cancel);
|
||||
}
|
||||
});
|
||||
if result.is_some() {
|
||||
ctx.data_mut(|d| d.remove::<(String, String)>(id));
|
||||
}
|
||||
},
|
||||
Dialog::Select(select) => {
|
||||
let rect = device_rect(ctx, f.page_rect.as_ref(), select.position());
|
||||
let multiple = select.allow_select_multiple();
|
||||
let mut chosen: Vec<usize> = select.selected_options();
|
||||
let area = egui::Area::new(egui::Id::new(("select", tab_id))).fixed_pos(rect.left_bottom()).order(egui::Order::Foreground).constrain(true).show(ctx, |ui| {
|
||||
egui::Frame::menu(ui.style()).show(ui, |ui| {
|
||||
ui.set_min_width(rect.width().max(160.0));
|
||||
let area = egui::Area::new(Id::new(("select", tab_id))).fixed_pos(rect.left_bottom()).order(egui::Order::Foreground).constrain(true).show(ctx, |ui| {
|
||||
surface(&palette, ctx).show(ui, |ui| {
|
||||
ui.set_min_width(rect.width().max(200.0));
|
||||
ui.spacing_mut().item_spacing.y = 2.0;
|
||||
egui::ScrollArea::vertical().max_height(360.0).show(ui, |ui| {
|
||||
let mut option = |ui: &mut Ui, o: &servo::SelectElementOption, indent: bool| {
|
||||
let mut option = |ui: &mut Ui, o: &servo::SelectElementOption| {
|
||||
let selected = chosen.contains(&o.id);
|
||||
let label = if indent { format!(" {}", o.label) } else { o.label.clone() };
|
||||
let r = ui.add_enabled(!o.is_disabled, egui::Button::new(label).selected(selected).frame(false));
|
||||
let r = ui.add_enabled_ui(!o.is_disabled, |ui| menu_item(ui, if selected { Some(icons::CHECK) } else { None }, &o.label, "", selected)).inner;
|
||||
if r.clicked() {
|
||||
if multiple {
|
||||
if selected { chosen.retain(|i| *i != o.id) } else { chosen.push(o.id) }
|
||||
|
|
@ -234,18 +316,24 @@ pub fn page_dialogs(ctx: &egui::Context, f: &mut Frame) {
|
|||
};
|
||||
for entry in select.options() {
|
||||
match entry {
|
||||
servo::SelectElementOptionOrOptgroup::Option(o) => option(ui, o, false),
|
||||
servo::SelectElementOptionOrOptgroup::Option(o) => option(ui, o),
|
||||
servo::SelectElementOptionOrOptgroup::Optgroup { label, options } => {
|
||||
ui.label(RichText::new(label).strong());
|
||||
ui.add_space(theme::GAP_XS);
|
||||
ui.label(RichText::new(label).font(theme::font(theme::SMALL, Weight::Medium)).color(palette.primary));
|
||||
for o in options {
|
||||
option(ui, o, true);
|
||||
option(ui, o);
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
});
|
||||
if multiple && ui.button("Done").clicked() {
|
||||
result = Some(DialogResult::Select(chosen.clone()));
|
||||
if multiple {
|
||||
ui.add_space(theme::GAP_S);
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
if button(ui, ButtonKind::Tonal, None, "Done").clicked() {
|
||||
result = Some(DialogResult::Select(chosen.clone()));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
@ -256,20 +344,20 @@ pub fn page_dialogs(ctx: &egui::Context, f: &mut Frame) {
|
|||
},
|
||||
Dialog::Color(picker, initial) => {
|
||||
let rect = device_rect(ctx, f.page_rect.as_ref(), picker.position());
|
||||
let id = egui::Id::new(("color", tab_id));
|
||||
let id = Id::new(("color", tab_id));
|
||||
let mut rgb = ctx.data_mut(|d| d.get_temp::<[u8; 3]>(id)).unwrap_or(*initial);
|
||||
egui::Area::new(id).fixed_pos(rect.left_bottom()).order(egui::Order::Foreground).constrain(true).show(ctx, |ui| {
|
||||
egui::Frame::popup(ui.style()).show(ui, |ui| {
|
||||
surface(&palette, ctx).inner_margin(egui::Margin::same(theme::GAP_L as i8)).show(ui, |ui| {
|
||||
let mut color = egui::Color32::from_rgb(rgb[0], rgb[1], rgb[2]);
|
||||
egui::color_picker::color_picker_color32(ui, &mut color, egui::color_picker::Alpha::Opaque);
|
||||
rgb = [color.r(), color.g(), color.b()];
|
||||
ui.horizontal(|ui| {
|
||||
if ui.button("Cancel").clicked() {
|
||||
result = Some(DialogResult::Color(None));
|
||||
}
|
||||
if ui.button("Choose").clicked() {
|
||||
dialog_actions(ui, |ui| {
|
||||
if button(ui, ButtonKind::Filled, None, "Choose").clicked() {
|
||||
result = Some(DialogResult::Color(Some(rgb)));
|
||||
}
|
||||
if button(ui, ButtonKind::Text, None, "Cancel").clicked() {
|
||||
result = Some(DialogResult::Color(None));
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -282,31 +370,34 @@ pub fn page_dialogs(ctx: &egui::Context, f: &mut Frame) {
|
|||
super::menus::page_menu(ctx, f, tab_id, menu);
|
||||
},
|
||||
Dialog::Bluetooth(request) => {
|
||||
card(ctx, "bluetooth", &mut |ui| {
|
||||
ui.label(RichText::new("Choose a Bluetooth device").strong());
|
||||
card(ctx, "bluetooth", 400.0, &mut |ui| {
|
||||
dialog_title(ui, "Choose a Bluetooth device");
|
||||
if request.devices().is_empty() {
|
||||
ui.label(RichText::new("No devices found nearby").weak());
|
||||
dialog_text(ui, "No devices found nearby. Check that the device is on and ready to pair.");
|
||||
}
|
||||
ui.spacing_mut().item_spacing.y = 2.0;
|
||||
for (i, device) in request.devices().iter().enumerate() {
|
||||
let name = if device.name.is_empty() { device.address.clone() } else { format!("{} ({})", device.name, device.address) };
|
||||
if ui.button(name).clicked() {
|
||||
if menu_item(ui, Some(icons::BLUETOOTH), &name, "", false).clicked() {
|
||||
result = Some(DialogResult::Device(Some(i)));
|
||||
}
|
||||
}
|
||||
if ui.button("Cancel").clicked() {
|
||||
result = Some(DialogResult::Device(None));
|
||||
}
|
||||
dialog_actions(ui, |ui| {
|
||||
if button(ui, ButtonKind::Text, None, "Cancel").clicked() || ui.input(|i| i.key_pressed(egui::Key::Escape)) {
|
||||
result = Some(DialogResult::Device(None));
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
Dialog::LeavePage(_) => {
|
||||
card(ctx, "leave", &mut |ui| {
|
||||
ui.label(RichText::new("Leave this page?").strong());
|
||||
ui.label("Changes you made may not be saved.");
|
||||
ui.horizontal(|ui| {
|
||||
if ui.button("Stay").clicked() {
|
||||
card(ctx, "leave", 400.0, &mut |ui| {
|
||||
dialog_title(ui, "Leave this page?");
|
||||
dialog_text(ui, "Changes you made may not be saved.");
|
||||
dialog_actions(ui, |ui| {
|
||||
if button(ui, ButtonKind::Filled, None, "Stay").clicked() || ui.input(|i| i.key_pressed(egui::Key::Escape)) {
|
||||
result = Some(DialogResult::Leave(false));
|
||||
}
|
||||
if ui.button("Leave").clicked() {
|
||||
if button(ui, ButtonKind::Text, None, "Leave").clicked() {
|
||||
result = Some(DialogResult::Leave(true));
|
||||
}
|
||||
});
|
||||
|
|
@ -314,48 +405,51 @@ pub fn page_dialogs(ctx: &egui::Context, f: &mut Frame) {
|
|||
},
|
||||
Dialog::Logins { x, y, items } => {
|
||||
let zoom = f.tabs.get(active).map(|t| t.zoom).unwrap_or(1.0);
|
||||
let pos = page.min + egui::vec2(x * zoom, y * zoom + 2.0);
|
||||
let pos = page.min + vec2(x * zoom, y * zoom + 2.0);
|
||||
let locked = f.shared.vault.borrow().locked();
|
||||
let mut close = false;
|
||||
let area = egui::Area::new(egui::Id::new(("logins", tab_id))).fixed_pos(pos).order(egui::Order::Foreground).constrain(true).show(ctx, |ui| {
|
||||
egui::Frame::menu(ui.style()).show(ui, |ui| {
|
||||
ui.set_min_width(240.0);
|
||||
let area = egui::Area::new(Id::new(("logins", tab_id))).fixed_pos(pos).order(egui::Order::Foreground).constrain(true).show(ctx, |ui| {
|
||||
surface(&palette, ctx).show(ui, |ui| {
|
||||
ui.set_min_width(260.0);
|
||||
ui.spacing_mut().item_spacing.y = 2.0;
|
||||
if locked {
|
||||
let id = egui::Id::new("vault-unlock");
|
||||
let id = Id::new("vault-unlock");
|
||||
let mut pw = ui.data_mut(|d| d.get_temp::<String>(id)).unwrap_or_default();
|
||||
ui.label("Unlock saved passwords");
|
||||
let r = ui.add(egui::TextEdit::singleline(&mut pw).password(true).hint_text("Master password"));
|
||||
ui.add_space(theme::GAP_XS);
|
||||
ui.label(RichText::new("Unlock saved passwords").font(theme::font(theme::BODY, Weight::Medium)).color(palette.on_surface));
|
||||
ui.add_space(theme::GAP_S);
|
||||
let r = password_field(ui, &mut pw, "Master password", 260.0);
|
||||
if r.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter)) {
|
||||
match f.shared.vault.borrow_mut().unlock(&pw) {
|
||||
Ok(()) => {
|
||||
pw.clear();
|
||||
close = true;
|
||||
},
|
||||
Err(error) => {
|
||||
ui.label(RichText::new(error.to_string()).color(palette.error));
|
||||
Err(_) => {
|
||||
ui.data_mut(|d| d.insert_temp(id.with("error"), true));
|
||||
},
|
||||
}
|
||||
}
|
||||
if ui.data(|d| d.get_temp::<bool>(id.with("error"))).unwrap_or(false) {
|
||||
ui.label(RichText::new("That master password is not right.").font(theme::font(theme::SMALL, Weight::Regular)).color(palette.error));
|
||||
}
|
||||
ui.data_mut(|d| d.insert_temp(id, pw));
|
||||
return;
|
||||
}
|
||||
for (id, user) in items {
|
||||
let label = if user.is_empty() { "(no user name)".to_owned() } else { user.clone() };
|
||||
if ui.button(format!("{} {label}", icons::KEY)).clicked() {
|
||||
let label = if user.is_empty() { "No user name".to_owned() } else { user.clone() };
|
||||
if menu_item(ui, Some(icons::KEY), &label, "", false).clicked() {
|
||||
extra.push(Command::FillLogin { tab: tab_id, id: *id });
|
||||
}
|
||||
}
|
||||
if !items.is_empty() {
|
||||
ui.separator();
|
||||
}
|
||||
let (len, symbols) = {
|
||||
let s = f.shared.settings.borrow();
|
||||
(s.vault.gen_length, s.vault.gen_symbols)
|
||||
};
|
||||
if ui.button("Use a strong password").on_hover_text("Fills a new random password; it is saved when you submit the form").clicked() {
|
||||
if menu_item(ui, Some(icons::PASSWORD), "Use a strong password", "", false).on_hover_text("Fills a new random password; it is saved when you submit the form").clicked() {
|
||||
extra.push(Command::FillPassword { tab: tab_id, password: crate::store::vault::generate(len as usize, symbols) });
|
||||
}
|
||||
if ui.button("Manage passwords").clicked() {
|
||||
if menu_item(ui, Some(icons::SETTINGS), "Manage passwords", "", false).clicked() {
|
||||
extra.push(Command::ShowPage(crate::tabs::Page::Passwords));
|
||||
close = true;
|
||||
}
|
||||
|
|
@ -368,20 +462,22 @@ pub fn page_dialogs(ctx: &egui::Context, f: &mut Frame) {
|
|||
},
|
||||
Dialog::Forms { kind, x, y } => {
|
||||
let zoom = f.tabs.get(active).map(|t| t.zoom).unwrap_or(1.0);
|
||||
let pos = page.min + egui::vec2(x * zoom, y * zoom + 2.0);
|
||||
let area = egui::Area::new(egui::Id::new(("forms", tab_id))).fixed_pos(pos).order(egui::Order::Foreground).constrain(true).show(ctx, |ui| {
|
||||
egui::Frame::menu(ui.style()).show(ui, |ui| {
|
||||
let pos = page.min + vec2(x * zoom, y * zoom + 2.0);
|
||||
let area = egui::Area::new(Id::new(("forms", tab_id))).fixed_pos(pos).order(egui::Order::Foreground).constrain(true).show(ctx, |ui| {
|
||||
surface(&palette, ctx).show(ui, |ui| {
|
||||
ui.set_min_width(260.0);
|
||||
ui.spacing_mut().item_spacing.y = 2.0;
|
||||
let vault = f.shared.vault.borrow();
|
||||
if kind == "card" {
|
||||
for c in &vault.contents.cards {
|
||||
let label = if c.nickname.is_empty() { c.masked() } else { format!("{} {}", c.nickname, c.masked()) };
|
||||
if ui.button(format!("{} {label}", icons::CREDIT_CARD)).clicked() {
|
||||
if menu_item(ui, Some(icons::CREDIT_CARD), &label, "", false).clicked() {
|
||||
extra.push(Command::FillCard { tab: tab_id, id: c.id });
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for a in &vault.contents.addresses {
|
||||
if ui.button(format!("{} {}, {}", icons::HOME, a.name, a.street)).clicked() {
|
||||
if menu_item(ui, Some(icons::PIN_DROP), &format!("{}, {}", a.name, a.street), "", false).clicked() {
|
||||
extra.push(Command::FillAddress { tab: tab_id, id: a.id });
|
||||
}
|
||||
}
|
||||
|
|
@ -404,9 +500,10 @@ pub fn page_dialogs(ctx: &egui::Context, f: &mut Frame) {
|
|||
f.send(command);
|
||||
}
|
||||
if let Some(result) = result {
|
||||
ctx.data_mut(|d| d.insert_temp(Id::new("dialog-count"), count + 1));
|
||||
f.send(Command::Dialog { tab: tab_id, result });
|
||||
}
|
||||
let _ = Vec2::ZERO;
|
||||
let _ = pos2(0.0, 0.0);
|
||||
}
|
||||
|
||||
fn device_rect(ctx: &egui::Context, page: Option<&egui::Rect>, rect: servo::DeviceIntRect) -> egui::Rect {
|
||||
|
|
|
|||
|
|
@ -171,6 +171,10 @@ pub const MEMORY: &str = "\u{e322}";
|
|||
pub const COLORIZE: &str = "\u{e3b8}";
|
||||
pub const FORMAT_COLOR_FILL: &str = "\u{e23a}";
|
||||
pub const RESTART_ALT: &str = "\u{f053}";
|
||||
pub const DIAMOND: &str = "\u{ead5}";
|
||||
pub const FINGERPRINT: &str = "\u{e90d}";
|
||||
pub const ROCKET_LAUNCH: &str = "\u{eb9b}";
|
||||
pub const LIGHTBULB: &str = "\u{e90f}";
|
||||
|
||||
/// Every icon with its name, for the gallery.
|
||||
pub const ALL: &[(&str, &str)] = &[
|
||||
|
|
@ -344,4 +348,8 @@ pub const ALL: &[(&str, &str)] = &[
|
|||
("colorize", COLORIZE),
|
||||
("format_color_fill", FORMAT_COLOR_FILL),
|
||||
("restart_alt", RESTART_ALT),
|
||||
("diamond", DIAMOND),
|
||||
("fingerprint", FINGERPRINT),
|
||||
("rocket_launch", ROCKET_LAUNCH),
|
||||
("lightbulb", LIGHTBULB),
|
||||
];
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ pub fn draw(ui: &mut Ui, f: &mut Frame) {
|
|||
section(ui, "Scripts and styles");
|
||||
ui.horizontal(|ui| {
|
||||
ui.add_space(theme::GAP_L);
|
||||
ui.scope(|ui| {
|
||||
ui.vertical(|ui| {
|
||||
ui.set_max_width(ui.available_width() - theme::GAP_L);
|
||||
ui.label(RichText::new("User scripts (.user.js) and user styles (.user.css) change sites the way extensions do. They run on matching pages from their next load. Opening a .user.js link offers to install it.").font(theme::font(theme::SMALL, Weight::Regular)).color(f.palette().on_surface_variant));
|
||||
});
|
||||
|
|
|
|||
|
|
@ -4,102 +4,149 @@
|
|||
|
||||
use egui::{RichText, Ui};
|
||||
|
||||
use super::super::widgets::{ButtonKind, button, choice_chips, empty_state, icon_button, text_field};
|
||||
use super::super::Frame;
|
||||
use crate::actions::Command;
|
||||
use crate::theme::{self, Weight};
|
||||
use crate::ui::icons;
|
||||
use crate::util;
|
||||
|
||||
/// A recessed panel for log text: a step above the page, large corners.
|
||||
fn panel<R>(ui: &mut Ui, height: f32, contents: impl FnOnce(&mut Ui) -> R) -> R {
|
||||
let p = theme::palette(ui.ctx());
|
||||
egui::Frame::NONE.fill(p.surface_container).corner_radius(theme::corner_radius(theme::radius(ui.ctx(), theme::L))).inner_margin(theme::GAP_M as i8).show(ui, |ui| {
|
||||
ui.set_min_height(height.max(80.0));
|
||||
ui.set_min_width(ui.available_width());
|
||||
contents(ui)
|
||||
}).inner
|
||||
}
|
||||
|
||||
pub fn draw(ui: &mut Ui, f: &mut Frame) {
|
||||
let p = f.palette();
|
||||
let target = f.ui.devtools_target.and_then(|id| f.tabs.iter().find(|t| t.id == id)).or_else(|| f.tabs.iter().find(|t| t.page.is_none()));
|
||||
let Some(target) = target else {
|
||||
ui.vertical_centered(|ui| {
|
||||
ui.add_space(40.0);
|
||||
ui.label("Open a web page in this window, then come back here.");
|
||||
});
|
||||
empty_state(ui, icons::BUG_REPORT, "No page to inspect", "Open a web page in this window, then come back here to see its console and requests.", None);
|
||||
return;
|
||||
};
|
||||
let target_id = target.id;
|
||||
let target_title = target.display_title();
|
||||
let webview = target.webview_id();
|
||||
ui.horizontal(|ui| {
|
||||
ui.heading("Developer tools");
|
||||
ui.label(RichText::new(format!("for {}", util::ellipsize(&target_title, 60))).weak());
|
||||
egui::ComboBox::from_id_salt("devtools-target").selected_text("Other tab").show_ui(ui, |ui| {
|
||||
for tab in f.tabs.iter().filter(|t| t.page.is_none()) {
|
||||
if ui.selectable_label(tab.id == target_id, util::ellipsize(&tab.display_title(), 50)).clicked() {
|
||||
f.ui.devtools_target = Some(tab.id);
|
||||
}
|
||||
}
|
||||
});
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
let remote = f.shared.settings.borrow().web.remote_debugging;
|
||||
if ui.button(if remote { "Remote debugging: on" } else { "Remote debugging: off" }).on_hover_text("Firefox → about:debugging → connect to localhost:6080 (restart to apply)").clicked() {
|
||||
f.send(Command::ToggleRemoteDebugging);
|
||||
}
|
||||
});
|
||||
});
|
||||
f.ui.devtools_target = Some(target_id);
|
||||
ui.horizontal(|ui| {
|
||||
for (i, name) in ["Console", "Network", "Elements"].iter().enumerate() {
|
||||
if ui.selectable_label(f.ui.pages.devtools_tab == i, *name).clicked() {
|
||||
f.ui.pages.devtools_tab = i;
|
||||
}
|
||||
}
|
||||
});
|
||||
ui.separator();
|
||||
match f.ui.pages.devtools_tab {
|
||||
0 => {
|
||||
let palette = f.palette();
|
||||
let lines: Vec<(servo::ConsoleLogLevel, String, u64)> = f.tabs.iter().find(|t| t.id == target_id).map(|t| t.console.iter().map(|l| (l.level.clone(), l.text.clone(), l.time_ms)).collect()).unwrap_or_default();
|
||||
egui::ScrollArea::vertical().stick_to_bottom(true).max_height(ui.available_height() - 40.0).auto_shrink([false, false]).show(ui, |ui| {
|
||||
for (level, text, time) in lines {
|
||||
let color = match level {
|
||||
servo::ConsoleLogLevel::Error => palette.error,
|
||||
servo::ConsoleLogLevel::Warn => palette.warning,
|
||||
servo::ConsoleLogLevel::Debug | servo::ConsoleLogLevel::Trace => palette.text_weak,
|
||||
_ => palette.text,
|
||||
};
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.label(RichText::new(util::format_clock(time / 1000)).weak().monospace().small());
|
||||
ui.label(RichText::new(text).color(color).monospace());
|
||||
});
|
||||
egui::Frame::NONE.inner_margin(egui::Margin::symmetric(theme::GAP_L as i8, theme::GAP_S as i8)).show(ui, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(RichText::new("Developer tools").font(theme::font(theme::HEADLINE, Weight::Medium)).color(p.on_surface));
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
let remote = f.shared.settings.borrow().web.remote_debugging;
|
||||
let kind = if remote { ButtonKind::Tonal } else { ButtonKind::Outlined };
|
||||
if button(ui, kind, Some(icons::BUG_REPORT), if remote { "Remote debugging on" } else { "Remote debugging off" }).on_hover_text("Firefox: about:debugging, then connect to localhost:6080. Restart Nacre to apply.").clicked() {
|
||||
f.send(Command::ToggleRemoteDebugging);
|
||||
}
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
let r = ui.add(egui::TextEdit::singleline(&mut f.ui.pages.devtools_input).hint_text("JavaScript to run in the page").code_editor().desired_width(ui.available_width() - 80.0));
|
||||
let run = ui.button("Run").clicked() || (r.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter)));
|
||||
if run && !f.ui.pages.devtools_input.trim().is_empty() {
|
||||
let script = std::mem::take(&mut f.ui.pages.devtools_input);
|
||||
f.send(Command::DevToolsEval(script));
|
||||
r.request_focus();
|
||||
}
|
||||
});
|
||||
},
|
||||
1 => {
|
||||
let entries: Vec<crate::hub::NetEntry> = webview.and_then(|id| f.hub.net_log.borrow().get(&id).map(|log| log.iter().cloned().collect())).unwrap_or_default();
|
||||
ui.label(RichText::new(format!("{} requests · {} blocked", entries.len(), entries.iter().filter(|e| e.blocked).count())).weak());
|
||||
egui::ScrollArea::vertical().auto_shrink([false, false]).show(ui, |ui| {
|
||||
egui::Grid::new("net").num_columns(4).striped(true).show(ui, |ui| {
|
||||
for e in entries.iter().rev() {
|
||||
ui.label(RichText::new(&e.method).monospace());
|
||||
ui.label(RichText::new(&e.kind).weak());
|
||||
ui.label(if e.blocked { RichText::new("blocked").color(f.palette().error) } else { RichText::new("") });
|
||||
ui.label(RichText::new(util::ellipsize(&e.url, 120)).monospace().small()).on_hover_text(&e.url);
|
||||
ui.end_row();
|
||||
});
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.spacing_mut().item_spacing = egui::vec2(theme::GAP_S, theme::GAP_S);
|
||||
ui.label(RichText::new(format!("for {}", util::ellipsize(&target_title, 60))).font(theme::font(theme::BODY, Weight::Regular)).color(p.on_surface_variant));
|
||||
let others: Vec<(u64, String)> = f.tabs.iter().filter(|t| t.page.is_none() && t.id != target_id).map(|t| (t.id, util::ellipsize(&t.display_title(), 40))).collect();
|
||||
if !others.is_empty() {
|
||||
ui.menu_button(format!("{} Other tab", icons::EXPAND_MORE), |ui| {
|
||||
for (id, title) in others {
|
||||
if ui.button(title).clicked() {
|
||||
f.ui.devtools_target = Some(id);
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
_ => {
|
||||
ui.label(RichText::new("The page's HTML as it is now (after scripts ran) shows in the console:").weak());
|
||||
if ui.button("Print document.documentElement.outerHTML").clicked() {
|
||||
f.send(Command::DevToolsEval("document.documentElement.outerHTML".into()));
|
||||
f.ui.pages.devtools_tab = 0;
|
||||
}
|
||||
if ui.button("View the original source").clicked()
|
||||
&& let Some(url) = f.tabs.iter().find(|t| t.id == target_id).map(|t| t.url.clone())
|
||||
{
|
||||
f.send(Command::Open { url: crate::tabs::Page::Source(url).url(), how: crate::actions::Disposition::NewForegroundTab, from: None });
|
||||
});
|
||||
ui.add_space(theme::GAP_S);
|
||||
f.ui.devtools_target = Some(target_id);
|
||||
let mut tab = f.ui.pages.devtools_tab;
|
||||
if choice_chips(ui, &mut tab, &[(0usize, "Console"), (1, "Network"), (2, "Elements")]) {
|
||||
f.ui.pages.devtools_tab = tab;
|
||||
}
|
||||
ui.add_space(theme::GAP_M);
|
||||
match f.ui.pages.devtools_tab {
|
||||
0 => console(ui, f, target_id),
|
||||
1 => network(ui, f, webview),
|
||||
_ => elements(ui, f, target_id),
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn console(ui: &mut Ui, f: &mut Frame, target_id: u64) {
|
||||
let palette = f.palette();
|
||||
let lines: Vec<(servo::ConsoleLogLevel, String, u64)> = f.tabs.iter().find(|t| t.id == target_id).map(|t| t.console.iter().map(|l| (l.level.clone(), l.text.clone(), l.time_ms)).collect()).unwrap_or_default();
|
||||
let height = ui.available_height() - theme::CONTROL - 3.0 * theme::GAP_L;
|
||||
panel(ui, height, |ui| {
|
||||
if lines.is_empty() {
|
||||
ui.label(RichText::new("Nothing logged yet. Messages from the page and results of what you run below show here.").font(theme::font(theme::SMALL, Weight::Regular)).color(palette.on_surface_variant));
|
||||
}
|
||||
egui::ScrollArea::vertical().stick_to_bottom(true).max_height(height).auto_shrink([false, false]).show(ui, |ui| {
|
||||
for (level, text, time) in lines {
|
||||
let color = match level {
|
||||
servo::ConsoleLogLevel::Error => palette.error,
|
||||
servo::ConsoleLogLevel::Warn => palette.warning,
|
||||
servo::ConsoleLogLevel::Debug | servo::ConsoleLogLevel::Trace => palette.on_surface_variant,
|
||||
_ => palette.on_surface,
|
||||
};
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.label(RichText::new(util::format_clock(time / 1000)).monospace().small().color(palette.on_surface_variant));
|
||||
ui.label(RichText::new(text).color(color).monospace());
|
||||
});
|
||||
}
|
||||
},
|
||||
}
|
||||
});
|
||||
});
|
||||
ui.add_space(theme::GAP_S);
|
||||
ui.horizontal(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = theme::GAP_S;
|
||||
let r = text_field(ui, &mut f.ui.pages.devtools_input, "JavaScript to run in the page", ui.available_width() - 100.0);
|
||||
let run = button(ui, ButtonKind::Filled, Some(icons::PLAY_ARROW), "Run").clicked() || (r.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter)));
|
||||
if run && !f.ui.pages.devtools_input.trim().is_empty() {
|
||||
let script = std::mem::take(&mut f.ui.pages.devtools_input);
|
||||
f.send(Command::DevToolsEval(script));
|
||||
r.request_focus();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn network(ui: &mut Ui, f: &mut Frame, webview: Option<servo::WebViewId>) {
|
||||
let p = f.palette();
|
||||
let entries: Vec<crate::hub::NetEntry> = webview.and_then(|id| f.hub.net_log.borrow().get(&id).map(|log| log.iter().cloned().collect())).unwrap_or_default();
|
||||
ui.label(RichText::new(format!("{} requests, {} blocked", entries.len(), entries.iter().filter(|e| e.blocked).count())).font(theme::font(theme::SMALL, Weight::Medium)).color(p.on_surface_variant));
|
||||
ui.add_space(theme::GAP_S);
|
||||
let height = ui.available_height() - theme::GAP_L;
|
||||
panel(ui, height, |ui| {
|
||||
if entries.is_empty() {
|
||||
ui.label(RichText::new("No requests yet. Load or reload the page to see what it asks for.").font(theme::font(theme::SMALL, Weight::Regular)).color(p.on_surface_variant));
|
||||
}
|
||||
egui::ScrollArea::vertical().max_height(height).auto_shrink([false, false]).show(ui, |ui| {
|
||||
egui::Grid::new("net").num_columns(4).spacing([theme::GAP_L, theme::GAP_XS]).show(ui, |ui| {
|
||||
for e in entries.iter().rev() {
|
||||
ui.label(RichText::new(&e.method).monospace().color(p.on_surface));
|
||||
ui.label(RichText::new(&e.kind).color(p.on_surface_variant));
|
||||
ui.label(if e.blocked { RichText::new("blocked").color(p.error) } else { RichText::new("") });
|
||||
ui.label(RichText::new(util::ellipsize(&e.url, 120)).monospace().small().color(p.on_surface)).on_hover_text(&e.url);
|
||||
ui.end_row();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn elements(ui: &mut Ui, f: &mut Frame, target_id: u64) {
|
||||
let p = f.palette();
|
||||
ui.label(RichText::new("The page's HTML as it is now, after scripts ran, is printed in the console.").font(theme::font(theme::BODY, Weight::Regular)).color(p.on_surface_variant));
|
||||
ui.add_space(theme::GAP_M);
|
||||
ui.horizontal(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = theme::GAP_S;
|
||||
if button(ui, ButtonKind::Tonal, Some(icons::CODE), "Print the current HTML").clicked() {
|
||||
f.send(Command::DevToolsEval("document.documentElement.outerHTML".into()));
|
||||
f.ui.pages.devtools_tab = 0;
|
||||
}
|
||||
if button(ui, ButtonKind::Outlined, Some(icons::OPEN_IN_NEW), "View the original source").clicked()
|
||||
&& let Some(url) = f.tabs.iter().find(|t| t.id == target_id).map(|t| t.url.clone())
|
||||
{
|
||||
f.send(Command::Open { url: crate::tabs::Page::Source(url).url(), how: crate::actions::Disposition::NewForegroundTab, from: None });
|
||||
}
|
||||
});
|
||||
let _ = icon_button;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,46 +1,76 @@
|
|||
//! Smaller pages: site settings, delete browsing data, about, first-run setup, task manager,
|
||||
//! page source, and errors.
|
||||
//! Smaller pages: site settings, delete browsing data, about, task manager, page source, and errors.
|
||||
//! (The first-run setup is in welcome.rs.)
|
||||
|
||||
use egui::{RichText, Ui};
|
||||
use egui::{RichText, Sense, Stroke, Ui, vec2};
|
||||
|
||||
use super::super::widgets::{card, page_column, row, segmented, switch, switch_row};
|
||||
use super::super::Frame;
|
||||
use super::super::widgets::{ButtonKind, button, card, empty_state, icon, icon_button, icon_row, icon_link_row, list_item, page_column, page_header, row, search_pill, section, segmented, status_state, switch, switch_row};
|
||||
use super::super::{Frame, paint};
|
||||
use crate::actions::Command;
|
||||
use crate::store::permissions::{Decision, Kind};
|
||||
use crate::store::settings::{ColourSource, DohProvider, ThemeMode};
|
||||
use crate::tabs::Page;
|
||||
use crate::util;
|
||||
use crate::theme::{self, Weight};
|
||||
use crate::ui::icons;
|
||||
use crate::util;
|
||||
|
||||
/// A sub-page header: a back button and the page title.
|
||||
fn back_header(ui: &mut Ui, title: &str, back_to: &str) -> bool {
|
||||
let p = theme::palette(ui.ctx());
|
||||
let mut back = false;
|
||||
ui.add_space(theme::GAP_S);
|
||||
ui.horizontal(|ui| {
|
||||
ui.set_min_height(theme::CONTROL);
|
||||
ui.add_space(theme::GAP_XS);
|
||||
back = icon_button(ui, icons::ARROW_BACK, &format!("Back to {back_to}")).clicked();
|
||||
ui.add_space(theme::GAP_XS);
|
||||
ui.label(RichText::new(title).font(theme::font(theme::HEADLINE, Weight::Medium)).color(p.on_surface));
|
||||
});
|
||||
ui.add_space(theme::GAP_M);
|
||||
back
|
||||
}
|
||||
|
||||
pub fn site_settings(ui: &mut Ui, f: &mut Frame, host: &str) {
|
||||
page_column(ui, "site-settings", 860.0, |ui| {
|
||||
if host.is_empty() {
|
||||
ui.heading("Site settings");
|
||||
ui.label(RichText::new("Sites you answered a permission request for. Defaults are in Settings → Privacy → Site settings.").weak());
|
||||
ui.add(egui::TextEdit::singleline(&mut f.ui.pages.site_search).hint_text("Search sites").desired_width(f32::INFINITY));
|
||||
page_header(ui, "Site settings", "Sites you answered a permission request for. The defaults are in Settings, under Privacy.", |ui| {
|
||||
if button(ui, ButtonKind::Text, Some(icons::SETTINGS), "Defaults").clicked() {
|
||||
f.send(Command::ShowPage(Page::Settings("permissions".into())));
|
||||
}
|
||||
});
|
||||
search_pill(ui, "sites", &mut f.ui.pages.site_search, "Search sites");
|
||||
let all = f.shared.permissions.borrow().all();
|
||||
let mut hosts: Vec<String> = all.iter().map(|(h, ..)| h.clone()).collect();
|
||||
hosts.dedup();
|
||||
let q = f.ui.pages.site_search.to_lowercase();
|
||||
card(ui, |ui| {
|
||||
let shown: Vec<&String> = hosts.iter().filter(|h| q.is_empty() || h.contains(&q)).collect();
|
||||
if shown.is_empty() {
|
||||
if hosts.is_empty() {
|
||||
ui.label(RichText::new("No sites yet.").weak());
|
||||
empty_state(ui, icons::PUBLIC, "No sites yet", "When a site asks for the camera, location or notifications and you answer, it shows up here so you can change your mind.", None);
|
||||
} else {
|
||||
empty_state(ui, icons::SEARCH, "Nothing matches", &format!("No site matches \"{}\".", q.trim()), None);
|
||||
}
|
||||
for h in hosts.iter().filter(|h| q.is_empty() || h.contains(&q)) {
|
||||
let summary: Vec<String> = all.iter().filter(|(x, ..)| x == h).map(|(_, k, d)| format!("{} {}", k.label(), if *d == Decision::Allow { icons::CHECK } else { icons::CLOSE })).collect();
|
||||
if row(ui, h, &summary.join(" · "), |ui| ui.button(icons::CHEVRON_RIGHT).clicked()) {
|
||||
return;
|
||||
}
|
||||
section(ui, &format!("{} {}", shown.len(), if shown.len() == 1 { "site" } else { "sites" }));
|
||||
card(ui, |ui| {
|
||||
for h in shown {
|
||||
let summary: Vec<String> = all.iter().filter(|(x, ..)| x == h).map(|(_, k, d)| format!("{} {}", k.label(), if *d == Decision::Allow { "allowed" } else { "blocked" })).collect();
|
||||
let r = list_item(ui, h, Some(icons::LANGUAGE), h, &summary.join(" · "), |ui| {
|
||||
let (rect, _) = ui.allocate_exact_size(vec2(24.0, 24.0), Sense::hover());
|
||||
icon(ui, rect.center(), icons::CHEVRON_RIGHT, theme::ICON, false, theme::palette(ui.ctx()).on_surface_variant);
|
||||
});
|
||||
if r.clicked() {
|
||||
f.send(Command::ShowPage(Page::SiteSettings(h.clone())));
|
||||
}
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
if ui.button("‹ All sites").clicked() {
|
||||
if back_header(ui, host, "all sites") {
|
||||
f.send(Command::ShowPage(Page::SiteSettings(String::new())));
|
||||
}
|
||||
ui.heading(host);
|
||||
let mut s = f.shared.settings.borrow().clone();
|
||||
let before = s.clone();
|
||||
section(ui, "Permissions");
|
||||
card(ui, |ui| {
|
||||
for kind in Kind::ALL {
|
||||
let current = f.shared.permissions.borrow().site_decision(host, *kind);
|
||||
|
|
@ -62,9 +92,10 @@ pub fn site_settings(ui: &mut Ui, f: &mut Frame, host: &str) {
|
|||
}
|
||||
}
|
||||
});
|
||||
section(ui, "This site");
|
||||
card(ui, |ui| {
|
||||
let mut ads = !s.adblock_paused_on(host);
|
||||
if switch_row(ui, "Block ads on this site", "", &mut ads) {
|
||||
if switch_row(ui, "Block ads", "", &mut ads) {
|
||||
if ads {
|
||||
s.adblock.allow.retain(|h| !util::host_matches(host, h));
|
||||
} else {
|
||||
|
|
@ -72,7 +103,7 @@ pub fn site_settings(ui: &mut Ui, f: &mut Frame, host: &str) {
|
|||
}
|
||||
}
|
||||
let mut active = s.keeps_active(host);
|
||||
if switch_row(ui, "Always keep active", "Its tabs are never frozen or unloaded", &mut active) {
|
||||
if switch_row(ui, "Always keep active", "Its tabs are never frozen or unloaded.", &mut active) {
|
||||
if active {
|
||||
s.perf.keep_active.push(host.to_owned());
|
||||
} else {
|
||||
|
|
@ -84,19 +115,19 @@ pub fn site_settings(ui: &mut Ui, f: &mut Frame, host: &str) {
|
|||
f.send(Command::ToggleMuteSite(host.to_owned()));
|
||||
}
|
||||
let mut http = s.privacy.https_exceptions.iter().any(|h| h == host);
|
||||
if switch_row(ui, "Allow without HTTPS", "Only matters when HTTPS-only mode is on", &mut http) {
|
||||
if switch_row(ui, "Allow without HTTPS", "Only matters when HTTPS-only mode is on.", &mut http) {
|
||||
if http {
|
||||
s.privacy.https_exceptions.push(host.to_owned());
|
||||
} else {
|
||||
s.privacy.https_exceptions.retain(|h| h != host);
|
||||
}
|
||||
}
|
||||
if let Some(zoom) = s.web.zoom_sites.get(host).copied() {
|
||||
if row(ui, "Zoom", &format!("{:.0}%", zoom * 100.0), |ui| ui.button("Reset").clicked()) {
|
||||
s.web.zoom_sites.remove(host);
|
||||
}
|
||||
if let Some(zoom) = s.web.zoom_sites.get(host).copied()
|
||||
&& row(ui, "Zoom", &format!("{:.0}%", zoom * 100.0), |ui| button(ui, ButtonKind::Outlined, None, "Reset").clicked())
|
||||
{
|
||||
s.web.zoom_sites.remove(host);
|
||||
}
|
||||
if row(ui, "Cookies and site data", "Stored by this site in Nacre", |ui| ui.button("Delete").clicked()) {
|
||||
if row(ui, "Cookies and site data", "Stored by this site in Nacre.", |ui| button(ui, ButtonKind::Outlined, Some(icons::DELETE), "Delete").clicked()) {
|
||||
f.send(Command::ClearSiteData(host.to_owned()));
|
||||
}
|
||||
});
|
||||
|
|
@ -107,14 +138,14 @@ pub fn site_settings(ui: &mut Ui, f: &mut Frame, host: &str) {
|
|||
}
|
||||
|
||||
const RANGES: &[(&str, u64)] = &[("Last hour", 3600), ("Last 24 hours", 86_400), ("Last 7 days", 7 * 86_400), ("Last 4 weeks", 28 * 86_400), ("All time", 0)];
|
||||
const WHAT: &[(&str, &str, &str)] = &[
|
||||
("history", "Browsing history", "Pages you visited and recently closed tabs"),
|
||||
("cookies", "Cookies and site data", "Signs you out of most sites"),
|
||||
("cache", "Cached files", "Pages load a little slower the first time"),
|
||||
("downloads", "Download list", "Files stay on disk"),
|
||||
("permissions", "Site permissions", ""),
|
||||
("passwords", "Passwords", ""),
|
||||
("autofill", "Addresses and cards", ""),
|
||||
const WHAT: &[(&str, &str, &str, &str)] = &[
|
||||
("history", icons::HISTORY, "Browsing history", "Pages you visited and recently closed tabs."),
|
||||
("cookies", icons::COOKIE, "Cookies and site data", "Signs you out of most sites."),
|
||||
("cache", icons::STORAGE, "Cached files", "Pages load a little slower the first time."),
|
||||
("downloads", icons::DOWNLOAD, "Download list", "The files stay on disk."),
|
||||
("permissions", icons::SHIELD, "Site permissions", "Answers you gave to permission requests."),
|
||||
("passwords", icons::PASSWORD, "Passwords", "Saved logins."),
|
||||
("autofill", icons::CREDIT_CARD, "Addresses and cards", "Saved for filling forms."),
|
||||
];
|
||||
|
||||
pub fn clear_data(ui: &mut Ui, f: &mut Frame) {
|
||||
|
|
@ -122,15 +153,20 @@ pub fn clear_data(ui: &mut Ui, f: &mut Frame) {
|
|||
f.ui.pages.clear_what = vec!["history".into(), "cookies".into(), "cache".into()];
|
||||
}
|
||||
page_column(ui, "clear-data", 640.0, |ui| {
|
||||
ui.heading("Delete browsing data");
|
||||
page_header(ui, "Clear browsing data", "Choose what to remove from this profile.", |_| {});
|
||||
let p = f.palette();
|
||||
section(ui, "Time range");
|
||||
card(ui, |ui| {
|
||||
let mut range = f.ui.pages.clear_range;
|
||||
let opts: Vec<(usize, &str)> = RANGES.iter().enumerate().map(|(i, (l, _))| (i, *l)).collect();
|
||||
row(ui, "Time range", "", |ui| segmented(ui, &mut range, &opts));
|
||||
super::super::widgets::wide_row(ui, "Remove data from", "", |ui| segmented(ui, &mut range, &opts));
|
||||
f.ui.pages.clear_range = range;
|
||||
for (key, label, desc) in WHAT {
|
||||
});
|
||||
section(ui, "Data");
|
||||
card(ui, |ui| {
|
||||
for (key, glyph, label, desc) in WHAT {
|
||||
let mut on = f.ui.pages.clear_what.iter().any(|k| k == key);
|
||||
if switch_row(ui, label, desc, &mut on) {
|
||||
if icon_row(ui, glyph, label, desc, |ui| switch(ui, &mut on)) {
|
||||
if on {
|
||||
f.ui.pages.clear_what.push((*key).to_owned());
|
||||
} else {
|
||||
|
|
@ -139,215 +175,161 @@ pub fn clear_data(ui: &mut Ui, f: &mut Frame) {
|
|||
}
|
||||
}
|
||||
});
|
||||
ui.label(RichText::new("Cookies, cache, permissions and passwords are deleted whatever the time range; Servo keeps no dates for them.").weak().small());
|
||||
if ui.button(RichText::new("Delete data").strong()).clicked() {
|
||||
let seconds = RANGES[f.ui.pages.clear_range.min(RANGES.len() - 1)].1;
|
||||
let since = if seconds == 0 { 0 } else { util::now().saturating_sub(seconds) };
|
||||
f.send(Command::ClearData { since, what: f.ui.pages.clear_what.clone() });
|
||||
}
|
||||
ui.add_space(theme::GAP_S);
|
||||
ui.horizontal(|ui| {
|
||||
ui.add_space(theme::GAP_L);
|
||||
ui.vertical(|ui| {
|
||||
ui.set_max_width(ui.available_width() - theme::GAP_L);
|
||||
ui.label(RichText::new("Cookies, cache, permissions and passwords are removed whatever the time range, because Servo keeps no dates for them.").font(theme::font(theme::SMALL, Weight::Regular)).color(p.on_surface_variant));
|
||||
});
|
||||
});
|
||||
ui.add_space(theme::GAP_L);
|
||||
ui.horizontal(|ui| {
|
||||
ui.add_space(theme::GAP_L);
|
||||
let any = !f.ui.pages.clear_what.is_empty();
|
||||
if ui.add_enabled_ui(any, |ui| button(ui, ButtonKind::Filled, Some(icons::DELETE), "Delete data")).inner.clicked() {
|
||||
let seconds = RANGES[f.ui.pages.clear_range.min(RANGES.len() - 1)].1;
|
||||
let since = if seconds == 0 { 0 } else { util::now().saturating_sub(seconds) };
|
||||
f.send(Command::ClearData { since, what: f.ui.pages.clear_what.clone() });
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
pub fn about(ui: &mut Ui, f: &mut Frame) {
|
||||
page_column(ui, "about", 640.0, |ui| {
|
||||
let p = f.palette();
|
||||
ui.add_space(theme::GAP_XL);
|
||||
ui.vertical_centered(|ui| {
|
||||
ui.add_space(20.0);
|
||||
ui.label(RichText::new("Nacre").size(40.0).strong());
|
||||
ui.label(format!("Version {}", crate::updates::current_version()));
|
||||
ui.label(RichText::new("Servo 0.7.0 engine · written in Rust").weak());
|
||||
let (rect, _) = ui.allocate_exact_size(vec2(120.0, 120.0), Sense::hover());
|
||||
paint::cookie(ui.painter(), rect.center(), 54.0, 9, 0.0, p.primary_container, Stroke::NONE);
|
||||
icon(ui, rect.center(), icons::DIAMOND, 56.0, true, p.on_primary_container);
|
||||
ui.add_space(theme::GAP_M);
|
||||
ui.label(RichText::new("Nacre").font(theme::font(theme::DISPLAY_SMALL, Weight::SemiBold)).color(p.on_surface));
|
||||
ui.label(RichText::new(format!("Version {}", crate::updates::current_version())).font(theme::font(theme::BODY, Weight::Regular)).color(p.on_surface_variant));
|
||||
ui.label(RichText::new("Servo 0.7.0 engine, written in Rust").font(theme::font(theme::SMALL, Weight::Regular)).color(p.on_surface_variant));
|
||||
});
|
||||
ui.add_space(16.0);
|
||||
ui.add_space(theme::GAP_L);
|
||||
card(ui, |ui| {
|
||||
let status = f.shared.update_status.borrow().clone();
|
||||
if row(ui, "Updates", if status.is_empty() { "Not checked yet" } else { &status }, |ui| ui.button("Check now").clicked()) {
|
||||
if icon_row(ui, icons::SYNC, "Updates", if status.is_empty() { "Not checked yet" } else { &status }, |ui| button(ui, ButtonKind::Tonal, None, "Check now").clicked()) {
|
||||
f.send(Command::CheckUpdates);
|
||||
}
|
||||
if f.shared.update.borrow().is_some() && row(ui, "A new version is ready", "", |ui| ui.button("Get it").clicked()) {
|
||||
if f.shared.update.borrow().is_some() && icon_row(ui, icons::DOWNLOAD, "A new version is ready", "", |ui| button(ui, ButtonKind::Filled, None, "Get it").clicked()) {
|
||||
f.send(Command::OpenUpdate);
|
||||
}
|
||||
let repo = f.shared.settings.borrow().update.repo.clone();
|
||||
if !repo.is_empty() && row(ui, "Source code and releases", &repo, |ui| ui.button("Open").clicked()) {
|
||||
if !repo.is_empty() && icon_row(ui, icons::CODE, "Source code and releases", &repo, |ui| button(ui, ButtonKind::Outlined, Some(icons::OPEN_IN_NEW), "Open").clicked()) {
|
||||
f.send(Command::Open { url: repo, how: crate::actions::Disposition::NewForegroundTab, from: None });
|
||||
}
|
||||
row(ui, "Licence", "Mozilla Public License 2.0 (Servo and Nacre)", |_| ());
|
||||
row(ui, "Engine limits", "No DRM video (Widevine), no Chrome extensions (use scripts and styles), no printing (save as PDF instead)", |_| ());
|
||||
icon_row(ui, icons::INFO, "Licence", "Mozilla Public License 2.0 (Servo and Nacre)", |_| ());
|
||||
icon_row(ui, icons::WARNING, "What the engine can't do", "No DRM video (Widevine), no Chrome extensions (use scripts and styles instead), no printing (save as PDF instead).", |_| ());
|
||||
});
|
||||
let _ = icon_link_row;
|
||||
});
|
||||
}
|
||||
|
||||
/// First run: a few choices, then the new tab page.
|
||||
pub fn welcome(ui: &mut Ui, f: &mut Frame) {
|
||||
let mut s = f.shared.settings.borrow().clone();
|
||||
let before = s.clone();
|
||||
page_column(ui, "welcome", 640.0, |ui| {
|
||||
let step = f.ui.pages.welcome_step;
|
||||
ui.add_space(20.0);
|
||||
match step {
|
||||
0 => {
|
||||
ui.label(RichText::new("Welcome to Nacre").size(32.0).strong());
|
||||
ui.label("A few choices and you're ready. You can change all of them later in Settings.");
|
||||
let sources = f.shared.import_sources.borrow().clone();
|
||||
if !sources.is_empty() {
|
||||
ui.add_space(12.0);
|
||||
ui.label(RichText::new("Bring your bookmarks and history").strong());
|
||||
card(ui, |ui| {
|
||||
for (i, src) in sources.iter().enumerate() {
|
||||
if row(ui, &src.name(), "Bookmarks, history, home page and search engine", |ui| ui.button("Import").clicked()) {
|
||||
f.send(Command::Import { source: i, bookmarks: true, history: true, settings: true });
|
||||
}
|
||||
}
|
||||
});
|
||||
let status = f.shared.import_status.borrow().clone();
|
||||
if !status.is_empty() {
|
||||
ui.label(RichText::new(status).weak());
|
||||
}
|
||||
}
|
||||
},
|
||||
1 => {
|
||||
ui.label(RichText::new("Search").size(26.0).strong());
|
||||
card(ui, |ui| {
|
||||
for (key, name, _, _) in s.search_engines() {
|
||||
ui.radio_value(&mut s.startup.search_engine, key, name);
|
||||
}
|
||||
});
|
||||
},
|
||||
2 => {
|
||||
ui.label(RichText::new("Look").size(26.0).strong());
|
||||
card(ui, |ui| {
|
||||
row(ui, "Mode", "", |ui| segmented(ui, &mut s.theme.mode, ThemeMode::ALL));
|
||||
row(ui, "Colours", "", |ui| segmented(ui, &mut s.theme.source, ColourSource::ALL));
|
||||
});
|
||||
},
|
||||
3 => {
|
||||
ui.label(RichText::new("Privacy").size(26.0).strong());
|
||||
card(ui, |ui| {
|
||||
switch_row(ui, "Block ads and trackers", "", &mut s.adblock.enabled);
|
||||
switch_row(ui, "HTTPS-only mode", "", &mut s.privacy.https_only);
|
||||
switch_row(ui, "Privacy mode", "Hides your browser's fingerprint", &mut s.privacy.mode);
|
||||
row(ui, "Secure DNS", "", |ui| {
|
||||
egui::ComboBox::from_id_salt("welcome-doh").selected_text(s.privacy.doh.label()).show_ui(ui, |ui| {
|
||||
for (v, l) in DohProvider::ALL {
|
||||
ui.selectable_value(&mut s.privacy.doh, *v, *l);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
_ => {
|
||||
ui.label(RichText::new("You're ready").size(32.0).strong());
|
||||
ui.label("Nacre is set up. Have a look at the new tab page and the menu ☰ for everything else.");
|
||||
},
|
||||
}
|
||||
ui.add_space(16.0);
|
||||
ui.horizontal(|ui| {
|
||||
if step > 0 && ui.button("Back").clicked() {
|
||||
f.ui.pages.welcome_step -= 1;
|
||||
}
|
||||
if step < 4 {
|
||||
if ui.button(RichText::new("Next").strong()).clicked() {
|
||||
f.ui.pages.welcome_step += 1;
|
||||
}
|
||||
if ui.button("Skip setup").clicked() {
|
||||
s.startup.welcome_done = true;
|
||||
s.startup.import_offered = true;
|
||||
f.send(Command::Navigate("nacre://newtab".into()));
|
||||
}
|
||||
} else if ui.button(RichText::new("Start browsing").strong()).clicked() {
|
||||
s.startup.welcome_done = true;
|
||||
s.startup.import_offered = true;
|
||||
f.ui.pages.welcome_step = 0;
|
||||
f.send(Command::Navigate("nacre://newtab".into()));
|
||||
}
|
||||
});
|
||||
});
|
||||
if s != before {
|
||||
*f.shared.settings.borrow_mut() = s;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn task_manager(ui: &mut Ui, f: &mut Frame) {
|
||||
page_column(ui, "task-manager", 860.0, |ui| {
|
||||
ui.heading("Task manager");
|
||||
let p = f.palette();
|
||||
let (total, available) = crate::perf::system_memory();
|
||||
ui.label(format!("Nacre uses {} with {} threads · {} of {} memory free", util::format_bytes(crate::perf::own_memory()), crate::perf::own_threads(), util::format_bytes(available), util::format_bytes(total)));
|
||||
ui.label(RichText::new("Servo runs every page in Nacre's own process, so memory isn't split per tab.").weak().small());
|
||||
ui.add_space(8.0);
|
||||
page_header(ui, "Task manager", "Servo runs every page in Nacre's own process, so memory isn't split per tab.", |ui| {
|
||||
if button(ui, ButtonKind::Tonal, Some(icons::MEMORY), "Unload background tabs").clicked() {
|
||||
f.send(Command::FreeMemory);
|
||||
}
|
||||
});
|
||||
// Three figures: what Nacre uses, its threads and what the computer has left.
|
||||
let figures = [("Nacre uses", util::format_bytes(crate::perf::own_memory())), ("Threads", crate::perf::own_threads().to_string()), ("Memory free", format!("{} of {}", util::format_bytes(available), util::format_bytes(total)))];
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.spacing_mut().item_spacing = vec2(theme::GAP_M, theme::GAP_M);
|
||||
let w = (((ui.available_width() - 2.0 * theme::GAP_M) / 3.0).floor() - 1.0).max(180.0);
|
||||
for (name, value) in figures {
|
||||
let (rect, _) = ui.allocate_exact_size(vec2(w, 88.0), Sense::hover());
|
||||
ui.painter().rect_filled(rect, theme::corner_radius(theme::radius(ui.ctx(), theme::L)), p.surface_container);
|
||||
ui.painter().text(rect.left_top() + vec2(theme::GAP_L, theme::GAP_M), egui::Align2::LEFT_TOP, name, theme::font(theme::SMALL, Weight::Medium), p.on_surface_variant);
|
||||
let galley = super::super::menus::one_line(ui, &value, theme::font(theme::TITLE + 4.0, Weight::Medium), p.on_surface, w - 2.0 * theme::GAP_L);
|
||||
ui.painter().galley(rect.left_top() + vec2(theme::GAP_L, 44.0), galley, p.on_surface);
|
||||
}
|
||||
});
|
||||
let rows: Vec<(u64, String, &'static str, bool)> = f
|
||||
.tabs
|
||||
.iter()
|
||||
.map(|t| {
|
||||
let state = if t.page.is_some() { "Nacre page" } else if t.web.is_none() { "Unloaded" } else if t.frozen { "Frozen" } else if t.audible() { "Playing" } else if t.loading() { "Loading" } else { "Running" };
|
||||
let state = if t.page.is_some() { "Nacre page" } else if t.web.is_none() { "Unloaded" } else if t.frozen { "Frozen" } else if t.audible() { "Playing sound" } else if t.loading() { "Loading" } else { "Running" };
|
||||
(t.id, t.display_title(), state, t.web.is_some())
|
||||
})
|
||||
.collect();
|
||||
egui::Grid::new("tasks").num_columns(3).striped(true).show(ui, |ui| {
|
||||
section(ui, &format!("{} {}", rows.len(), if rows.len() == 1 { "tab" } else { "tabs" }));
|
||||
card(ui, |ui| {
|
||||
for (id, title, state, has_web) in rows {
|
||||
ui.label(util::ellipsize(&title, 60));
|
||||
ui.label(state);
|
||||
ui.horizontal(|ui| {
|
||||
if has_web && ui.small_button("Reload").clicked() {
|
||||
f.send(Command::ReloadTab(id));
|
||||
}
|
||||
if ui.small_button("Close").clicked() {
|
||||
list_item(ui, id, Some(icons::TAB), &title, state, |ui| {
|
||||
if icon_button(ui, icons::CLOSE, "Close tab").clicked() {
|
||||
f.send(Command::CloseTab(id));
|
||||
}
|
||||
if has_web && icon_button(ui, icons::REFRESH, "Reload tab").clicked() {
|
||||
f.send(Command::ReloadTab(id));
|
||||
}
|
||||
});
|
||||
ui.end_row();
|
||||
}
|
||||
});
|
||||
ui.add_space(8.0);
|
||||
if ui.button("Unload background tabs").clicked() {
|
||||
f.send(Command::FreeMemory);
|
||||
}
|
||||
ui.ctx().request_repaint_after(std::time::Duration::from_secs(2));
|
||||
});
|
||||
}
|
||||
|
||||
pub fn source(ui: &mut Ui, f: &mut Frame, url: &str) {
|
||||
let p = f.palette();
|
||||
let source = f.shared.sources.borrow().get(url).cloned();
|
||||
match source {
|
||||
None => {
|
||||
f.send(Command::FetchSource(url.to_owned()));
|
||||
ui.spinner();
|
||||
},
|
||||
Some(None) => {
|
||||
ui.spinner();
|
||||
None | Some(None) => {
|
||||
if source.is_none() {
|
||||
f.send(Command::FetchSource(url.to_owned()));
|
||||
}
|
||||
status_state(ui, icons::CODE, "Loading the source", &util::ellipsize(url, 80), false);
|
||||
},
|
||||
Some(Some(Err(error))) => {
|
||||
ui.label(format!("The source couldn't be loaded: {error}"));
|
||||
if ui.button("Try again").clicked() {
|
||||
f.shared.sources.borrow_mut().remove(url);
|
||||
}
|
||||
},
|
||||
Some(Some(Ok(text))) => {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(RichText::new(format!("Source of {}", util::ellipsize(url, 100))).strong());
|
||||
if ui.small_button("Copy").clicked() {
|
||||
ui.ctx().copy_text(text.clone());
|
||||
}
|
||||
if ui.small_button("Reload").clicked() {
|
||||
status_state(ui, icons::ERROR, "Couldn't load the source", &format!("{} {error}", util::ellipsize(url, 60)), true);
|
||||
ui.add_space(theme::GAP_L);
|
||||
ui.vertical_centered(|ui| {
|
||||
if button(ui, ButtonKind::Tonal, Some(icons::REFRESH), "Try again").clicked() {
|
||||
f.shared.sources.borrow_mut().remove(url);
|
||||
}
|
||||
});
|
||||
egui::ScrollArea::both().auto_shrink([false, false]).show(ui, |ui| {
|
||||
// Very long sources are shown in part to keep the window responsive.
|
||||
let mut shown: &str = if text.len() > 2_000_000 { &text[..text.char_indices().nth(2_000_000).map(|(i, _)| i).unwrap_or(text.len())] } else { &text };
|
||||
// A &str buffer is read-only: selectable and copyable, not editable.
|
||||
ui.add(egui::TextEdit::multiline(&mut shown).code_editor().desired_width(f32::INFINITY));
|
||||
},
|
||||
Some(Some(Ok(text))) => {
|
||||
ui.add_space(theme::GAP_S);
|
||||
ui.horizontal(|ui| {
|
||||
ui.add_space(theme::GAP_L);
|
||||
ui.spacing_mut().item_spacing.x = theme::GAP_S;
|
||||
ui.label(RichText::new(format!("Source of {}", util::ellipsize(url, 90))).font(theme::font(theme::BODY, Weight::Medium)).color(p.on_surface));
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
ui.add_space(theme::GAP_S);
|
||||
if button(ui, ButtonKind::Outlined, Some(icons::REFRESH), "Reload").clicked() {
|
||||
f.shared.sources.borrow_mut().remove(url);
|
||||
}
|
||||
if button(ui, ButtonKind::Tonal, Some(icons::CONTENT_COPY), "Copy").clicked() {
|
||||
ui.ctx().copy_text(text.clone());
|
||||
}
|
||||
});
|
||||
});
|
||||
ui.add_space(theme::GAP_S);
|
||||
egui::Frame::NONE.fill(p.surface_container).corner_radius(theme::corner_radius(theme::radius(ui.ctx(), theme::L))).inner_margin(theme::GAP_M as i8).outer_margin(egui::Margin::symmetric(theme::GAP_M as i8, 0)).show(ui, |ui| {
|
||||
egui::ScrollArea::both().auto_shrink([false, false]).show(ui, |ui| {
|
||||
// Very long sources are shown in part to keep the window responsive.
|
||||
let mut shown: &str = if text.len() > 2_000_000 { &text[..text.char_indices().nth(2_000_000).map(|(i, _)| i).unwrap_or(text.len())] } else { &text };
|
||||
// A &str buffer is read-only: selectable and copyable, not editable.
|
||||
ui.add(egui::TextEdit::multiline(&mut shown).code_editor().frame(egui::Frame::NONE).desired_width(f32::INFINITY));
|
||||
});
|
||||
});
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn error(ui: &mut Ui, f: &mut Frame, url: &str, why: &str) {
|
||||
status_state(ui, icons::ERROR, crate::resources::ERROR_TITLE, &format!("{}\n{why}", util::ellipsize(url, 80)), true);
|
||||
ui.add_space(theme::GAP_L);
|
||||
ui.vertical_centered(|ui| {
|
||||
ui.add_space(80.0);
|
||||
ui.heading(crate::resources::ERROR_TITLE);
|
||||
ui.label(url);
|
||||
ui.label(RichText::new(why).weak());
|
||||
if ui.button("Try again").clicked() {
|
||||
if button(ui, ButtonKind::Tonal, Some(icons::REFRESH), "Try again").clicked() {
|
||||
f.send(Command::Navigate(url.to_owned()));
|
||||
}
|
||||
});
|
||||
let _ = switch;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ pub mod misc;
|
|||
pub mod newtab;
|
||||
pub mod passwords;
|
||||
pub mod settings;
|
||||
pub mod welcome;
|
||||
|
||||
use std::collections::HashSet;
|
||||
|
||||
|
|
@ -77,7 +78,7 @@ pub fn draw(ui: &mut Ui, f: &mut Frame, page: &Page) {
|
|||
Page::SiteSettings(host) => misc::site_settings(ui, f, host),
|
||||
Page::ClearData => misc::clear_data(ui, f),
|
||||
Page::About => misc::about(ui, f),
|
||||
Page::Welcome => misc::welcome(ui, f),
|
||||
Page::Welcome => welcome::draw(ui, f),
|
||||
Page::TaskManager => misc::task_manager(ui, f),
|
||||
Page::DevTools => devtools::draw(ui, f),
|
||||
Page::Gallery => gallery::draw(ui),
|
||||
|
|
|
|||
|
|
@ -477,7 +477,7 @@ fn master(ui: &mut Ui, f: &mut Frame) {
|
|||
ui.horizontal(|ui| {
|
||||
pad(ui);
|
||||
ui.add_space(theme::GAP_S);
|
||||
ui.scope(|ui| {
|
||||
ui.vertical(|ui| {
|
||||
ui.set_max_width(ui.available_width() - theme::GAP_L);
|
||||
ui.label(RichText::new(intro).font(theme::font(theme::BODY, Weight::Regular)).color(p.on_surface_variant));
|
||||
});
|
||||
|
|
|
|||
|
|
@ -553,7 +553,7 @@ fn scheme_preview(ui: &mut Ui, s: &Settings) {
|
|||
|
||||
/// Each preset as a scheme swatch (primary over secondary and tertiary, like a wallpaper colour). Returns the hex
|
||||
/// of the one clicked.
|
||||
fn swatches(ui: &mut Ui, s: &Settings, dark: bool, using_palette: bool) -> Option<&'static str> {
|
||||
pub(super) fn swatches(ui: &mut Ui, s: &Settings, dark: bool, using_palette: bool) -> Option<&'static str> {
|
||||
let p = theme::palette(ui.ctx());
|
||||
// Building a scheme takes a moment, so keep them while the mode, style and contrast stay.
|
||||
let key = format!("{dark}-{}-{:.2}", s.theme.variant, s.theme.contrast);
|
||||
|
|
|
|||
315
src/ui/pages/welcome.rs
Normal file
315
src/ui/pages/welcome.rs
Normal file
|
|
@ -0,0 +1,315 @@
|
|||
//! nacre://welcome — the first-run setup: six steps in a card over the new tab backdrop. Every choice is written to
|
||||
//! the settings at once, so the colours, mode and background preview live as you click.
|
||||
|
||||
use egui::{Id, Rect, RichText, Sense, Stroke, Ui, UiBuilder, pos2, vec2};
|
||||
|
||||
use super::super::widgets::{ButtonKind, button, card, choice_chips, icon, icon_row, row, switch, toggle_chips, wide_row};
|
||||
use super::super::{Frame, paint};
|
||||
use crate::actions::Command;
|
||||
use crate::store::settings::{ColourSource, DohProvider, NtpBackground, StartupMode, ThemeMode};
|
||||
use crate::theme::{self, Weight};
|
||||
use crate::ui::icons;
|
||||
|
||||
const STEPS: usize = 6;
|
||||
const CARD_WIDTH: f32 = 560.0;
|
||||
const PAD: f32 = 28.0;
|
||||
const INDICATOR: f32 = 24.0;
|
||||
const FOOTER: f32 = theme::CONTROL;
|
||||
const SPACE: f32 = theme::GAP_XL;
|
||||
|
||||
pub fn draw(ui: &mut Ui, f: &mut Frame) {
|
||||
let page = ui.max_rect();
|
||||
let ntp = f.shared.settings.borrow().ntp.clone();
|
||||
super::backdrop::draw(ui, f, &ntp, page, None);
|
||||
let mut s = f.shared.settings.borrow().clone();
|
||||
let before = s.clone();
|
||||
let p = f.palette();
|
||||
let ctx = ui.ctx().clone();
|
||||
let step = f.ui.pages.welcome_step.min(STEPS - 1);
|
||||
let mut next: Option<usize> = None;
|
||||
let mut finish = false;
|
||||
|
||||
// A new id per step change, so each step fades in from the start.
|
||||
let (last, count): (usize, u32) = ctx.data(|d| d.get_temp(Id::new("welcome-step"))).unwrap_or((usize::MAX, 0));
|
||||
let count = if last != step { count + 1 } else { count };
|
||||
ctx.data_mut(|d| d.insert_temp(Id::new("welcome-step"), (step, count)));
|
||||
let enter = Id::new(("welcome-in", count));
|
||||
let fresh = last != step && last != usize::MAX;
|
||||
let t = if theme::tokens(&ctx).motion <= 0.0 {
|
||||
1.0
|
||||
} else {
|
||||
let seen = ctx.data(|d| d.get_temp::<bool>(enter.with("seen"))).unwrap_or(false);
|
||||
if !seen && fresh {
|
||||
ctx.data_mut(|d| d.insert_temp(enter.with("seen"), true));
|
||||
ctx.request_repaint();
|
||||
theme::spring(&ctx, enter, 0.0, theme::EFFECT)
|
||||
} else {
|
||||
theme::spring(&ctx, enter, 1.0, theme::EFFECT)
|
||||
}
|
||||
};
|
||||
|
||||
egui::ScrollArea::vertical().id_salt(("welcome", count)).auto_shrink([false, false]).show(ui, |ui| {
|
||||
let avail = ui.available_width();
|
||||
let width = (avail - 2.0 * theme::GAP_L).clamp(280.0, CARD_WIDTH);
|
||||
let measured: f32 = ctx.data(|d| d.get_temp(Id::new(("welcome-height", step)))).unwrap_or(360.0);
|
||||
let height = theme::spring(&ctx, Id::new("welcome-card-height"), measured, theme::DEFAULT);
|
||||
let total = INDICATOR + SPACE + height + SPACE + FOOTER;
|
||||
let top = ((page.height() - total) / 2.0).max(theme::GAP_L);
|
||||
let (area, _) = ui.allocate_exact_size(vec2(avail, top + total + theme::GAP_L), Sense::hover());
|
||||
let left = area.center().x - width / 2.0;
|
||||
let y = area.top() + top;
|
||||
|
||||
// Step indicator: the current step is a stretched pill; the others are dots you can jump back to.
|
||||
let ind = Rect::from_min_size(pos2(left, y), vec2(width, INDICATOR));
|
||||
let mut x = ind.center().x - (STEPS as f32 * 8.0 + 28.0 + (STEPS as f32 - 1.0) * 8.0) / 2.0;
|
||||
for i in 0..STEPS {
|
||||
let on = theme::spring(&ctx, Id::new(("welcome-dot", i)), if i == step { 1.0 } else { 0.0 }, theme::DEFAULT);
|
||||
let w = 8.0 + 20.0 * on;
|
||||
let r = Rect::from_min_size(pos2(x, ind.center().y - 4.0), vec2(w, 8.0));
|
||||
let hit = ui.interact(r.expand2(vec2(4.0, 8.0)), Id::new(("welcome-dot-hit", i)), Sense::click());
|
||||
let colour = theme::layer(p.outline_variant, p.primary, on.clamp(0.0, 1.0));
|
||||
ui.painter().rect_filled(r, theme::corner_radius(theme::FULL), if hit.hovered() && i != step { p.on_surface_variant } else { colour });
|
||||
if i != step && hit.on_hover_cursor(egui::CursorIcon::PointingHand).clicked() {
|
||||
next = Some(i);
|
||||
}
|
||||
x += w + 8.0;
|
||||
}
|
||||
|
||||
// The card.
|
||||
let card_rect = Rect::from_min_size(pos2(left, ind.bottom() + SPACE), vec2(width, height));
|
||||
let radius = theme::radius(&ctx, theme::XL);
|
||||
paint::shadow(ui.painter(), card_rect, radius, p.dark);
|
||||
ui.painter().rect_filled(card_rect, theme::corner_radius(radius), p.surface_container_low.gamma_multiply(0.94));
|
||||
ui.painter().rect_stroke(card_rect, theme::corner_radius(radius), Stroke::new(1.0, p.outline_variant.gamma_multiply(0.6)), egui::StrokeKind::Inside);
|
||||
let inner = card_rect.shrink2(vec2(PAD, PAD));
|
||||
let mut content = ui.new_child(UiBuilder::new().max_rect(Rect::from_min_size(inner.min, vec2(inner.width(), 4000.0))).layout(egui::Layout::top_down(egui::Align::Min)));
|
||||
content.set_clip_rect(card_rect.shrink(1.0).intersect(ui.clip_rect()));
|
||||
content.set_opacity(t);
|
||||
content.add_space((1.0 - t) * 14.0);
|
||||
match step {
|
||||
0 => step_welcome(&mut content, &p, t),
|
||||
1 => step_import(&mut content, f),
|
||||
2 => step_look(&mut content, f, &mut s),
|
||||
3 => step_privacy(&mut content, &mut s),
|
||||
4 => step_search(&mut content, &mut s),
|
||||
_ => step_done(&mut content, &p, t),
|
||||
}
|
||||
let wanted = content.min_rect().height() + 2.0 * PAD - (1.0 - t) * 14.0;
|
||||
let wanted = wanted.max(260.0);
|
||||
if (wanted - measured).abs() > 0.5 {
|
||||
ctx.data_mut(|d| d.insert_temp(Id::new(("welcome-height", step)), wanted));
|
||||
ctx.request_repaint();
|
||||
}
|
||||
|
||||
// Footer: Back on the left, Skip and Continue on the right.
|
||||
let foot = Rect::from_min_size(pos2(left, card_rect.bottom() + SPACE), vec2(width, FOOTER));
|
||||
if step > 0 {
|
||||
let mut l = ui.new_child(UiBuilder::new().max_rect(foot).layout(egui::Layout::left_to_right(egui::Align::Center)));
|
||||
if button(&mut l, ButtonKind::Text, Some(icons::ARROW_BACK), "Back").clicked() {
|
||||
next = Some(step - 1);
|
||||
}
|
||||
}
|
||||
let mut r = ui.new_child(UiBuilder::new().max_rect(foot).layout(egui::Layout::right_to_left(egui::Align::Center)));
|
||||
r.spacing_mut().item_spacing.x = theme::GAP_S;
|
||||
let last_step = step == STEPS - 1;
|
||||
let label = match step {
|
||||
0 => format!("Get started {}", icons::ARROW_FORWARD),
|
||||
_ if last_step => format!("Start browsing {}", icons::ARROW_FORWARD),
|
||||
_ => format!("Continue {}", icons::ARROW_FORWARD),
|
||||
};
|
||||
if button(&mut r, ButtonKind::Filled, None, &label).clicked() {
|
||||
if last_step {
|
||||
finish = true;
|
||||
} else {
|
||||
next = Some(step + 1);
|
||||
}
|
||||
}
|
||||
if !last_step && button(&mut r, ButtonKind::Text, None, "Skip setup").clicked() {
|
||||
finish = true;
|
||||
}
|
||||
});
|
||||
|
||||
// Enter goes on, Escape skips; neither while a field has the keyboard.
|
||||
if ctx.memory(|m| m.focused().is_none()) {
|
||||
if ui.input(|i| i.key_pressed(egui::Key::Enter)) {
|
||||
if step == STEPS - 1 {
|
||||
finish = true;
|
||||
} else {
|
||||
next = Some(step + 1);
|
||||
}
|
||||
}
|
||||
if ui.input(|i| i.key_pressed(egui::Key::Escape)) {
|
||||
finish = true;
|
||||
}
|
||||
}
|
||||
if let Some(n) = next {
|
||||
f.ui.pages.welcome_step = n;
|
||||
}
|
||||
if finish {
|
||||
s.startup.welcome_done = true;
|
||||
s.startup.import_offered = true;
|
||||
f.ui.pages.welcome_step = 0;
|
||||
f.send(Command::Navigate("nacre://newtab".into()));
|
||||
}
|
||||
if s != before {
|
||||
*f.shared.settings.borrow_mut() = s;
|
||||
}
|
||||
}
|
||||
|
||||
/// A step's title and the line under it.
|
||||
fn heading(ui: &mut Ui, title: &str, lead: &str) {
|
||||
let p = theme::palette(ui.ctx());
|
||||
ui.label(RichText::new(title).font(theme::font(theme::HEADLINE, Weight::Medium)).color(p.on_surface));
|
||||
ui.add_space(theme::GAP_XS);
|
||||
ui.label(RichText::new(lead).font(theme::font(theme::BODY, Weight::Regular)).color(p.on_surface_variant));
|
||||
ui.add_space(theme::GAP_L);
|
||||
}
|
||||
|
||||
/// A small group title inside a step.
|
||||
fn label(ui: &mut Ui, text: &str) {
|
||||
let p = theme::palette(ui.ctx());
|
||||
ui.add_space(theme::GAP_S);
|
||||
ui.label(RichText::new(text).font(theme::font(theme::BODY, Weight::Medium)).color(p.primary));
|
||||
ui.add_space(theme::GAP_XS);
|
||||
}
|
||||
|
||||
/// A round mark in a cookie that pops in, with an icon in it.
|
||||
fn mark(ui: &mut Ui, glyph: &str, t: f32) {
|
||||
let p = theme::palette(ui.ctx());
|
||||
let (rect, _) = ui.allocate_exact_size(vec2(ui.available_width(), 120.0), Sense::hover());
|
||||
let pop = theme::spring(ui.ctx(), Id::new(("welcome-pop", glyph)), t, theme::DEFAULT).max(0.0);
|
||||
let c = rect.center();
|
||||
paint::cookie(ui.painter(), c, 54.0 * pop, 9, (1.0 - t) * 0.6, p.primary_container, Stroke::NONE);
|
||||
icon(ui, c, glyph, 56.0 * pop, true, p.on_primary_container);
|
||||
}
|
||||
|
||||
/// A static feature tag.
|
||||
fn tag(ui: &mut Ui, glyph: &str, text: &str) {
|
||||
let p = theme::palette(ui.ctx());
|
||||
let galley = ui.painter().layout_no_wrap(text.to_owned(), theme::font(theme::BODY, Weight::Medium), p.on_secondary_container);
|
||||
let (rect, _) = ui.allocate_exact_size(vec2(theme::GAP_M + 18.0 + theme::GAP_S + galley.size().x + theme::GAP_L, theme::CONTROL_SMALL + 4.0), Sense::hover());
|
||||
ui.painter().rect_filled(rect, theme::corner_radius(theme::FULL), p.secondary_container);
|
||||
icon(ui, pos2(rect.left() + theme::GAP_M + 9.0, rect.center().y), glyph, 18.0, false, p.on_secondary_container);
|
||||
ui.painter().galley(pos2(rect.left() + theme::GAP_M + 18.0 + theme::GAP_S, rect.center().y - galley.size().y / 2.0), galley, p.on_secondary_container);
|
||||
}
|
||||
|
||||
fn step_welcome(ui: &mut Ui, p: &theme::Palette, t: f32) {
|
||||
mark(ui, icons::DIAMOND, t);
|
||||
ui.add_space(theme::GAP_S);
|
||||
ui.vertical_centered(|ui| {
|
||||
ui.label(RichText::new("Welcome to Nacre").font(theme::font(theme::HEADLINE + 8.0, Weight::SemiBold)).color(p.on_surface));
|
||||
ui.add_space(theme::GAP_S);
|
||||
ui.scope(|ui| {
|
||||
ui.set_max_width(420.0);
|
||||
ui.label(RichText::new("A browser that takes its colours from the sites you visit. Bring your things over and set it up in a minute. Everything can be changed later in Settings.").font(theme::font(theme::BODY, Weight::Regular)).color(p.on_surface_variant));
|
||||
});
|
||||
ui.add_space(theme::GAP_L);
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.spacing_mut().item_spacing = vec2(theme::GAP_S, theme::GAP_S);
|
||||
tag(ui, icons::SHIELD, "Ad blocking");
|
||||
tag(ui, icons::FINGERPRINT, "Privacy mode");
|
||||
tag(ui, icons::PALETTE, "Your colours");
|
||||
tag(ui, icons::VPN_LOCK, "Built-in VPN");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn step_import(ui: &mut Ui, f: &mut Frame) {
|
||||
heading(ui, "Bring your things", "Copy what you keep in another browser. Nothing is removed from it.");
|
||||
let id = Id::new("welcome-import");
|
||||
let mut what: Vec<String> = ui.data(|d| d.get_temp(id)).unwrap_or_else(|| vec!["bookmarks".into(), "history".into(), "settings".into()]);
|
||||
label(ui, "What to bring");
|
||||
toggle_chips(ui, &mut what, &[("bookmarks", "Bookmarks"), ("history", "History"), ("settings", "Home page and search")]);
|
||||
ui.data_mut(|d| d.insert_temp(id, what.clone()));
|
||||
label(ui, "Browsers on this computer");
|
||||
let sources = f.shared.import_sources.borrow().clone();
|
||||
if sources.is_empty() {
|
||||
let p = f.palette();
|
||||
ui.label(RichText::new("None found. Nacre looks for Chrome, Edge, Brave, Vivaldi, Opera, Chromium, Firefox and their relatives. You can still import a file later from Settings.").font(theme::font(theme::SMALL, Weight::Regular)).color(p.on_surface_variant));
|
||||
} else {
|
||||
let none = what.is_empty();
|
||||
card(ui, |ui| {
|
||||
for (i, src) in sources.iter().enumerate() {
|
||||
let go = icon_row(ui, icons::INPUT, &src.name(), "", |ui| ui.add_enabled_ui(!none, |ui| button(ui, ButtonKind::Tonal, None, "Import")).inner.clicked());
|
||||
if go {
|
||||
let has = |k: &str| what.iter().any(|w| w == k);
|
||||
f.send(Command::Import { source: i, bookmarks: has("bookmarks"), history: has("history"), settings: has("settings") });
|
||||
}
|
||||
}
|
||||
});
|
||||
let status = f.shared.import_status.borrow().clone();
|
||||
if !status.is_empty() {
|
||||
ui.add_space(theme::GAP_S);
|
||||
ui.label(RichText::new(status).font(theme::font(theme::SMALL, Weight::Regular)).color(f.palette().on_surface_variant));
|
||||
}
|
||||
}
|
||||
label(ui, "Passwords from a file");
|
||||
card(ui, |ui| {
|
||||
row(ui, "Choose a CSV file", "Export your passwords from the old browser as CSV first.", |ui| {
|
||||
if button(ui, ButtonKind::Outlined, Some(icons::UPLOAD), "Choose file").clicked() {
|
||||
f.send(Command::ImportPasswords);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn step_look(ui: &mut Ui, f: &mut Frame, s: &mut crate::store::settings::Settings) {
|
||||
heading(ui, "Make it yours", "Try the choices: the window changes as you click.");
|
||||
label(ui, "Mode");
|
||||
choice_chips(ui, &mut s.theme.mode, &[(ThemeMode::System, "Follow the system"), (ThemeMode::Light, "Light"), (ThemeMode::Dark, "Dark")]);
|
||||
label(ui, "Colour");
|
||||
choice_chips(ui, &mut s.theme.source, &[(ColourSource::Website, "From each website"), (ColourSource::System, "System accent"), (ColourSource::Palette, "A palette colour")]);
|
||||
ui.add_space(theme::GAP_S);
|
||||
let using_palette = s.theme.source == ColourSource::Palette;
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
if let Some(hex) = super::settings::swatches(ui, s, f.palette().dark, using_palette) {
|
||||
s.theme.preset = hex.to_owned();
|
||||
s.theme.source = ColourSource::Palette;
|
||||
}
|
||||
});
|
||||
label(ui, "New tab background");
|
||||
let options: Vec<(NtpBackground, &str)> = NtpBackground::ALL.iter().map(|(v, l)| (*v, *l)).collect();
|
||||
choice_chips(ui, &mut s.ntp.bg, &options);
|
||||
}
|
||||
|
||||
fn step_privacy(ui: &mut Ui, s: &mut crate::store::settings::Settings) {
|
||||
heading(ui, "Privacy, your way", "Sensible choices are already on. Change any of them now or later.");
|
||||
card(ui, |ui| {
|
||||
icon_row(ui, icons::SHIELD, "Block ads and trackers", "Fewer ads, faster pages.", |ui| switch(ui, &mut s.adblock.enabled));
|
||||
icon_row(ui, icons::FINGERPRINT, "Privacy mode", "Hides details that make your browser easy to recognise.", |ui| switch(ui, &mut s.privacy.mode));
|
||||
icon_row(ui, icons::LOCK, "HTTPS only", "Asks before opening a site that isn't encrypted.", |ui| switch(ui, &mut s.privacy.https_only));
|
||||
icon_row(ui, icons::VISIBILITY_OFF, "Ask sites not to track you", "Sends the Do Not Track signal.", |ui| switch(ui, &mut s.privacy.dnt));
|
||||
let options: Vec<(DohProvider, &str)> = DohProvider::ALL.iter().filter(|(v, _)| *v != DohProvider::Custom).map(|(v, l)| (*v, *l)).collect();
|
||||
wide_row(ui, "Secure DNS", "Hides which sites you look up from your network.", |ui| choice_chips(ui, &mut s.privacy.doh, &options));
|
||||
});
|
||||
}
|
||||
|
||||
fn step_search(ui: &mut Ui, s: &mut crate::store::settings::Settings) {
|
||||
heading(ui, "Search with", "What the address bar uses when you type words.");
|
||||
let engines: Vec<(String, String)> = s.search_engines().into_iter().map(|(k, n, ..)| (k, n)).collect();
|
||||
let options: Vec<(String, &str)> = engines.iter().map(|(k, n)| (k.clone(), n.as_str())).collect();
|
||||
choice_chips(ui, &mut s.startup.search_engine, &options);
|
||||
label(ui, "When Nacre starts");
|
||||
choice_chips(ui, &mut s.startup.mode, &[(StartupMode::NewTab, "Open a new tab"), (StartupMode::Restore, "Continue where I left off"), (StartupMode::Home, "Open my home page")]);
|
||||
ui.add_space(theme::GAP_M);
|
||||
card(ui, |ui| {
|
||||
icon_row(ui, icons::SPELLCHECK, "Check spelling", "Underlines mistakes as you type.", |ui| switch(ui, &mut s.spell.enabled));
|
||||
});
|
||||
}
|
||||
|
||||
fn step_done(ui: &mut Ui, p: &theme::Palette, t: f32) {
|
||||
// A check pops into a tonal circle.
|
||||
let (rect, _) = ui.allocate_exact_size(vec2(ui.available_width(), 120.0), Sense::hover());
|
||||
let pop = theme::spring(ui.ctx(), Id::new("welcome-done"), t, theme::DEFAULT).max(0.0);
|
||||
ui.painter().circle_filled(rect.center(), 52.0 * pop, p.primary_container);
|
||||
icon(ui, rect.center(), icons::CHECK, 64.0 * pop, false, p.on_primary_container);
|
||||
ui.add_space(theme::GAP_S);
|
||||
ui.vertical_centered(|ui| {
|
||||
ui.label(RichText::new("You're all set").font(theme::font(theme::HEADLINE + 8.0, Weight::SemiBold)).color(p.on_surface));
|
||||
ui.add_space(theme::GAP_S);
|
||||
ui.scope(|ui| {
|
||||
ui.set_max_width(420.0);
|
||||
ui.label(RichText::new("Every choice here lives in Settings too, so nothing is final. Open a new tab to start.").font(theme::font(theme::BODY, Weight::Regular)).color(p.on_surface_variant));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -319,7 +319,7 @@ fn row_frame<R>(ui: &mut Ui, text: RowText, click: Option<Id>, control: impl FnO
|
|||
let known: Option<Vec2> = ui.data(|d| d.get_temp(width_id));
|
||||
let lead = if text.lead.is_some() { theme::ICON + theme::GAP_L } else { 0.0 };
|
||||
let inner_width = ui.available_width() - 2.0 * theme::GAP_L - lead;
|
||||
let control_width = known.map_or(260.0, |k| k.x);
|
||||
let control_width = known.map_or(0.0, |k| k.x);
|
||||
let control_height = known.map_or(0.0, |k| k.y);
|
||||
let stacked = text.below || control_width > inner_width - ROW_TEXT_MIN;
|
||||
let mut result = None;
|
||||
|
|
@ -812,34 +812,41 @@ mod tests {
|
|||
pub fn page_header(ui: &mut Ui, title: &str, subtitle: &str, actions: impl FnOnce(&mut Ui)) {
|
||||
let p = theme::palette(ui.ctx());
|
||||
let wide = ui.available_width() >= 640.0;
|
||||
let text = |ui: &mut Ui| {
|
||||
ui.vertical(|ui| {
|
||||
ui.label(RichText::new(title).font(theme::font(theme::HEADLINE, Weight::Medium)).color(p.on_surface));
|
||||
if !subtitle.is_empty() {
|
||||
ui.label(RichText::new(subtitle).font(theme::font(theme::BODY, Weight::Regular)).color(p.on_surface_variant));
|
||||
}
|
||||
});
|
||||
};
|
||||
let mut actions = Some(actions);
|
||||
let title = |ui: &mut Ui| ui.label(RichText::new(title).font(theme::font(theme::HEADLINE, Weight::Medium)).color(p.on_surface));
|
||||
ui.add_space(theme::GAP_S);
|
||||
if wide {
|
||||
ui.horizontal(|ui| {
|
||||
ui.set_min_height(theme::CONTROL);
|
||||
ui.add_space(theme::GAP_L - ui.spacing().item_spacing.x);
|
||||
text(ui);
|
||||
title(ui);
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
ui.spacing_mut().item_spacing.x = theme::GAP_S;
|
||||
actions(ui);
|
||||
if let Some(actions) = actions.take() {
|
||||
actions(ui);
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
ui.horizontal(|ui| {
|
||||
ui.add_space(theme::GAP_L - ui.spacing().item_spacing.x);
|
||||
text(ui);
|
||||
title(ui);
|
||||
});
|
||||
}
|
||||
if !subtitle.is_empty() {
|
||||
ui.horizontal(|ui| {
|
||||
ui.add_space(theme::GAP_L - ui.spacing().item_spacing.x);
|
||||
ui.add(egui::Label::new(RichText::new(subtitle).font(theme::font(theme::BODY, Weight::Regular)).color(p.on_surface_variant)).truncate());
|
||||
});
|
||||
}
|
||||
if !wide {
|
||||
ui.add_space(theme::GAP_S);
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.spacing_mut().item_spacing = vec2(theme::GAP_S, theme::GAP_S);
|
||||
ui.add_space(theme::GAP_S);
|
||||
actions(ui);
|
||||
if let Some(actions) = actions.take() {
|
||||
actions(ui);
|
||||
}
|
||||
});
|
||||
}
|
||||
ui.add_space(theme::GAP_M);
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue