Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

✨ feat(desktop): show hovered link URL in bottom-left status bar (#21291)

Innei393757ae64e9
diff --git a/src/features/Electron/system/LinkHoverStatus/index.tsx b/src/features/Electron/system/LinkHoverStatus/index.tsx
new file mode 100644
index 00000000000..6c33b50ce3d
--- /dev/null
+++ b/src/features/Electron/system/LinkHoverStatus/index.tsx
@@ -0,0 +1,77 @@
+'use client';
+
+import { createStaticStyles, cssVar, cx } from '@lobehub/ui';
+import { memo, useEffect, useState } from 'react';
+
+import { externalLinkHref, truncateUrl } from './utils';
+
+const styles = createStaticStyles(({ css }) => ({
+ root: css`
+ pointer-events: none;
+
+ position: fixed;
+ z-index: 1500;
+ inset-block-end: 0;
+ inset-inline-start: 0;
+
+ overflow: hidden;
+
+ max-width: 60vw;
+ padding-block: 2px;
+ padding-inline: 8px;
+ border-block-start: 1px solid ${cssVar.colorBorderSecondary};
+ border-inline-end: 1px solid ${cssVar.colorBorderSecondary};
+ border-start-end-radius: ${cssVar.borderRadiusSM};
+
+ font-size: 12px;
+ line-height: 18px;
+ color: ${cssVar.colorTextSecondary};
+ text-overflow: ellipsis;
+ white-space: nowrap;
+
+ opacity: 0;
+ background: ${cssVar.colorBgElevated};
+ box-shadow: ${cssVar.boxShadowTertiary};
+
+ transition: opacity 120ms ease;
+ `,
+ visible: css`
+ opacity: 1;
+ `,
+}));
+
+const LinkHoverStatus = memo(() => {
+ const [url, setUrl] = useState('');
+ const [visible, setVisible] = useState(false);
+
+ useEffect(() => {
+ const onOver = (event: MouseEvent) => {
+ const target = event.target instanceof Element ? event.target : null;
+ const anchor = target?.closest('a[href]');
+ const next = externalLinkHref(anchor?.getAttribute('href'));
+ if (next) {
+ setUrl(next);
+ setVisible(true);
+ } else {
+ setVisible(false);
+ }
+ };
+ const onLeave = () => setVisible(false);
+ document.addEventListener('mouseover', onOver);
+ document.documentElement.addEventListener('mouseleave', onLeave);
+ return () => {
+ document.removeEventListener('mouseover', onOver);
+ document.documentElement.removeEventListener('mouseleave', onLeave);
+ };
+ }, []);
+
+ return (
+ <div aria-hidden className={cx(styles.root, visible && styles.visible)}>
+ {truncateUrl(url)}
+ </div>
+ );
+});
+
+LinkHoverStatus.displayName = 'LinkHoverStatus';
+
+export default LinkHoverStatus;
diff --git a/src/features/Electron/system/LinkHoverStatus/utils.test.ts b/src/features/Electron/system/LinkHoverStatus/utils.test.ts
new file mode 100644
index 00000000000..0b880d95479
--- /dev/null
+++ b/src/features/Electron/system/LinkHoverStatus/utils.test.ts
@@ -0,0 +1,34 @@
+import { describe, expect, it } from 'vitest';
+
+import { externalLinkHref, truncateUrl } from './utils';
+
+describe('externalLinkHref', () => {
+ it('keeps http(s) links', () => {
+ expect(externalLinkHref('https://example.com/a')).toBe('https://example.com/a');
+ expect(externalLinkHref('HTTP://example.com')).toBe('HTTP://example.com');
+ });
+
+ it('rejects internal and non-web hrefs', () => {
+ expect(externalLinkHref('/settings')).toBeNull();
+ expect(externalLinkHref('#anchor')).toBeNull();
+ expect(externalLinkHref('javascript:void(0)')).toBeNull();
+ expect(externalLinkHref('mailto:[email protected]')).toBeNull();
+ expect(externalLinkHref(null)).toBeNull();
+ expect(externalLinkHref('')).toBeNull();
+ });
+});
+
+describe('truncateUrl', () => {
+ it('returns short urls unchanged', () => {
+ expect(truncateUrl('https://example.com')).toBe('https://example.com');
+ });
+
+ it('truncates the middle of long urls', () => {
+ const url = `https://example.com/${'a'.repeat(200)}/tail-segment`;
+ const out = truncateUrl(url);
+ expect(out).toHaveLength(100);
+ expect(out.startsWith('https://example.com/')).toBe(true);
+ expect(out).toContain('…');
+ expect(out.endsWith(url.slice(-30))).toBe(true);
+ });
+});
diff --git a/src/features/Electron/system/LinkHoverStatus/utils.ts b/src/features/Electron/system/LinkHoverStatus/utils.ts
new file mode 100644
index 00000000000..7fb87b5f9e5
--- /dev/null
+++ b/src/features/Electron/system/LinkHoverStatus/utils.ts
@@ -0,0 +1,9 @@
+export const externalLinkHref = (href: string | null | undefined): string | null => {
+ if (!href || !/^https?:\/\//i.test(href)) return null;
+ return href;
+};
+
+export const truncateUrl = (url: string, max = 100): string => {
+ if (url.length <= max) return url;
+ return `${url.slice(0, max - 31)}…${url.slice(-30)}`;
+};
diff --git a/src/routes/(main)/_layout/index.desktop.tsx b/src/routes/(main)/_layout/index.desktop.tsx
index 5b423109752..5c0d9c8c9d5 100644
--- a/src/routes/(main)/_layout/index.desktop.tsx
+++ b/src/routes/(main)/_layout/index.desktop.tsx
@@ -23,6 +23,7 @@ import {
useLastWorkspaceSlugSync,
useWindowUrlMirror,
} from '@/features/Electron/shell';
+import LinkHoverStatus from '@/features/Electron/system/LinkHoverStatus';
import ZoomHUD from '@/features/Electron/system/ZoomHUD';
import { TabHost, useSeedTabsOnBoot } from '@/features/Electron/TabHost';
import TabCacheBridges from '@/features/Electron/titlebar/TabBar/TabCacheBridges';
@@ -72,6 +73,7 @@ const Layout: FC = () => {
{showCloudPromotion && <CloudBanner />}
</Suspense>
<ZoomHUD />
+ <LinkHoverStatus />
<Suspense fallback={null}>
<TitleBar />