>>({});
+ const windowOrigin = useRef<{ x: number; y: number } | null>(null);
function flash(message: string, duration = 2600) {
if (toastTimer.current) window.clearTimeout(toastTimer.current);
@@ -255,12 +256,32 @@ export function MainWindow() {
}, 450);
}
- // Drag positions arrive in physical pixels relative to the webview, while the
- // buttons are measured in CSS pixels, so both sides need the same scale.
- function actionAt(position: { x: number; y: number }): DropAction | null {
+ // wry reports drag positions two different ways: AppKit passes draggingLocation,
+ // i.e. points relative to the webview and therefore 1:1 with CSS pixels, while
+ // the Windows drag controller forwards OLE screen coordinates in physical
+ // pixels. Only the second reading needs the window origin and scale removed.
+ function localPoint(position: { x: number; y: number }): { x: number; y: number } | null {
+ if (IS_MAC) return position;
+ const origin = windowOrigin.current;
+ if (!origin) return null;
const scale = window.devicePixelRatio || 1;
- const x = position.x / scale;
- const y = position.y / scale;
+ return { x: (position.x - origin.x) / scale, y: (position.y - origin.y) / scale };
+ }
+
+ async function readWindowOrigin() {
+ if (IS_MAC) return;
+ try {
+ const position = await getCurrentWebview().position();
+ windowOrigin.current = { x: position.x, y: position.y };
+ } catch {
+ windowOrigin.current = null;
+ }
+ }
+
+ function actionAt(position: { x: number; y: number }): DropAction | null {
+ const point = localPoint(position);
+ if (!point) return null;
+ const { x, y } = point;
const entries: Array<[DropAction, HTMLElement | null | undefined]> = [
["formats", dropTargets.current.formats],
["tools", dropTargets.current.tools],
@@ -384,6 +405,12 @@ export function MainWindow() {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
+ // Reading the status also consumes a "second copy tried to start" marker.
+ useEffect(() => {
+ if (settingsOpen && isTauri()) void refreshHotkeys();
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [settingsOpen]);
+
useEffect(() => {
const unlisteners: Array<() => void> = [];
if (isTauri()) {
@@ -391,7 +418,9 @@ export function MainWindow() {
.onDragDropEvent((event) => {
if (event.payload.type === "enter") {
setDragging(true);
- setDropAction(actionAt(event.payload.position));
+ const position = event.payload.position;
+ // Cache the origin once per drag: it cannot move while dragging.
+ void readWindowOrigin().then(() => setDropAction(actionAt(position)));
}
if (event.payload.type === "over") {
setDropAction(actionAt(event.payload.position));
@@ -777,6 +806,11 @@ export function MainWindow() {
{t("hotkeys")}
+ {hotkeys && hotkeys.live && hotkeys.others.length === 0 ? (
+
+ {hotkeys.recentDuplicate ? t("hotkeysDuplicate") : t("hotkeysOk")}
+
+ ) : null}
{hotkeys && (!hotkeys.live || hotkeys.others.length > 0) ? (
@@ -789,9 +823,7 @@ export function MainWindow() {
{t("hotkeysFix")}
- ) : (
- {t("hotkeysOk")}
- )}
+ ) : null}
{(hotkeys?.hotkeys.length
? hotkeys.hotkeys
diff --git a/src/i18n.ts b/src/i18n.ts
index 368c452..16a092c 100644
--- a/src/i18n.ts
+++ b/src/i18n.ts
@@ -131,6 +131,15 @@ const messages: Record> = {
dragRingsHint: "Hold Shift while dragging a file to open the radial menu.",
autostart: "Launch at login",
autostartHint: "Start Shift automatically when you sign in.",
+ hotkeys: "Keyboard shortcuts",
+ hotkeysOk: "This copy of Shift owns the shortcuts, so the keyboard works.",
+ hotkeysDuplicate:
+ "A second copy of Shift tried to start and was closed automatically. macOS only gives global hotkeys to one copy, so keeping a single copy is what keeps the keyboard shortcuts working.",
+ hotkeysNotLive:
+ "macOS refused these shortcuts, usually because another app already uses them. Close the conflicting app and retry.",
+ hotkeysOthers:
+ "{count} other Shift process is already running. macOS gives global hotkeys to only one of them, so the shortcuts of the others do nothing.",
+ hotkeysFix: "Quit the other copies and reclaim the shortcuts",
accessCheck: "Write access",
accessCheckHint: "Confirm Shift can write to each output folder. macOS may ask for permission the first time.",
checking: "Checking…",
@@ -275,6 +284,12 @@ const messages: Record> = {
dragRingsHint: "在访达或资源管理器中拖动文件时按住 Shift 即可唤出圆环。",
autostart: "开机时启动",
autostartHint: "登录系统后自动启动 Shift。",
+ hotkeys: "键盘快捷键",
+ hotkeysOk: "当前副本已持有快捷键,键盘快捷键可以正常使用。",
+ hotkeysDuplicate: "刚才有第二个 Shift 副本启动,已自动退出。macOS 只把全局快捷键交给其中一个副本,只保留一个副本才能保证快捷键生效。",
+ hotkeysNotLive: "macOS 拒绝了这些快捷键,通常是被其他应用占用了。关闭冲突的应用后重试。",
+ hotkeysOthers: "检测到 {count} 个其他 Shift 进程。macOS 只把全局快捷键交给其中一个,其余副本按键盘不会有任何反应。",
+ hotkeysFix: "退出其他副本并重新接管快捷键",
accessCheck: "写入权限",
accessCheckHint: "检查 Shift 是否可写入各输出目录。macOS 可能首次请求授权。",
checking: "检测中…",
diff --git a/src/styles.css b/src/styles.css
index 109e134..6da2d73 100644
--- a/src/styles.css
+++ b/src/styles.css
@@ -3020,6 +3020,41 @@ kbd {
transform: translateX(14px);
}
+/* Hotkey ownership panel: duplicate copies silently lose the global shortcuts. */
+.home-hotkeys.is-warn {
+ display: flex;
+ flex-direction: column;
+ gap: 8px;
+ margin-bottom: 10px;
+ padding: 10px 11px;
+ border: 1px solid rgba(217, 79, 31, 0.2);
+ border-radius: 12px;
+ background: rgba(255, 241, 232, 0.78);
+}
+
+.home-hotkeys.is-warn .home-settings-hint {
+ margin: 0;
+ color: #7a3a20;
+}
+
+.home-hotkey-list {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 6px;
+ margin-top: 9px;
+}
+
+.home-hotkey-list span {
+ padding: 4px 9px;
+ border: 1px solid rgba(104, 68, 47, 0.12);
+ border-radius: 8px;
+ color: #7c5d4d;
+ background: rgba(255, 255, 255, 0.75);
+ font-size: 10px;
+ font-weight: 650;
+ letter-spacing: 0.02em;
+}
+
.home-checks {
display: flex;
flex-direction: column;
diff --git a/src/types.ts b/src/types.ts
index bc6c5ee..6423670 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -81,6 +81,8 @@ export interface HotkeyStatus {
hotkeys: string[];
/** Pids of other running Shift processes. */
others: number[];
+ /** A second copy tried to start in the last ten minutes. */
+ recentDuplicate: boolean;
}
export interface WriteCheck {