Show each site's own icon; restore the native title bar
Both previous attempts asked a question about a domain, and a domain does not know which product it is serving. Google's favicon service returned a marketing site's icon for anything behind a login and nothing for a private host; Simple Icons returned one flat brand mark where the real one is multicoloured and, for Gmail, carries the unread count. The page already holds the answer - fetched, authenticated, current. The injected script now reads link[rel~="icon"] and reports the best one: largest declared sizes wins, an Apple touch icon counts as 180, and an .ico is penalised as usually the 16px tab icon. It rechecks on the same tick as the unread count, which is when a site like Gmail redraws its icon with a badge. The URL is stored, so the nav is right at launch rather than blank until every page has loaded. The custom frame is gone with it: ordinary macOS title bar, traffic lights where every other window puts them, and the bar following the app's Light/Dark choice through set_theme. A window that behaves like a window beats one that looks bespoke.
This commit is contained in:
+2
-11
@@ -23,13 +23,6 @@ interface Props {
|
||||
*/
|
||||
const RAIL = 72;
|
||||
const PANEL = 240;
|
||||
/**
|
||||
* The strip the traffic lights sit in. Draggable, since there is no title bar.
|
||||
*
|
||||
* Deep enough to give them room: with the window's own frame around it too,
|
||||
* anything shallower leaves them crowding the corner.
|
||||
*/
|
||||
const TITLEBAR = 48;
|
||||
|
||||
export const navWidth = (collapsed: boolean) => (collapsed ? RAIL : PANEL);
|
||||
|
||||
@@ -110,7 +103,7 @@ export default function Nav({
|
||||
}
|
||||
>
|
||||
{active && <span className="absolute left-0 h-5 w-[3px] rounded-full bg-sky-500" />}
|
||||
<Favicon url={app.url} name={app.name} size={20} />
|
||||
<Favicon icon={app.icon} name={app.name} size={20} />
|
||||
{(unread[app.id] ?? 0) > 0 && (
|
||||
<span
|
||||
title={`${unread[app.id]} new since you last looked`}
|
||||
@@ -126,7 +119,6 @@ export default function Nav({
|
||||
|
||||
return (
|
||||
<aside className={`${shell} items-center`} style={{ width: RAIL }}>
|
||||
<div data-tauri-drag-region style={{ height: TITLEBAR }} className="w-full shrink-0" />
|
||||
{/* Only the expander survives the rail's header. Back and forward are
|
||||
a two-finger swipe and reload is ⌘R, so a toolbar here would be
|
||||
clutter standing in for something nobody asked for. */}
|
||||
@@ -172,7 +164,7 @@ export default function Nav({
|
||||
title={app.url}
|
||||
className={`${row} ${app.id === activeId ? active : inactive}`}
|
||||
>
|
||||
<Favicon url={app.url} name={app.name} />
|
||||
<Favicon icon={app.icon} name={app.name} />
|
||||
<span className="truncate">{app.name}</span>
|
||||
{badge(app.id, app.id === activeId)}
|
||||
</button>
|
||||
@@ -181,7 +173,6 @@ export default function Nav({
|
||||
|
||||
return (
|
||||
<aside className={shell} style={{ width: PANEL }}>
|
||||
<div data-tauri-drag-region style={{ height: TITLEBAR }} className="shrink-0" />
|
||||
<header className="flex items-center gap-0.5 border-b border-slate-200 px-1.5 pb-2 dark:border-slate-800">
|
||||
{controls}
|
||||
<button
|
||||
|
||||
@@ -107,7 +107,7 @@ export default function Settings({
|
||||
key={app.id}
|
||||
className="flex items-center gap-2 rounded-lg border border-slate-200 px-2 py-1.5 dark:border-slate-800"
|
||||
>
|
||||
<Favicon url={app.url} name={app.name} />
|
||||
<Favicon icon={app.icon} name={app.name} />
|
||||
<input
|
||||
value={app.name}
|
||||
onChange={(e) => patch(app, { name: e.target.value })}
|
||||
@@ -183,7 +183,7 @@ export default function Settings({
|
||||
{withHidden.map((app) => (
|
||||
<div key={app.id} className={SUBPANEL}>
|
||||
<div className="mb-2 flex items-center gap-2">
|
||||
<Favicon url={app.url} name={app.name} />
|
||||
<Favicon icon={app.icon} name={app.name} />
|
||||
<span className="text-[12px] font-medium">{app.name}</span>
|
||||
<Badge tone="accent">{app.hidden.length}</Badge>
|
||||
</div>
|
||||
@@ -231,7 +231,7 @@ export default function Settings({
|
||||
key={app.id}
|
||||
className="flex items-center gap-3 rounded-lg border border-slate-200 px-2 py-1.5 dark:border-slate-800"
|
||||
>
|
||||
<Favicon url={app.url} name={app.name} />
|
||||
<Favicon icon={app.icon} name={app.name} />
|
||||
<span className="w-28 shrink-0 truncate text-[12px]">{app.name}</span>
|
||||
<input
|
||||
type="range"
|
||||
|
||||
+33
-56
@@ -5,16 +5,7 @@
|
||||
* Ported from FlightTube: slate and sky, a 9–15px type ladder, outline-first
|
||||
* controls, borders for separation and shadows only for elevation.
|
||||
*/
|
||||
import { useEffect, useState, type ReactNode } from "react";
|
||||
|
||||
import {
|
||||
colourFor,
|
||||
glyphOn,
|
||||
hostOf,
|
||||
loadBrandIcons,
|
||||
slugForHost,
|
||||
type BrandIcon,
|
||||
} from "../brandIcons";
|
||||
import { useState, type ReactNode } from "react";
|
||||
|
||||
/** Every control in the app is this tall, so a row of mixed ones lines up. */
|
||||
export const CONTROL_H = "h-[30px]";
|
||||
@@ -210,64 +201,50 @@ export function Dialog({
|
||||
}
|
||||
|
||||
/**
|
||||
* An app's mark: its brand glyph, white, on a round tile of its own colour.
|
||||
* An app's mark: the icon the site itself declared, as the browser would use.
|
||||
*
|
||||
* Local rather than fetched. The favicon service this replaced returned a
|
||||
* sign-in page's icon for anything behind a login, nothing at all for a
|
||||
* private host, and cached both answers past any way of asking again.
|
||||
* Not an icon service. Asked about a domain, a service can only guess, and it
|
||||
* guesses badly — a marketing site's icon for a tool behind a login, nothing
|
||||
* at all for a private host, and no way to make it reconsider. The page is
|
||||
* carrying the real answer already, so it reports it and this draws it.
|
||||
*/
|
||||
export function Favicon({
|
||||
url,
|
||||
icon,
|
||||
name,
|
||||
size = 16,
|
||||
}: {
|
||||
url: string;
|
||||
icon?: string | null;
|
||||
name: string;
|
||||
size?: number;
|
||||
}) {
|
||||
const [icons, setIcons] = useState<Record<string, BrandIcon> | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
let live = true;
|
||||
void loadBrandIcons().then((i) => live && setIcons(i));
|
||||
return () => {
|
||||
live = false;
|
||||
};
|
||||
}, []);
|
||||
|
||||
const host = hostOf(url);
|
||||
const slug = icons ? slugForHost(host, icons) : null;
|
||||
const icon = slug ? icons?.[slug] : undefined;
|
||||
// The brand's own colour where there is one; a stable stand-in where there
|
||||
// is not, so an unbranded tool still reads as a distinct thing in the list.
|
||||
const colour = icon ? `#${icon[1]}` : colourFor(host || name);
|
||||
const ink = glyphOn(colour);
|
||||
const [failed, setFailed] = useState(false);
|
||||
const letter = name.trim().charAt(0).toUpperCase() || "?";
|
||||
|
||||
if (!icon || failed) {
|
||||
/* Until a page has loaded and said, or if its icon will not load: the
|
||||
initial, in a tile the same size, so the row does not reflow later. */
|
||||
return (
|
||||
<span
|
||||
aria-hidden
|
||||
className="grid shrink-0 place-items-center rounded bg-slate-200 font-semibold
|
||||
text-slate-500 dark:bg-slate-700 dark:text-slate-300"
|
||||
style={{ width: size, height: size, fontSize: Math.max(8, size * 0.5) }}
|
||||
>
|
||||
{letter}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<span
|
||||
className="grid shrink-0 place-items-center rounded-full"
|
||||
style={{ width: size, height: size, background: colour }}
|
||||
<img
|
||||
src={icon}
|
||||
alt=""
|
||||
aria-hidden
|
||||
>
|
||||
{icon ? (
|
||||
<svg
|
||||
viewBox="0 0 24 24"
|
||||
fill={ink}
|
||||
style={{ width: size * 0.58, height: size * 0.58 }}
|
||||
>
|
||||
<path d={icon[0]} />
|
||||
</svg>
|
||||
) : (
|
||||
/* No glyph for this host — its initial, in the same round tile, so a
|
||||
private tool sits in the row looking like it belongs. */
|
||||
<span
|
||||
className="font-semibold leading-none"
|
||||
style={{ fontSize: Math.max(8, size * 0.5), color: ink }}
|
||||
>
|
||||
{letter}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
width={size}
|
||||
height={size}
|
||||
onError={() => setFailed(true)}
|
||||
className="shrink-0 rounded-[3px] object-contain"
|
||||
style={{ width: size, height: size }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user