feat(ui): quiet the drop gesture, and refuse files OCR cannot read
Four changes to how the main window answers a drag. The tray row said "识别图片文字…" where the window says 文字识别, and the ellipsis made it read like a preview rather than a command. It now carries the same words as the button, in both languages. OCR refuses a file it cannot read instead of handing it to the format ring. The fallback was meant to be helpful - "the format ring is more useful than a failing OCR run" - but from the user's side it looked like the button they dropped on had ignored their file and opened something else. A drop on OCR is now either a read or a refusal that names the reason. Dragging an outside file and dragging a Recent row are now the same interaction. The panel used to scale, recolour and swap its heading when a file entered the window from Finder, while a row dragged from the list did none of that, because an in-webview drag raises no native drag events. The panel no longer animates at all: the is-dragging class, its two rules, and the transition they drove are gone, and feedback lives only on the three buttons, which both paths already share. Releasing off a button no longer pops the toast. 0.1.9 added it to explain why nothing had run, but it fired at the pointer, in a place the user had not chosen to aim at, and the buttons already show where a drop lands. Off a button, nothing happens, silently, on both paths. The version comparison test gains the patch-component case: 0.1.10 is the first release whose patch number reaches two digits, and the rule was only asserted for the minor position.main
parent
b524b69fc8
commit
45325f0a6c
|
|
@ -128,7 +128,7 @@ pub fn tray_titles(language: &str) -> TrayTitles {
|
|||
capture: "区域截图",
|
||||
fullscreen: "全屏截图",
|
||||
record: "区域录屏",
|
||||
ocr: "识别图片文字…",
|
||||
ocr: "文字识别",
|
||||
update: "发现新版本 ",
|
||||
quit: "退出 Shift",
|
||||
}
|
||||
|
|
@ -138,7 +138,7 @@ pub fn tray_titles(language: &str) -> TrayTitles {
|
|||
capture: "Capture area",
|
||||
fullscreen: "Capture full screen",
|
||||
record: "Record area",
|
||||
ocr: "OCR an image…",
|
||||
ocr: "OCR",
|
||||
update: "Update available ",
|
||||
quit: "Quit Shift",
|
||||
}
|
||||
|
|
@ -198,9 +198,13 @@ mod tests {
|
|||
let chinese = tray_titles(CHINESE);
|
||||
assert_eq!(chinese.quit, "退出 Shift");
|
||||
assert_eq!(chinese.capture, "区域截图");
|
||||
// The tray row carries the same words as the window's own OCR button, and
|
||||
// no ellipsis: every other row is a command, not a preview.
|
||||
assert_eq!(chinese.ocr, "文字识别");
|
||||
let english = tray_titles(ENGLISH);
|
||||
assert_eq!(english.quit, "Quit Shift");
|
||||
assert_eq!(english.capture, "Capture area");
|
||||
assert_eq!(english.ocr, "OCR");
|
||||
// Chinese is the only other language, so anything else means English.
|
||||
assert_eq!(tray_titles("de").open, english.open);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1031,6 +1031,10 @@ mod tests {
|
|||
assert!(version_is_newer("v1.0.0", "0.9.0"));
|
||||
assert!(!version_is_newer("0.1.0", "0.1.0"));
|
||||
assert!(!version_is_newer("0.0.9", "0.1.0"));
|
||||
// 0.1.10 was the first release whose *patch* component reached two digits, so
|
||||
// the double-digit rule is asserted for that position too and not just above it.
|
||||
assert!(version_is_newer("0.1.10", "0.1.9"));
|
||||
assert!(!version_is_newer("0.1.9", "0.1.10"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -316,13 +316,15 @@ export function MainWindow() {
|
|||
}
|
||||
|
||||
async function runOcrOn(paths: string[]) {
|
||||
const image = paths.find((path) => OCR_EXTENSIONS.includes(extensionOf(path)));
|
||||
if (!image) {
|
||||
// No image in the batch: the format ring is more useful than a failing OCR run.
|
||||
await api.showFilesInRadial(paths, "formats");
|
||||
// No fallback: a drop the OCR button cannot serve is refused rather than
|
||||
// silently handed to another ring, which used to look like the button
|
||||
// ignoring the file and doing something else instead.
|
||||
const unsupported = paths.filter((path) => !OCR_EXTENSIONS.includes(extensionOf(path)));
|
||||
if (unsupported.length > 0) {
|
||||
flash(t("ocrUnsupported"), 2600);
|
||||
return;
|
||||
}
|
||||
await api.openInEditor(image);
|
||||
await api.openInEditor(paths[0]);
|
||||
window.setTimeout(() => {
|
||||
void emitTo("editor", "editor://run-ocr", {});
|
||||
}, 450);
|
||||
|
|
@ -350,29 +352,26 @@ export function MainWindow() {
|
|||
/**
|
||||
* Run the one action a drop was aimed at.
|
||||
*
|
||||
* The button *is* the choice: a drop that lands on the panel rather than on one of
|
||||
* the three buttons runs nothing, so the gesture can never open a ring the user did
|
||||
* not ask for. `dropOnButton` says why instead of leaving the drop silent.
|
||||
* The button *is* the choice. `null` means the file was released on the panel
|
||||
* rather than on a button, and that runs nothing and says nothing - the same
|
||||
* nothing a row released off a button does, which is why a file from outside and
|
||||
* a row from the list are now one gesture with one set of consequences.
|
||||
*/
|
||||
function dropFiles(paths: string[], action: DropAction) {
|
||||
function dropFiles(paths: string[], action: DropAction | null) {
|
||||
if (paths.length === 0) return Promise.resolve();
|
||||
if (!action) return Promise.resolve();
|
||||
if (action === "ocr") return runOcrOn(paths);
|
||||
return api.showFilesInRadial(paths, action).then(() => undefined);
|
||||
}
|
||||
|
||||
/**
|
||||
* Land a dragged Recent row, at most once per gesture. Off a button it runs nothing,
|
||||
* the same rule a file from Finder follows, and says so rather than going silent.
|
||||
* Land a dragged Recent row, at most once per gesture.
|
||||
*/
|
||||
function landRecentRow(action: DropAction | null) {
|
||||
const drag = recentDrag.current;
|
||||
if (!drag || drag.landed) return;
|
||||
drag.landed = true;
|
||||
setDropAction(null);
|
||||
if (!action) {
|
||||
flash(t("dropOnButton"), 2600);
|
||||
return;
|
||||
}
|
||||
void dropFiles([drag.path], action).catch((error) => flash(String(error), 3200));
|
||||
}
|
||||
|
||||
|
|
@ -675,12 +674,6 @@ export function MainWindow() {
|
|||
landRecentRow(action);
|
||||
return;
|
||||
}
|
||||
// Off a button there is no action to run, so the drop says what it expects
|
||||
// instead of opening a ring the user never aimed at.
|
||||
if (!action) {
|
||||
flash(t("dropOnButton"), 2600);
|
||||
return;
|
||||
}
|
||||
void dropFiles(event.payload.paths, action).catch((error) => flash(String(error), 3200));
|
||||
return;
|
||||
}
|
||||
|
|
@ -816,7 +809,7 @@ export function MainWindow() {
|
|||
) : null}
|
||||
|
||||
<main className="home-main">
|
||||
<section className={`home-drop ${dragging ? "is-dragging" : ""}`}>
|
||||
<section className="home-drop">
|
||||
{screenAccess === false ? (
|
||||
<div className="permission-banner">
|
||||
<ShieldAlert size={16} />
|
||||
|
|
@ -855,9 +848,10 @@ export function MainWindow() {
|
|||
);
|
||||
})}
|
||||
</div>
|
||||
<h1>{dragging ? t("homeDropRelease") : t("homeDropTitle")}</h1>
|
||||
{/* While any drag is in flight all three buttons show as candidates, so the
|
||||
aim is visible before the pointer reaches one. */}
|
||||
<h1>{t("homeDropTitle")}</h1>
|
||||
{/* The buttons are the only thing a drag reacts to: while one is in flight
|
||||
all three show as candidates, so the aim is visible before the pointer
|
||||
reaches one, and the panel itself never animates. */}
|
||||
<div
|
||||
className={`home-primary-actions ${
|
||||
dragging || rowDragging || dropAction ? "has-drop-target" : ""
|
||||
|
|
|
|||
|
|
@ -85,9 +85,8 @@ const messages: Record<Lang, Record<string, string>> = {
|
|||
tools: "Tools",
|
||||
unsupported: "No formats for this file type",
|
||||
homeDropTitle: "Drop files to get started",
|
||||
homeDropRelease: "Release over one of the buttons",
|
||||
homeDropHint: "Drop a file on a button to run that action.",
|
||||
dropOnButton: "Drop the file on one of the three buttons.",
|
||||
ocrUnsupported: "OCR works on image files only.",
|
||||
convertFiles: "Convert files",
|
||||
fileTools: "File tools",
|
||||
nothingYet: "Nothing yet",
|
||||
|
|
@ -313,9 +312,8 @@ const messages: Record<Lang, Record<string, string>> = {
|
|||
tools: "工具",
|
||||
unsupported: "此文件类型暂时没有可用格式",
|
||||
homeDropTitle: "拖入文件开始处理",
|
||||
homeDropRelease: "请松开在按钮上",
|
||||
homeDropHint: "把文件拖到对应按钮上,执行该操作。",
|
||||
dropOnButton: "请把文件拖到下方三个按钮之一。",
|
||||
ocrUnsupported: "文字识别仅支持图片格式。",
|
||||
convertFiles: "文件转换",
|
||||
fileTools: "文件工具",
|
||||
nothingYet: "暂无内容",
|
||||
|
|
|
|||
|
|
@ -1648,10 +1648,6 @@ kbd {
|
|||
inset 0 1px 0 rgba(255, 255, 255, 0.8);
|
||||
text-align: center;
|
||||
backdrop-filter: blur(18px);
|
||||
transition:
|
||||
border-color 0.18s ease,
|
||||
background 0.18s ease,
|
||||
transform 0.18s ease;
|
||||
}
|
||||
|
||||
.permission-banner {
|
||||
|
|
@ -1720,16 +1716,6 @@ kbd {
|
|||
pointer-events: none;
|
||||
}
|
||||
|
||||
.home-drop.is-dragging {
|
||||
border-color: rgba(242, 106, 51, 0.38);
|
||||
background: rgba(255, 245, 235, 0.94);
|
||||
transform: scale(0.995);
|
||||
}
|
||||
|
||||
.home-drop.is-dragging::after {
|
||||
border-color: rgba(242, 106, 51, 0.58);
|
||||
}
|
||||
|
||||
.home-drop-art {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
|
|
|
|||
Loading…
Reference in New Issue