Sync window title (Closes #13)

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

View File

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

View File

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

View File

@@ -11,6 +11,7 @@ import { useRecentWorkspaces } from '../hooks/useRecentWorkspaces';
import { requestsQueryKey } from '../hooks/useRequests'; import { requestsQueryKey } from '../hooks/useRequests';
import { useRequestUpdateKey } from '../hooks/useRequestUpdateKey'; import { useRequestUpdateKey } from '../hooks/useRequestUpdateKey';
import { responsesQueryKey } from '../hooks/useResponses'; import { responsesQueryKey } from '../hooks/useResponses';
import { useSyncWindowTitle } from '../hooks/useSyncWindowTitle';
import { workspacesQueryKey } from '../hooks/useWorkspaces'; import { workspacesQueryKey } from '../hooks/useWorkspaces';
import { trackPage } from '../lib/analytics'; import { trackPage } from '../lib/analytics';
import { DEFAULT_FONT_SIZE } from '../lib/constants'; import { DEFAULT_FONT_SIZE } from '../lib/constants';
@@ -26,6 +27,8 @@ export function GlobalHooks() {
useRecentEnvironments(); useRecentEnvironments();
useRecentRequests(); useRecentRequests();
useSyncWindowTitle();
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const { wasUpdatedExternally } = useRequestUpdateKey(null); 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]);
}