Skip to content

Commit da3fea8

Browse files
authored
Merge pull request #37 from slaveofcode/develop
feat: hide desktop-only tools (Hotkey Test) from web
2 parents 742aeda + c15dcc1 commit da3fea8

6 files changed

Lines changed: 31 additions & 14 deletions

File tree

src/components/ToolGrid.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function ToolGrid() {
2222
/>
2323
<h2 className="text-xl font-bold uppercase tracking-tight">{category}</h2>
2424
<span className="text-sm font-bold text-muted-foreground">
25-
({categoryTools.length})
25+
({categoryTools.filter(tool => !tool.desktopOnly).length})
2626
</span>
2727
</div>
2828
<div className="grid grid-cols-1 gap-5 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
@@ -32,6 +32,7 @@ export function ToolGrid() {
3232
<a
3333
key={tool.id}
3434
href={tool.route}
35+
{...(tool.desktopOnly ? { 'data-desktop-only': '' } : {})}
3536
className="group flex items-start gap-3 border-2 border-border bg-muted p-4 shadow-brutal press-brutal"
3637
>
3738
<span

src/components/shell/CommandPalette.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ import { useState, useEffect, useRef } from 'react';
22
import { Command } from 'cmdk';
33
import { searchTools } from '@/registry/tools';
44
import { categories } from '@/registry/categories';
5+
import { isTauri } from '@/services/platform';
56

67
export function CommandPalette() {
78
const [open, setOpen] = useState(false);
89
const [search, setSearch] = useState('');
10+
const [isDesktop, setIsDesktop] = useState(false);
911
const inputRef = useRef<HTMLInputElement>(null);
10-
const results = searchTools(search);
12+
// Desktop-only tools (e.g. Hotkey Test) are excluded from web search results.
13+
const results = searchTools(search).filter(tool => isDesktop || !tool.desktopOnly);
1114

1215
useEffect(() => {
1316
const down = (e: KeyboardEvent) => {
@@ -19,6 +22,7 @@ export function CommandPalette() {
1922
// Let any element open search by clicking (dispatch 'gwt:open-search'),
2023
// so it works without a keyboard.
2124
const openSearch = () => setOpen(true);
25+
setIsDesktop(isTauri());
2226
document.addEventListener('keydown', down);
2327
window.addEventListener('gwt:open-search', openSearch);
2428
return () => {

src/layouts/Base.astro

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,18 @@ const jsonLdBlocks = [siteJsonLd, ...(Array.isArray(jsonLd) ? jsonLd : jsonLd ?
102102

103103
<ViewTransitions />
104104
<script is:inline>
105-
// Apply the saved theme before paint — on the initial load AND after every
106-
// View Transitions navigation. Without the astro:after-swap re-apply, the
107-
// runtime `dark` class is lost when the incoming (light) page swaps in, so
108-
// dark mode "resets" when navigating between pages.
109-
function applyStoredTheme() {
110-
document.documentElement.classList.toggle(
111-
'dark',
112-
localStorage.getItem('theme') === 'dark',
113-
);
105+
// Apply environment classes before paint — on initial load AND after every
106+
// View Transitions navigation (otherwise the class is lost when the incoming
107+
// static page swaps in). `dark` = saved theme; `tauri` = running in the
108+
// desktop app (reveals desktop-only tools that are hidden on the web).
109+
var __isTauri = '__TAURI__' in window && window.__TAURI__ !== undefined;
110+
function applyEnvClasses() {
111+
var root = document.documentElement;
112+
root.classList.toggle('dark', localStorage.getItem('theme') === 'dark');
113+
root.classList.toggle('tauri', __isTauri);
114114
}
115-
applyStoredTheme();
116-
document.addEventListener('astro:after-swap', applyStoredTheme);
115+
applyEnvClasses();
116+
document.addEventListener('astro:after-swap', applyEnvClasses);
117117
</script>
118118

119119
<!-- Google Analytics (GDPR): loads only when configured AND consent granted. -->

src/registry/tools.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ export const tools: ToolDef[] = [
9999
icon: Keyboard,
100100
summary: 'Test global hotkey registration (desktop only)',
101101
load: () => import('@/islands/dev/HotkeyTest'),
102-
status: 'beta'
102+
status: 'beta',
103+
desktopOnly: true
103104
},
104105
{
105106
id: 'csv-json',

src/styles/global.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,12 @@ body {
179179
background-size: 20px 20px;
180180
background-position: 0 0, 0 10px, 10px -10px, -10px 0;
181181
}
182+
183+
/* Desktop-only tools (e.g. Hotkey Test) are hidden on the web and revealed only
184+
in the Tauri desktop app, where an inline script sets `.tauri` on <html>. */
185+
[data-desktop-only] {
186+
display: none;
187+
}
188+
html.tauri [data-desktop-only] {
189+
display: flex;
190+
}

src/types/tool.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export interface ToolDef {
1919
summary: string;
2020
load: () => Promise<{ default: React.ComponentType }>;
2121
needsIsolation?: boolean;
22+
/** Hidden from web listings (grid + search); only shown in the Tauri desktop app. */
23+
desktopOnly?: boolean;
2224
assets?: AssetRef[];
2325
status: 'stable' | 'beta' | 'experimental';
2426
}

0 commit comments

Comments
 (0)