{"record":{"id":"4c6096c4cff2061c","repo":"jlcodes99/cockpit-tools","slug":"window-startdragging-failed","errorCode":null,"errorMessage":"[Window] startDragging failed:","messagePattern":"\\[Window\\] startDragging failed:","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/App.tsx","lineNumber":3582,"sourceCode":"        }\n        console.info('[ExternalImport][App] 启动时读取到待处理导入 payload');\n        void handleExternalProviderImportRawPayload(payload);\n      })\n      .catch((error) => {\n        console.warn('[ExternalImport] 读取待处理导入请求失败:', error);\n      });\n    return () => {\n      canceled = true;\n    };\n  }, [handleExternalProviderImportRawPayload]);\n\n  // 窗口拖拽处理\n  const handleDragStart = (event: ReactMouseEvent<HTMLDivElement>) => {\n    if (event.button !== 0) {\n      return;\n    }\n    void getCurrentWindow().startDragging().catch((error) => {\n      console.warn('[Window] startDragging failed:', error);\n    });\n  };\n\n  useEffect(() => {\n    const handleRequestNavigate = (e: Event) => {\n      const custom = e as CustomEvent<Page>;\n      if (custom.detail) {\n        setPage(custom.detail);\n      }\n    };\n    window.addEventListener('app-request-navigate', handleRequestNavigate as EventListener);\n    return () => {\n      window.removeEventListener('app-request-navigate', handleRequestNavigate as EventListener);\n    };\n  }, []);\n\n  useEffect(() => {\n    const handleOpenPlatformLayout = (e: Event) => {","sourceCodeStart":3564,"sourceCodeEnd":3600,"githubUrl":"https://github.com/jlcodes99/cockpit-tools/blob/1ed8b77992d62ca81fabf744deb0839ad361d5bf/src/App.tsx#L3564-L3600","documentation":"Tauri's `startDragging()` on the current WebviewWindow asks the native window manager to begin an OS-level drag of the window. It fails when the runtime or platform refuses the drag operation (window not found, permission/decoration constraints, or the webview already has another operation in flight). The app only logs a warning since a failed drag is non-fatal.","triggerScenarios":"User presses the left mouse button (button === 0) on the custom title bar div in MainApp, and `getCurrentWindow().startDragging()` rejects — e.g. the window was closed/minimized mid-call, the platform does not support programmatic drag, or the call races with another window operation.","commonSituations":"Custom frameless title bars in Tauri apps; rapid clicks during window teardown; Linux/Wayland environments where dragging support differs from Windows/macOS; calling drag on a window handle after the window was destroyed.","solutions":["Check the window still exists before dragging: guard with `await getCurrentWindow().isVisible()` or wrap in a try/catch that ignores NotFound errors.","Verify the Tauri version and platform: on Linux/Wayland programmatic dragging may be unsupported; test on the target platform.","Ensure `decorations: false` window config matches the drag-region setup and no overlaying element intercepts the event with a conflicting handler.","If the error is intermittent during shutdown, debounce or skip drag requests when a close is already in progress."],"exampleFix":"// before\nvoid getCurrentWindow().startDragging().catch((error) => {\n  console.warn('[Window] startDragging failed:', error);\n});\n// after\nvoid getCurrentWindow()\n  .startDragging()\n  .catch((error) => {\n    if (String(error).includes('window not found')) return;\n    console.warn('[Window] startDragging failed:', error);\n  });","handlingStrategy":"try-catch","validationCode":"const win = getCurrentWindow();\nif (event.button === 0 && win && document.visibilityState === 'visible') {\n  void win.startDragging();\n}","typeGuard":"function isLeftButton(e: ReactMouseEvent): boolean {\n  return e.button === 0;\n}","tryCatchPattern":"try {\n  await getCurrentWindow().startDragging();\n} catch (error) {\n  if (!String(error).includes('window not found')) {\n    console.warn('[Window] startDragging failed:', error);\n  }\n}","preventionTips":["Guard drag initiation on left-button and window visibility","Test frameless dragging on all target platforms (especially Linux/Wayland)","Skip drag requests once a window close/teardown has started"],"tags":["tauri","window","drag","gui"],"backgroundTag":"window-drag-operation-failed","analyzedSha":"1ed8b77992d62ca81fabf744deb0839ad361d5bf","analyzedAt":"2026-09-05T09:51:41.178Z","contentChangedAt":"2026-09-05T09:51:41.178Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}