mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-24 18:31:16 +01:00
Sync window title (Closes #13)
This commit is contained in:
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