Skip to content

feat: drag-drop and OS Open with for PDFs#3

Open
Matbe34 wants to merge 20 commits into
masterfrom
feature/pdf-entry-points
Open

feat: drag-drop and OS Open with for PDFs#3
Matbe34 wants to merge 20 commits into
masterfrom
feature/pdf-entry-points

Conversation

@Matbe34

@Matbe34 Matbe34 commented May 4, 2026

Copy link
Copy Markdown
Owner

Summary

Two related PDF entry points layered on top of the existing tabs system:

  1. Drag-drop a PDF (or several) onto a running lankir window → each opens as a new tab.
  2. "Open with Lankir" from the OS file manager → opens as a new tab in the existing window (single-instance default), or starts a fresh window if none is running. `Ctrl+Shift+N` spawns an explicit new window for side-by-side viewing.

App code is cross-platform (Linux/Windows/macOS); OS-side file association ships only on Linux for now (the `.desktop` file gets MIME registration). Windows and macOS need an installer / `.app` bundle that don't exist yet — flagged out of scope.

What changed

  • Backend

    • `main.go` — new `parseArgs` helper splits args into "CLI subcommand" vs "GUI files to open" (Cobra-aware predicate, no extension matching).
    • `runGUI(initialFiles []string)` accepts startup files; emits them as `open-files` event in `OnStartup`.
    • `app.go` — three new methods: `onFileDrop` (filter + emit), `onSecondInstance` (resolve relative paths against the second-launch cwd + emit), `OpenInNewWindow` (`os/exec` self with `LANKIR_NEW_WINDOW=1` env signal).
    • `runGUI` wires `options.DragAndDrop`, `options.SingleInstanceLock` (skipped when `LANKIR_NEW_WINDOW=1` set), and `runtime.OnFileDrop`.
    • `cli.ExecuteWithArgs` shim added so `main.go` can pass parsed args explicitly; the existing `cli.Execute` becomes a thin wrapper for back-compat.
  • Frontend

    • New `fileOpener.js` — single source funneling drag-drop / second-instance / startup files through the existing `OpenPDFByPath → createPDFTab → switchToTab` flow. Per-file errors get a toast and don't abort the batch.
    • `app.js` subscribes `fileOpener.handleOpenFiles` to the Wails `open-files` event.
    • `Ctrl+Shift+N` keyboard shortcut → `App.OpenInNewWindow(activeFilePath)`.
    • `style.css` marks `.pdf-viewer` and `.welcome-screen` as Wails drop targets via `--wails-drop-target: drop`.
  • Packaging / CLI

    • `packaging/lankir.desktop` — `Exec=...lankir %f` + `MimeType=application/pdf;`.
    • `cmd/cli/root.go` — `--help` clarifies GUI dispatch and the `./pdf` workaround for files literally named after Cobra subcommands.

Tests added

  • `TestParseArgs` (table-driven, 7 cases incl. `./pdf` workaround and unknown-subcommand fallback).
  • `TestFilterPDFPaths`, `TestResolveSecondInstancePaths`, `TestNewWindowEnv` in `app_test.go`.
  • `fileOpener.test.js` (vitest, 3 cases: single PDF, empty batch, partial backend error).

Test plan

  • `go build ./...` and `go test -count=1 ./...` clean (3/3 runs).
  • `task vet-cross` — Linux clean (Windows/Darwin failures are pre-existing CGO chains, unaffected).
  • Frontend `./build.sh` clean; `npm test` 112/112 (pre-existing flaky perf assertion in `tests/performance.test.js` exists on master too — tracked in `TODOs.md` for separate fix).
  • Manual: drag a PDF onto running window → opens as new tab.
  • Manual: install .deb → "Open with Lankir" appears in Files right-click menu for PDFs.
  • Manual: `Ctrl+Shift+N` spawns a separate lankir window.
  • Manual: `lankir foo.pdf bar.pdf` from terminal opens both as tabs in one new window.

Out of scope (flagged in plan, deferred)

  • Windows file-association registration (no installer yet).
  • macOS file-association registration (no .app bundle / Wails darwin build yet).
  • Tab persistence across launches.
  • Drag-tab-out-to-new-window.
  • Pre-existing perf-test wall-clock flake (in TODOs.md).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant