Файли
openidea/src/features/app/title.ts
T
l0ng-ai 2ec2b76d7a fix(remote): keep the host in a remote window's title (#1146)
Connecting a remote window titles it `<project> [<user@host>]`, but the frontend rewrote the title from the project and active file whenever either changed (and after a reload), dropping the host. The title now includes the remote session's host.
2026-11-04 09:58:51 +08:00

53 рядки
1.9 KiB
TypeScript
Неформатований Анотація Історія

Цей файл містить неоднозначні символи Юнікоду
Цей файл містить символи Юнікоду, які можна сплутати з іншими символами. Якщо ви вважаєте, що це зроблено навмисно, можете сміливо ігнорувати це попередження. Щоб показати їх, скористайтеся кнопкою Escape.
/**
* Window title, IDEA style: `<project> – <file>`; with Settings › Appearance ›
* "Always show full path in window header" the file's full path. A remote
* project names its host: `<project> [<user@host>] – <file>`.
*/
import { useEditorRegistry } from "@/editor/api";
import { t, useI18n } from "@/platform/i18n";
import { isTauri } from "@/platform/ipc";
import { basename, useProject } from "@/platform/project";
import { useRemote } from "@/platform/remote";
export function windowTitle(
project: string | null | undefined,
file: string | null | undefined,
fullPath = false,
host: string | null = null,
): string {
const name = file ? (fullPath ? file : basename(file)) : null;
if (!project) return name ?? t("app.title.default");
const where = host ? `${project} [${host}]` : project;
return name ? `${where} – ${name}` : where;
}
export function installWindowTitle(): () => void {
let last: string | null = null;
let setNative: ((title: string) => void) | null = null;
if (isTauri()) {
void import("@tauri-apps/api/window").then(({ getCurrentWindow }) => {
const w = getCurrentWindow();
setNative = (title) => void w.setTitle(title).catch(() => {});
if (last !== null) setNative(last);
});
}
const update = () => {
const { project, settings } = useProject.getState();
const fullPath = settings?.appearance?.fullPathInTitle === true;
const host = useRemote.getState().session?.host ?? null;
const title = windowTitle(project?.name, useEditorRegistry.getState().active?.ctx.path, fullPath, host);
if (title === last) return;
last = title;
if (typeof document !== "undefined") document.title = title;
setNative?.(title);
};
update();
const unsubs = [
useProject.subscribe(update),
useEditorRegistry.subscribe(update),
useI18n.subscribe(update),
useRemote.subscribe(update),
];
return () => unsubs.forEach((u) => u());
}