Sync window title (Closes #13)

This commit is contained in:
Gregory Schier
2023-11-10 15:55:50 -08:00
parent 4ffce4a534
commit e4533088ed
4 changed files with 28 additions and 1 deletions

View File

@@ -41,6 +41,7 @@ tauri = { version = "1.3", features = [
"window-start-dragging",
"dialog-open",
"dialog-save",
"window-set-title",
] }
tauri-plugin-window-state = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }
tauri-plugin-log = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1", features = ["colored"] }

View File

@@ -51,7 +51,8 @@
"open": true
},
"window": {
"startDragging": true
"startDragging": true,
"setTitle": true
},
"dialog": {
"all": false,

View File

@@ -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);

View 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]);
}