mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-17 06:11:21 +01:00
feat(gui): one window for recording and reviewing
The recorder is now the pinned first tab (Record, not closable, with a REC marker while recording) of the viewer window; sessions follow as tabs. There is one process and one window: komorebi-recorder, gui and view all claim the same socket, and a second launch forwards (gui shows the Record tab, view opens tabs) and exits. The request protocol gains an optional "tab" field; old requests still parse. gui takes the record options (they only seed the window that is started) and --new-window. The window starts compact (420x380, always on top, Record tab only) when launched plainly and full size for view; opening any session expands it, and Compact / Expand is remembered in the prefs. RecorderApp::poll runs on every frame whichever tab is showing, so recordings continue and finalize while another tab is looked at. Cmd/Ctrl+0 shows the Record tab; Cmd/Ctrl+W on it does nothing; closing the last session tab returns to Record. KOMOREBI_RECORDER_PREFS_DIR and KOMOREBI_RECORDER_NO_IGNORE_RULE let tests and end-to-end runs avoid the real prefs and the real komorebi. The macOS/unix cfg branches (hidden title bar spacing) mirror the existing tested patterns and could not be compiled on the Windows machine this was written on.
This commit is contained in:
1 parent
72d600c8f6
commit
8e454e1e03
19 files changed
+1603
-571
No files matched your search
@@ -82,9 +82,10 @@ when things happened (events | errors | incidents):
|
||||
00:04.500 ############################## 1 0 0
|
||||
```
|
||||
|
||||
`komorebi-recorder view ./repro` opens the recording in the viewer, which is where you mark where the bug is. There is
|
||||
one viewer window: running `view` again (or **Open session…** in the recorder window) opens another recording as a tab
|
||||
of it, and `view --new-window` makes a window of its own.
|
||||
`komorebi-recorder view ./repro` opens the recording in the window, which is where you mark where the bug is. There is
|
||||
only ever one window, for recording and for reviewing: its first tab is **Record** and each recording is a tab after it.
|
||||
Running `komorebi-recorder` or `view` again (or **Open session…** in the Record tab) raises that window instead of
|
||||
making another, and `--new-window` makes a window of its own.
|
||||
Every command takes `--json` (including `record`, `displays`, `reindex` and `selftest`), and `komorebi-recorder guide`
|
||||
prints a playbook for an agent.
|
||||
[Investigating a recording](docs/usage/investigating-a-recording.md) walks through both ways of working.
|
||||
|
||||
+11
-4
@@ -83,13 +83,20 @@ recorded in the manifest, and everything that reads a session asks the manifest.
|
||||
|
||||
## Why can a bug only be marked in the viewer?
|
||||
|
||||
The recorder window has no button for marking a bug, and the viewer has one. I found it confusing to have two places to do
|
||||
the same thing, so a bug is marked in the viewer only. `komorebi-recorder annotate` writes the same annotations for a
|
||||
The Record tab has no button for marking a bug, and a session's tab has one. I found it confusing to have two places to do
|
||||
the same thing, so a bug is marked in a session's tab only. `komorebi-recorder annotate` writes the same annotations for a
|
||||
script or an agent that has no window.
|
||||
|
||||
## Why is the recorder window untitled?
|
||||
## Why is there one window?
|
||||
|
||||
komorebi does not manage windows with an empty title, so a borderless untitled window is never tiled: opening the recorder
|
||||
Recording and reviewing used to be two windows, and the recorder's buttons for opening a recording started the other one.
|
||||
Now the recorder is the pinned first tab of the one window and each recording is a tab after it, so there is one thing to
|
||||
keep out of the video and out of komorebi's layout. It starts small, always on top, with only the Record tab, which is what
|
||||
the old recorder window was for, and grows when a recording is opened.
|
||||
|
||||
## Why is the window untitled?
|
||||
|
||||
komorebi does not manage windows with an empty title, so an untitled window is never tiled: opening the recorder
|
||||
does not move the layout of the machine whose bug is being recorded.
|
||||
|
||||
## Why is ffmpeg not part of the program?
|
||||
|
||||
+4
-1
@@ -127,7 +127,10 @@ that a contact sheet never decodes more pixels than it shows.
|
||||
|
||||
### The program's own windows
|
||||
|
||||
The recorder window and the viewer must not be in the video they are recording, and komorebi must not tile them.
|
||||
The program has one window, with the recorder as its first tab and the recordings as the others. It must not be in the
|
||||
video it is recording, in either of its sizes (the small always-on-top one and the full one), and komorebi must not tile
|
||||
it. Every `komorebi-recorder` launch (`gui`, `view`, no command, and `komorebi-recorder-gui.exe`) shares one local socket,
|
||||
so there is never a second window to exclude.
|
||||
|
||||
| | macOS | Windows |
|
||||
|---|---|---|
|
||||
|
||||
@@ -22,14 +22,15 @@ budget, 6 an `assert` check did not hold.
|
||||
komorebi-recorder view <session>
|
||||
```
|
||||
|
||||
opens the recording in the viewer window, for the person who made it (or anyone with the folder) to play, scrub and mark.
|
||||
The recorder window has **Open session…** and **Open last** for the same thing.
|
||||
opens the recording in the window, for the person who made it (or anyone with the folder) to play, scrub and mark.
|
||||
The Record tab of the same window has **Open session…** and **Open last** for the same thing.
|
||||
|
||||
There is only ever one viewer window. Each recording is a tab of it: `komorebi-recorder view <session>...` (from another
|
||||
terminal, or from the recorder window) adds tabs to the window that is already open and brings it to the front, so
|
||||
several recordings can be loaded side by side. A recording that is already open is just switched to. **+** (or ⌘/Ctrl-T)
|
||||
adds a start tab with your recent recordings and **Open…**, × (or middle-click, or ⌘/Ctrl-W) closes a tab, Ctrl-Tab and
|
||||
⌘/Ctrl-1 to 9 move between them, and only the tab you are looking at plays. `view --new-window` skips all of this and
|
||||
There is only ever one window, for recording and for reviewing: its first tab is **Record** (see [Recording a bug
|
||||
repro](recording-a-bug-repro.md#the-window)) and each recording is a tab after it. `komorebi-recorder view
|
||||
<session>...` (from another terminal, or from the Record tab) adds tabs to the window that is already open and brings it
|
||||
to the front, so several recordings can be loaded side by side. A recording that is already open is just switched to. **+** (or ⌘/Ctrl-T)
|
||||
adds a start tab with your recent recordings and **Open…**, × (or middle-click, or ⌘/Ctrl-W) closes a tab (closing the
|
||||
last one shows the Record tab), Ctrl-Tab and ⌘/Ctrl-1 to 9 move between them, ⌘/Ctrl-0 goes to the Record tab, and only the tab you are looking at plays. `view --new-window` skips all of this and
|
||||
opens a window of its own.
|
||||
|
||||
- The **video** of every display, side by side. A display that was unplugged or asleep shows why it has nothing there,
|
||||
@@ -137,7 +138,7 @@ and `event:12.end` when it finished.
|
||||
| `assert --check "KIND ARGS METRIC<=N"` | Pass/fail checks for a scripted scenario, repeatable. Kinds: `findings kind=K [severity=S] count<=N`, `log "<logq query>" count==N`, `motion [region=x,y,w,h] [from=T] [to=T] segments\|active_ms\|peak_share<=N`, `blank region=x,y,w,h [from=T] [to=T] [color=white] ms<=N`, `annotations kind=note\|bug\|finding count>=N`. Operators `== != <= >= < >`. Prints `PASS`/`FAIL` per check; exit 0 if all pass, 6 if one fails, 4 if one cannot be measured (no video), 2 if malformed. `--json` gives `assert/1` |
|
||||
| `annotate`, `annotations` | Add, change and list bug regions, notes and findings |
|
||||
| `mark TEXT` | While recording: drop a named point note (author `script`) onto the timeline from a script; it then appears in `annotations`, `brief` and the viewer like any note |
|
||||
| `view [SESSION...] [--new-window]` | Open recordings in the viewer window, each as a tab of the one window that is running (it is started if there is none and brought to the front if there is); `--new-window` makes a window of its own instead |
|
||||
| `view [SESSION...] [--new-window]` | Open recordings in the window, each as a tab of the one window that is running (it is started if there is none and brought to the front if there is); `--new-window` makes a window of its own instead |
|
||||
|
||||
### Who changed it
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ was the OS doing, at 00:12.5 in the video?" and the other way around.
|
||||
|
||||
```
|
||||
komorebi-recorder record --duration 30 # record without a window
|
||||
komorebi-recorder # or open the Record / Stop window
|
||||
komorebi-recorder # or open the window, with its Record / Stop tab
|
||||
```
|
||||
|
||||
It is built for the situations where komorebi bugs actually show up: laptops that get docked and undocked, woken with the
|
||||
@@ -46,7 +46,7 @@ Start komorebi with `komorebi.exe --log-level debug` before recording a bug. (`R
|
||||
prints every dependency's log; `RUST_LOG=komorebi=debug` does not.)
|
||||
`komorebi-recorder doctor` says what the machine can do, and `komorebi-recorder record --no-video` records without the
|
||||
screen.
|
||||
The recorder window keeps itself out of the video (Windows 10 version 2004 or later).
|
||||
The window keeps itself out of the video (Windows 10 version 2004 or later).
|
||||
|
||||
## Before you record
|
||||
|
||||
@@ -58,9 +58,11 @@ The recorder window keeps itself out of the video (Windows 10 version 2004 or la
|
||||
- **`ffmpeg`** is only needed for `frames` and `selftest`. It is never used to capture. The `nix develop` shell provides
|
||||
it; otherwise `brew install ffmpeg`.
|
||||
|
||||
The recorder window is borderless, and on Windows is named `komorebi-recorder` only once komorebi is told to ignore it:
|
||||
There is one window for everything. It opens small (the Record tab alone, always on top, to leave over the application
|
||||
you are reproducing a bug in) and grows when you open a recording; see [The window](#the-window). On Windows it is named
|
||||
`komorebi-recorder` only once komorebi is told to ignore it:
|
||||
at start the recorder runs `komorebic ignore-rule exe komorebi-recorder.exe` (and the same for
|
||||
`komorebi-recorder-gui.exe`, which opens the viewer) against the running komorebi, a live rule that is not saved. If
|
||||
`komorebi-recorder-gui.exe`, the build with no console window) against the running komorebi, a live rule that is not saved. If
|
||||
komorebi is not running the window is named too; if `komorebic` is not found or fails, and on a Mac, the window stays
|
||||
untitled, because komorebi does not manage windows without a title, and the recorder says so on standard error and in
|
||||
the window. Either way opening it does not move your layout around while you are trying to reproduce a layout bug.
|
||||
@@ -89,14 +91,33 @@ the same match is an `ignore_rules` entry with `kind: Exe`, `id: komorebi-record
|
||||
}
|
||||
```
|
||||
It is also excluded from the video, as is any other `komorebi-recorder` process.
|
||||
The viewer is one such process.
|
||||
The window is one such process, in either size.
|
||||
|
||||
## Recording
|
||||
|
||||
Press **Record**, reproduce the problem, press **Stop**. The window shows live counters, recent events (a display being
|
||||
unplugged, a wake) and any warnings. The session is written to
|
||||
Press **Record**, reproduce the problem, press **Stop**. The Record tab shows live counters, recent events (a display
|
||||
being unplugged, a wake) and any warnings. The session is written to
|
||||
`~/Library/Application Support/komorebi/recordings/<UTC timestamp>/` unless you pass `--out`.
|
||||
|
||||
The **Review** row of the tab has **Open session…** (choose a recording's folder) and **Open last** (the newest one);
|
||||
each opens the recording as a new tab of this same window, and the window grows to show it.
|
||||
|
||||
### The window
|
||||
|
||||
`komorebi-recorder` (or `komorebi-recorder gui`) opens one window, and there is never a second: starting it again, or
|
||||
running `komorebi-recorder view <session>`, raises the window that is already open instead. The first tab, **Record**,
|
||||
cannot be closed, and says `REC` and the time in the tab bar while a recording is going, so you can look at another tab
|
||||
and see that it still is (the recording carries on whichever tab is showing, and closing the window while recording
|
||||
finishes the session first). The recordings you open follow it as tabs, and **+**, ⌘/Ctrl-T and ⌘/Ctrl-0 (the Record
|
||||
tab) work as in a browser.
|
||||
|
||||
Started plainly, the window is _compact_: 420 by 380, always on top, showing the Record tab and nothing else, the small
|
||||
control window you leave over the application you are reproducing the bug in. **Expand** (on the Record tab) makes it
|
||||
the full window with the tab bar, and opening a recording does that for you; **Compact** goes back, and the choice is
|
||||
remembered. While recording, the full window has a **pin on top** checkbox. Options such as `--fps` or `--no-komorebi`
|
||||
given to `komorebi-recorder`/`gui` set up the Record tab of the window that gets started; if a window is already open
|
||||
they are ignored. `--new-window` opens a window of its own instead of raising the open one.
|
||||
|
||||
With every display ticked, the recorder follows _all_ displays, including ones connected while it is recording. Untick a
|
||||
display to record only the others.
|
||||
|
||||
@@ -148,9 +169,10 @@ Useful options:
|
||||
|
||||
### Marking where the bug is
|
||||
|
||||
A bug is marked in one place, the viewer, after the recording: `komorebi-recorder view <session>` opens it, and **Mark
|
||||
bug** (or **B**) takes a stretch of the recording and what went wrong in it. That marks a _region_, not a single moment.
|
||||
The recorder window has no button for it, so while recording there is nothing to do but reproduce the problem.
|
||||
A bug is marked in one place, a session's tab, after the recording: `komorebi-recorder view <session>` opens it (the
|
||||
Record tab's **Open last** does too), and **Mark bug** (or **B**) takes a stretch of the recording and what went wrong in
|
||||
it. That marks a _region_, not a single moment. The Record tab has no button for it, so while recording there is nothing
|
||||
to do but reproduce the problem.
|
||||
|
||||
This is what makes the recording useful to whoever investigates it, person or agent: your description is the ground
|
||||
truth of _what_ went wrong, and everything else in the session is evidence of _why_. See
|
||||
|
||||
+407
-304
@@ -1,56 +1,64 @@
|
||||
//! The recorder window: Record / Stop, live counters and warnings.
|
||||
//! The recorder tab: Record / Stop, live counters and warnings.
|
||||
//!
|
||||
//! This is what `komorebi-recorder` opens when it is run with no subcommand, and with `gui`: [`run`]
|
||||
//! shows a small window and keeps it until it is closed. It is the same recorder as
|
||||
//! `komorebi-recorder record`, with a window instead of Ctrl-C.
|
||||
//! The recorder is not a window of its own. It is the pinned first tab of the one window of the
|
||||
//! program ([`crate::viewer`]), which `komorebi-recorder` (with no command) and `komorebi-recorder
|
||||
//! gui` open, and which also holds a tab for every session being reviewed. This module is the
|
||||
//! recorder itself, [`RecorderApp`]: the host window draws it into the Record tab with
|
||||
//! [`RecorderApp::ui`] and, on every frame whichever tab is showing, calls [`RecorderApp::poll`], so
|
||||
//! that a recording carries on, and is finalized, while a session is being looked at. [`run`] opens
|
||||
//! the window; it is the same recorder as `komorebi-recorder record`, with a window instead of
|
||||
//! Ctrl-C.
|
||||
//!
|
||||
//! # What the window does
|
||||
//! # What the tab does
|
||||
//!
|
||||
//! | control | effect |
|
||||
//! |---|---|
|
||||
//! | Record | starts a recording on a thread named `recorder` ([`recorder::record`]), with the options the window was started with, the displays ticked below and the predicate typed under Advanced |
|
||||
//! | Stop | asks the recording to finish ([`Live::request_stop`]); it indexes and finalizes the session, which the window shows as "finalizing..." |
|
||||
//! | Open session..., Open last | open a recording as a tab of the viewer window, which is started in a process of its own if it is not running ([`crate::viewer::ipc`]) |
|
||||
//! | Stop | asks the recording to finish ([`Live::request_stop`]); it indexes and finalizes the session, which the tab shows as "finalizing..." |
|
||||
//! | Open session..., Open last | open a recording as a new tab of this same window (a folder dialog, or the newest session); the window expands if it was compact |
|
||||
//! | Compact / Expand | switches the window between the small control window and the full one ([`crate::viewer`]) |
|
||||
//! | Copy path, Open in the file manager | after a recording: copy where the session was saved, or show it (Finder or Explorer) |
|
||||
//!
|
||||
//! While idle the list of displays is read again every second, so a display that was docked or
|
||||
//! undocked appears or disappears and a new one starts ticked. With every display ticked the
|
||||
//! recorder follows all of them, including any connected while recording; with one unticked it
|
||||
//! records only the ticked ones. While recording the window shows counters (video frames and the
|
||||
//! records only the ticked ones. While recording the tab shows counters (video frames and the
|
||||
//! frames dropped, the size of komorebi's log, the number of komorebi events, the OS trace and each
|
||||
//! of its streams), the most recent incidents to the recording environment, and any warnings.
|
||||
//! of its streams), the most recent incidents to the recording environment, and any warnings, and
|
||||
//! the tab's label in the tab bar says `REC` and the time.
|
||||
//!
|
||||
//! The window does not mark where a bug is: that is done afterwards, in the viewer.
|
||||
//! The tab does not mark where a bug is: that is done afterwards, in a session's tab.
|
||||
//!
|
||||
//! Closing the window while recording, or delivering SIGINT or SIGTERM to the process (the handler
|
||||
//! also runs on SIGHUP on Unix, and on Ctrl-C on Windows), finishes and indexes the session first
|
||||
//! rather than leaving it half-written, and only then closes the window.
|
||||
//! rather than leaving it half-written, and only then closes the window. With no recording the
|
||||
//! window closes at once.
|
||||
//!
|
||||
//! # Staying out of the video and out of the layout
|
||||
//!
|
||||
//! The window is for use on the machine whose behavior is being recorded, so it must not appear in
|
||||
//! the video and must not be tiled by komorebi.
|
||||
//! the video and must not be tiled by komorebi. Both hold for the one window, in either size.
|
||||
//!
|
||||
//! - **Not in the video.** On macOS the capture filter excludes this whole application (this
|
||||
//! process and every process named `komorebi-recorder`), so the controls never appear in the
|
||||
//! process and every process named `komorebi-recorder`), so the window never appears in the
|
||||
//! video. On Windows a whole monitor is captured, so about once a second the window asks Windows
|
||||
//! to leave it out of captures (`WDA_EXCLUDEFROMCAPTURE`) through
|
||||
//! [`crate::platform::window::Chrome`].
|
||||
//! - **Not tiled.** The window is borderless, with its own drag handle and close button, and always
|
||||
//! on top. It is named only when it is safely ignored ([`crate::komorebi_ignore`]): on Windows,
|
||||
//! [`run`] first asks a running komorebi, with `komorebic ignore-rule exe`, to ignore the
|
||||
//! recorder's executables (komorebi's live rule, nothing is written to `komorebi.json`), and
|
||||
//! - **Not tiled.** The window is named only when it is safely ignored ([`crate::komorebi_ignore`]):
|
||||
//! on Windows, [`run`] first asks a running komorebi, with `komorebic ignore-rule exe`, to ignore
|
||||
//! the recorder's executables (komorebi's live rule, nothing is written to `komorebi.json`), and
|
||||
//! then titles the window `komorebi-recorder`; with no komorebi running it is titled too. If
|
||||
//! `komorebic` cannot be found or fails, and always on macOS (komorebi for Mac manages any window
|
||||
//! with a title, in `Window::should_manage`), the window stays untitled so that opening the
|
||||
//! recorder does not perturb the very layout being observed, and one line on standard error and
|
||||
//! the window's message area say how to add the rule by hand. On Windows
|
||||
//! the tab's message area say how to add the rule by hand. On Windows
|
||||
//! `KOMOREBI_RECORDER_PROBE_WINDOW=1` makes the window ask komorebi whether it would manage it
|
||||
//! (see [`crate::platform::window::PROBE_VARIABLE`]).
|
||||
//!
|
||||
//! The window needs an `egui::Context` to draw and a screen to record, so it has no example. Its
|
||||
//! logic that does not need either is covered by this module's unit test
|
||||
//! (`the_latest_session_is_the_last_by_name_and_must_be_a_session`).
|
||||
//! The tab needs an `egui::Ui` to draw and a screen to record, so it has no example. Its logic that
|
||||
//! does not need either is covered by this module's unit test
|
||||
//! (`the_latest_session_is_the_last_by_name_and_must_be_a_session`), and the tests of
|
||||
//! `viewer::app` drive it inside the window.
|
||||
|
||||
use crate::capture::DisplayDescriptor;
|
||||
use crate::cli::RecordArgs;
|
||||
@@ -112,25 +120,32 @@ pub fn latest_session_in(recordings: &std::path::Path) -> Option<PathBuf> {
|
||||
.max()
|
||||
}
|
||||
|
||||
/// Open `session` (or just a start-screen tab, with none) in the viewer.
|
||||
/// Open `session` (or just a start-screen tab, with none) in the program's window, from another
|
||||
/// process.
|
||||
///
|
||||
/// If a viewer is already running it is asked, over its socket, to open the session as a tab and
|
||||
/// to come to the front: no process is started. Only when none answers is `komorebi-recorder view`
|
||||
/// started, in a process of its own, so that reviewing a recording can never disturb one being
|
||||
/// made, and kept out of the video (by name on macOS, and by each of its windows asking on
|
||||
/// Windows). It then becomes the one viewer window.
|
||||
fn open_viewer(session: Option<&std::path::Path>) -> std::io::Result<()> {
|
||||
/// This is for a process that is not the window, such as a script or another tool: the window
|
||||
/// itself opens sessions as tabs without any of this. If a window is already running it is asked,
|
||||
/// over its socket, to open the session as a tab and to come to the front: no process is started.
|
||||
/// Only when none answers is `komorebi-recorder view` started, in a process of its own, and kept out
|
||||
/// of the video (by name on macOS, and by each of its windows asking on Windows). It then becomes
|
||||
/// the one window.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns an error if the window refused the request, or none was running and `view` could not be
|
||||
/// started.
|
||||
pub fn open_viewer(session: Option<&std::path::Path>) -> std::io::Result<()> {
|
||||
use crate::viewer::ipc;
|
||||
|
||||
let request = ipc::Request {
|
||||
open: session.map(ipc::absolute).into_iter().collect(),
|
||||
focus: true,
|
||||
..ipc::Request::default()
|
||||
};
|
||||
if ipc::send(&ipc::default_socket(), &request)? == ipc::Delivery::Delivered {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// on Windows the viewer is the build without a console, so that no console window opens with it
|
||||
// on Windows the window is the build without a console, so that no console window opens with it
|
||||
let this = std::env::current_exe()?;
|
||||
let gui = this.with_file_name(format!(
|
||||
"komorebi-recorder-gui{}",
|
||||
@@ -147,7 +162,7 @@ fn open_viewer(session: Option<&std::path::Path>) -> std::io::Result<()> {
|
||||
crate::platform::process::isolate(&mut command);
|
||||
command.arg("view");
|
||||
if let Some(session) = session {
|
||||
command.arg(crate::viewer::ipc::absolute(session));
|
||||
command.arg(ipc::absolute(session));
|
||||
}
|
||||
command.spawn().map(|_| ())
|
||||
}
|
||||
@@ -155,67 +170,57 @@ fn open_viewer(session: Option<&std::path::Path>) -> std::io::Result<()> {
|
||||
/// Set by SIGINT/SIGTERM: the window finishes any recording in progress, then closes.
|
||||
static QUIT: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
/// Installs the handler that sets the quit flag on SIGINT and SIGTERM (it also runs on SIGHUP on
|
||||
/// Unix, and on Ctrl-C on Windows), so that killing the window, or logging out, still finalizes a
|
||||
/// recording in progress. Failing to install it (another is already installed) is ignored.
|
||||
pub(crate) fn install_quit_handler() {
|
||||
let _ = ctrlc::set_handler(|| QUIT.store(true, Ordering::SeqCst));
|
||||
}
|
||||
|
||||
/// How often the list of attached displays is refreshed while idle.
|
||||
const DISPLAY_REFRESH: Duration = Duration::from_secs(1);
|
||||
|
||||
/// Opens the recorder window and runs it until it is closed.
|
||||
/// Opens the program's one window on the Record tab, in the small control window, and runs it
|
||||
/// until it is closed.
|
||||
///
|
||||
/// `args` are the options of `komorebi-recorder record` that the window starts from, such as
|
||||
/// `--fps`, `--codec` and `--no-komorebi`. Each recording uses them, except that the displays ticked in
|
||||
/// the window replace `--display` (every display ticked means every display, including any
|
||||
/// `args` are the options of `komorebi-recorder record` that the Record tab starts from, such as
|
||||
/// `--fps`, `--codec` and `--no-komorebi`. Each recording uses them, except that the displays ticked
|
||||
/// in the tab replace `--display` (every display ticked means every display, including any
|
||||
/// connected while recording) and a predicate typed under Advanced replaces `--predicate`.
|
||||
///
|
||||
/// This blocks the calling thread: the window's event loop runs on it. It installs a handler for
|
||||
/// SIGINT and SIGTERM (it also runs on SIGHUP on Unix, and on Ctrl-C on Windows) that asks the
|
||||
/// window to finish any recording in progress and close, so that killing the window, or logging
|
||||
/// out, still finalizes the session. Failing to install the handler (another is already
|
||||
/// installed) is ignored.
|
||||
/// `socket` is the path of the window's socket ([`crate::viewer::ipc::default_socket`]), or `None`
|
||||
/// for a window of its own that no other process can reach (`gui --new-window`). With a socket, if
|
||||
/// a window is already running it is asked to show its Record tab and this returns `Ok` at once
|
||||
/// without making a window, and `args` are ignored: they only seed the window that is started.
|
||||
///
|
||||
/// A recording that fails does not make this fail: the window shows why, and can record again.
|
||||
///
|
||||
/// The window is 420 by 380 points (at least 360 by 260), borderless and always on top, titled `komorebi-recorder` only when komorebi ignores it:
|
||||
/// see the [module documentation](self#staying-out-of-the-video-and-out-of-the-layout). Needs a
|
||||
/// window, so there is no example.
|
||||
/// This blocks the calling thread: the window's event loop runs on it. A recording that fails does
|
||||
/// not make this fail: the tab shows why, and can record again. The window is described in
|
||||
/// [`crate::viewer::run_with`]; whether it starts small comes from the preferences
|
||||
/// ([`crate::viewer::prefs::Prefs::compact`]). Needs a window, so there is no example.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns an error saying "the recorder window failed" if the window cannot be created or its
|
||||
/// event loop fails (for example, there is no display or no usable graphics adapter).
|
||||
pub fn run(args: RecordArgs) -> eyre::Result<()> {
|
||||
// killing the window (or logging out) must still finalize a recording in progress
|
||||
let _ = ctrlc::set_handler(|| QUIT.store(true, Ordering::SeqCst));
|
||||
|
||||
// before the window exists, so komorebi never sees a titled window it was not told to ignore
|
||||
let setup = crate::komorebi_ignore::prepare_window();
|
||||
let options = eframe::NativeOptions {
|
||||
viewport: egui::ViewportBuilder::default()
|
||||
// titled only when komorebi ignores it (or is not running); see `komorebi_ignore`
|
||||
.with_title(setup.title)
|
||||
.with_app_id("komorebi-recorder")
|
||||
.with_icon(crate::icon::window_icon())
|
||||
.with_decorations(false)
|
||||
.with_inner_size([420.0, 380.0])
|
||||
.with_min_inner_size([360.0, 260.0])
|
||||
.with_always_on_top(),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
eframe::run_native(
|
||||
"komorebi-recorder",
|
||||
options,
|
||||
Box::new(move |_creation_context| {
|
||||
let mut app = RecorderApp::new(args);
|
||||
app.last = setup.note.map(Err);
|
||||
Ok(Box::new(app))
|
||||
}),
|
||||
/// Returns an error saying "the window failed" if the window cannot be created or its event loop
|
||||
/// fails (for example, there is no display or no usable graphics adapter).
|
||||
pub fn run(args: RecordArgs, socket: Option<&std::path::Path>) -> eyre::Result<()> {
|
||||
crate::viewer::run_with(
|
||||
crate::viewer::Launch {
|
||||
sessions: Vec::new(),
|
||||
record: args,
|
||||
show: crate::viewer::Show::Record,
|
||||
},
|
||||
socket,
|
||||
)
|
||||
.map_err(|error| eyre::Report::msg(format!("the recorder window failed: {error}")))
|
||||
}
|
||||
|
||||
type Worker = JoinHandle<eyre::Result<PathBuf>>;
|
||||
|
||||
struct RecorderApp {
|
||||
chrome: crate::platform::window::Chrome,
|
||||
/// The recorder: what is needed to record, and the Record tab that shows it.
|
||||
///
|
||||
/// The host window makes one with [`RecorderApp::new`], calls [`RecorderApp::poll`] on every frame
|
||||
/// and [`RecorderApp::ui`] on the frames the Record tab is showing. It owns the recording's thread,
|
||||
/// so dropping it without stopping leaves that thread to finish on its own.
|
||||
pub struct RecorderApp {
|
||||
args: RecordArgs,
|
||||
live: Arc<Live>,
|
||||
worker: Option<Worker>,
|
||||
@@ -226,12 +231,26 @@ struct RecorderApp {
|
||||
closing: bool,
|
||||
predicate: String,
|
||||
show_streams: bool,
|
||||
quit: &'static AtomicBool,
|
||||
}
|
||||
|
||||
/// What the Record tab asks of the window in one frame.
|
||||
#[derive(Debug, Default, Clone, PartialEq, Eq)]
|
||||
pub struct RecorderOutput {
|
||||
/// "Open session…" was pressed: ask for a folder and open it in a tab.
|
||||
pub choose: bool,
|
||||
/// "Open last" was pressed: open this session in a tab.
|
||||
pub open: Option<PathBuf>,
|
||||
/// "Compact" or "Expand" was pressed.
|
||||
pub toggle_compact: bool,
|
||||
}
|
||||
|
||||
impl RecorderApp {
|
||||
fn new(args: RecordArgs) -> Self {
|
||||
/// Returns a recorder that starts from `args`: see [`run`] for how they are used. It reads the
|
||||
/// attached displays and whether the screen may be recorded, and records nothing.
|
||||
#[must_use]
|
||||
pub fn new(args: RecordArgs) -> Self {
|
||||
let mut app = Self {
|
||||
chrome: crate::platform::window::Chrome::default(),
|
||||
predicate: args.predicate.clone().unwrap_or_default(),
|
||||
args,
|
||||
live: Live::new(),
|
||||
@@ -242,6 +261,7 @@ impl RecorderApp {
|
||||
last: None,
|
||||
closing: false,
|
||||
show_streams: false,
|
||||
quit: &QUIT,
|
||||
};
|
||||
|
||||
app.refresh_displays();
|
||||
@@ -275,10 +295,45 @@ impl RecorderApp {
|
||||
.collect();
|
||||
}
|
||||
|
||||
fn recording(&self) -> bool {
|
||||
/// Whether a recording is going: from pressing Record until its thread has been joined,
|
||||
/// including while it finalizes.
|
||||
#[must_use]
|
||||
pub fn recording(&self) -> bool {
|
||||
self.worker.is_some()
|
||||
}
|
||||
|
||||
/// Says `note` in the tab as a message (as an error, in red), for something the window learned
|
||||
/// before it was shown.
|
||||
pub fn say(&mut self, note: String) {
|
||||
self.last = Some(Err(note));
|
||||
}
|
||||
|
||||
/// Returns the session the last recording saved, or `None` if none has finished since the
|
||||
/// window was started, or one is going.
|
||||
#[must_use]
|
||||
pub fn saved(&self) -> Option<&std::path::Path> {
|
||||
match &self.last {
|
||||
Some(Ok(dir)) => Some(dir),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the text of the Record tab in the tab bar, and whether it is marking a recording
|
||||
/// (so the window can draw it in red): `Record` when idle, `● REC 00:12` while recording.
|
||||
#[must_use]
|
||||
pub fn tab_label(&self) -> (String, bool) {
|
||||
let snapshot = self.live.snapshot();
|
||||
if !self.recording() {
|
||||
return ("Record".to_string(), false);
|
||||
}
|
||||
let text = match snapshot.phase {
|
||||
Phase::Starting => "● starting…".to_string(),
|
||||
Phase::Stopping => "● finalizing…".to_string(),
|
||||
_ => format!("● REC {}", timecode::format(snapshot.elapsed_s)),
|
||||
};
|
||||
(text, true)
|
||||
}
|
||||
|
||||
fn start(&mut self) {
|
||||
let mut args = self.args.clone();
|
||||
// with every display ticked, record *every* display including ones connected while
|
||||
@@ -309,7 +364,18 @@ impl RecorderApp {
|
||||
}
|
||||
}
|
||||
|
||||
fn poll(&mut self, context: &egui::Context) {
|
||||
/// Does what the recorder has to do on every frame, whichever tab is showing: refreshes the
|
||||
/// displays while idle, joins a recording that has finished (its session becomes
|
||||
/// [`RecorderApp::saved`], or the reason it failed is shown), and honours a close request or
|
||||
/// SIGINT/SIGTERM. While recording, those cancel the close, ask the recording to stop and close
|
||||
/// the window once it has finalized; with none going they close it. It also asks `context` to
|
||||
/// draw again soon, so the label of the tab keeps time.
|
||||
pub fn poll(&mut self, context: &egui::Context) {
|
||||
context.request_repaint_after(if self.recording() {
|
||||
Duration::from_millis(200)
|
||||
} else {
|
||||
Duration::from_millis(500)
|
||||
});
|
||||
if !self.recording() && self.displays_refreshed.elapsed() >= DISPLAY_REFRESH {
|
||||
self.refresh_displays();
|
||||
}
|
||||
@@ -325,7 +391,7 @@ impl RecorderApp {
|
||||
self.live.reset();
|
||||
}
|
||||
|
||||
let quit_signalled = QUIT.load(Ordering::SeqCst);
|
||||
let quit_signalled = self.quit.load(Ordering::SeqCst);
|
||||
if (quit_signalled || context.input(|input| input.viewport().close_requested()))
|
||||
&& self.recording()
|
||||
{
|
||||
@@ -339,6 +405,230 @@ impl RecorderApp {
|
||||
context.send_viewport_cmd(egui::ViewportCommand::Close);
|
||||
}
|
||||
}
|
||||
|
||||
/// Draws the Record tab into `ui`: the content of the tab, with no window chrome of its own.
|
||||
///
|
||||
/// `compact` says whether the window is the small control window, which changes the label of
|
||||
/// the button that switches it. It returns what the tab asked the window to do.
|
||||
pub fn ui(&mut self, ui: &mut egui::Ui, compact: bool) -> RecorderOutput {
|
||||
let mut output = RecorderOutput::default();
|
||||
let snapshot = self.live.snapshot();
|
||||
let recording = self.recording();
|
||||
let busy = matches!(snapshot.phase, Phase::Starting | Phase::Stopping);
|
||||
|
||||
egui::ScrollArea::vertical()
|
||||
.id_salt("record-tab")
|
||||
.auto_shrink([false, false])
|
||||
.show(ui, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(egui::RichText::new("komorebi-recorder").strong());
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
let (label, tip) = if compact {
|
||||
("Expand", "the full window, with tabs for sessions")
|
||||
} else {
|
||||
("Compact", "the small window that stays on top")
|
||||
};
|
||||
if ui.button(label).on_hover_text(tip).clicked() {
|
||||
output.toggle_compact = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
ui.separator();
|
||||
ui.horizontal(|ui| {
|
||||
let can_record = !recording && self.permission && !self.displays.is_empty();
|
||||
if ui
|
||||
.add_enabled(
|
||||
can_record,
|
||||
egui::Button::new("Record").min_size([110.0, 32.0].into()),
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
self.start();
|
||||
}
|
||||
|
||||
if ui
|
||||
.add_enabled(
|
||||
recording && !busy && !self.live.stop_requested(),
|
||||
egui::Button::new("Stop").min_size([110.0, 32.0].into()),
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
self.live.request_stop();
|
||||
}
|
||||
|
||||
let state = match snapshot.phase {
|
||||
Phase::Starting => "starting...".to_string(),
|
||||
Phase::Recording => format!("REC {}", timecode::format(snapshot.elapsed_s)),
|
||||
Phase::Stopping => "finalizing...".to_string(),
|
||||
_ => "ready".to_string(),
|
||||
};
|
||||
ui.label(egui::RichText::new(state).size(18.0).monospace());
|
||||
});
|
||||
|
||||
ui.separator();
|
||||
|
||||
// reviewing: open a recording in the viewer, which is its own window
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(egui::RichText::new("Review").small().weak());
|
||||
if ui
|
||||
.button("Open session…")
|
||||
.on_hover_text("play and scrub a recording")
|
||||
.clicked()
|
||||
&& let Err(error) = open_viewer(None)
|
||||
{
|
||||
self.last = Some(Err(format!("could not open the viewer: {error}")));
|
||||
}
|
||||
|
||||
let last = match &self.last {
|
||||
Some(Ok(dir)) => Some(dir.clone()),
|
||||
_ => latest_session_in(&crate::session::default_recordings_dir()),
|
||||
};
|
||||
if ui
|
||||
.add_enabled(last.is_some(), egui::Button::new("Open last"))
|
||||
.on_hover_text("the most recent recording")
|
||||
.clicked()
|
||||
&& let Some(dir) = last
|
||||
&& let Err(error) = open_viewer(Some(&dir))
|
||||
{
|
||||
self.last = Some(Err(format!("could not open the viewer: {error}")));
|
||||
}
|
||||
});
|
||||
|
||||
ui.separator();
|
||||
|
||||
if !self.permission {
|
||||
ui.colored_label(
|
||||
egui::Color32::YELLOW,
|
||||
"Screen Recording permission is needed to record the screen.",
|
||||
);
|
||||
if ui.button("Grant permission").clicked() {
|
||||
match capture::ensure_permission() {
|
||||
Ok(()) => self.permission = true,
|
||||
Err(error) => self.last = Some(Err(format!("{error:#}"))),
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ui.add_enabled_ui(!recording, |ui| {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.label("Displays:");
|
||||
for (display, selected) in &mut self.displays {
|
||||
ui.checkbox(
|
||||
selected,
|
||||
format!(
|
||||
"{} ({}×{})",
|
||||
display.id, display.width_points, display.height_points
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if recording {
|
||||
ui.add_space(6.0);
|
||||
egui::Grid::new("counters").num_columns(2).show(ui, |ui| {
|
||||
ui.label("displays");
|
||||
ui.label(if snapshot.displays_retrying.is_empty() {
|
||||
format!("{} recording", snapshot.displays_recording)
|
||||
} else {
|
||||
format!(
|
||||
"{} recording, waiting to retry {:?}",
|
||||
snapshot.displays_recording, snapshot.displays_retrying
|
||||
)
|
||||
});
|
||||
ui.end_row();
|
||||
ui.label("video frames");
|
||||
ui.label(format!(
|
||||
"{} ({} dropped)",
|
||||
snapshot.frames, snapshot.dropped
|
||||
));
|
||||
ui.end_row();
|
||||
ui.label("komorebi log");
|
||||
ui.label(human_bytes(snapshot.log_bytes));
|
||||
ui.end_row();
|
||||
ui.label("komorebi events");
|
||||
ui.label(snapshot.events.to_string());
|
||||
ui.end_row();
|
||||
ui.label("OS trace");
|
||||
ui.label(format!(
|
||||
"{} events, {} across {} streams",
|
||||
snapshot.oslog_events,
|
||||
human_bytes(snapshot.oslog_bytes),
|
||||
snapshot.streams.len()
|
||||
));
|
||||
ui.end_row();
|
||||
});
|
||||
|
||||
ui.collapsing("OS trace streams", |ui| {
|
||||
self.show_streams = true;
|
||||
for stream in &snapshot.streams {
|
||||
ui.label(format!(
|
||||
"{}: {} events, {}",
|
||||
stream.name,
|
||||
stream.events,
|
||||
human_bytes(stream.bytes)
|
||||
));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
ui.collapsing("Advanced", |ui| {
|
||||
ui.label("`system` OS trace predicate (blank for the default):");
|
||||
ui.text_edit_singleline(&mut self.predicate);
|
||||
});
|
||||
}
|
||||
|
||||
if !snapshot.incidents.is_empty() {
|
||||
ui.add_space(6.0);
|
||||
ui.label(egui::RichText::new("Recent events").small().weak());
|
||||
for incident in snapshot.incidents.iter().rev().take(4) {
|
||||
ui.label(egui::RichText::new(incident).small().weak());
|
||||
}
|
||||
}
|
||||
|
||||
if !snapshot.warnings.is_empty() {
|
||||
ui.add_space(6.0);
|
||||
egui::ScrollArea::vertical()
|
||||
.max_height(110.0)
|
||||
.id_salt("warnings")
|
||||
.show(ui, |ui| {
|
||||
for warning in &snapshot.warnings {
|
||||
ui.colored_label(egui::Color32::YELLOW, format!("! {warning}"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
match &self.last {
|
||||
Some(Ok(dir)) => {
|
||||
ui.add_space(8.0);
|
||||
ui.separator();
|
||||
ui.label("Saved session:");
|
||||
ui.monospace(dir.display().to_string());
|
||||
ui.horizontal(|ui| {
|
||||
if ui.button("Copy path").clicked() {
|
||||
ui.ctx().copy_text(dir.display().to_string());
|
||||
}
|
||||
|
||||
if ui
|
||||
.button(format!("Open in {}", shell::FILE_MANAGER))
|
||||
.clicked()
|
||||
{
|
||||
shell::reveal(dir);
|
||||
}
|
||||
});
|
||||
ui.label(format!(
|
||||
"Investigate it: komorebi-recorder brief {}",
|
||||
dir.display()
|
||||
));
|
||||
}
|
||||
Some(Err(error)) => {
|
||||
ui.add_space(8.0);
|
||||
ui.colored_label(egui::Color32::LIGHT_RED, error);
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
});
|
||||
output
|
||||
}
|
||||
}
|
||||
|
||||
fn human_bytes(bytes: u64) -> String {
|
||||
@@ -357,230 +647,43 @@ fn human_bytes(bytes: u64) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
impl eframe::App for RecorderApp {
|
||||
fn update(&mut self, context: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
self.chrome.tick();
|
||||
self.poll(context);
|
||||
context.request_repaint_after(Duration::from_millis(200));
|
||||
#[cfg(test)]
|
||||
impl RecorderApp {
|
||||
/// A recorder that touches no screen: no permission check, no displays, and its own quit flag,
|
||||
/// for the tests of the window.
|
||||
pub(crate) fn quiet(quit: &'static AtomicBool) -> Self {
|
||||
Self {
|
||||
args: RecordArgs::default(),
|
||||
live: Live::new(),
|
||||
worker: None,
|
||||
permission: true,
|
||||
displays: Vec::new(),
|
||||
displays_refreshed: Instant::now(),
|
||||
last: None,
|
||||
closing: false,
|
||||
predicate: String::new(),
|
||||
show_streams: false,
|
||||
quit,
|
||||
}
|
||||
}
|
||||
|
||||
let snapshot = self.live.snapshot();
|
||||
let recording = self.recording();
|
||||
let busy = matches!(snapshot.phase, Phase::Starting | Phase::Stopping);
|
||||
|
||||
egui::CentralPanel::default().show(context, |ui| {
|
||||
// drag handle and close button, since there is no title bar
|
||||
let header = egui::Rect::from_min_size(
|
||||
ui.min_rect().min,
|
||||
egui::vec2(ui.available_width(), 24.0),
|
||||
);
|
||||
let drag = ui.interact(header, ui.id().with("drag"), egui::Sense::drag());
|
||||
if drag.drag_started() {
|
||||
context.send_viewport_cmd(egui::ViewportCommand::StartDrag);
|
||||
}
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(egui::RichText::new("komorebi-recorder").strong());
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
if ui.button("×").on_hover_text("Close").clicked() {
|
||||
context.send_viewport_cmd(egui::ViewportCommand::Close);
|
||||
}
|
||||
});
|
||||
});
|
||||
ui.separator();
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
let can_record = !recording && self.permission && !self.displays.is_empty();
|
||||
if ui
|
||||
.add_enabled(
|
||||
can_record,
|
||||
egui::Button::new("Record").min_size([110.0, 32.0].into()),
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
self.start();
|
||||
}
|
||||
|
||||
if ui
|
||||
.add_enabled(
|
||||
recording && !busy && !self.live.stop_requested(),
|
||||
egui::Button::new("Stop").min_size([110.0, 32.0].into()),
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
self.live.request_stop();
|
||||
}
|
||||
|
||||
let state = match snapshot.phase {
|
||||
Phase::Starting => "starting...".to_string(),
|
||||
Phase::Recording => format!("REC {}", timecode::format(snapshot.elapsed_s)),
|
||||
Phase::Stopping => "finalizing...".to_string(),
|
||||
_ => "ready".to_string(),
|
||||
};
|
||||
ui.label(egui::RichText::new(state).size(18.0).monospace());
|
||||
});
|
||||
|
||||
ui.separator();
|
||||
|
||||
// reviewing: open a recording in the viewer, which is its own window
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(egui::RichText::new("Review").small().weak());
|
||||
if ui
|
||||
.button("Open session…")
|
||||
.on_hover_text("play and scrub a recording")
|
||||
.clicked()
|
||||
&& let Err(error) = open_viewer(None)
|
||||
{
|
||||
self.last = Some(Err(format!("could not open the viewer: {error}")));
|
||||
}
|
||||
|
||||
let last = match &self.last {
|
||||
Some(Ok(dir)) => Some(dir.clone()),
|
||||
_ => latest_session_in(&crate::session::default_recordings_dir()),
|
||||
};
|
||||
if ui
|
||||
.add_enabled(last.is_some(), egui::Button::new("Open last"))
|
||||
.on_hover_text("the most recent recording")
|
||||
.clicked()
|
||||
&& let Some(dir) = last
|
||||
&& let Err(error) = open_viewer(Some(&dir))
|
||||
{
|
||||
self.last = Some(Err(format!("could not open the viewer: {error}")));
|
||||
}
|
||||
});
|
||||
|
||||
ui.separator();
|
||||
|
||||
if !self.permission {
|
||||
ui.colored_label(
|
||||
egui::Color32::YELLOW,
|
||||
"Screen Recording permission is needed to record the screen.",
|
||||
);
|
||||
if ui.button("Grant permission").clicked() {
|
||||
match capture::ensure_permission() {
|
||||
Ok(()) => self.permission = true,
|
||||
Err(error) => self.last = Some(Err(format!("{error:#}"))),
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ui.add_enabled_ui(!recording, |ui| {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.label("Displays:");
|
||||
for (display, selected) in &mut self.displays {
|
||||
ui.checkbox(
|
||||
selected,
|
||||
format!(
|
||||
"{} ({}×{})",
|
||||
display.id, display.width_points, display.height_points
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if recording {
|
||||
ui.add_space(6.0);
|
||||
egui::Grid::new("counters").num_columns(2).show(ui, |ui| {
|
||||
ui.label("displays");
|
||||
ui.label(if snapshot.displays_retrying.is_empty() {
|
||||
format!("{} recording", snapshot.displays_recording)
|
||||
} else {
|
||||
format!(
|
||||
"{} recording, waiting to retry {:?}",
|
||||
snapshot.displays_recording, snapshot.displays_retrying
|
||||
)
|
||||
});
|
||||
ui.end_row();
|
||||
ui.label("video frames");
|
||||
ui.label(format!(
|
||||
"{} ({} dropped)",
|
||||
snapshot.frames, snapshot.dropped
|
||||
));
|
||||
ui.end_row();
|
||||
ui.label("komorebi log");
|
||||
ui.label(human_bytes(snapshot.log_bytes));
|
||||
ui.end_row();
|
||||
ui.label("komorebi events");
|
||||
ui.label(snapshot.events.to_string());
|
||||
ui.end_row();
|
||||
ui.label("OS trace");
|
||||
ui.label(format!(
|
||||
"{} events, {} across {} streams",
|
||||
snapshot.oslog_events,
|
||||
human_bytes(snapshot.oslog_bytes),
|
||||
snapshot.streams.len()
|
||||
));
|
||||
ui.end_row();
|
||||
});
|
||||
|
||||
ui.collapsing("OS trace streams", |ui| {
|
||||
self.show_streams = true;
|
||||
for stream in &snapshot.streams {
|
||||
ui.label(format!(
|
||||
"{}: {} events, {}",
|
||||
stream.name,
|
||||
stream.events,
|
||||
human_bytes(stream.bytes)
|
||||
));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
ui.collapsing("Advanced", |ui| {
|
||||
ui.label("`system` OS trace predicate (blank for the default):");
|
||||
ui.text_edit_singleline(&mut self.predicate);
|
||||
});
|
||||
}
|
||||
|
||||
if !snapshot.incidents.is_empty() {
|
||||
ui.add_space(6.0);
|
||||
ui.label(egui::RichText::new("Recent events").small().weak());
|
||||
for incident in snapshot.incidents.iter().rev().take(4) {
|
||||
ui.label(egui::RichText::new(incident).small().weak());
|
||||
}
|
||||
}
|
||||
|
||||
if !snapshot.warnings.is_empty() {
|
||||
ui.add_space(6.0);
|
||||
egui::ScrollArea::vertical()
|
||||
.max_height(110.0)
|
||||
.id_salt("warnings")
|
||||
.show(ui, |ui| {
|
||||
for warning in &snapshot.warnings {
|
||||
ui.colored_label(egui::Color32::YELLOW, format!("! {warning}"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
match &self.last {
|
||||
Some(Ok(dir)) => {
|
||||
ui.add_space(8.0);
|
||||
ui.separator();
|
||||
ui.label("Saved session:");
|
||||
ui.monospace(dir.display().to_string());
|
||||
ui.horizontal(|ui| {
|
||||
if ui.button("Copy path").clicked() {
|
||||
context.copy_text(dir.display().to_string());
|
||||
}
|
||||
|
||||
if ui
|
||||
.button(format!("Open in {}", shell::FILE_MANAGER))
|
||||
.clicked()
|
||||
{
|
||||
shell::reveal(dir);
|
||||
}
|
||||
});
|
||||
ui.label(format!(
|
||||
"Investigate it: komorebi-recorder brief {}",
|
||||
dir.display()
|
||||
));
|
||||
}
|
||||
Some(Err(error)) => {
|
||||
ui.add_space(8.0);
|
||||
ui.colored_label(egui::Color32::LIGHT_RED, error);
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
/// Makes the recorder look as if `worker` were a recording that has begun, with `phase`.
|
||||
pub(crate) fn pretend(&mut self, worker: Worker, phase: Phase, elapsed_s: f64) {
|
||||
self.live.update(|snapshot| {
|
||||
snapshot.phase = phase;
|
||||
snapshot.elapsed_s = elapsed_s;
|
||||
});
|
||||
self.worker = Some(worker);
|
||||
}
|
||||
|
||||
/// The handle the recording would publish through.
|
||||
pub(crate) fn live(&self) -> Arc<Live> {
|
||||
self.live.clone()
|
||||
}
|
||||
|
||||
/// Whether the recorder has been asked to close the window once the recording is done.
|
||||
pub(crate) fn closing(&self) -> bool {
|
||||
self.closing
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
//! The same program as `komorebi-recorder`, built for the Windows GUI subsystem: it opens no
|
||||
//! console window, which is what a shortcut or the recorder window launching the viewer wants.
|
||||
//! console window, which is what a shortcut wants.
|
||||
//! Its output goes nowhere, so use `komorebi-recorder` to run a command and read what it prints.
|
||||
//! (On other systems there is no such distinction and this is the same binary.)
|
||||
//!
|
||||
//! `main` is [`komorebi_recorder::cli::main`], as it is for `komorebi-recorder`: it reads the
|
||||
//! command line and runs the command, and with no command opens the recorder window
|
||||
//! ([`komorebi_recorder::app::run`]). The recorder window starts the viewer by running this
|
||||
//! command line and runs the command, and with no command opens the one window on its Record tab
|
||||
//! ([`komorebi_recorder::app::run`]). It shares the window's socket with `komorebi-recorder`, so
|
||||
//! whichever of the two is started second raises the window the first one opened. A process that
|
||||
//! wants a window to open a recording ([`komorebi_recorder::app::open_viewer`]) starts this
|
||||
//! executable with `view` when it is next to the one that is running (on Windows), so that
|
||||
//! opening a recording does not open a console window beside it.
|
||||
#![cfg_attr(windows, windows_subsystem = "windows")]
|
||||
|
||||
@@ -63,6 +63,7 @@ pub use video::CompareArgs;
|
||||
pub use video::FramediffArgs;
|
||||
pub use video::MotionArgs;
|
||||
pub use video::SheetArgs;
|
||||
pub use viewer_command::GuiArgs;
|
||||
pub use viewer_command::ViewArgs;
|
||||
|
||||
/// The command line of `komorebi-recorder`.
|
||||
@@ -76,7 +77,7 @@ pub use viewer_command::ViewArgs;
|
||||
all on one clock, into a session directory. \
|
||||
Then ask what was happening at any second of the video, or where in the video any \
|
||||
log line or event is.\n\n\
|
||||
Run with no subcommand to open the recorder window."
|
||||
Run with no subcommand to open the window on its Record tab."
|
||||
)]
|
||||
pub struct Opts {
|
||||
/// The command to run.
|
||||
@@ -87,8 +88,12 @@ pub struct Opts {
|
||||
/// What `komorebi-recorder` was asked to do.
|
||||
#[derive(Subcommand)]
|
||||
pub enum Command {
|
||||
/// Open the recorder window with Record / Stop buttons (the default)
|
||||
Gui(RecordArgs),
|
||||
/// Open the window, on its Record tab, with Record / Stop buttons (the default)
|
||||
///
|
||||
/// There is only ever one window, for recording and for reviewing sessions. If one is already
|
||||
/// running it is raised and shown on its Record tab, and the options given here are ignored:
|
||||
/// they only set up the window that is started.
|
||||
Gui(GuiArgs),
|
||||
/// Record without a window; Ctrl-C (or --duration) stops and finalizes the session
|
||||
Record(RecordArgs),
|
||||
/// List the displays that can be recorded
|
||||
@@ -140,7 +145,7 @@ pub enum Command {
|
||||
Compare(CompareArgs),
|
||||
/// A contact sheet image of frames, with the times, events and bug region marked
|
||||
Sheet(SheetArgs),
|
||||
/// Open a recording in a window: play and scrub the video with every event on a timeline
|
||||
/// Open a recording as a tab of the window: play and scrub the video with every event on a timeline
|
||||
View(ViewArgs),
|
||||
/// Which line of komorebi's source wrote a line of its log, with the code around it
|
||||
Code(CodeArgs),
|
||||
@@ -276,7 +281,10 @@ pub fn execute(command: Command) -> std::process::ExitCode {
|
||||
/// Returns whatever error the command fails with; [`execute`] turns it into an exit status.
|
||||
pub fn run(command: Command) -> eyre::Result<()> {
|
||||
match command {
|
||||
Command::Gui(args) => crate::app::run(args),
|
||||
Command::Gui(args) => {
|
||||
let socket = (!args.new_window).then(crate::viewer::ipc::default_socket);
|
||||
crate::app::run(args.record, socket.as_deref())
|
||||
}
|
||||
Command::Record(args) => record::record(&args),
|
||||
Command::Displays(args) => record::displays(&args),
|
||||
Command::Doctor(args) => doctor::doctor(&args),
|
||||
@@ -320,7 +328,7 @@ pub fn run(command: Command) -> eyre::Result<()> {
|
||||
|
||||
/// What both binaries (`komorebi-recorder` and, on Windows, the no-console
|
||||
/// `komorebi-recorder-gui`) do: read the command line and run it.
|
||||
/// No command opens the recorder window.
|
||||
/// No command opens the window on its Record tab.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
@@ -335,7 +343,7 @@ pub fn main() -> eyre::Result<std::process::ExitCode> {
|
||||
let opts = Opts::parse();
|
||||
Ok(execute(
|
||||
opts.command
|
||||
.unwrap_or_else(|| Command::Gui(RecordArgs::default())),
|
||||
.unwrap_or_else(|| Command::Gui(GuiArgs::default())),
|
||||
))
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! `record`, `gui` and `displays`: the arguments of a recording and the headless recorder.
|
||||
//!
|
||||
//! [`RecordArgs`] is the one set of options for both ways of recording: `record` runs without a
|
||||
//! window and `gui` opens the recorder window with the same options as its starting settings.
|
||||
//! window and `gui` opens the window, on its Record tab, with the same options as its starting settings.
|
||||
//! [`RecordArgs::to_options`] turns them into the [`RecordOptions`] that [`recorder::record`] takes.
|
||||
//!
|
||||
//! `record --until-exit -- <command>` runs a command while recording and stops when it exits (see
|
||||
|
||||
@@ -1,17 +1,34 @@
|
||||
//! `view`: the arguments of the viewer window.
|
||||
//! `gui` and `view`: the arguments of the one window.
|
||||
//!
|
||||
//! The command table runs the command with `crate::viewer::run`; this file holds only its arguments.
|
||||
//! The command table runs `gui` with `crate::app::run` and `view` with `crate::viewer::run`; this
|
||||
//! file holds only their arguments.
|
||||
|
||||
use super::RecordArgs;
|
||||
use clap::Args;
|
||||
use std::path::PathBuf;
|
||||
|
||||
/// The arguments of `gui` (and of running with no command): the options the Record tab starts
|
||||
/// from, which are those of `record`.
|
||||
///
|
||||
/// If a window is already running they are ignored: the second launch only raises it and shows its
|
||||
/// Record tab.
|
||||
#[derive(Args, Clone, Debug, Default)]
|
||||
pub struct GuiArgs {
|
||||
/// The options of `record`, which each recording started from the window uses
|
||||
#[command(flatten)]
|
||||
pub record: RecordArgs,
|
||||
/// Open a window of its own, instead of raising the one that is already running
|
||||
#[arg(long)]
|
||||
pub new_window: bool,
|
||||
}
|
||||
|
||||
/// The arguments of `view`: the sessions to open, if any are given.
|
||||
#[derive(Args, Debug)]
|
||||
pub struct ViewArgs {
|
||||
/// The recordings' folders, each opened as a tab of the one viewer window [default: choose
|
||||
/// The recordings' folders, each opened as a tab of the one window [default: choose
|
||||
/// one in the window]
|
||||
pub session: Vec<PathBuf>,
|
||||
/// Open a window of its own, instead of a tab of the viewer that is already running
|
||||
/// Open a window of its own, instead of a tab of the window that is already running
|
||||
#[arg(long)]
|
||||
pub new_window: bool,
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Naming the recorder's windows, and telling komorebi to leave them alone.
|
||||
//!
|
||||
//! The recorder window and the viewer are used on the machine whose behavior is being investigated, so komorebi
|
||||
//! The program's one window (the Record tab and the tabs of recordings) is used on the machine whose behavior is being investigated, so komorebi
|
||||
//! must not tile them. For a long time that was done by giving them no title at all, which komorebi does not
|
||||
//! manage. This module lets them have a real title, `komorebi-recorder`, on one condition: _the window is only
|
||||
//! named when it is safely ignored_.
|
||||
@@ -36,7 +36,7 @@ use std::time::Instant;
|
||||
/// The title of the windows when it is safe to give them one.
|
||||
pub const TITLE: &str = "komorebi-recorder";
|
||||
|
||||
/// The executable of the windows that have no console, which the recorder window opens the viewer with.
|
||||
/// The executable of the windows that have no console, which a process that opens a recording in the window starts it with.
|
||||
pub const GUI_EXE: &str = "komorebi-recorder-gui.exe";
|
||||
|
||||
/// How long `komorebic ignore-rule` has before it is killed.
|
||||
@@ -194,7 +194,7 @@ pub fn describe_exit(code: i32) -> String {
|
||||
/// Registers an ignore rule for each of the recorder's executables, if komorebi is running and a `komorebic` is
|
||||
/// found. Pure apart from what `runner` does; `current` is this executable's file name.
|
||||
///
|
||||
/// Each `komorebic` that exists is tried in turn ([`candidates`]), and the first that registers every rule
|
||||
/// Each `komorebic` that exists is tried in turn (`candidates`), and the first that registers every rule
|
||||
/// wins. One that crashes or refuses does not end the attempt while another is left; if none works the
|
||||
/// failure names every one tried and how it failed.
|
||||
pub fn ensure_with(runner: &mut dyn Runner, current: &str, windows: bool) -> Outcome {
|
||||
@@ -350,9 +350,18 @@ fn current_exe_name() -> String {
|
||||
})
|
||||
}
|
||||
|
||||
/// The environment variable that stops [`ensure_self_ignored`] from running `komorebic` at all, for trying the
|
||||
/// window out (or testing it end to end) on a machine whose real komorebi must not be told anything. The window is
|
||||
/// then not titled. It is not meant for anything else.
|
||||
pub const SKIP_VARIABLE: &str = "KOMOREBI_RECORDER_NO_IGNORE_RULE";
|
||||
|
||||
/// Registers the ignore rules for this machine's real komorebi (see the [module documentation](self)). Call it
|
||||
/// before a window is created.
|
||||
/// before a window is created. With [`SKIP_VARIABLE`] set it registers nothing and returns
|
||||
/// [`Outcome::NotApplicable`].
|
||||
pub fn ensure_self_ignored() -> Outcome {
|
||||
if std::env::var_os(SKIP_VARIABLE).is_some_and(|value| !value.is_empty()) {
|
||||
return Outcome::NotApplicable;
|
||||
}
|
||||
ensure_with(&mut SystemRunner, ¤t_exe_name(), cfg!(windows))
|
||||
}
|
||||
|
||||
|
||||
@@ -57,12 +57,12 @@
|
||||
//! | [`recovery`] | rebuilding a session whose recorder died |
|
||||
//! | [`cli`] | the command line |
|
||||
//! | [`icon`] | the icon of the windows |
|
||||
//! | [`app`] | the recorder window |
|
||||
//! | [`app`] | the recorder: the Record tab of the one window |
|
||||
//! | [`av`] and [`selftest`] | decoding the recorded video and checking it against the clocks |
|
||||
//! | [`doctor`] | what a recording leans on, and probes that measure it |
|
||||
//! | [`report`] | answers as text for a terminal |
|
||||
//! | [`playback`] | a clock that runs forwards or backwards, and the decoding that follows it |
|
||||
//! | [`viewer`] | the window that plays a recording |
|
||||
//! | [`viewer`] | the one window: the Record tab, and a tab for each recording that is played |
|
||||
//!
|
||||
//! # What is not supported
|
||||
//!
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! What this program's windows do about being in the video and being tiled, which differs by OS.
|
||||
//!
|
||||
//! The recorder window ([`crate::app`]) and the viewer must not be in the video they are
|
||||
//! The program's one window ([`crate::viewer`], with the recorder of [`crate::app`] as a tab) must not be in the video it is
|
||||
//! recording, and komorebi must not tile them. The two hosts get there differently:
|
||||
//!
|
||||
//! | | macOS | Windows |
|
||||
|
||||
@@ -287,7 +287,7 @@ impl Live {
|
||||
*self.snapshot.lock() = LiveSnapshot::default();
|
||||
}
|
||||
|
||||
fn update(&self, change: impl FnOnce(&mut LiveSnapshot)) {
|
||||
pub(crate) fn update(&self, change: impl FnOnce(&mut LiveSnapshot)) {
|
||||
change(&mut self.snapshot.lock());
|
||||
}
|
||||
}
|
||||
|
||||
+788
-113
File diff suppressed because it is too large.
Load diff
@@ -1,16 +1,18 @@
|
||||
//! One viewer window, however many times a recording is opened: the viewer's local socket.
|
||||
//! One window, however many times the program is started: the window's local socket.
|
||||
//!
|
||||
//! The first viewer to start listens on a unix domain socket in the per-user data directory
|
||||
//! ([`default_socket`]); every later `komorebi-recorder view SESSION...`, and the recorder
|
||||
//! window's "Open session..." and "Open last", connect to it, ask it to open the sessions as tabs
|
||||
//! and exit, instead of making a window of their own. The socket types are the ones
|
||||
//! The first `komorebi-recorder` to start a window (with no command, `gui` or `view`) listens on a
|
||||
//! unix domain socket in the per-user data directory ([`default_socket`]); every later one connects
|
||||
//! to it, asks it to open the sessions as tabs or to show the Record tab, and exits, instead of
|
||||
//! making a window of its own. The socket types are the ones
|
||||
//! [`crate::komorebi_link`] uses (std's on unix, the `uds_windows` crate's on Windows), so there is
|
||||
//! one place where the two hosts differ.
|
||||
//!
|
||||
//! # Protocol
|
||||
//!
|
||||
//! A request is one line of JSON, [`Request`], for example
|
||||
//! `{"open":["/recordings/20261028T154619Z"],"focus":true}`. The server answers with one line,
|
||||
//! `{"open":["/recordings/20261028T154619Z"],"focus":true}`. A request may also say which tab to
|
||||
//! show, `"tab":"record"` (what `gui` sends: see [`TabName`]); a request without `"tab"`, which is
|
||||
//! what older programs send, is still accepted. The server answers with one line,
|
||||
//! [`Reply`] (`{"ok":true}`, or `{"ok":false,"error":"..."}`), and closes the connection. An empty
|
||||
//! `open` asks only for the window to be raised and a start-screen tab to be there. Paths must be
|
||||
//! absolute: the viewer runs somewhere else, so a relative path would mean nothing to it
|
||||
@@ -67,9 +69,9 @@ pub const TIMEOUT: Duration = Duration::from_secs(2);
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// use komorebi_recorder::viewer::ipc::Request;
|
||||
/// use komorebi_recorder::viewer::ipc::{Request, TabName};
|
||||
///
|
||||
/// let request = Request { open: vec!["/recordings/a".into()], focus: true };
|
||||
/// let request = Request { open: vec!["/recordings/a".into()], ..Request::default() };
|
||||
/// assert_eq!(
|
||||
/// serde_json::to_string(&request)?,
|
||||
/// r#"{"open":["/recordings/a"],"focus":true}"#
|
||||
@@ -77,7 +79,11 @@ pub const TIMEOUT: Duration = Duration::from_secs(2);
|
||||
///
|
||||
/// // both fields may be left out
|
||||
/// let empty: Request = serde_json::from_str("{}")?;
|
||||
/// assert!(empty.open.is_empty() && empty.focus);
|
||||
/// assert!(empty.open.is_empty() && empty.focus && empty.tab.is_none());
|
||||
///
|
||||
/// // `gui` asks for the Record tab
|
||||
/// let record = Request { tab: Some(TabName::Record), ..Request::default() };
|
||||
/// assert_eq!(serde_json::to_string(&record)?, r#"{"open":[],"focus":true,"tab":"record"}"#);
|
||||
/// # Ok::<(), serde_json::Error>(())
|
||||
/// ```
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
@@ -89,6 +95,18 @@ pub struct Request {
|
||||
/// Whether to raise the window and un-minimise it. The default is `true`.
|
||||
#[serde(default = "yes")]
|
||||
pub focus: bool,
|
||||
/// Which tab to show once the sessions are open. `None`, the default and what `view` sends,
|
||||
/// shows the last session opened (or a start screen, when there is none).
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub tab: Option<TabName>,
|
||||
}
|
||||
|
||||
/// A tab a [`Request`] can ask for by name.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum TabName {
|
||||
/// The pinned Record tab, first in the window.
|
||||
Record,
|
||||
}
|
||||
|
||||
fn yes() -> bool {
|
||||
@@ -100,6 +118,7 @@ impl Default for Request {
|
||||
Self {
|
||||
open: Vec::new(),
|
||||
focus: true,
|
||||
tab: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -134,8 +153,8 @@ impl Reply {
|
||||
/// empty, else [`SOCKET_NAME`] in komorebi's data directory
|
||||
/// ([`data_dir`](crate::komorebi_link::data_dir)).
|
||||
///
|
||||
/// Only the edges of the program call this (the `view` command and the recorder window); everything
|
||||
/// else takes the path as a parameter.
|
||||
/// Only the edges of the program call this (the `gui` and `view` commands); everything else takes
|
||||
/// the path as a parameter.
|
||||
#[must_use]
|
||||
pub fn default_socket() -> PathBuf {
|
||||
match std::env::var_os(SOCKET_VARIABLE) {
|
||||
@@ -464,6 +483,7 @@ mod tests {
|
||||
let request = Request {
|
||||
open: vec![abs("a"), abs("b")],
|
||||
focus: true,
|
||||
..Request::default()
|
||||
};
|
||||
assert_eq!(send(&path, &request).expect("sent"), Delivery::Delivered);
|
||||
assert_eq!(wait_for(&server, 1), [request]);
|
||||
@@ -473,6 +493,7 @@ mod tests {
|
||||
let more = Request {
|
||||
open: vec![abs("c")],
|
||||
focus: false,
|
||||
..Request::default()
|
||||
};
|
||||
assert!(matches!(
|
||||
claim(&path, &more).expect("claim"),
|
||||
@@ -481,6 +502,24 @@ mod tests {
|
||||
assert_eq!(wait_for(&server, 1), [more]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_tab_is_additive_and_old_requests_still_read() {
|
||||
let old: Request = serde_json::from_str(r#"{"open":["/a"],"focus":false}"#).expect("old");
|
||||
assert_eq!(old.tab, None);
|
||||
let new: Request = serde_json::from_str(r#"{"tab":"record"}"#).expect("new");
|
||||
assert_eq!(new.tab, Some(TabName::Record));
|
||||
assert!(serde_json::from_str::<Request>(r#"{"tab":"nowhere"}"#).is_err());
|
||||
|
||||
let path = socket("tab");
|
||||
let server = serving(&path);
|
||||
let request = Request {
|
||||
tab: Some(TabName::Record),
|
||||
..Request::default()
|
||||
};
|
||||
assert_eq!(send(&path, &request).expect("sent"), Delivery::Delivered);
|
||||
assert_eq!(wait_for(&server, 1), [request]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nothing_is_delivered_when_nobody_listens() {
|
||||
let path = socket("nobody");
|
||||
@@ -514,6 +553,7 @@ mod tests {
|
||||
let request = Request {
|
||||
open: vec![abs("x")],
|
||||
focus: true,
|
||||
..Request::default()
|
||||
};
|
||||
assert_eq!(send(&path, &request).expect("sent"), Delivery::Delivered);
|
||||
assert_eq!(wait_for(&server, 1), [request]);
|
||||
@@ -537,6 +577,7 @@ mod tests {
|
||||
let request = Request {
|
||||
open: vec![abs(&format!("s{index}"))],
|
||||
focus: true,
|
||||
..Request::default()
|
||||
};
|
||||
match claim(&path, &request).expect("claim") {
|
||||
Claim::Forwarded => None,
|
||||
@@ -602,6 +643,7 @@ mod tests {
|
||||
let request = Request {
|
||||
open: vec![abs("fine")],
|
||||
focus: true,
|
||||
..Request::default()
|
||||
};
|
||||
assert_eq!(send(&path, &request).expect("sent"), Delivery::Delivered);
|
||||
assert_eq!(wait_for(&server, 1), [request]);
|
||||
@@ -614,6 +656,7 @@ mod tests {
|
||||
let relative = Request {
|
||||
open: vec![PathBuf::from("relative")],
|
||||
focus: true,
|
||||
..Request::default()
|
||||
};
|
||||
let error = send(&path, &relative).expect_err("refused");
|
||||
assert_eq!(error.kind(), std::io::ErrorKind::InvalidInput);
|
||||
|
||||
@@ -93,6 +93,8 @@ pub enum Action {
|
||||
GoToTab(usize),
|
||||
/// Go to the last tab (`Cmd`/`Ctrl` `9`).
|
||||
LastTab,
|
||||
/// Go to the pinned Record tab (`Cmd`/`Ctrl` `0`).
|
||||
ShowRecord,
|
||||
}
|
||||
|
||||
impl Action {
|
||||
@@ -107,6 +109,7 @@ impl Action {
|
||||
| Self::PreviousTab
|
||||
| Self::GoToTab(_)
|
||||
| Self::LastTab
|
||||
| Self::ShowRecord
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -152,7 +155,8 @@ pub const BINDINGS: &[(&str, &str)] = &[
|
||||
"Ctrl Tab Ctrl Shift Tab",
|
||||
"next / previous tab (on a Mac also Cmd Shift ] [)",
|
||||
),
|
||||
("Cmd/Ctrl 1 – 9", "go to that tab (9 is the last)"),
|
||||
("Cmd/Ctrl 1 – 9", "go to that session tab (9 is the last)"),
|
||||
("Cmd/Ctrl 0", "go to the Record tab"),
|
||||
];
|
||||
|
||||
/// Returns the action for a key pressed with `modifiers`, if it is bound.
|
||||
@@ -165,7 +169,7 @@ pub const BINDINGS: &[(&str, &str)] = &[
|
||||
/// display).
|
||||
///
|
||||
/// The tab keys hold `Command` (`Cmd` on a Mac, `Ctrl` elsewhere): `T` opens a tab, `W` closes
|
||||
/// one, `1` to `9` go to a tab. `Ctrl` `Tab` (with `Shift`, backwards) and, on a Mac, `Command`
|
||||
/// one, `1` to `9` go to a session tab and `0` to the Record tab. `Ctrl` `Tab` (with `Shift`, backwards) and, on a Mac, `Command`
|
||||
/// `Shift` `]` and `[` move between tabs. Anything else pressed with `Command`, `Ctrl` or `Alt`
|
||||
/// gives `None`, as does any key that is not bound. [`Action::ClearSelection`] is never returned.
|
||||
///
|
||||
@@ -269,6 +273,7 @@ fn tab_action(key: Key, modifiers: Modifiers) -> Option<Action> {
|
||||
Some(match key {
|
||||
Key::T => Action::NewTab,
|
||||
Key::W => Action::CloseTab,
|
||||
Key::Num0 => Action::ShowRecord,
|
||||
Key::Num1 => Action::GoToTab(0),
|
||||
Key::Num2 => Action::GoToTab(1),
|
||||
Key::Num3 => Action::GoToTab(2),
|
||||
@@ -482,6 +487,11 @@ mod tests {
|
||||
action(Key::Num9, Modifiers::COMMAND, None),
|
||||
Some(Action::LastTab)
|
||||
);
|
||||
assert_eq!(
|
||||
action(Key::Num0, Modifiers::COMMAND, None),
|
||||
Some(Action::ShowRecord)
|
||||
);
|
||||
assert_eq!(action(Key::Num0, plain(), None), Some(Action::FitTimeline));
|
||||
// the plain digit still picks a display, the plain letters still do what they did
|
||||
assert_eq!(
|
||||
action(Key::Num1, plain(), None),
|
||||
@@ -513,7 +523,16 @@ mod tests {
|
||||
.map(|(keys, _)| *keys)
|
||||
.collect::<Vec<_>>()
|
||||
.join(" ");
|
||||
for key in ["Space", "J", "Home", "B", "Esc", "Cmd/Ctrl T", "Ctrl Tab"] {
|
||||
for key in [
|
||||
"Space",
|
||||
"J",
|
||||
"Home",
|
||||
"B",
|
||||
"Esc",
|
||||
"Cmd/Ctrl T",
|
||||
"Ctrl Tab",
|
||||
"Cmd/Ctrl 0",
|
||||
] {
|
||||
assert!(listed.contains(key), "{key}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
//! The viewer: a window for playing and scrubbing a recording with everything that happened in it
|
||||
//! laid out on a timeline.
|
||||
//! The program's one window: recording and reviewing, in tabs.
|
||||
//!
|
||||
//! It is started by `komorebi-recorder view [SESSION...]` ([`crate::cli::ViewArgs`]), which calls
|
||||
//! [`run`], and by the "Open session..." and "Open last" buttons of the recorder window
|
||||
//! ([`crate::app`]), which start that command in a process of its own so that reviewing a
|
||||
//! recording cannot disturb one being made. It is an `egui` application run by `eframe`.
|
||||
//! `komorebi-recorder` with no command, `komorebi-recorder gui` and `komorebi-recorder view
|
||||
//! [SESSION...]` ([`crate::cli::GuiArgs`], [`crate::cli::ViewArgs`]) all open this window, with
|
||||
//! [`run_with`] (the recorder's [`crate::app::run`] and the viewer's [`run`] are the two ways in),
|
||||
//! or hand their request to the one that is already open. It is an `egui` application run by
|
||||
//! `eframe`.
|
||||
//!
|
||||
//! There is one viewer window. Each session is a tab of it, and opening another session (from
|
||||
//! the window, from the command line or from the recorder window) adds a tab to the window that
|
||||
//! is already open instead of making a new one: see [`ipc`] and
|
||||
//! [Tabs and one window](self#tabs-and-one-window).
|
||||
//! The first tab is **Record**: the recorder ([`crate::app`]) with its Record and Stop buttons. It
|
||||
//! is pinned, cannot be closed, and shows `REC` and the time in the tab bar while a recording goes
|
||||
//! on, which it does whichever tab is showing. After it come the session tabs, one for each
|
||||
//! recording being reviewed. There is only ever one window: opening another session (from the
|
||||
//! window, from the command line or from the Record tab) adds a tab to the window that is already
|
||||
//! open instead of making a new one: see [`ipc`] and [Tabs and one window](self#tabs-and-one-window).
|
||||
//!
|
||||
//! ```text
|
||||
//! +-------------------------------------------------+
|
||||
//! | [15:46:19 x] [15:51:02 x] [+] Open... | tab bar
|
||||
//! | session name counts and warnings | top bar
|
||||
//! | [Record] [15:46:19 x] [15:51:02 x] [+] Open... | tab bar
|
||||
//! | session name counts and warnings | top bar (a session)
|
||||
//! +----------------------------------+--------------+
|
||||
//! | | Now |
|
||||
//! | the video of every display, | Event |
|
||||
@@ -27,27 +29,46 @@
|
||||
//! +-------------------------------------------------+
|
||||
//! ```
|
||||
//!
|
||||
//! # Compact and full
|
||||
//!
|
||||
//! Started plainly (`komorebi-recorder`, `gui`), the window is *compact*: the old small recorder
|
||||
//! window, 420 by 380 points (at least 360 by 260), always on top, showing the Record tab alone
|
||||
//! with no tab bar, to leave over the application a bug is being reproduced in. The Expand button
|
||||
//! of the Record tab, and opening any session (the Review buttons, a request from another process,
|
||||
//! a key), make it the full window: 1500 by 920 points (at least 900 by 600), not on top, with the
|
||||
//! tab bar; the size it had last is restored. The Compact button goes back, and the choice is
|
||||
//! kept in the preferences ([`prefs::Prefs::compact`]). `view` with sessions starts full. While
|
||||
//! recording, the full window has a "pin on top" checkbox. The window uses the system's title bar
|
||||
//! and frame on Windows; on macOS the title bar is hidden and the content runs under it.
|
||||
//!
|
||||
//! # Tabs and one window
|
||||
//!
|
||||
//! A tab is one session ([`Open`]), or a start screen with the recent sessions, or a session that
|
||||
//! failed to open with the reason. A tab is named for when its session began (`15:46:19`, from the
|
||||
//! folder's name), with the whole path on hover; `x` (or a middle click) closes it and `+` adds a
|
||||
//! start screen. Closing the last tab leaves a start screen: the window itself is closed
|
||||
//! with the system's close button. Opening a session follows one rule, whatever asked for it: if a
|
||||
//! tab has the session, that tab is shown; else if the current tab is a start screen or a failure
|
||||
//! the session loads into it; else it goes in a new tab. Only the tab in view plays: the others
|
||||
//! are paused (their scan for changes carries on), and closing one stops its scan and its decoding.
|
||||
//! The keys are in [`keymap`] (`Cmd`/`Ctrl` `T`, `W`, `Tab`, and `1` to `9`). Tabs are not
|
||||
//! restored when the viewer is started again; the recent sessions are shared by all of them.
|
||||
//! A session tab is one session ([`Open`]), or a start screen with the recent sessions, or a
|
||||
//! session that failed to open with the reason. A tab is named for when its session began
|
||||
//! (`15:46:19`, from the folder's name), with the whole path on hover; `x` (or a middle click)
|
||||
//! closes it and `+` adds a start screen. The Record tab has no `x`. Closing the last session tab
|
||||
//! shows the Record tab; the window itself is closed with the system's close button. Opening a
|
||||
//! session follows one rule, whatever asked for it: if a tab has the session, that tab is shown;
|
||||
//! else if the current tab is a start screen or a failure the session loads into it; else it goes
|
||||
//! in a new tab. Only the tab in view plays: the others are paused (their scan for changes carries
|
||||
//! on), and closing one stops its scan and its decoding. The keys are in [`keymap`] (`Cmd`/`Ctrl`
|
||||
//! `T`, `W`, `Tab`, `0` for the Record tab, and `1` to `9`). Tabs are not restored when the window
|
||||
//! is started again; the recent sessions are shared by all of them.
|
||||
//!
|
||||
//! `komorebi-recorder view` finds out whether a viewer is running by connecting to a socket in
|
||||
//! komorebi's data directory, `komorebi-recorder-viewer.sock`. If one answers, it is sent the
|
||||
//! sessions (as absolute paths) and asked to come to the front, and the command exits without a
|
||||
//! window; if not, the command becomes the viewer and listens there. `view --new-window` skips
|
||||
//! the socket and makes an independent window. The recorder window talks to the socket directly and
|
||||
//! starts `view` only if nobody answers. The protocol, the start-up race and a stale socket
|
||||
//! are covered in [`ipc`]. `KOMOREBI_RECORDER_VIEWER_SOCKET` names another socket, for trying the
|
||||
//! viewer out without touching a real one.
|
||||
//! Every launch that opens a window finds out whether one is already running by connecting to a
|
||||
//! socket in komorebi's data directory, `komorebi-recorder-viewer.sock`. If one answers, it is
|
||||
//! sent what was asked (the sessions as absolute paths, or the Record tab for `gui`) and asked to
|
||||
//! come to the front, and the command exits without a window; if not, the command becomes the
|
||||
//! window and listens there. A second `gui` therefore raises the window and shows its Record tab,
|
||||
//! and its options (`--fps` and the rest) are ignored: they only seed the window that is started.
|
||||
//! `--new-window` on `gui` and `view` skips the socket and makes an independent window.
|
||||
//! `komorebi-recorder-gui.exe` (the Windows build with no console) uses the same socket. The
|
||||
//! protocol, the start-up race and a stale socket are covered in [`ipc`].
|
||||
//!
|
||||
//! Two environment variables point the window somewhere else, for trying it out or testing it end
|
||||
//! to end without touching the real ones: `KOMOREBI_RECORDER_VIEWER_SOCKET` names another socket
|
||||
//! ([`ipc::SOCKET_VARIABLE`]) and `KOMOREBI_RECORDER_PREFS_DIR` another directory for the
|
||||
//! preferences ([`prefs::DIRECTORY_VARIABLE`]).
|
||||
//!
|
||||
//! # What plays and what is read
|
||||
//!
|
||||
@@ -66,13 +87,13 @@
|
||||
//!
|
||||
//! | module | what it is |
|
||||
//! |---|---|
|
||||
//! | [`ipc`] | the viewer's local socket: how one window takes sessions from other processes |
|
||||
//! | [`ipc`] | the window's local socket: how one window takes requests from other processes |
|
||||
//! | [`keymap`] | the keys: a key press becomes an [`Action`](keymap::Action) |
|
||||
//! | [`timeline`] | the arithmetic of the timeline: the visible stretch, the ruler, dense lanes |
|
||||
//! | [`loaded`] | the session as the window draws it, read once |
|
||||
//! | [`prefs`] | what the viewer remembers between runs |
|
||||
//! | [`prefs`] | what the window remembers between runs |
|
||||
//! | [`theme`] | colors |
|
||||
//! | `app` | [`ViewerApp`] (the tabs), [`Screen`] (what a tab shows) and [`Open`], the state of the window and how it is kept in step |
|
||||
//! | `app` | [`ViewerApp`] (the Record tab and the session tabs), [`Screen`] (what a session tab shows) and [`Open`], the state of the window and how it is kept in step |
|
||||
//! | `lanes` | the transport bar and the timeline lanes, and what a mouse does on them |
|
||||
//! | `inspector` | the panel on the right and its five tabs |
|
||||
//! | `video` | the pictures and the state overlay drawn over them |
|
||||
@@ -85,11 +106,11 @@
|
||||
//!
|
||||
//! # Staying out of the way of what is being investigated
|
||||
//!
|
||||
//! The viewer is used on the machine whose behavior is being investigated, so it must neither be
|
||||
//! tiled by komorebi nor appear in a recording being made.
|
||||
//! The window is used on the machine whose behavior is being investigated, so it must neither be
|
||||
//! tiled by komorebi nor appear in a recording being made, in either size.
|
||||
//!
|
||||
//! - **Not tiled.** The window is named `komorebi-recorder` only when it is safely ignored
|
||||
//! ([`crate::komorebi_ignore`]): [`run`] first registers `komorebic ignore-rule exe` for the
|
||||
//! ([`crate::komorebi_ignore`]): [`run_with`] first registers `komorebic ignore-rule exe` for the
|
||||
//! recorder's executables with a running komorebi for Windows, or finds none running. When it
|
||||
//! cannot (no `komorebic`, the command fails, or any macOS host, where komorebi manages every
|
||||
//! window with a title) the title is empty, and komorebi leaves windows with no title alone.
|
||||
@@ -99,7 +120,7 @@
|
||||
//! it and writes the answer to `komorebi-recorder-window-probe.txt` in the temp directory
|
||||
//! (see [`crate::platform::window::PROBE_VARIABLE`]).
|
||||
//! - **Not in the video.** On macOS the recorder's capture filter excludes by name every process
|
||||
//! called `komorebi-recorder` (and its own), which includes the viewer. On Windows a whole
|
||||
//! called `komorebi-recorder` (and its own), which includes this window. On Windows a whole
|
||||
//! monitor is captured, so about once a second the window asks Windows to leave it out of captures
|
||||
//! (`WDA_EXCLUDEFROMCAPTURE`) through [`crate::platform::window::Chrome`], which it ticks on
|
||||
//! every frame.
|
||||
@@ -126,68 +147,155 @@ pub use app::Open;
|
||||
pub use app::Screen;
|
||||
pub use app::ViewerApp;
|
||||
|
||||
/// Opens the viewer window, with each of `sessions` open in a tab, and runs it until it is closed.
|
||||
/// What the window is started to show: the Record tab (plain `gui`) or sessions (`view`).
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Show {
|
||||
/// The Record tab, in the compact window if the preferences say so.
|
||||
Record,
|
||||
/// The sessions in [`Launch::sessions`], in the full window; with none, a start screen.
|
||||
Sessions,
|
||||
}
|
||||
|
||||
/// What a launch of the window asks for.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Launch {
|
||||
/// The sessions to open as tabs, as given. Only used with [`Show::Sessions`].
|
||||
pub sessions: Vec<PathBuf>,
|
||||
/// The options the Record tab starts from (see [`crate::app::run`]).
|
||||
pub record: crate::cli::RecordArgs,
|
||||
/// What to show.
|
||||
pub show: Show,
|
||||
}
|
||||
|
||||
impl Launch {
|
||||
/// Returns the launch of plain `gui`: the Record tab, starting from `record`.
|
||||
#[must_use]
|
||||
pub fn record(record: crate::cli::RecordArgs) -> Self {
|
||||
Self {
|
||||
sessions: Vec::new(),
|
||||
record,
|
||||
show: Show::Record,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the launch of `view`: `sessions` as tabs, in the full window.
|
||||
#[must_use]
|
||||
pub fn sessions(sessions: Vec<PathBuf>) -> Self {
|
||||
Self {
|
||||
sessions,
|
||||
record: crate::cli::RecordArgs::default(),
|
||||
show: Show::Sessions,
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the window starts as the small control window: when it shows the Record tab and
|
||||
/// `prefs` say so.
|
||||
#[must_use]
|
||||
pub fn starts_compact(&self, prefs: &prefs::Prefs) -> bool {
|
||||
self.show == Show::Record && prefs.compact
|
||||
}
|
||||
|
||||
/// The request that hands this launch to a window that is already running.
|
||||
fn request(&self) -> ipc::Request {
|
||||
match self.show {
|
||||
Show::Record => ipc::Request {
|
||||
tab: Some(ipc::TabName::Record),
|
||||
..ipc::Request::default()
|
||||
},
|
||||
Show::Sessions => ipc::Request {
|
||||
open: self
|
||||
.sessions
|
||||
.iter()
|
||||
.map(|path| ipc::absolute(path))
|
||||
.collect(),
|
||||
..ipc::Request::default()
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Opens the window with each of `sessions` open in a tab, and runs it until it is closed: what
|
||||
/// `komorebi-recorder view` does. See [`run_with`], of which this is the launch [`Launch::sessions`].
|
||||
///
|
||||
/// This blocks the calling thread: the window's event loop runs on it. Each of `sessions` is the
|
||||
/// # Errors
|
||||
///
|
||||
/// As [`run_with`].
|
||||
pub fn run(sessions: Vec<PathBuf>, socket: Option<&Path>) -> eyre::Result<()> {
|
||||
run_with(Launch::sessions(sessions), socket)
|
||||
}
|
||||
|
||||
/// Opens the window as `launch` asks, and runs it until it is closed.
|
||||
///
|
||||
/// This blocks the calling thread: the window's event loop runs on it. Each of the sessions is the
|
||||
/// folder of a recording. They open in the background, so a session that cannot be opened does not
|
||||
/// make this fail: the window comes up and shows why. With no sessions the window shows a start
|
||||
/// screen with the recent sessions that still exist ([`prefs::Prefs::existing`]) and a button to
|
||||
/// choose one.
|
||||
/// make this fail: the window comes up and shows why. With [`Show::Sessions`] and no sessions the
|
||||
/// window shows a start screen with the recent sessions that still exist
|
||||
/// ([`prefs::Prefs::existing`]) and a button to choose one.
|
||||
///
|
||||
/// `socket` is the path of the viewer's socket ([`ipc::default_socket`]), or `None` for a window
|
||||
/// of its own that no other process can reach (`view --new-window`). With a socket, if a viewer is
|
||||
/// already running it is asked to open `sessions` as tabs (an empty list raises it) and this
|
||||
/// returns `Ok` at once without making a window; otherwise this window listens on the socket and
|
||||
/// opens what arrives as tabs. If the socket cannot be used, a message is printed and the window
|
||||
/// is made without it.
|
||||
/// `socket` is the path of the window's socket ([`ipc::default_socket`]), or `None` for a window of
|
||||
/// its own that no other process can reach (`--new-window`). With a socket, if a window is already
|
||||
/// running it is handed the launch (the sessions as tabs, or its Record tab, which raises it) and
|
||||
/// this returns `Ok` at once without making a window; the options of [`Launch::record`] are then
|
||||
/// ignored. Otherwise this window listens on the socket and takes what arrives as tabs. If the
|
||||
/// socket cannot be used, a message is printed and the window is made without it.
|
||||
///
|
||||
/// The window is 1500 by 920 points (at least 900 by 600), dark, and titled only when komorebi ignores it: see the [module
|
||||
/// documentation](self#staying-out-of-the-way-of-what-is-being-investigated) for why. Needs a
|
||||
/// window, so there is no example; the tests in `viewer::app` drive the same [`ViewerApp`]
|
||||
/// The window is 1500 by 920 points (at least 900 by 600), or 420 by 380 (at least 360 by 260) and
|
||||
/// always on top when compact ([`Launch::starts_compact`]), dark, and titled only when komorebi
|
||||
/// ignores it: see the [module documentation](self#staying-out-of-the-way-of-what-is-being-investigated)
|
||||
/// for why. A SIGINT or SIGTERM while recording finishes the recording and then closes the window.
|
||||
/// Needs a window, so there is no example; the tests in `viewer::app` drive the same [`ViewerApp`]
|
||||
/// headlessly.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns an error saying "the viewer window failed" if the window cannot be created or its event
|
||||
/// loop fails (for example, there is no display or no usable graphics adapter).
|
||||
pub fn run(sessions: Vec<PathBuf>, socket: Option<&Path>) -> eyre::Result<()> {
|
||||
/// Returns an error saying "the window failed" if the window cannot be created or its event loop
|
||||
/// fails (for example, there is no display or no usable graphics adapter).
|
||||
pub fn run_with(launch: Launch, socket: Option<&Path>) -> eyre::Result<()> {
|
||||
let bound = match socket {
|
||||
Some(socket) => {
|
||||
let sessions: Vec<PathBuf> = sessions.iter().map(|path| ipc::absolute(path)).collect();
|
||||
let request = ipc::Request {
|
||||
open: sessions,
|
||||
focus: true,
|
||||
};
|
||||
match ipc::claim(socket, &request) {
|
||||
// a viewer is running and has taken the sessions as tabs
|
||||
Ok(ipc::Claim::Forwarded) => return Ok(()),
|
||||
Ok(ipc::Claim::Serving(bound)) => Some(bound),
|
||||
// not being able to share a window is no reason not to show the recording
|
||||
Err(error) => {
|
||||
eprintln!("could not reach or start the viewer's socket: {error}");
|
||||
None
|
||||
}
|
||||
Some(socket) => match ipc::claim(socket, &launch.request()) {
|
||||
// a window is running and has taken the request
|
||||
Ok(ipc::Claim::Forwarded) => return Ok(()),
|
||||
Ok(ipc::Claim::Serving(bound)) => Some(bound),
|
||||
// not being able to share a window is no reason not to show the recording
|
||||
Err(error) => {
|
||||
eprintln!("could not reach or start the window's socket: {error}");
|
||||
None
|
||||
}
|
||||
}
|
||||
},
|
||||
None => None,
|
||||
};
|
||||
|
||||
// only a viewer that is going to open a window needs komorebi to ignore it, and it must be
|
||||
// told before the window exists, so komorebi never sees a titled window it was not told to ignore
|
||||
let title = crate::komorebi_ignore::prepare_window().title;
|
||||
// killing the window (or logging out) must still finalize a recording in progress
|
||||
crate::app::install_quit_handler();
|
||||
|
||||
// only a window that is really going to open needs komorebi to ignore it, and it must be told
|
||||
// before the window exists, so komorebi never sees a titled window it was not told to ignore
|
||||
let setup = crate::komorebi_ignore::prepare_window();
|
||||
|
||||
let directory = prefs::directory();
|
||||
let compact = launch.starts_compact(&prefs::Prefs::load(&directory));
|
||||
let (size, min) = if compact {
|
||||
(app::COMPACT_SIZE, app::COMPACT_MIN)
|
||||
} else {
|
||||
(app::FULL_SIZE, app::FULL_MIN)
|
||||
};
|
||||
let mut viewport = egui::ViewportBuilder::default()
|
||||
// titled only when komorebi ignores it (or is not running), so opening the window does
|
||||
// not move the layout of the machine whose behavior is being investigated
|
||||
.with_title(setup.title)
|
||||
.with_app_id("komorebi-recorder")
|
||||
.with_icon(crate::icon::window_icon())
|
||||
.with_title_shown(false)
|
||||
.with_titlebar_shown(false)
|
||||
.with_fullsize_content_view(true)
|
||||
.with_inner_size(size)
|
||||
.with_min_inner_size(min);
|
||||
if compact {
|
||||
// the small control window stays over the application being recorded
|
||||
viewport = viewport.with_always_on_top();
|
||||
}
|
||||
let options = eframe::NativeOptions {
|
||||
viewport: egui::ViewportBuilder::default()
|
||||
// titled only when komorebi ignores it (or is not running), so opening the viewer does
|
||||
// not move the layout of the machine whose behavior is being investigated
|
||||
.with_title(title)
|
||||
.with_app_id("komorebi-recorder")
|
||||
.with_icon(crate::icon::window_icon())
|
||||
.with_title_shown(false)
|
||||
.with_titlebar_shown(false)
|
||||
.with_fullsize_content_view(true)
|
||||
.with_inner_size([1500.0, 920.0])
|
||||
.with_min_inner_size([900.0, 600.0]),
|
||||
viewport,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
@@ -200,9 +308,9 @@ pub fn run(sessions: Vec<PathBuf>, socket: Option<&Path>) -> eyre::Result<()> {
|
||||
visuals.window_fill = theme::BACKGROUND;
|
||||
creation.egui_ctx.set_visuals(visuals);
|
||||
|
||||
let mut app = ViewerApp::new(prefs::directory());
|
||||
for dir in &sessions {
|
||||
app.open(dir);
|
||||
let mut app = ViewerApp::start(directory, launch);
|
||||
if let Some(note) = setup.note {
|
||||
app.recorder_mut().say(note);
|
||||
}
|
||||
if let Some(bound) = bound {
|
||||
let ctx = creation.egui_ctx.clone();
|
||||
@@ -214,7 +322,7 @@ pub fn run(sessions: Vec<PathBuf>, socket: Option<&Path>) -> eyre::Result<()> {
|
||||
)))
|
||||
}),
|
||||
)
|
||||
.map_err(|error| eyre::Report::msg(format!("the viewer window failed: {error}")))
|
||||
.map_err(|error| eyre::Report::msg(format!("the window failed: {error}")))
|
||||
}
|
||||
|
||||
/// Adapts [`ViewerApp`] to eframe.
|
||||
|
||||
@@ -26,7 +26,7 @@ const RECENT: usize = 12;
|
||||
/// use std::path::Path;
|
||||
///
|
||||
/// let mut prefs = Prefs::default();
|
||||
/// assert!(prefs.overlay);
|
||||
/// assert!(prefs.overlay && prefs.compact);
|
||||
///
|
||||
/// prefs.opened(Path::new("/recordings/a"));
|
||||
/// prefs.opened(Path::new("/recordings/b"));
|
||||
@@ -41,6 +41,10 @@ pub struct Prefs {
|
||||
pub recent: Vec<String>,
|
||||
/// Whether komorebi's state is drawn over the video. The default is `true`.
|
||||
pub overlay: bool,
|
||||
/// Whether the window, when started with no session to show, is the small control window: the
|
||||
/// Record tab alone, always on top. Switched with the Compact / Expand button. The default is
|
||||
/// `true`, so a file from a build that did not have it keeps the small window.
|
||||
pub compact: bool,
|
||||
}
|
||||
|
||||
impl Default for Prefs {
|
||||
@@ -48,6 +52,7 @@ impl Default for Prefs {
|
||||
Self {
|
||||
recent: Vec::new(),
|
||||
overlay: true,
|
||||
compact: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -177,14 +182,23 @@ impl Prefs {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns where preferences live: komorebi's data directory, `<local data dir>/komorebi` (see
|
||||
/// The environment variable that replaces [`directory`]. It exists so that the window can be tried
|
||||
/// out, or tested end to end, without reading or writing the user's real preferences; it is not
|
||||
/// meant for anything else.
|
||||
pub const DIRECTORY_VARIABLE: &str = "KOMOREBI_RECORDER_PREFS_DIR";
|
||||
|
||||
/// Returns where preferences live: `$KOMOREBI_RECORDER_PREFS_DIR` if it is set and not empty
|
||||
/// ([`DIRECTORY_VARIABLE`]), else komorebi's data directory, `<local data dir>/komorebi` (see
|
||||
/// [`komorebi_link::data_dir`](crate::komorebi_link::data_dir)).
|
||||
///
|
||||
/// It depends on the machine, so it is not shown with an example: the viewer passes it to
|
||||
/// [`Prefs::load`] and [`Prefs::save`].
|
||||
#[must_use]
|
||||
pub fn directory() -> PathBuf {
|
||||
crate::komorebi_link::data_dir().to_path_buf()
|
||||
match std::env::var_os(DIRECTORY_VARIABLE) {
|
||||
Some(path) if !path.is_empty() => PathBuf::from(path),
|
||||
_ => crate::komorebi_link::data_dir().to_path_buf(),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in new issue
Block a user