Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 30 additions & 28 deletions src/celemod-ui/src/routes/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
} from "../states";
import "./Home.scss";
import { useGlobalContext } from "src/App";
import { detectDesktopPlatform } from "../tauri/window";
import { detectDesktopPlatform, isMobileLayout } from "../tauri/window";
import { SteamAccount } from "../components/SteamAccount";

export const Home = () => {
Expand Down Expand Up @@ -367,33 +367,35 @@ export const Home = () => {

{detectDesktopPlatform() === "android" && <SteamAccount />}

<section className="home-section home-shortcuts-section">
<div className="home-section-heading">
<Icon name="grid" />
<h2>{chinese ? "常用功能" : "Quick access"}</h2>
</div>
<div className="home-shortcuts">
{shortcuts.map((shortcut) => (
<button
type="button"
key={shortcut.page}
className={`home-shortcut tone-${shortcut.tone}`}
onClick={() => globalCtx.pageController.setPage(shortcut.page)}
>
<span className="shortcut-icon">
<Icon name={shortcut.icon} />
</span>
<span className="shortcut-copy">
<strong title={shortcut.title}>{shortcut.title}</strong>
<small title={shortcut.description}>
{shortcut.description}
</small>
</span>
<Icon name="i-right" />
</button>
))}
</div>
</section>
{isMobileLayout() && (
<section className="home-section home-shortcuts-section">
<div className="home-section-heading">
<Icon name="grid" />
<h2>{chinese ? "常用功能" : "Quick access"}</h2>
</div>
<div className="home-shortcuts">
{shortcuts.map((shortcut) => (
<button
type="button"
key={shortcut.page}
className={`home-shortcut tone-${shortcut.tone}`}
onClick={() => globalCtx.pageController.setPage(shortcut.page)}
>
<span className="shortcut-icon">
<Icon name={shortcut.icon} />
</span>
<span className="shortcut-copy">
<strong title={shortcut.title}>{shortcut.title}</strong>
<small title={shortcut.description}>
{shortcut.description}
</small>
</span>
<Icon name="i-right" />
</button>
))}
</div>
</section>
)}

{profileEnabled && (
<section className="home-section home-profiles-section">
Expand Down
27 changes: 17 additions & 10 deletions src/celemod-ui/src/tauri/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,22 @@ export function detectDesktopPlatform(): DesktopPlatform {
return "linux";
}

/**
* Mobile layout is a property of the platform, not of the window width.
*
* The interface scale is applied with WebView zoom (`setZoom`), which shrinks
* the CSS viewport: a 1100px window at 150% reports `innerWidth === 733`, so a
* `(max-width: 760px)` check switched desktop users to the Android layout
* (sidebar hidden, bottom navigation shown). Desktop windows also cannot get
* narrower than `minWidth` (800px), so the width check only ever fired because
* of that zoom.
*/
export function isMobileLayout(): boolean {
return detectDesktopPlatform() === "android";
}

export function initializeWindowChrome() {
document.documentElement.dataset.platform = detectDesktopPlatform();
const compact = window.matchMedia("(max-width: 760px)");
const updateLayout = () => {
document.documentElement.toggleAttribute(
"data-mobile-layout",
detectDesktopPlatform() === "android" || compact.matches,
);
};
updateLayout();
compact.addEventListener("change", updateLayout);
const platform = detectDesktopPlatform();
document.documentElement.dataset.platform = platform;
document.documentElement.toggleAttribute("data-mobile-layout", isMobileLayout());
}
Loading