Set window title on Mac

This commit is contained in:
Gregory Schier
2024-05-23 09:40:00 -07:00
parent d32b462bd9
commit 002b61f0d7
2 changed files with 55 additions and 19 deletions

View File

@@ -1,13 +1,17 @@
import { emit } from '@tauri-apps/api/event';
import { getCurrent } from '@tauri-apps/api/webviewWindow';
import { useEffect } from 'react';
import { fallbackRequestName } from '../lib/fallbackRequestName';
import { useActiveEnvironment } from './useActiveEnvironment';
import { useActiveRequest } from './useActiveRequest';
import { useActiveWorkspace } from './useActiveWorkspace';
import { useOsInfo } from './useOsInfo';
export function useSyncWindowTitle() {
const activeRequest = useActiveRequest();
const activeWorkspace = useActiveWorkspace();
const activeEnvironment = useActiveEnvironment();
const osInfo = useOsInfo();
useEffect(() => {
let newTitle = activeWorkspace ? activeWorkspace.name : 'Yaak';
if (activeEnvironment) {
@@ -18,7 +22,12 @@ export function useSyncWindowTitle() {
newTitle += ` ${fallbackRequestName(activeRequest)}`;
}
// TODO: This resets the stoplight position so we can't use it yet
// invoke('cmd_set_title', { title: newTitle }).catch(console.error);
}, [activeEnvironment, activeRequest, activeWorkspace]);
// TODO: This resets the stoplight position so we can't use it on macOS yet. Perhaps
// we can
if (osInfo?.osType !== 'macos') {
getCurrent().setTitle(newTitle).catch(console.error);
} else {
emit('yaak_title_changed', newTitle).catch(console.error);
}
}, [activeEnvironment, activeRequest, activeWorkspace, osInfo?.osType]);
}