mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-19 07:53:54 +01:00
Sync window title (Closes #13)
This commit is contained in:
@@ -11,6 +11,7 @@ import { useRecentWorkspaces } from '../hooks/useRecentWorkspaces';
|
||||
import { requestsQueryKey } from '../hooks/useRequests';
|
||||
import { useRequestUpdateKey } from '../hooks/useRequestUpdateKey';
|
||||
import { responsesQueryKey } from '../hooks/useResponses';
|
||||
import { useSyncWindowTitle } from '../hooks/useSyncWindowTitle';
|
||||
import { workspacesQueryKey } from '../hooks/useWorkspaces';
|
||||
import { trackPage } from '../lib/analytics';
|
||||
import { DEFAULT_FONT_SIZE } from '../lib/constants';
|
||||
@@ -26,6 +27,8 @@ export function GlobalHooks() {
|
||||
useRecentEnvironments();
|
||||
useRecentRequests();
|
||||
|
||||
useSyncWindowTitle();
|
||||
|
||||
const queryClient = useQueryClient();
|
||||
const { wasUpdatedExternally } = useRequestUpdateKey(null);
|
||||
|
||||
|
||||
22
src-web/hooks/useSyncWindowTitle.ts
Normal file
22
src-web/hooks/useSyncWindowTitle.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { appWindow } from '@tauri-apps/api/window';
|
||||
import { useEffect } from 'react';
|
||||
import { fallbackRequestName } from '../lib/fallbackRequestName';
|
||||
import { useActiveEnvironment } from './useActiveEnvironment';
|
||||
import { useActiveRequest } from './useActiveRequest';
|
||||
import { useActiveWorkspace } from './useActiveWorkspace';
|
||||
|
||||
export function useSyncWindowTitle() {
|
||||
const activeRequest = useActiveRequest();
|
||||
const activeWorkspace = useActiveWorkspace();
|
||||
const activeEnvironment = useActiveEnvironment();
|
||||
useEffect(() => {
|
||||
let newTitle = activeWorkspace ? activeWorkspace.name : 'Yaak';
|
||||
if (activeEnvironment) {
|
||||
newTitle += ` [${activeEnvironment.name}]`;
|
||||
}
|
||||
if (activeRequest) {
|
||||
newTitle += ` – ${fallbackRequestName(activeRequest)}`;
|
||||
}
|
||||
appWindow.setTitle(newTitle).catch(console.error);
|
||||
}, [activeEnvironment, activeRequest, activeWorkspace]);
|
||||
}
|
||||
Reference in New Issue
Block a user