Skip to content

Commit

Permalink
Show speeds in app window titlebar
Browse files Browse the repository at this point in the history
Issue #162
  • Loading branch information
qu1ck committed Feb 9, 2024
1 parent 1a3c1c7 commit 0fe9b79
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
7 changes: 3 additions & 4 deletions src/components/servertabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,13 @@ export const ServerTabs = React.forwardRef<ServerTabsRef, ServerTabsProps>(funct

const [tabs, setTabs] = useState({
openTabs: config.getOpenTabs(),
currentTab: 0,
currentTab: config.getOpenTabs().length > 0 ? 0 : -1,
});

useEffect(() => {
config.setOpenTabs(tabs.openTabs);
if (tabs.currentTab < tabs.openTabs.length) {
const tab = tabs.openTabs[tabs.currentTab];
void appWindow.setTitle(`Transmission GUI - ${tab}`);
if (tabs.currentTab < 0) {
void appWindow.setTitle("Transmission GUI");
}
}, [config, tabs]);

Expand Down
13 changes: 9 additions & 4 deletions src/components/statusbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import { Box, Flex, Menu } from "@mantine/core";
import type { SessionInfo } from "rpc/client";
import type { Torrent } from "rpc/torrent";
import { ColorSchemeToggle, ShowVersion } from "components/miscbuttons";
import { ConfigContext } from "config";
import { ConfigContext, ServerConfigContext } from "config";
import { useContextMenu } from "./contextmenu";
import { MemoSectionsContextMenu, getSectionsMap } from "./sectionscontextmenu";

const TAURI = Object.prototype.hasOwnProperty.call(window, "__TAURI__");
const { TAURI, appWindow } = await import(/* webpackChunkName: "taurishim" */"taurishim");

export interface StatusbarProps {
session: SessionInfo | undefined,
Expand All @@ -39,6 +39,7 @@ export interface StatusbarProps {

export function Statusbar({ session, torrents, filteredTorrents, selectedTorrents, hostname }: StatusbarProps) {
const config = useContext(ConfigContext);
const serverConfig = useContext(ServerConfigContext);

const serverFields = useMemo(() => ({
downRateLimit: session !== undefined
Expand Down Expand Up @@ -91,8 +92,12 @@ export function Statusbar({ session, torrents, filteredTorrents, selectedTorrent
], [showGlobalSpeeds, torrents, filteredTorrents]);

useEffect(() => {
document.title = `↓${downRate}/s ↑${upRate}/s - TrguiNG`;
}, [downRate, upRate]);
const speeds = `↓${downRate}/s ↑${upRate}/s`;
document.title = `${speeds} - TrguiNG`;
if (TAURI) {
void appWindow.setTitle(`Transmission GUI - ${serverConfig.name} (${speeds})`);
}
}, [serverConfig, downRate, upRate]);

const [info, setInfo, handler] = useContextMenu();

Expand Down

0 comments on commit 0fe9b79

Please sign in to comment.