Commit Graph

5 Commits (main)

Author SHA1 Message Date
mula.liu 7e3bf5efc1 perf: stop sampling when nothing is looking
Reported: "参考nex_squid的代码,进一步降低软件本身占用的系统资源." The
pattern worth copying out of nex_squid's `useSystemSnapshot` is that a
poll stops when nothing can see its answer. Shift had four places that
polled for the life of the process instead.

- `native/macos/drag-bridge.swift` — a separate tracked process polling at
  30 Hz forever, and allocating a CGEvent each pass to read a cursor
  position nothing wants while no button is held. A/B against the shipped
  0.1.11 binary: 20 ms CPU per 6 s idle is now 0 ms, while 12 s of holding
  the button still costs 30 ms either way, so a gesture is sampled exactly
  as finely as before and an idle Shift stops touching the CPU. It runs at
  10 Hz until the button goes down.
- `src-tauri/src/drag_bridge.rs` — the Windows gesture watch slept 33 ms
  unconditionally. An *enabled* ring keeps 33 ms, and not from
  conservatism: the loop has to observe the press to measure the drag
  threshold from where the button went down, so slowing it does not notice
  a gesture late, it never records it. Only a switched-off ring can afford
  a quarter second, since the one thing it waits for is the switch.
- `src-tauri/src/share.rs` — the discovery loop. Measured on the 0.1.11
  bundle: 0.22% CPU with ShiftDrop on, 0.03% with it off. Switching the
  feature off means "stop announcing", never "be deaf" — a silent copy
  still hears beacons so another machine can still find and send to it, and
  expiry must keep running or an hour-old peer pretends to be live forever.
  So the saving comes from waking less often while silent and from skipping
  bookkeeping when there is no peer to expire, not from probing less.
  Announce and sweep intervals are untouched, so discovery stays as fast.
  `a_silent_copy_still_knows_and_still_loses_peers` pins that distinction.
- `src/components/MainWindow.tsx` — the 30 s clock ticked for the life of
  the app while Shift sits parked in the menu bar with this window hidden,
  re-rendering a list nobody could see. It now exists only while the page is
  visible, and an empty library is not worth a render at all.

Co-Authored-By: Codex <noreply@openai.com>
2026-11-19 17:50:57 +08:00
mula.liu df35111326 release: prepare Shift 0.1.8 2026-10-27 18:45:32 +08:00
mula.liu 19602b79f0 fix(docx): keep figures when a DOCX is printed to PDF
Two bugs, both visible in 平台技术方案(带图测试专用).docx: one figure, eleven
tables and 357 paragraphs, whose PDF came out as a text-only document.

First, AppKit's OOXML reader returns the text of a DOCX and silently drops every
inline drawing - an attributed string with zero attachments for a document with a
picture in it. That is not a rendering loss, it is a parse loss, so no margin,
print setting or layout change can recover the figure: by the time the page is
drawn, the picture is simply not in the attributed string. A DOCX whose body
contains an image is now converted by Pandoc into HTML with its media extracted
beside it, and the HTML - which Pandoc reads faithfully, headings, tables and
pictures - goes to the same printer. Image-only DOCX files keep the existing
page-scan path, which runs first, and a machine without Pandoc falls back to the
old text-only behaviour rather than failing.

Second, once pictures could arrive they printed as a cropped fragment of
themselves. The layout sizes an attachment from the density header inside the
file, assumes 72 dpi when there is none, and ignores both bounds and CSS width: a
1600 px screenshot at 96 dpi asks for 1200 points and lands on a 595 pt page.
Measured across PNG pHYs and JPEG JFIF, the placed width is exactly
pixels / dpi * 64. A plain NSTextAttachment does honour bounds, so the renderer
now replaces any oversized attachment with one that fits the text column; the
print operation scales it to the page with the text, landing at 499pt, which is
the printable width the body text already uses. Nothing is resampled, only the
size the layout asks for changes. This also fixes Markdown and HTML documents
with wide images, which had the same overflow.

Both halves are pinned by tests, and both fail against the previous build:
keeps_pictures_when_rendering_a_text_docx_to_pdf sees no image at all, and
fits_a_wide_picture_onto_the_page reports a picture placed 1066.77pt wide on a
595pt page. The second reads the Form XObject's /BBox, so it needs no content
stream decoded and no pixel compared.
2026-10-26 14:50:52 +08:00
mula.liu c6eff4e131 修复bug 2026-10-25 12:24:05 +08:00
Shift 0eb75595c6 baseline: capture workspace state (bug fixes in progress) 2026-10-21 08:54:54 +08:00