Open the bundled manual from Help and from Settings

The packages now carry the manual, but nothing in the application opened
it: the help sheet listed gestures and stopped there.

The help sheet gains a Manual button beside Done, and Settings a Manual
row under About beside the version. Both go through dr_ui::manual, which
finds the installed page through dr_plat::system_data_dirs (the package's
share directory on Linux, the executable's directory on Windows), and a
development build also in the checkout it was compiled from. A copy with
no manual says so on the status line rather than doing nothing.

On the desktop the page goes to the system browser. A section is a URL
fragment, and xdg-open's generic mode and Windows' FileProtocolHandler
both turn a file: URL into a path and drop the fragment, so a section is
opened through a one-line redirect page written to the data directory:
the opener gets a plain path, which every opener keeps, and the browser
follows the redirect to index.html#section itself. The launcher behind
the sign-in's open_in_browser is split out so both share it; the https
check stays with the sign-in.

Android has no path to give a browser: an asset is not a file, a copy in
private storage is unreadable to other apps, a file: URI across apps is
refused, and a content: URI leaves the browser resolving every picture
against the provider. So ManualActivity, a WebView reading
file:///android_asset/manual/index.html straight out of the APK, shows
it, started by class name with the section as an extra. JavaScript is
off, links off the page go to the browser, and the theme is day-night so
the page's own light and dark follow the system. A test checks that the
manifest, the Java class and dr_ui agree on the name and the extra.
This commit is contained in:
2026-09-24 22:56:09 -04:00
parent d8f26fb5cd
commit 352e59498b
19 changed files with 571 additions and 98 deletions
Generated
+1
View File
@@ -1717,6 +1717,7 @@ dependencies = [
"slint-build",
"thiserror 2.0.20",
"tokio",
"url",
"wgpu",
]
@@ -141,6 +141,23 @@
</intent-filter>
</activity>
<!-- The manual (dr_ui::manual): a WebView over the copy the APK
carries in assets/manual. See ManualActivity.java for why it is
not the browser.
Not exported: nothing outside this app has a reason to start it,
and dr_ui starts it by class name, which needs no intent filter.
Its own task entry is not wanted either — it is a page over the
app, and Back returns to the photograph it was opened from.
configChanges so a rotation reflows the page rather than
reloading it at the top. -->
<activity
android:name="paris.tourolle.darkroom.ManualActivity"
android:exported="false"
android:label="DarkRoom manual"
android:theme="@style/ManualTheme"
android:configChanges="orientation|keyboardHidden|screenSize|screenLayout|uiMode" />
<!-- FR-PLAT-AND-6, outbound. Android has refused file:// URIs
between apps since API 24 — handing one out raises
FileUriExposedException in *this* process — so an exported JPEG
@@ -0,0 +1,105 @@
package paris.tourolle.darkroom;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
/**
* The manual that ships in the APK, shown in a WebView.
*
* <h2>Why an activity of our own rather than the browser</h2>
*
* <p>The desktop hands the manual to the system browser. Android leaves no
* way to do the same: the page is an asset inside the APK, which is not a
* file; an unpacked copy in app-private storage is a file no browser may
* read; a {@code file:} URI handed to another app is refused since API 24;
* and a {@code content:} URI serves the page but leaves the browser to fetch
* every picture by a relative URL against the provider, which browsers do not
* reliably do. A WebView reads {@code file:///android_asset/} straight from
* the APK, pictures and section anchor included, and nothing is unpacked.
*
* <h2>What it is not</h2>
*
* <p>A browser. JavaScript stays off (the page has none), and a link that
* leaves the manual — the design documents are on the forge — goes to the
* user's browser rather than opening inside this view, so the only thing ever
* shown here is the page the APK carries.
*
* <p>Started by {@code dr_ui::manual} with {@code Intent.setClassName}, so the
* name here and there must agree; a test in lib.rs checks the manifest
* declares it.
*/
public final class ManualActivity extends Activity {
/** The section to open at, a heading's anchor. Absent opens the top. */
public static final String EXTRA_ANCHOR = "anchor";
private static final String PAGE = "file:///android_asset/manual/index.html";
private WebView web;
@Override
protected void onCreate(Bundle saved) {
super.onCreate(saved);
setTitle("DarkRoom manual");
web = new WebView(this);
WebSettings settings = web.getSettings();
settings.setJavaScriptEnabled(false);
// Pinch to zoom into a screenshot, which is 1600 pixels wide and drawn
// at the width of a phone.
settings.setBuiltInZoomControls(true);
settings.setDisplayZoomControls(false);
web.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
Uri uri = request.getUrl();
if ("file".equals(uri.getScheme())) {
return false;
}
try {
startActivity(new Intent(Intent.ACTION_VIEW, uri));
} catch (ActivityNotFoundException e) {
// No browser on the device: the link does nothing, which
// is all it could do.
}
return true;
}
});
setContentView(web);
if (saved != null) {
web.restoreState(saved);
} else {
String anchor = getIntent().getStringExtra(EXTRA_ANCHOR);
web.loadUrl(anchor == null || anchor.isEmpty() ? PAGE : PAGE + "#" + anchor);
}
}
@Override
protected void onSaveInstanceState(Bundle out) {
super.onSaveInstanceState(out);
web.saveState(out);
}
/** Back walks back through the sections visited, then leaves. */
@Override
public void onBackPressed() {
if (web.canGoBack()) {
web.goBack();
} else {
super.onBackPressed();
}
}
@Override
protected void onDestroy() {
web.destroy();
super.onDestroy();
}
}
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Day or night as the system is; see values/themes.xml. -->
<resources>
<style name="ManualTheme" parent="@android:style/Theme.DeviceDefault.DayNight" />
</resources>
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
The manual's theme (ManualActivity). Light below API 29, which has no
day-night theme in the platform; values-v29 follows the system from there.
The WebView takes prefers-color-scheme from whether this theme is light, and
the manual's stylesheet takes its colours from that.
-->
<resources>
<style name="ManualTheme" parent="@android:style/Theme.DeviceDefault.Light" />
</resources>
+31
View File
@@ -581,6 +581,37 @@ mod tests {
);
}
/// `dr_ui::manual` starts the manual by class name. A name the manifest
/// does not declare is an `ActivityNotFoundException` on the device and a
/// Manual button that does nothing, so the three spellings — dr_ui's, the
/// manifest's and the Java file's — are checked to be one.
#[test]
fn the_manual_activity_dr_ui_starts_is_declared() {
let manifest = manifest();
let wanted = dr_ui::manual::ANDROID_ACTIVITY;
let element = manifest
.split("<activity")
.skip(1)
.find(|a| attribute(a, "android:name").as_deref() == Some(wanted))
.unwrap_or_else(|| panic!("the manifest declares no activity {wanted}"));
assert_eq!(
attribute(element, "android:exported").as_deref(),
Some("false"),
"the manual activity has no reason to be startable by another app"
);
let java = include_str!("../android/java/paris/tourolle/darkroom/ManualActivity.java");
let (package, class) = wanted.rsplit_once('.').expect("unqualified class name");
assert!(java.contains(&format!("package {package};")));
assert!(java.contains(&format!("class {class} ")));
assert!(
java.contains(&format!(
"EXTRA_ANCHOR = \"{}\"",
dr_ui::manual::ANDROID_EXTRA_ANCHOR
)),
"ManualActivity reads the section from a different extra than dr_ui writes"
);
}
#[test]
fn the_provider_hands_out_one_file_at_a_time_and_nothing_by_itself() {
let manifest = manifest();
File diff suppressed because one or more lines are too long
+35 -35
View File
@@ -25,7 +25,7 @@ Sampling a neutral is the first move of the tonal pass — every colour judgemen
Anchored on the fingers' midpoint, and on the pointer, so the gesture reads as magnifying the picture rather than sliding it about. Double-tap is the way to an exact 1:1; this is the way to everything in between. Past 1:1 the pixels are shown as they are, square and unsmoothed; below it, filtered.
<sub>`ui/dr-ui/ui/app.slint:1778`</sub>
<sub>`ui/dr-ui/ui/app.slint:1780`</sub>
### Move a magnified photograph about
@@ -34,7 +34,7 @@ Anchored on the fingers' midpoint, and on the pointer, so the gesture reads as m
Only once there is something outside the viewport to reach, which is why the cursor becomes a hand exactly then. The view is clamped to the frame: panning past the edge would show undefined area beside the photograph, and that reads as a rendering fault rather than as the end of the picture.
<sub>`ui/dr-ui/ui/app.slint:1871`</sub>
<sub>`ui/dr-ui/ui/app.slint:1873`</sub>
### Paint a mask by hand
@@ -43,7 +43,7 @@ Only once there is something outside the viewport to reach, which is why the cur
A model's mask stops inside a shoulder and leaks into the hair, and no single edge control fixes two errors that go opposite ways. The whole stroke is one step in the history, so taking a mark back costs one press however long it took to make.
<sub>`ui/dr-ui/ui/app.slint:1958`</sub>
<sub>`ui/dr-ui/ui/app.slint:1960`</sub>
### Take back the last change
@@ -53,7 +53,7 @@ A model's mask stops inside a shoulder and leaks into the hair, and no single ed
A whole drag is one step, so undo takes back a decision rather than a frame of a gesture. The list is there because arriving six steps back costs what arriving from one does.
<sub>`ui/dr-ui/ui/app.slint:2189`</sub>
<sub>`ui/dr-ui/ui/app.slint:2191`</sub>
### Do it again after taking it back
@@ -61,7 +61,7 @@ A whole drag is one step, so undo takes back a decision rather than a frame of a
- **Pointer** — Click it, or press Redo in the History header
- **Keyboard** — Ctrl+Shift+Z
<sub>`ui/dr-ui/ui/app.slint:2202`</sub>
<sub>`ui/dr-ui/ui/app.slint:2204`</sub>
### Copy the settings from this photograph
@@ -71,7 +71,7 @@ A whole drag is one step, so undo takes back a decision rather than a frame of a
The button is the copy that has to work: a tablet has no modifier key to hold and no menu bar to hang the action from. The shortcut is an accelerator for a control that is on screen either way.
<sub>`ui/dr-ui/ui/app.slint:2235`</sub>
<sub>`ui/dr-ui/ui/app.slint:2237`</sub>
### Paste the settings onto this photograph
@@ -81,7 +81,7 @@ The button is the copy that has to work: a tablet has no modifier key to hold an
The button names what would be pasted — "3 adjustments", and whether the crop is coming with it — which the shortcut cannot say. Both paste the same scope.
<sub>`ui/dr-ui/ui/app.slint:2247`</sub>
<sub>`ui/dr-ui/ui/app.slint:2249`</sub>
### Choose which kinds of edit a copy carries
@@ -91,7 +91,7 @@ The button names what would be pasted — "3 adjustments", and whether the crop
Lightroom's Copy Settings. Pasting a look across a shoot usually means leaving each frame's crop and rotation alone, and that is a choice to make at the moment of copying.
<sub>`ui/dr-ui/ui/app.slint:2264`</sub>
<sub>`ui/dr-ui/ui/app.slint:2266`</sub>
### Export this photograph as the last one was
@@ -101,7 +101,7 @@ Lightroom's Copy Settings. Pasting a look across a shoot usually means leaving e
Every export runs on the defaults in Settings, so "as the last one was" is what the button already does. The chord is Lightroom's and darktable's, kept so hands that learned it there need not learn it again.
<sub>`ui/dr-ui/ui/app.slint:2293`</sub>
<sub>`ui/dr-ui/ui/app.slint:2295`</sub>
### Choose how to export, then export
@@ -111,7 +111,7 @@ Every export runs on the defaults in Settings, so "as the last one was" is what
The export sheet is the export defaults alone with an Export button. What is chosen there is kept, so it is also what the next Ctrl+Shift+E uses.
<sub>`ui/dr-ui/ui/app.slint:2305`</sub>
<sub>`ui/dr-ui/ui/app.slint:2307`</sub>
### Change which group of adjustments is on screen
@@ -121,7 +121,7 @@ The export sheet is the export defaults alone with an Export button. What is cho
The groups are whatever the operation set declares itself to be about, so there are as many as the pipeline has and no key can be assigned to one of them by name. Stepping is the binding that survives a node being added.
<sub>`ui/dr-ui/ui/app.slint:2330`</sub>
<sub>`ui/dr-ui/ui/app.slint:2332`</sub>
### Look at the photograph at 1:1
@@ -131,7 +131,7 @@ The groups are whatever the operation set declares itself to be about, so there
Noise reduction and capture sharpening are judgements about single pixels, and a fitted view averages several of the file's into each one on screen — so the frame looks softer than it is and the correction goes too far. The point and the magnification survive opening the next photograph, which is what makes checking the same eye across forty portraits forty keystrokes rather than forty pans. From 1:1 on the photograph is drawn as its own pixels, each a hard-edged square, rather than smoothed into a blur.
<sub>`ui/dr-ui/ui/app.slint:2365`</sub>
<sub>`ui/dr-ui/ui/app.slint:2367`</sub>
### Give this photograph a colour label
@@ -141,7 +141,7 @@ Noise reduction and capture sharpening are judgements about single pixels, and a
The grid's keys, on the photograph that is open, so labelling while stepping through a folder is one hand's work. The bar names the label in words beside its mark.
<sub>`ui/dr-ui/ui/app.slint:2420`</sub>
<sub>`ui/dr-ui/ui/app.slint:2422`</sub>
### Move to the next or previous photograph
@@ -151,7 +151,7 @@ The grid's keys, on the photograph that is open, so labelling while stepping thr
The edit on screen is saved on the way out, so stepping through a folder is as much a departure as going back to the grid and loses nothing. A and D as well as the arrows, so the left hand steps along the roll while the right stays on the mouse. Unmodified only: Ctrl+D and Ctrl+A are not this.
<sub>`ui/dr-ui/ui/app.slint:2445`</sub>
<sub>`ui/dr-ui/ui/app.slint:2447`</sub>
### See the photograph before you edited it
@@ -161,7 +161,7 @@ The edit on screen is saved on the way out, so stepping through a folder is as m
Held rather than toggled, and no split screen: a split halves the working image on the tablet the column was sized for, and the comparison photographers describe making is a flick back and forth. It takes no history step, so checking whether a frame is overcooked costs nothing to undo afterwards.
<sub>`ui/dr-ui/ui/app.slint:2578`</sub>
<sub>`ui/dr-ui/ui/app.slint:2580`</sub>
### Put one control back to its default
@@ -313,7 +313,7 @@ The right match confidence is a property of your library, not of the model. "Wha
Touch has no ctrl, so without a mode there is no way to select a second photograph — the first tap would open it. The hold is the fast way in and the button is the one that can be found.
<sub>`ui/dr-ui/ui/library.slint:1625`</sub>
<sub>`ui/dr-ui/ui/library.slint:1629`</sub>
### Add or remove one photograph
@@ -322,7 +322,7 @@ Touch has no ctrl, so without a mode there is no way to select a second photogra
While selecting, a tap never opens. That is the whole point of the mode: one meaning per gesture at a time. Press Done to get tap-to-open back.
<sub>`ui/dr-ui/ui/library.slint:1634`</sub>
<sub>`ui/dr-ui/ui/library.slint:1638`</sub>
### Leave selecting
@@ -330,7 +330,7 @@ While selecting, a tap never opens. That is the whole point of the mode: one mea
- **Pointer** — Press Done in the header
- **Keyboard** — Escape
<sub>`ui/dr-ui/ui/library.slint:1642`</sub>
<sub>`ui/dr-ui/ui/library.slint:1646`</sub>
### Pick a photograph up to drag it
@@ -339,7 +339,7 @@ While selecting, a tap never opens. That is the whole point of the mode: one mea
A finger on a photograph might be starting a scroll, and for the first half-second the grid assumes it is. Holding says otherwise, and the ring is the grid saying it heard — from there the drag cannot be lost to a scroll. A mouse never waits: the cursor is precise enough that a sideways drag is unambiguous from the first pixel.
<sub>`ui/dr-ui/ui/library.slint:1672`</sub>
<sub>`ui/dr-ui/ui/library.slint:1676`</sub>
### Select a range
@@ -348,7 +348,7 @@ A finger on a photograph might be starting a scroll, and for the first half-seco
This replaced a double tap, which had no visible state and could take forty photographs by accident. The run is resolved by the catalog rather than by what is on screen, so the grid can scroll between the two taps — the ranges that hurt on a tablet are longer than a screenful, which is exactly where a finger sweep runs out.
<sub>`ui/dr-ui/ui/library.slint:1737`</sub>
<sub>`ui/dr-ui/ui/library.slint:1741`</sub>
### Take the blinks out of a burst
@@ -357,7 +357,7 @@ This replaced a double tap, which had no visible state and could take forty phot
Face indexing reads each face's eyes. The chip drops frames where the chosen people are caught blinking, and leaves sunglasses and eyes it could not read alone.
<sub>`ui/dr-ui/ui/library.slint:2450`</sub>
<sub>`ui/dr-ui/ui/library.slint:2454`</sub>
### Find photographs with two people in them
@@ -366,7 +366,7 @@ Face indexing reads each face's eyes. The chip drops frames where the chosen peo
"Any of them" is a union and "all of them" is an intersection. The tray is where both terms and the choice between them live, because a filter belongs on the filter bar.
<sub>`ui/dr-ui/ui/library.slint:2479`</sub>
<sub>`ui/dr-ui/ui/library.slint:2483`</sub>
### Show only photographs with one colour label
@@ -375,7 +375,7 @@ Face indexing reads each face's eyes. The chip drops frames where the chosen peo
Each chip is the label's mark and its name, so the one you want is found by reading it; tap the lit chip again to show every label.
<sub>`ui/dr-ui/ui/library.slint:2602`</sub>
<sub>`ui/dr-ui/ui/library.slint:2606`</sub>
### Export the selection as the last export was
@@ -385,7 +385,7 @@ Each chip is the label's mark and its name, so the one you want is found by read
Lightroom's and darktable's chords. Every export runs on the saved defaults, so the plain chord opens them beside an Export button and the shifted one skips straight to exporting.
<sub>`ui/dr-ui/ui/library.slint:3065`</sub>
<sub>`ui/dr-ui/ui/library.slint:3069`</sub>
### Paste copied settings onto the selection
@@ -393,7 +393,7 @@ Lightroom's and darktable's chords. Every export runs on the saved defaults, so
- **Pointer** — Select them, then "Paste to N"
- **Keyboard** — Ctrl+V
<sub>`ui/dr-ui/ui/library.slint:3089`</sub>
<sub>`ui/dr-ui/ui/library.slint:3093`</sub>
### Show only photographs with some number of stars
@@ -403,7 +403,7 @@ Lightroom's and darktable's chords. Every export runs on the saved defaults, so
The chips say "this many or more". A range with a ceiling — the twos and threes still to be decided — is the keyboard's alone, and the bar says so in words while it holds.
<sub>`ui/dr-ui/ui/library.slint:3111`</sub>
<sub>`ui/dr-ui/ui/library.slint:3115`</sub>
### Give photographs a colour label
@@ -413,7 +413,7 @@ The chips say "this many or more". A range with a ceiling — the twos and three
Lightroom's keys, so hands that learned them there need not learn them again. Purple has no key there either, and is on the bar. Every mark carries its label's initial, so the label is read without telling the colours apart.
<sub>`ui/dr-ui/ui/library.slint:3160`</sub>
<sub>`ui/dr-ui/ui/library.slint:3164`</sub>
### Resize the thumbnails
@@ -422,7 +422,7 @@ Lightroom's keys, so hands that learned them there need not learn them again. Pu
There is no wheel on a tablet, so without the pinch the cell size could only be changed by a control a finger cannot reach.
<sub>`ui/dr-ui/ui/library.slint:3340`</sub>
<sub>`ui/dr-ui/ui/library.slint:3344`</sub>
### File photographs in a collection
@@ -431,7 +431,7 @@ There is no wheel on a tablet, so without the pinch the cell size could only be
The selection is what the drag carries, which is why selecting several is worth the mode: forty photographs file in one gesture.
<sub>`ui/dr-ui/ui/library.slint:3537`</sub>
<sub>`ui/dr-ui/ui/library.slint:3541`</sub>
### Open a photograph
@@ -440,7 +440,7 @@ The selection is what the drag carries, which is why selecting several is worth
A tap opens; a tap that *moved* does not. Travel is what separates a deliberate tap from a hand brushing past, and it is the only thing that does: the two are the same length. An earlier version required the finger to dwell 120 ms instead, and that rejected ordinary taps — a real tap is often quicker than a brush.
<sub>`ui/dr-ui/ui/library.slint:3833`</sub>
<sub>`ui/dr-ui/ui/library.slint:3837`</sub>
### Rate a photograph without opening it
@@ -450,7 +450,7 @@ A tap opens; a tap that *moved* does not. Travel is what separates a deliberate
A star has to take the press without it also reaching the cell, or every rating throws the user into develop.
<sub>`ui/dr-ui/ui/library.slint:3953`</sub>
<sub>`ui/dr-ui/ui/library.slint:3957`</sub>
### Choose the frame a folded burst shows
@@ -459,7 +459,7 @@ A star has to take the press without it also reaching the cell, or every rating
A folded burst draws its earliest frame, which is a fact about the clock and not a judgement about the photograph — nothing in this application ranks a frame (FR-CULL-5). But the point of a burst is that one of the twelve is better than the other eleven, and the photographer is the only one who knows which. So the choice is offered on the frames themselves, while they are open and side by side, which is the one moment the alternatives are on screen to be compared.
<sub>`ui/dr-ui/ui/library.slint:4085`</sub>
<sub>`ui/dr-ui/ui/library.slint:4089`</sub>
### Drop the selection but keep selecting
@@ -468,7 +468,7 @@ A folded burst draws its earliest frame, which is a fact about the clock and not
Distinct from Done, which leaves the mode entirely. Clearing keeps it, so the next selection can start straight away.
<sub>`ui/dr-ui/ui/library.slint:4761`</sub>
<sub>`ui/dr-ui/ui/library.slint:4765`</sub>
### Select everything the grid is showing
@@ -478,7 +478,7 @@ Distinct from Done, which leaves the mode entirely. Clearing keeps it, so the ne
A scoped grid of two hundred frames is two hundred taps otherwise, and "all of them, except those three" is a far more common shape than the taps it took to say it.
<sub>`ui/dr-ui/ui/library.slint:4778`</sub>
<sub>`ui/dr-ui/ui/library.slint:4782`</sub>
### Take photographs out of a collection
@@ -487,4 +487,4 @@ A scoped grid of two hundred frames is two hundred taps otherwise, and "all of t
The badge on a cell says a photograph is filed in three collections and never which. This is the sheet that names them, and the only way out of one the grid is not currently scoped to.
<sub>`ui/dr-ui/ui/library.slint:4919`</sub>
<sub>`ui/dr-ui/ui/library.slint:4923`</sub>
+5
View File
@@ -238,6 +238,11 @@ a private X server and records each scene; `record.sh <library>` re-makes
every picture here. Run it after a change to the interface and commit what
changed. The pictures are in LFS.
The application carries this page. `cargo run -p traceability -- manual`
renders it to `index.html` beside it, which the packages install with the
pictures and the app opens from Help, from Settings, and from the "See it"
link beside a gesture on the help sheet. CI fails when the two differ.
Making it the first time turned up nine faults, each fixed in its own
commit before the pictures were taken: the folder picker could not choose
the top level, month headings overprinted each other, a category mask
+4
View File
@@ -291,6 +291,10 @@ here, for the obvious reason — <a href="https://gitea.tourolle.paris/dtourolle
a private X server and records each scene; <code>record.sh &lt;library&gt;</code> re-makes
every picture here. Run it after a change to the interface and commit what
changed. The pictures are in LFS.</p>
<p>The application carries this page. <code>cargo run -p traceability -- manual</code>
renders it to <code>index.html</code> beside it, which the packages install with the
pictures and the app opens from Help, from Settings, and from the "See it"
link beside a gesture on the help sheet. CI fails when the two differ.</p>
<p>Making it the first time turned up nine faults, each fixed in its own
commit before the pictures were taken: the folder picker could not choose
the top level, month headings overprinted each other, a category mask
+4
View File
@@ -115,6 +115,10 @@ slint = { workspace = true, features = [
"renderer-femtovg-wgpu",
"unstable-wgpu-29",
] }
# The manual's `file:` URL (`manual::desktop_open`): a Windows path and a
# path with a space in it are both URLs only after encoding, and this is the
# crate the workspace already encodes URLs with.
url.workspace = true
[target.'cfg(target_os = "android")'.dependencies]
slint = { workspace = true, features = ["backend-android-activity-06"] }
+10
View File
@@ -847,6 +847,16 @@ fn open_in_browser(url: &str) -> std::io::Result<()> {
format!("refusing to open a sign-in address that is not https: {url}"),
));
}
hand_to_system(url)
}
/// Hand `target` — a URL, or a local file's path — to whatever the platform
/// opens it with.
///
/// No check on what it is: [`open_in_browser`] is the caller with a server's
/// URL in hand and refuses anything but https before it gets here, and
/// `manual::open` hands over a page it wrote itself.
pub(crate) fn hand_to_system(url: &str) -> std::io::Result<()> {
// Not `target_os = "linux"`: Android is its own target_os, and reached this
// arm's `Ok(())` fallback, so the browser silently never opened.
#[cfg(all(unix, not(target_os = "android"), not(target_os = "macos")))]
+1
View File
@@ -48,6 +48,7 @@ mod library;
mod library_ui;
#[cfg(live_style)]
mod live_style;
pub mod manual;
mod masks_ui;
pub mod memory;
pub mod merge;
+20
View File
@@ -199,6 +199,26 @@ pub fn wire<F>(
.collect::<Vec<_>>(),
)));
// TRACES: FR-UI-4
// The manual, from the help sheet and from Settings. Opened on this
// thread: all it does is write a one-line page and start a process (or,
// on Android, an activity), which is quicker than handing it to a worker.
// A failure — in practice, a build with no manual installed — goes to the
// status line, since the button the user pressed otherwise did nothing.
{
let weak = window.as_weak();
window
.global::<Library>()
.on_library_open_manual(move |anchor| {
if let Err(e) = crate::manual::open(&anchor) {
log::warn!("manual: {e}");
if let Some(w) = weak.upgrade() {
w.global::<Library>().set_library_status(e.into());
}
}
});
}
// Shared rather than moved: a click and `Return` both open an image, and
// they are two callbacks.
let on_open_image: OpenImage = Rc::new(on_open_image);
+221
View File
@@ -0,0 +1,221 @@
//! TRACES: FR-UI-4
//! Opening the bundled manual, at a section when asked for one.
//!
//! The manual is `docs/manual/index.html` and its pictures, rendered by
//! `tools/traceability` and installed by each package beside the models:
//! `/usr/share/darkroom/manual` on Linux, `manual\` beside the executable on
//! Windows, `assets/manual` inside the APK. Bundled rather than linked to on
//! the forge, because the moment somebody opens a help sheet is not a moment
//! to require a network.
//!
//! # Desktop: the system browser, by way of a one-line page
//!
//! A section is a fragment — `index.html#rating-and-flagging` — and the
//! fragment is exactly what the platforms' openers lose. `xdg-open` in its
//! generic mode, and `url.dll,FileProtocolHandler` on Windows, turn a `file:`
//! URL into a path before they hand it on, and a path has no fragment: the
//! manual opens at the top and the "See it" link has done nothing a plain
//! "Manual" link would not. So a section is opened through a small page of
//! our own whose only content is a redirect to the full URL, fragment and
//! all; the opener is handed that page's *path*, which every opener keeps
//! intact, and the browser follows the redirect itself. Written to the user
//! data directory, overwritten on each use.
//!
//! # Android: a WebView of our own
//!
//! Android has no path to hand a browser. An asset inside the APK is not a
//! file; a copy unpacked to app-private storage is a file no other app may
//! read, and a `file:` URI handed across apps is refused outright since API
//! 24. A content provider would serve the page, but a browser then asks the
//! same provider for every picture by a relative URL it resolves against a
//! `content:` authority — which the browsers do not reliably do. So the page is
//! shown by `ManualActivity`, a WebView that reads
//! `file:///android_asset/manual/index.html` straight out of the APK, pictures
//! and fragment included, with nothing unpacked.
use std::path::PathBuf;
/// The Android activity that shows the manual. Named by string in the Intent,
/// so no class has to be loaded to start it; the manifest test in
/// `darkroom-android` checks the manifest declares this exact name.
pub const ANDROID_ACTIVITY: &str = "paris.tourolle.darkroom.ManualActivity";
/// The Intent extra carrying the section, read by `ManualActivity`.
pub const ANDROID_EXTRA_ANCHOR: &str = "anchor";
/// Where the installed manual is, if a package installed one.
///
/// The package directories first, as the models are found. A development
/// build also looks in the checkout it was compiled from, so `cargo run`
/// opens the page the tree has; a release build never does, because the
/// checkout is not on the user's machine.
pub fn page() -> Option<PathBuf> {
#[allow(unused_mut)]
let mut candidates: Vec<PathBuf> = dr_plat::system_data_dirs()
.into_iter()
.map(|d| d.join("manual").join("index.html"))
.collect();
#[cfg(debug_assertions)]
candidates.push(PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../docs/manual/index.html"));
candidates.into_iter().find(|p| p.is_file())
}
/// A section's anchor, as it may appear in a URL.
///
/// Anchors are the forge's slugs — lower-case letters, digits and hyphens — so
/// anything else in one is not a section of this manual and is dropped rather
/// than escaped: it came from the generated gesture table, and a table entry
/// that needs escaping is a bug to notice, not to route around.
fn clean_anchor(anchor: &str) -> String {
anchor
.chars()
.filter(|c| c.is_alphanumeric() || *c == '-' || *c == '_')
.collect()
}
/// The redirect page for one section of the manual at `target`.
#[cfg(not(target_os = "android"))]
fn redirect_page(target: &str) -> String {
format!(
"<!DOCTYPE html>\n<html lang=\"en\"><head><meta charset=\"utf-8\">\n\
<title>DarkRoom manual</title>\n\
<meta http-equiv=\"refresh\" content=\"0; url={target}\">\n\
</head><body><p><a href=\"{target}\">Open the DarkRoom manual</a></p></body></html>\n"
)
}
/// Open the manual, at `anchor` when it is not empty.
///
/// The error is a sentence for the status line: the one case a user can do
/// anything about is a manual that is not installed.
pub fn open(anchor: &str) -> Result<(), String> {
let anchor = clean_anchor(anchor);
#[cfg(target_os = "android")]
{
android_open(&anchor)
}
#[cfg(not(target_os = "android"))]
{
desktop_open(&anchor)
}
}
#[cfg(not(target_os = "android"))]
fn desktop_open(anchor: &str) -> Result<(), String> {
let Some(page) = page() else {
return Err("The manual is not installed with this copy of DarkRoom".into());
};
// Unix only: on Windows `canonicalize` answers with a `\\?\` verbatim
// path, which is not one a `file:` URL can be made from — and there the
// path is the executable's directory, already absolute.
#[cfg(unix)]
let page = page.canonicalize().unwrap_or(page);
if anchor.is_empty() {
log::info!("opening the manual at {}", page.display());
return crate::launch_ui::hand_to_system(&page.to_string_lossy())
.map_err(|e| format!("Could not open the manual: {e}"));
}
let Ok(mut url) = url::Url::from_file_path(&page) else {
return Err(format!(
"{} is not a path a browser can open",
page.display()
));
};
url.set_fragment(Some(anchor));
let link = dr_plat::base_dir(dr_plat::Base::Data).join("manual-link.html");
if let Some(dir) = link.parent() {
std::fs::create_dir_all(dir).map_err(|e| format!("Could not open the manual: {e}"))?;
}
std::fs::write(&link, redirect_page(url.as_str()))
.map_err(|e| format!("Could not open the manual: {e}"))?;
log::info!("opening the manual at {url} by way of {}", link.display());
crate::launch_ui::hand_to_system(&link.to_string_lossy())
.map_err(|e| format!("Could not open the manual: {e}"))
}
/// Start `ManualActivity` with the section as an extra.
///
/// `Intent.setClassName(Context, String)` rather than a class object: the
/// activity's class is in this APK's dex, which a native thread's `FindClass`
/// cannot see (see `darkroom-android`'s `load_class`), and a name needs no
/// class at all. The extra is a string rather than the Intent's data URI,
/// because a `file:` data URI trips the platform's exposure check.
#[cfg(target_os = "android")]
fn android_open(anchor: &str) -> Result<(), String> {
let ctx = ndk_context::android_context();
if ctx.vm().is_null() || ctx.context().is_null() {
return Err("no Android context available".into());
}
// SAFETY: the pointer comes from ndk_context, which android-activity fills
// in with the process's real JavaVM before any Rust runs.
let vm = unsafe { jni::JavaVM::from_raw(ctx.vm().cast()) };
let raw_activity: jni::sys::jobject = ctx.context().cast();
vm.attach_current_thread(|env| {
// SAFETY: valid for this frame, which is all the Intent needs.
let activity = unsafe { jni::objects::JObject::from_raw(env, raw_activity) };
let intent = env.new_object(
jni::jni_str!("android/content/Intent"),
jni::jni_sig!("()V"),
&[],
)?;
let class = env.new_string(ANDROID_ACTIVITY)?;
env.call_method(
&intent,
jni::jni_str!("setClassName"),
jni::jni_sig!("(Landroid/content/Context;Ljava/lang/String;)Landroid/content/Intent;"),
&[(&activity).into(), (&class).into()],
)?;
let key = env.new_string(ANDROID_EXTRA_ANCHOR)?;
let value = env.new_string(anchor)?;
env.call_method(
&intent,
jni::jni_str!("putExtra"),
jni::jni_sig!("(Ljava/lang/String;Ljava/lang/String;)Landroid/content/Intent;"),
&[(&key).into(), (&value).into()],
)?;
env.call_method(
&activity,
jni::jni_str!("startActivity"),
jni::jni_sig!("(Landroid/content/Intent;)V"),
&[(&intent).into()],
)?;
if env.exception_check() {
env.exception_clear();
return Err(jni::errors::Error::JavaException);
}
Ok(())
})
.map_err(|e: jni::errors::Error| format!("Could not open the manual: {e}"))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn an_anchor_keeps_only_what_a_slug_can_hold() {
assert_eq!(clean_anchor("rating-and-flagging"), "rating-and-flagging");
assert_eq!(clean_anchor("x\"><script>"), "xscript");
assert_eq!(clean_anchor(""), "");
}
#[cfg(not(target_os = "android"))]
#[test]
fn the_redirect_carries_the_fragment() {
let page = redirect_page("file:///usr/share/darkroom/manual/index.html#looking-closer");
assert!(page.contains(
"content=\"0; url=file:///usr/share/darkroom/manual/index.html#looking-closer\""
));
}
/// A development build finds the page in the checkout, so this is also
/// the test that the committed page is where the packagers copy it from.
#[test]
fn a_development_build_finds_the_page() {
let page = page().expect("docs/manual/index.html is not where the packagers expect it");
assert!(page.ends_with("index.html"));
}
}
+2
View File
@@ -1121,6 +1121,7 @@ in property <bool> panel-visible: true;
diagnostics-prepare() => { root.diagnostics-prepare(); }
diagnostics-save() => { root.diagnostics-save(); }
diagnostics-discard() => { root.diagnostics-discard(); }
open-manual() => { Library.library-open-manual(""); }
close() => { root.settings-close(); }
reset-defaults() => { root.settings-reset(); }
@@ -1439,6 +1440,7 @@ in property <bool> panel-visible: true;
filter-eyes-open: Library.library-filter-eyes-open;
people: Library.library-people;
gestures: Library.library-gestures;
open-manual(anchor) => { Library.library-open-manual(anchor); }
filter-min-rating: Library.library-filter-min-rating;
filter-max-rating: Library.library-filter-max-rating;
filter-rating-range(low, high) => {
+10
View File
@@ -69,6 +69,8 @@ export component GestureSheet inherits Rectangle {
in property <[GestureRow]> rows;
callback close();
/// Open the manual, at a section's anchor or, empty, at the top.
callback open-manual(string);
background: #000000CC;
@@ -172,6 +174,14 @@ export component GestureSheet inherits Rectangle {
HorizontalLayout {
alignment: end;
spacing: Theme.gap;
// The manual is the other half of this sheet: the sheet says
// which move does a thing, the manual shows the thing being
// done. From the one place a puzzled user already is.
Button {
text: "Manual";
clicked => { root.open-manual(""); }
}
Button {
text: "Done";
primary: true;
+5
View File
@@ -723,6 +723,8 @@ export global Library {
/// TRACES: FR-UI-4
/// The gesture reference's rows, read from the generated table.
in property <[GestureRow]> library-gestures;
/// Open the bundled manual, at a section's anchor or, empty, at the top.
callback library-open-manual(string);
in property <[PersonChip]> library-people;
callback library-people-listed();
callback library-filter-person-toggled(int);
@@ -1586,6 +1588,8 @@ export component LibraryGrid inherits Rectangle {
/// The gesture reference's rows, from Rust — which reads them from the
/// generated table. See gestures.slint for why they cannot be written here.
in property <[GestureRow]> gestures;
/// Open the manual, at the section `anchor` names or at the top.
callback open-manual(string);
/// Whether the reference is up. Local, like `naming` and `filing`: nothing
/// in Rust needs to know a sheet is open.
property <bool> helping: false;
@@ -4978,6 +4982,7 @@ export component LibraryGrid inherits Rectangle {
height: 100%;
rows: root.gestures;
close => { root.helping = false; }
open-manual(anchor) => { root.open-manual(anchor); }
}
// --- the naming sheet (FR-CAT-5, FR-CAT-7) ------------------------------
+22
View File
@@ -163,6 +163,10 @@ export component SettingsPage inherits Rectangle {
callback diagnostics-save();
callback diagnostics-discard();
/// TRACES: FR-UI-4
/// Open the manual that came with the application (`dr_ui::manual`).
callback open-manual();
/// TRACES: FR-DSP-8
/// The display showing the canvas, and the colour it is being given.
///
@@ -741,6 +745,24 @@ export component SettingsPage inherits Rectangle {
Value { text: root.app-version; horizontal-stretch: 1; overflow: elide; }
}
// The manual, beside the version because both answer
// "what is this application": one says which, the
// other what it does. Installed with it, so it opens
// with no network.
HorizontalLayout {
spacing: Theme.gap;
Label { text: "Manual"; vertical-alignment: center; }
Rectangle {
horizontal-stretch: 1;
height: Theme.control-height;
Button {
x: 0;
text: "Open the manual";
clicked => { root.open-manual(); }
}
}
}
HorizontalLayout {
spacing: Theme.gap;
Label { text: "Graphics"; }