drone-path 0.12.1 → 1.0.0-rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/README.md +20 -74
  2. package/THIRD-PARTY-NOTICES.md +3 -82
  3. package/bin/drone-path.mjs +0 -0
  4. package/dist/cli.d.ts +14 -0
  5. package/dist/cli.js +7 -7
  6. package/dist/version.d.ts +1 -0
  7. package/package.json +21 -68
  8. package/CHANGELOG.md +0 -336
  9. package/app/ipc.d.mts +0 -43
  10. package/app/ipc.mjs +0 -216
  11. package/app/main.mjs +0 -356
  12. package/app/preload.cjs +0 -34
  13. package/app/update-policy.d.mts +0 -6
  14. package/app/update-policy.mjs +0 -6
  15. package/app/update.d.mts +0 -10
  16. package/app/update.mjs +0 -54
  17. package/dist/appassets.js +0 -35
  18. package/dist/apppaths.js +0 -20
  19. package/dist/appsession.js +0 -121
  20. package/dist/appstate.js +0 -94
  21. package/dist/assets.js +0 -60
  22. package/dist/buildinfo.js +0 -64
  23. package/dist/cammeta-decode.js +0 -237
  24. package/dist/cammeta.js +0 -92
  25. package/dist/changeset-gate.js +0 -39
  26. package/dist/config.js +0 -631
  27. package/dist/configfile.js +0 -86
  28. package/dist/decimate.js +0 -84
  29. package/dist/errors.js +0 -34
  30. package/dist/exec-tool.js +0 -13
  31. package/dist/exportjob.js +0 -90
  32. package/dist/ffmpeg-tools.js +0 -56
  33. package/dist/ffmpeg.js +0 -98
  34. package/dist/frametime.js +0 -32
  35. package/dist/geo.js +0 -60
  36. package/dist/logging.js +0 -1
  37. package/dist/manual/anchors.js +0 -17
  38. package/dist/manual/build.js +0 -67
  39. package/dist/manual/cliref.js +0 -34
  40. package/dist/manual/links.js +0 -59
  41. package/dist/manual/markdown.js +0 -98
  42. package/dist/manual/model.js +0 -1
  43. package/dist/manual/module.js +0 -5
  44. package/dist/manual/nav.js +0 -11
  45. package/dist/manual/reference.js +0 -18
  46. package/dist/paths.js +0 -16
  47. package/dist/pipeline.js +0 -402
  48. package/dist/plan.js +0 -106
  49. package/dist/png.js +0 -32
  50. package/dist/protobuf-wire.js +0 -102
  51. package/dist/range.js +0 -50
  52. package/dist/recordings.js +0 -55
  53. package/dist/render-page.js +0 -85
  54. package/dist/render.js +0 -268
  55. package/dist/renderer/boot.js +0 -7
  56. package/dist/renderer/dom.js +0 -177
  57. package/dist/renderer/framemath.js +0 -30
  58. package/dist/renderer/scene.js +0 -385
  59. package/dist/renderer/theme.js +0 -82
  60. package/dist/renderer/tilesources.js +0 -38
  61. package/dist/renderer/trail.js +0 -42
  62. package/dist/restyle.js +0 -16
  63. package/dist/serve.js +0 -27
  64. package/dist/srt.js +0 -98
  65. package/dist/telemetry-json-schema.js +0 -18
  66. package/dist/telemetry-json.js +0 -126
  67. package/dist/telemetry-math.js +0 -267
  68. package/dist/telemetry-summary.js +0 -19
  69. package/dist/telemetry.js +0 -95
  70. package/dist/tilecache.js +0 -21
  71. package/dist/tiles.js +0 -155
  72. package/dist/track-format.js +0 -13
  73. package/dist/track-geojson.js +0 -44
  74. package/dist/track-gpx.js +0 -34
  75. package/dist/track-kml.js +0 -47
  76. package/dist/track-kmz.js +0 -68
  77. package/dist/track-write.js +0 -41
  78. package/dist/track.js +0 -79
package/CHANGELOG.md DELETED
@@ -1,336 +0,0 @@
1
- # drone-path
2
-
3
- ## 0.12.1
4
-
5
- - **Fixed:** The Export video dialog handles every outcome cleanly: a
6
- failed or canceled run returns to the form with the outcome sentence
7
- as a notice, so retry stays one click away, and a canceled run always
8
- reads "Export canceled; its unfinished file was removed." The export
9
- summary now reports the media duration (frames at the frame rate)
10
- instead of the encode wall time, which read as a wrong duration
11
- between the media specs.
12
- - **Fixed:** Exported frames carry the heading pill: the HDG readout
13
- joins ALT and SPD in the top-left HUD column, toggled by the heading
14
- readout setting, exactly as the Map appearance preview shows it. The
15
- preview pills use the export's placement and stacking, and on-video
16
- pills read HDG/ALT/SPD.
17
- - **Fixed:** Selected controls keep their accent selection marker while
18
- hovered: HUD chips, map style tiles, trail swatches and structure bar
19
- segments no longer read unselected under the cursor. Disabled HUD
20
- chips dim to the disabled look instead of the "off" look, and select
21
- and text fields lighten their border on hover like number fields.
22
- - **Fixed:** A failed "Reveal in folder" in the Export telemetry dialog
23
- no longer leaves its error notice behind after a successful retry;
24
- every reveal attempt clears the previous error first.
25
- - **Fixed:** The PiP overlay's map strip shows the zoom level and
26
- announces refused zoom steps, so the `+` and `-` hotkeys give
27
- feedback in every layout instead of silently re-pinning the zoom.
28
-
29
- ## 0.12.0
30
-
31
- - **New:** The flight map zooms in and out with a small `−`/`+` pill
32
- below the map (split view) and the `+` / `-` keys: every step pins the
33
- level as the fixed "Zoom" setting, so the export renders exactly the
34
- zoom the preview shows. Zooming clamps at the map's usable levels with
35
- the matching button disabling at either end, and opening a recording
36
- resets Zoom to auto-fit.
37
- - **New:** The map card's Speed, Altitude and Zoom readouts now sit in
38
- one compact strip below the map — labeled columns with a bare `−`
39
- level `+` stepper instead of separate chip pills and a zoom row — and
40
- the map reclaims the freed height. A turned-off HUD chip keeps its
41
- column and shows a dimmed `--`.
42
- - **New:** Map appearance is now a modal dialog with a live preview of
43
- the export frame — the loaded recording or a bundled example flight —
44
- and grouped settings: map style as thumbnail tiles, a trail color
45
- swatch row with an explicit Style default, an Auto-fit zoom toggle
46
- with a zoom level slider and Frame padding, clickable HUD chips, and
47
- an opening & ending strip. The entry moved from File to View, and the
48
- player shortcuts pause while the dialog is open.
49
-
50
- ## 0.11.1
51
-
52
- - **Fixed:** Video export in the packaged desktop app ("Export video…")
53
- works again: the app now bundles the renderer's `playwright-core` and
54
- renders with the system browser (Google Chrome or Microsoft Edge), the
55
- same as the CLI.
56
-
57
- ## 0.11.0
58
-
59
- - **New:** Flight track files: `--track-out <file>` writes the decoded
60
- flight track in the format the file extension picks — GPX (`.gpx`),
61
- GeoJSON (`.geojson`), KML/KMZ (`.kml`/`.kmz`) — or the existing
62
- telemetry JSON document (`.json`, unchanged bytes). Vertices sit at
63
- decoded GPS fixes with telemetry gaps breaking the line, altitude is
64
- the absolute/GPS altitude in meters above mean sea level, and times
65
- appear only where a recording carries trustworthy UTC — none does
66
- today (the CAM-meta device timestamp counts since power-up), so KML
67
- exports plain line segments instead of a timed flythrough. The
68
- desktop **Export telemetry…** dialog offers the same five formats and
69
- honors the In–Out range; for the same recording and range the app and
70
- the CLI write byte-identical files. `--telemetry-json <file>` is a
71
- deprecated alias of `--track-out <file>.json` — same output, warns on
72
- use, removed in a future version — and mixing the two spellings in
73
- one run is an error. A frame range of a single frame is now valid
74
- everywhere ranges are accepted.
75
- - **New:** The timeline shows a lone in or out point as a half-open
76
- In–Out segment — the in point runs to the end of the recording, the
77
- out point from its start — and the readout names the same passage.
78
- Playback wrap and both exports honor a lone point, setting a point
79
- past the other replaces it, and the readout announces point changes
80
- to screen readers.
81
- - **New:** The app's copy is unified and the dialogs are polished: the
82
- marked range is the In–Out segment with "Set in point" / "Set out
83
- point" controls and an `in 0:12 · out 0:34` readout, the export flow
84
- says "export" throughout with codec and encode-speed labels, every
85
- failure reads as a sentence with a next step (raw text under
86
- "Technical details"), and a failed update restart is reported. Each
87
- dialog dismisses through its header ✕ alone, the export-done dialog
88
- leads with "Export finished." and one accent primary (**Reveal in
89
- folder**), output paths wrap with a full-path tooltip, and export and
90
- telemetry phase text is announced in a live region and keeps keyboard
91
- focus through phase changes.
92
- - **New:** Accessibility hardening for the menu bar and dialogs: AltGr
93
- characters type normally in every field, Left/Right move between the
94
- menu labels with disabled rows announcing themselves, Tab stays
95
- inside dialogs and the Help overlay, and the timeline scrubber
96
- announces times instead of raw frame numbers.
97
- - **New:** The transport and loop controls are compact and stable: the
98
- Play/Pause button is icon-only with a tooltip and accessible name,
99
- the in/out-point buttons form one group beside a fixed readout slot,
100
- and toggling playback or marking points no longer shifts neighboring
101
- controls. The ALT/SPD readouts sit in a strip along the map card's
102
- bottom edge, the Map appearance popover docks left of the map card
103
- and opens from **File → Map appearance…**, the empty workspace drops
104
- its tooling hint and status footer, the header hides the duration
105
- until a recording loads, and the map card shows "Preparing map…"
106
- while its tiles load.
107
- - **Internal:** Code consolidation and dead-export cleanup from a
108
- refactoring pass; no behavior changes.
109
-
110
- ## 0.10.0
111
-
112
- - **New:** Telemetry now comes from the embedded CAM meta (DVTM) stream
113
- whenever a recording has one; the `.SRT` sidecar is only used when no
114
- CAM meta stream is present. A CAM meta stream without GPS positions
115
- fails the run with a clear error instead of silently falling back to
116
- the sidecar.
117
- - **New:** The opt-in OpenTelemetry trace export is removed along with
118
- its `OTEL_*` environment variables. Stage logs, progress reporting
119
- and rendered output are unchanged.
120
-
121
- ## 0.9.0
122
-
123
- - **New:** The flight trail is now configurable: `--trail-color <hex>`
124
- (RGB or RGBA hex like `#e63946` or `#e63946cc`, `#` optional) and the
125
- `trailColor` setting recolor the flight trail, the drone marker and
126
- the HUD accents. Glow and casing are derived from the chosen color,
127
- so the layered trail stays readable on both map styles; omitting the
128
- option keeps the per-style theme defaults.
129
- - **New:** `--telemetry-json <file>` exports per-frame telemetry —
130
- time, position, altitude, body and gimbal attitude, heading and
131
- camera exposure — as one versioned JSON document with a record per
132
- source frame; the schema is checked in as
133
- `docs/telemetry-json.schema.json`. The desktop workspace writes the
134
- same document through Export telemetry…, straight from the loaded
135
- recording (the In–Out segment or the full recording) and
136
- byte-identical to the CLI output.
137
- - **New:** The desktop workspace has a top menu bar with the workspace
138
- actions moved into it: **File** holds Open… (Ctrl+O), Export video…,
139
- Export telemetry…, Settings and Exit, **View** holds Swap (S), and
140
- right-aligned **Help** holds Documentation and About. It follows
141
- Windows menu conventions (click or Alt opens, hover switches, arrows
142
- navigate, Enter/Space activate, Esc closes, Alt+F/V/H mnemonics) with
143
- the accent-forward menu state styling. "Export…" is now "Export
144
- video…" on every surface, the header and status footer keep only
145
- their informational content, the auto-hidden native Electron menu is
146
- gone, and Exit still guards against closing during a running export.
147
- - **New:** **Help → About** shows the drone / path lockup, the running
148
- build's version — `MAJOR.MINOR.PATCH` for releases,
149
- `MAJOR.MINOR.PATCH+<short commit>` for every other build, injected at
150
- build time — an MIT license line, and a link that opens the
151
- `MrManny/drone-path` repository in the default browser.
152
-
153
- ## 0.8.1
154
-
155
- - **Fixed:** The GitHub repository moved to `MrManny/drone-path`:
156
- `npx github:` commands, links and the desktop app's update feed point
157
- at the new home, and old URLs redirect.
158
- - **Internal:** Routine dependency updates.
159
-
160
- ## 0.8.0
161
-
162
- - **New:** The tool is now called **Drone Path**. The rename is a clean
163
- break with no compatibility aliases — on upgrade, use the `drone-path`
164
- command (previously `neo2-flightpath`), move the config file to
165
- `.dronepath.json` (from `.neo2flightpath.json`), and rename the tile-cache
166
- environment variable to `DRONEPATH_TILE_CACHE` (from
167
- `NEO2_FLIGHTPATH_TILE_CACHE`). The per-user data directory moves to
168
- `drone-path`, leaving the old one behind.
169
- - **New:** The desktop app ships as "Drone Path" under a new app identity.
170
- Installed apps do not auto-update in place — uninstall the old version
171
- and install the new one.
172
-
173
- ## 0.7.0
174
-
175
- - **New:** The desktop player is now a synchronized video-and-map review
176
- workspace: dedicated footage and flight-map panes with a swappable overlay
177
- layout, a bare map sidebar with a map appearance popover, and a timeline of
178
- square preview stills spread from the first frame to the last with a
179
- draggable loop band and icon-only loop controls. The transport controls sit
180
- centered under the footage.
181
- - **New:** The app opens straight into the review workspace — the landing
182
- screen is gone and no tile warm-up stands between the user and the footage.
183
- Before a recording is loaded the workspace shows its disabled controls with
184
- an accent **Open…** call to action in the footage pane, a quiet "No
185
- telemetry yet" map pane and a "No recording loaded" status bar. A picked
186
- recording loads right into the player, with map tiles streaming on demand
187
- (rendering and exporting still prefetch their tiles beforehand).
188
- - **New:** The export dialog is wider and shows a map-only output preview at
189
- the export's exact size, with range, output-size and encoding choices
190
- clearly separated and the familiar destination, progress, cancel, done and
191
- error states beside the preview.
192
- - **New:** New color scheme: dark neutral surfaces with a warm coral accent,
193
- sand loop state and warmer semantic tones, plus one shared accent-colored
194
- flight trail in the map island and in rendered frames.
195
- - **New:** The app icon is the final branded artwork: a circular drone badge
196
- rasterized to a metadata-free 512x512 master and re-derived for every
197
- platform format (Windows ICO, Linux icon set).
198
- - **Fixed:** Loading a second recording now switches the footage and the
199
- filmstrip to the new recording instead of replaying the previous one's bytes
200
- from a URL-keyed cache.
201
-
202
- ## 0.6.1
203
-
204
- - **Fixed:** Maintenance release with updated dependencies that contain
205
- security fixes.
206
-
207
- ## 0.6.0
208
-
209
- - **New:** Renders and exports no longer need a local ffmpeg install:
210
- static ffmpeg and ffprobe 7.1.0 binaries ship with the desktop app and
211
- the npm package. `--ffmpeg <path>` and `--ffprobe <path>` override
212
- them, PATH remains a fallback, and installing downloads both tools in
213
- a postinstall step (~250 MB).
214
- - **New:** The export dialog and the CLI now configure the encoder:
215
- video codec (H.264 or H.265), quality (near-lossless down to low) and
216
- encoding speed. The defaults reproduce the previous output exactly.
217
- - **New:** The export dialog opens on the In–Out segment when a loop is
218
- set and keeps the output size for the session.
219
- - **Fixed:** Dialogs now manage keyboard focus: opening a dialog moves
220
- focus onto it, closing hands it back to the control that opened it.
221
-
222
- ## 0.5.0
223
-
224
- - **New:** The player opens as soon as the map tiles around the drone at
225
- the first frame are warm; the remaining tiles the map can show keep
226
- loading into the cache behind a small "Warming tiles…" hint, and
227
- changing the map style, zoom or view moves the loading onto the new
228
- plan.
229
- - **New:** The settings panel's look — map style, view, zoom, intro/outro
230
- and HUD chips — is remembered between launches, and the Open dialog
231
- starts in the folder the last recording was opened from. A fresh
232
- install, or a state file the app cannot read, starts at the documented
233
- defaults.
234
- - **New:** Help now opens a full offline user manual inside the app —
235
- how playback, settings and export fit together, keyboard shortcuts and
236
- a CLI/config reference — from the landing card and the control bar.
237
- - **Fixed:** All tile downloads share one polite queue, so the combined
238
- request rate stays inside the 2-per-second tile budget even when
239
- several loading lanes run at once.
240
- - **Fixed:** Tile cache write failures (a full disk, an unwritable
241
- cache, a cache path that is not a directory) now fail the affected
242
- tile with an error naming the cache instead of silently degrading to a
243
- placeholder.
244
-
245
- ## 0.4.0
246
-
247
- - **New:** The desktop app now updates itself from GitHub Releases:
248
- packaged builds download a newer version in the background and ask
249
- once whether to restart into it. Windows releases gain a self-updating
250
- NSIS installer next to the portable exe (which never self-updates).
251
- - **Fixed:** Escape now closes the Settings and Export dialogs even
252
- while a select field is focused: the first Escape is still reserved
253
- for the select's own dropdown, and the second one closes the dialog.
254
- - **Fixed:** The export dialog's Width and Height fields now show
255
- exactly what the export renders: typing an odd size and leaving the
256
- field commits the even size (rounded down, at least 64 px), so the
257
- fields, the export and the done summary always agree.
258
- - **Fixed:** The preparation progress bar no longer shrinks mid-load:
259
- its percent now grows monotonically to 100 across probing, telemetry,
260
- view planning and the tile pre-warm.
261
- - **Fixed:** The map trail now grows with playback and ends at the
262
- drone: the flown path is drawn up to the current frame's position
263
- instead of stalling on the decimated points, so the trail appears and
264
- grows on every recording (including hovering and straight flights) in
265
- the app and exported overlays alike.
266
- - **Internal:** The test tree is type-checked before the unit tests
267
- run, and the OpenTelemetry packages are up to date.
268
-
269
- ## 0.3.0
270
-
271
- - **New:** The desktop app — pick a recording and watch its flight path on a
272
- map in sync with the footage, one shared timeline scrubber and a swappable
273
- picture-in-picture layout. It ships as a Windows portable executable and a
274
- Linux AppImage, with its own application icon and the window title
275
- "Neo2 Flightpath".
276
- - **New:** Export the look you see: a modal renders the preview as a video,
277
- the full recording or the In–Out loop segment at a chosen size, written
278
- through a native save dialog. Exports run as one cancelable job and are
279
- verified before they replace the chosen file, so a failed or canceled
280
- export never touches an existing file; "Reveal in folder" and "Open video"
281
- act on the exported file, and a refused cancel explains itself.
282
- - **New:** Playback and review: speed 1x–4x, a loop region with I/O points
283
- that auto-engage and wrap on repeat (Esc or Clear to remove), and keyboard
284
- shortcuts for play/pause, speed, frame stepping, one-second jumps and
285
- swapping the views. Seeking is frame-exact: End reaches the last frame and
286
- every step lands exactly where requested.
287
- - **New:** A settings panel (cog button): map style, view, zoom/zoom-out,
288
- intro/outro seconds and HUD chips mirror the CLI options and restyle the
289
- preview instantly, fetching any missing map tiles on demand. The alt chip
290
- hides itself when the telemetry has no altitude.
291
- - **New:** Preparation progress on the landing card: a bar that advances one
292
- step per preparation stage and per warmed map tile, and the status notice
293
- names the running stage.
294
- - **New:** Errors and progress read as plain sentences with the original
295
- system text under "Technical details", and the control bar fits the
296
- 1024×600 minimum window.
297
- - **New:** The map trail is drawn with one incremental update in the app and
298
- the CLI alike; the `--trail` option is removed — drop the `trail` key from
299
- config files.
300
- - **Fixed:** One rule now counts GPS fixes in every telemetry source: exactly
301
- (0, 0) is the no-lock placeholder, so near-equator and near-prime-meridian
302
- coordinates count as fixes again, and fix counts agree between the SRT
303
- sidecar and camera metadata. Frames after the last GPS fix hold that fix
304
- instead of jumping back to the flight's start.
305
- - **Fixed:** ffmpeg/ffprobe failures surface their real cause instead of a
306
- false "no telemetry found", mistyped numbers in config files fail fast
307
- naming the option instead of being silently coerced, and odd canvas
308
- dimensions normalize to even.
309
- - **Fixed:** On Windows, output names differing only in case are one file —
310
- collision suffixing and the overwrite guard agree on it (on Linux and macOS
311
- they stay two distinct names).
312
- - **Internal:** The app and the headless CLI share one map renderer, and CLI
313
- output stays frame-exact. Option defaults live in one table, the
314
- `--out-dir` default is documented as the `out` folder, CLI help names the
315
- offending flag, and the agent helpers move project statuses past the first
316
- result page.
317
-
318
- ## 0.2.0
319
-
320
- - **New:** See where render time goes — opt-in OpenTelemetry traces for the
321
- render pipeline via `OTEL_EXPORTER_OTLP_ENDPOINT` (OTLP/HTTP protobuf);
322
- nothing is loaded or sent without it.
323
- - **Internal:** Release notes are now curated for users; Dependabot keeps
324
- `@types/node` on the Node 24 line.
325
-
326
- ## 0.1.1
327
-
328
- - **Internal:** Code base restructuring and README improvements.
329
-
330
- ## 0.1.0
331
-
332
- - **New:** First release — flight-path map overlay videos from DJI drone
333
- recordings at exactly the source frame rate and frame count, with telemetry
334
- from the `.SRT` sidecar or the embedded CAM-meta (DVTM) stream; `satellite`
335
- and `topo` map styles, batch processing, config file support, `--json`
336
- summaries and `out` as the default output directory.
package/app/ipc.d.mts DELETED
@@ -1,43 +0,0 @@
1
- import type { AppSession } from '../src/appsession.js';
2
- import type { AppState } from '../src/appstate.js';
3
- import type { ExportRequest, RenderConfig } from '../src/config.js';
4
- import type { UpdateController } from './update.mjs';
5
-
6
- export interface IpcWindow {
7
- isDestroyed(): boolean;
8
- close(): void;
9
- }
10
-
11
- export interface IpcState {
12
- session: AppSession | null;
13
- config: RenderConfig;
14
- appState: AppState;
15
- win: IpcWindow | null;
16
- exportRunner: {
17
- start(videoPath: string, request: ExportRequest): void;
18
- cancel(): void;
19
- };
20
- updates: UpdateController | null;
21
- updateReady: boolean;
22
- lastExportOut: string | null;
23
- lastTrackOut: string | null;
24
- }
25
-
26
- export interface IpcHandlersOptions {
27
- devUrl: string | null;
28
- log: (message: string) => void;
29
- sendToWindow(state: IpcState, channel: string, payload: unknown): void;
30
- }
31
-
32
- export function registerIpcHandlers(state: IpcState, options: IpcHandlersOptions): void;
33
-
34
- /**
35
- * Resolves the final save path: the typed name stands as typed when it already
36
- * ends in one of the accepted extensions (any case); otherwise the default
37
- * extension is appended to it.
38
- */
39
- export function resolveSavePath(
40
- typedPath: string,
41
- extensions: readonly string[],
42
- defaultExtension: string,
43
- ): string;
package/app/ipc.mjs DELETED
@@ -1,216 +0,0 @@
1
- // IPC for the app window: handlers throw plain Errors and the handle()
2
- // envelope answers the renderer with { ok: false, error }.
3
-
4
- import fs from 'node:fs';
5
- import path from 'node:path';
6
-
7
- import { dialog, ipcMain, shell } from 'electron';
8
-
9
- import { parsePickRequest, parseTrackSaveRequest } from '../dist/appsession.js';
10
- import { applyAppState, writeAppState } from '../dist/appstate.js';
11
- import { APP_ORIGIN, appStateFile } from '../dist/apppaths.js';
12
- import { parseExportRequest, parseSettingsPatch } from '../dist/config.js';
13
- import { ERR_NO_RECORDING, errorMessage } from '../dist/errors.js';
14
- import { videoBaseName } from '../dist/recordings.js';
15
- import { outputPathFor } from '../dist/pipeline.js';
16
- import { TRACK_FORMAT_VALUES } from '../dist/track-format.js';
17
-
18
- // Only this app's window may drive the session state machine.
19
- function assertTrusted(event, devUrl) {
20
- const url = (event.senderFrame && event.senderFrame.url) || '';
21
- const devOk = devUrl !== null && url.startsWith(devUrl);
22
- if (!url.startsWith(APP_ORIGIN + '/') && !devOk) {
23
- throw new Error('untrusted ipc sender');
24
- }
25
- }
26
-
27
- function handle(devUrl, channel, fn) {
28
- ipcMain.handle(channel, async (event, ...args) => {
29
- // Outside the envelope: an untrusted sender must see a rejected promise,
30
- // never a well-formed reply.
31
- assertTrusted(event, devUrl);
32
- try {
33
- return await fn(...args);
34
- } catch (e) {
35
- return { ok: false, error: errorMessage(e) };
36
- }
37
- });
38
- }
39
-
40
- function requireVideo(state) {
41
- const video = state.session ? state.session.videoPath() : null;
42
- if (!video) throw new Error(ERR_NO_RECORDING);
43
- return video;
44
- }
45
-
46
- // The reveal/open guard: the renderer may only name a file this shell wrote
47
- // (the last export or the last track file, both set only by trusted
48
- // handlers), never an arbitrary path.
49
- function knownOutputOf(state, payload) {
50
- const out = payload && typeof payload === 'object' ? payload.out : null;
51
- if (typeof out !== 'string' || (out !== state.lastExportOut && out !== state.lastTrackOut)) {
52
- throw new Error('unknown output');
53
- }
54
- return out;
55
- }
56
-
57
- // The native dialog confirmed the name as typed, but the extension may have
58
- // been appended after it: re-check the final path on every platform so an
59
- // existing file is never replaced without a confirmation.
60
- async function confirmReplace(state, chosen) {
61
- if (!fs.existsSync(chosen)) return true;
62
- const box = {
63
- type: 'warning',
64
- buttons: ['Replace', 'Cancel'],
65
- defaultId: 1,
66
- cancelId: 1,
67
- message: `Replace ${path.basename(chosen)}?`,
68
- detail: chosen,
69
- };
70
- const confirm = state.win
71
- ? await dialog.showMessageBox(state.win, box)
72
- : await dialog.showMessageBox(box);
73
- return confirm.response === 0;
74
- }
75
-
76
- // The CLI's default naming, with a relative out dir anchored at the
77
- // recording: the app process has no meaningful working directory.
78
- function exportDefaultFor(state, video) {
79
- const outDir = state.config.outDir
80
- ? path.resolve(path.dirname(video), state.config.outDir)
81
- : null;
82
- return outputPathFor(video, { ...state.config, outDir });
83
- }
84
-
85
- // Pure name rule for save dialogs: the typed name stands as typed when it
86
- // already ends in one of the accepted extensions (any case); otherwise the
87
- // default extension is appended to it as typed, so "notes.csv" becomes
88
- // "notes.csv.json". The dialogs that report the result show this final name,
89
- // so the append is never silent.
90
- export function resolveSavePath(typedPath, extensions, defaultExtension) {
91
- const lower = typedPath.toLowerCase();
92
- return extensions.some((extension) => lower.endsWith(`.${extension}`))
93
- ? typedPath
94
- : `${typedPath}.${defaultExtension}`;
95
- }
96
-
97
- async function pickSavePath(state, { title, defaultPath, filters, extensions, defaultExtension }) {
98
- const options = { title, defaultPath, filters };
99
- const result = state.win
100
- ? await dialog.showSaveDialog(state.win, options)
101
- : await dialog.showSaveDialog(options);
102
- if (result.canceled || !result.filePath) return { ok: false, canceled: true };
103
- const chosen = resolveSavePath(result.filePath, extensions, defaultExtension);
104
- if (!(await confirmReplace(state, chosen))) return { ok: false, canceled: true };
105
- return { ok: true, path: chosen };
106
- }
107
-
108
- function registerSessionHandlers(state, devUrl) {
109
- handle(devUrl, 'dronepath:pick', (raw) => state.session.pick(parsePickRequest(raw)));
110
- handle(devUrl, 'dronepath:session', () => state.session.getSession());
111
- }
112
-
113
- function registerSettingsHandlers(state, devUrl, log) {
114
- handle(devUrl, 'dronepath:settings', () => state.config);
115
- handle(devUrl, 'dronepath:settings:save', (raw) => {
116
- const settings = parseSettingsPatch(raw, 'settings');
117
- state.appState = { ...state.appState, settings };
118
- state.config = applyAppState(state.config, state.appState);
119
- try {
120
- writeAppState(appStateFile(), state.appState);
121
- } catch (e) {
122
- // The look still applies when the state file cannot be written.
123
- log(`app state not saved: ${errorMessage(e)}`);
124
- }
125
- return { ok: true };
126
- });
127
- }
128
-
129
- function registerExportHandlers(state, devUrl) {
130
- handle(devUrl, 'dronepath:export:pick-output', async () => {
131
- const video = requireVideo(state);
132
- return pickSavePath(state, {
133
- title: 'Export video',
134
- defaultPath: exportDefaultFor(state, video),
135
- filters: [{ name: 'MP4 video', extensions: ['mp4'] }],
136
- extensions: ['mp4'],
137
- defaultExtension: 'mp4',
138
- });
139
- });
140
- handle(devUrl, 'dronepath:export:start', (raw) => {
141
- const video = requireVideo(state);
142
- state.exportRunner.start(video, parseExportRequest(raw, state.config));
143
- return { ok: true };
144
- });
145
- handle(devUrl, 'dronepath:export:cancel', () => {
146
- state.exportRunner.cancel();
147
- return { ok: true };
148
- });
149
- handle(devUrl, 'dronepath:export:reveal', (payload) => {
150
- shell.showItemInFolder(knownOutputOf(state, payload));
151
- return { ok: true };
152
- });
153
- handle(devUrl, 'dronepath:export:open', async (payload) => {
154
- const error = await shell.openPath(knownOutputOf(state, payload));
155
- return error ? { ok: false, error } : { ok: true };
156
- });
157
- }
158
-
159
- function registerTrackHandlers(state, devUrl, log) {
160
- handle(devUrl, 'dronepath:track:pick-output', async () => {
161
- const video = requireVideo(state);
162
- // The export dialog's default folder, named after the recording
163
- // (<basename>.telemetry.json); the typed name selects the format by its
164
- // extension, with the telemetry document as the bare-name default.
165
- const exportDefault = exportDefaultFor(state, video);
166
- return pickSavePath(state, {
167
- title: 'Export telemetry',
168
- defaultPath: path.join(path.dirname(exportDefault), `${videoBaseName(video)}.telemetry.json`),
169
- filters: [
170
- { name: 'Telemetry document (JSON)', extensions: ['json'] },
171
- { name: 'GPX track', extensions: ['gpx'] },
172
- { name: 'GeoJSON track', extensions: ['geojson'] },
173
- { name: 'KML track', extensions: ['kml'] },
174
- { name: 'KMZ track', extensions: ['kmz'] },
175
- ],
176
- extensions: [...TRACK_FORMAT_VALUES],
177
- defaultExtension: 'json',
178
- });
179
- });
180
- handle(devUrl, 'dronepath:track:save', (raw) => {
181
- requireVideo(state);
182
- const request = parseTrackSaveRequest(raw);
183
- state.session.saveTrack(request.outPath, request.range);
184
- state.lastTrackOut = request.outPath;
185
- log(`track: wrote ${request.outPath}`);
186
- return { ok: true };
187
- });
188
- }
189
-
190
- function registerUpdateHandlers(state, devUrl, sendToWindow) {
191
- handle(devUrl, 'dronepath:update:restart', () => {
192
- if (!state.updates) return { ok: false, error: 'this build does not self-update' };
193
- // No pendingClose here: the prompt never opens over a running export, and
194
- // a failed restart must not poison the export close guard.
195
- return state.updates.restart({
196
- onError: (message) => sendToWindow(state, 'dronepath:update:restart-failed', message),
197
- });
198
- });
199
- handle(devUrl, 'dronepath:update:state', () => ({ ready: state.updateReady }));
200
- }
201
-
202
- function registerWindowHandlers(state, devUrl) {
203
- handle(devUrl, 'dronepath:window:close', () => {
204
- // The window's close handler runs the running-export guard.
205
- if (state.win && !state.win.isDestroyed()) state.win.close();
206
- });
207
- }
208
-
209
- export function registerIpcHandlers(state, { devUrl, log, sendToWindow }) {
210
- registerSessionHandlers(state, devUrl);
211
- registerSettingsHandlers(state, devUrl, log);
212
- registerExportHandlers(state, devUrl);
213
- registerTrackHandlers(state, devUrl, log);
214
- registerUpdateHandlers(state, devUrl, sendToWindow);
215
- registerWindowHandlers(state, devUrl);
216
- }