mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Add a settings window with pages
- Split the settings into Appearance, Keymap, Graphics and About pages - Choose the theme in Appearance instead of cycling it from the toolbar - Add a UI scale, saved with the studio settings and applied when the window opens - Filter the keymap by name or key - Show the GPU choice on every machine, saying why it is fixed without an NVIDIA GPU - Show the studio and runtime versions and the icon licences in About
This commit is contained in:
1 parent
b128df4720
commit
646850df43
10 files changed
+482
-192
No files matched your search
@@ -3,7 +3,7 @@ import { readFileSync } from 'node:fs'
|
||||
import { mkdir, readdir, readFile, writeFile } from 'node:fs/promises'
|
||||
import { homedir } from 'node:os'
|
||||
import { dirname, join } from 'node:path'
|
||||
import type { BridgeConnection, GraphicsInfo, StoredShortcuts, ThemeChoice } from '../shared/bridge'
|
||||
import { DEFAULT_UI_SCALE, isUiScale, type AboutInfo, type BridgeConnection, type GraphicsInfo, type StoredShortcuts, type ThemeChoice, type UiScale } from '../shared/bridge'
|
||||
import {
|
||||
dedicatedGpuDriver,
|
||||
runsOnDedicatedGpu,
|
||||
@@ -17,6 +17,7 @@ const CONNECTION_FOLDER = join(homedir(), '.iris', 'studio', 'bridges')
|
||||
const SETTINGS_FILE = 'studio.json'
|
||||
const SHORTCUTS_KEY = 'shortcuts'
|
||||
const DEDICATED_GPU_KEY = 'dedicatedGpu'
|
||||
const UI_SCALE_KEY = 'uiScale'
|
||||
const SETTINGS_INDENT = 2
|
||||
const LINK_PREFIX = 'iris-studio://'
|
||||
const DARK_BACKGROUND = '#1e1f22'
|
||||
@@ -91,16 +92,38 @@ async function saveSetting(key: string, value: unknown): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
/** Read before the app is ready, as the GPU the studio draws on is chosen by how it was started. */
|
||||
function choosesDedicatedGpu(): boolean {
|
||||
/** For settings needed before the app is ready or the window opens, when nothing can wait for a read. */
|
||||
function readSettingsNow(): Record<string, unknown> {
|
||||
try {
|
||||
const settings: unknown = JSON.parse(readFileSync(settingsPath(), 'utf8'))
|
||||
return typeof settings === 'object' && settings !== null && (settings as Record<string, unknown>)[DEDICATED_GPU_KEY] === true
|
||||
return typeof settings === 'object' && settings !== null && !Array.isArray(settings) ? (settings as Record<string, unknown>) : {}
|
||||
} catch {
|
||||
return false
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
||||
/** Read before the app is ready, as the GPU the studio draws on is chosen by how it was started. */
|
||||
function choosesDedicatedGpu(): boolean {
|
||||
return readSettingsNow()[DEDICATED_GPU_KEY] === true
|
||||
}
|
||||
|
||||
function savedUiScale(settings: Record<string, unknown>): UiScale {
|
||||
const scale = settings[UI_SCALE_KEY]
|
||||
return isUiScale(scale) ? scale : DEFAULT_UI_SCALE
|
||||
}
|
||||
|
||||
function setUiScale(scale: unknown): void {
|
||||
if (!isUiScale(scale)) {
|
||||
return
|
||||
}
|
||||
window?.webContents.setZoomFactor(scale)
|
||||
void saveSetting(UI_SCALE_KEY, scale)
|
||||
}
|
||||
|
||||
function aboutInfo(): AboutInfo {
|
||||
return { version: app.getVersion(), electron: process.versions.electron, chromium: process.versions.chrome }
|
||||
}
|
||||
|
||||
function restartOnGpu(dedicated: boolean): void {
|
||||
const args = process.argv.slice(1)
|
||||
if (dedicated && dedicatedGpu !== null) {
|
||||
@@ -132,7 +155,8 @@ function createWindow(): void {
|
||||
webPreferences: {
|
||||
preload: join(import.meta.dirname, '../preload/index.cjs'),
|
||||
sandbox: true,
|
||||
contextIsolation: true
|
||||
contextIsolation: true,
|
||||
zoomFactor: savedUiScale(readSettingsNow())
|
||||
}
|
||||
})
|
||||
window.once('ready-to-show', () => window?.show())
|
||||
@@ -191,6 +215,9 @@ if (dedicatedGpu !== null && choosesDedicatedGpu() && !runsOnDedicatedGpu(proces
|
||||
ipcMain.on('studio:save-shortcuts', (_event, shortcuts: StoredShortcuts) => void saveSetting(SHORTCUTS_KEY, shortcuts))
|
||||
ipcMain.handle('studio:graphics', graphicsInfo)
|
||||
ipcMain.on('studio:use-dedicated-gpu', (_event, dedicated: boolean) => void useDedicatedGpu(dedicated))
|
||||
ipcMain.handle('studio:ui-scale', async () => savedUiScale(await readSettings()))
|
||||
ipcMain.on('studio:set-ui-scale', (_event, scale: unknown) => setUiScale(scale))
|
||||
ipcMain.handle('studio:about', aboutInfo)
|
||||
ipcMain.on('studio:copy-text', (_event, text: string) => clipboard.writeText(text))
|
||||
|
||||
void app.whenReady().then(createWindow)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { contextBridge, ipcRenderer, type IpcRendererEvent } from 'electron'
|
||||
import type { StoredShortcuts, StudioHost, ThemeChoice } from '../shared/bridge'
|
||||
import type { StoredShortcuts, StudioHost, ThemeChoice, UiScale } from '../shared/bridge'
|
||||
|
||||
const host: StudioHost = {
|
||||
listBridges: () => ipcRenderer.invoke('studio:list-bridges'),
|
||||
@@ -14,7 +14,10 @@ const host: StudioHost = {
|
||||
loadShortcuts: () => ipcRenderer.invoke('studio:load-shortcuts'),
|
||||
saveShortcuts: (shortcuts: StoredShortcuts) => ipcRenderer.send('studio:save-shortcuts', shortcuts),
|
||||
graphics: () => ipcRenderer.invoke('studio:graphics'),
|
||||
useDedicatedGpu: (dedicated: boolean) => ipcRenderer.send('studio:use-dedicated-gpu', dedicated)
|
||||
useDedicatedGpu: (dedicated: boolean) => ipcRenderer.send('studio:use-dedicated-gpu', dedicated),
|
||||
uiScale: () => ipcRenderer.invoke('studio:ui-scale'),
|
||||
setUiScale: (scale: UiScale) => ipcRenderer.send('studio:set-ui-scale', scale),
|
||||
about: () => ipcRenderer.invoke('studio:about')
|
||||
}
|
||||
|
||||
contextBridge.exposeInMainWorld('studio', host)
|
||||
@@ -0,0 +1,144 @@
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { cn } from '@/lib/utils'
|
||||
import type { ViewInfo } from '../bridge/types'
|
||||
import { Glyph } from './Glyph'
|
||||
import { chordOf, chordText, chordsOf, chordsText, clashesWith, defaultChords, shortcutRows, type Bindings, type ShortcutGroup, type ShortcutRow } from './shortcuts'
|
||||
import { SettingGroup, SettingsPage } from './SettingsLayout'
|
||||
import { shortcutStore, useBindings } from './useBindings'
|
||||
|
||||
interface Note {
|
||||
text: string
|
||||
warning: boolean
|
||||
}
|
||||
|
||||
const GROUPS: ShortcutGroup[] = ['Views', 'Everywhere', 'Map', 'Node editor']
|
||||
const RECORDING_TEXT = 'Press a key…'
|
||||
const NO_KEYS_TEXT = 'None'
|
||||
|
||||
/** Every shortcut with its keys, rebound by clicking its keys and pressing the new one. Changes are saved at once. */
|
||||
export function KeymapPage({ views }: { views: ViewInfo[] }): React.JSX.Element {
|
||||
const bindings = useBindings()
|
||||
const rows = useMemo(() => shortcutRows(views), [views])
|
||||
const [filter, setFilter] = useState('')
|
||||
const [recording, setRecording] = useState<ShortcutRow | null>(null)
|
||||
const [note, setNote] = useState<Note | null>(null)
|
||||
const shown = rows.filter((row) => matchesFilter(row, bindings, filter))
|
||||
|
||||
useEffect(() => {
|
||||
if (recording === null) {
|
||||
return
|
||||
}
|
||||
const record = (event: KeyboardEvent): void => {
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
const chord = chordOf(event)
|
||||
if (chord === null) {
|
||||
return
|
||||
}
|
||||
const clashes = clashesWith(recording, chord, rows, shortcutStore.snapshot())
|
||||
shortcutStore.rebind(recording.id, [chord])
|
||||
setRecording(null)
|
||||
setNote(
|
||||
clashes.length === 0
|
||||
? { text: `${recording.label} is now ${chordText(chord)}`, warning: false }
|
||||
: { text: `${chordText(chord)} is also ${clashes.map((clash) => clash.label).join(', ')}`, warning: true }
|
||||
)
|
||||
}
|
||||
window.addEventListener('keydown', record, true)
|
||||
return () => window.removeEventListener('keydown', record, true)
|
||||
}, [recording, rows])
|
||||
|
||||
const resetAll = (): void => {
|
||||
setRecording(null)
|
||||
setNote(null)
|
||||
shortcutStore.resetAll()
|
||||
}
|
||||
|
||||
return (
|
||||
<SettingsPage
|
||||
title="Keymap"
|
||||
description="Click a shortcut's keys, then press the new key. Esc can be chosen too; click the keys again to cancel."
|
||||
toolbar={
|
||||
<div className="relative flex-1">
|
||||
<Glyph glyph="search" className="pointer-events-none absolute top-1.5 left-2" />
|
||||
<Input className="pl-7" placeholder="Filter by name or key" value={filter} onChange={(event) => setFilter(event.target.value)} />
|
||||
</div>
|
||||
}
|
||||
footer={
|
||||
<>
|
||||
<span className={cn('min-w-0 flex-1 truncate text-[12px]', note?.warning ? 'text-warning' : 'text-secondary-text')}>{note?.text}</span>
|
||||
<Button variant="outline" onClick={resetAll}>
|
||||
Reset all
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
{shown.length === 0 && <p className="text-muted-foreground">No shortcut matches</p>}
|
||||
{GROUPS.map((group) => {
|
||||
const groupRows = shown.filter((row) => row.group === group)
|
||||
if (groupRows.length === 0) {
|
||||
return null
|
||||
}
|
||||
return (
|
||||
<SettingGroup key={group} title={group}>
|
||||
{groupRows.map((row) => (
|
||||
<ShortcutRowView
|
||||
key={row.id}
|
||||
row={row}
|
||||
keys={chordsOf(row.id, bindings)}
|
||||
changed={bindings[row.id] !== undefined}
|
||||
recording={recording?.id === row.id}
|
||||
onRecord={() => setRecording((current) => (current?.id === row.id ? null : row))}
|
||||
onReset={() => {
|
||||
setRecording(null)
|
||||
shortcutStore.reset(row.id)
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</SettingGroup>
|
||||
)
|
||||
})}
|
||||
</SettingsPage>
|
||||
)
|
||||
}
|
||||
|
||||
function matchesFilter(row: ShortcutRow, bindings: Bindings, filter: string): boolean {
|
||||
const wanted = filter.trim().toLowerCase()
|
||||
if (wanted === '') {
|
||||
return true
|
||||
}
|
||||
return row.label.toLowerCase().includes(wanted) || chordsText(chordsOf(row.id, bindings)).toLowerCase().includes(wanted)
|
||||
}
|
||||
|
||||
interface ShortcutRowViewProps {
|
||||
row: ShortcutRow
|
||||
keys: string[]
|
||||
changed: boolean
|
||||
recording: boolean
|
||||
onRecord(): void
|
||||
onReset(): void
|
||||
}
|
||||
|
||||
function ShortcutRowView({ row, keys, changed, recording, onRecord, onReset }: ShortcutRowViewProps): React.JSX.Element {
|
||||
return (
|
||||
<div className="-mx-2 flex items-center gap-2 rounded-md px-2 py-0.5 hover:bg-accent">
|
||||
<span className="min-w-0 flex-1 truncate" title={row.label}>
|
||||
{row.label}
|
||||
</span>
|
||||
<Button variant="outline" size="xs" className={cn('w-36 bg-card', recording && 'focused')} onClick={onRecord} title="Click, then press the new key">
|
||||
{recording ? RECORDING_TEXT : keys.length === 0 ? NO_KEYS_TEXT : chordsText(keys)}
|
||||
</Button>
|
||||
<Button
|
||||
variant="link"
|
||||
size="xs"
|
||||
className={cn('w-14 text-link', !changed && 'invisible')}
|
||||
onClick={onReset}
|
||||
title={chordsText(defaultChords(row.id)) || NO_KEYS_TEXT}
|
||||
>
|
||||
Default
|
||||
</Button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||
import type { ThemeChoice } from '../../../shared/bridge'
|
||||
import type { BridgeClient, MapLayerQuery, WorldRect } from '../bridge/BridgeClient'
|
||||
import type { MapHover, MapLabel, Marker, ModuleViewInfo, PickDisplay, ServerUsage, ViewInfo, WorldInfo } from '../bridge/types'
|
||||
import type { Share } from '../map/census'
|
||||
@@ -20,10 +19,11 @@ import { SavedWorldStudio } from './SavedWorldStudio'
|
||||
import { SceneStudio } from './SceneStudio'
|
||||
import { WorldStudio3D } from './WorldStudio3D'
|
||||
import { isTypingInto, shortcutRows, viewOfShortcutId, windowShortcutFor, type ShortcutAction } from './shortcuts'
|
||||
import { ShortcutSettings } from './ShortcutSettings'
|
||||
import { SettingsDialog } from './SettingsDialog'
|
||||
import { Panel, SidebarPanel, SidebarSlot, ViewIsland } from './Sidebar'
|
||||
import { StatusBar } from './StatusBar'
|
||||
import { MapTools, StudioToolbar } from './StudioToolbar'
|
||||
import type { Theme } from './theme'
|
||||
import { useBindings } from './useBindings'
|
||||
import { usePickInspection } from './usePickInspection'
|
||||
import { ViewList } from './ViewList'
|
||||
@@ -37,7 +37,7 @@ const PICK_VIEWS = new Set(['biomes', 'regions'])
|
||||
interface MapStudioProps {
|
||||
client: BridgeClient
|
||||
world: WorldInfo
|
||||
theme: { choice: ThemeChoice; next: () => void }
|
||||
theme: Theme
|
||||
onDisconnect(): void
|
||||
}
|
||||
|
||||
@@ -219,7 +219,7 @@ export function MapStudio({ client, world, theme, onDisconnect }: MapStudioProps
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col">
|
||||
<StudioToolbar world={world} theme={theme} onHelp={() => setHelpOpen(true)} onSettings={() => setSettingsOpen(true)} onDisconnect={onDisconnect} />
|
||||
<StudioToolbar world={world} onHelp={() => setHelpOpen(true)} onSettings={() => setSettingsOpen(true)} onDisconnect={onDisconnect} />
|
||||
<SidebarSlot.Provider value={sidebarSlot}>
|
||||
<div className="flex min-h-0 flex-1 gap-1.5 pr-1.5">
|
||||
<ViewList views={views} current={viewId} onSelect={selectView} slotRef={setSidebarSlot} />
|
||||
@@ -324,7 +324,7 @@ export function MapStudio({ client, world, theme, onDisconnect }: MapStudioProps
|
||||
</SidebarSlot.Provider>
|
||||
<StatusBar viewLabel={statusLabel(view.label, previewName, showsMap ? null : sceneSummary)} status={showsMap ? status : null} notice={notice} usage={usage} progress={showsMap ? null : sceneProgress} />
|
||||
<HelpDialog open={helpOpen} onOpenChange={setHelpOpen} views={views} />
|
||||
<ShortcutSettings open={settingsOpen} onOpenChange={setSettingsOpen} views={views} />
|
||||
<SettingsDialog open={settingsOpen} onOpenChange={setSettingsOpen} views={views} theme={theme} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,208 @@
|
||||
import { useEffect, useState, type ReactNode } from 'react'
|
||||
import { Info, Keyboard, MonitorCog, Palette } from 'lucide-react'
|
||||
import { Dialog, DialogContent, DialogTitle } from '@/components/ui/dialog'
|
||||
import { ToggleGroup, ToggleGroupItem } from '@/components/ui/toggle-group'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { UI_SCALES, type AboutInfo, type GraphicsInfo, type ThemeChoice, type UiScale } from '../../../shared/bridge'
|
||||
import type { ViewInfo } from '../bridge/types'
|
||||
import intellijNotice from '../icons/intellij/NOTICE.txt?raw'
|
||||
import { KeymapPage } from './KeymapSettings'
|
||||
import { SettingGroup, SettingRow, SettingsPage } from './SettingsLayout'
|
||||
import type { Theme } from './theme'
|
||||
|
||||
type PageId = 'appearance' | 'keymap' | 'graphics' | 'about'
|
||||
|
||||
interface PageLink {
|
||||
id: PageId
|
||||
label: string
|
||||
icon: ReactNode
|
||||
}
|
||||
|
||||
const STUDIO_PAGES: PageLink[] = [
|
||||
{ id: 'appearance', label: 'Appearance', icon: <Palette /> },
|
||||
{ id: 'keymap', label: 'Keymap', icon: <Keyboard /> },
|
||||
{ id: 'graphics', label: 'Graphics', icon: <MonitorCog /> }
|
||||
]
|
||||
const ABOUT_PAGE: PageLink = { id: 'about', label: 'About', icon: <Info /> }
|
||||
|
||||
const THEME_LABELS: Record<ThemeChoice, string> = { system: 'System', light: 'Light', dark: 'Dark' }
|
||||
const PERCENT = 100
|
||||
const APACHE_LICENSE_URL = 'https://www.apache.org/licenses/LICENSE-2.0'
|
||||
const LUCIDE_LICENSE_URL = 'https://lucide.dev/license'
|
||||
|
||||
interface SettingsDialogProps {
|
||||
open: boolean
|
||||
onOpenChange(open: boolean): void
|
||||
views: ViewInfo[]
|
||||
theme: Theme
|
||||
}
|
||||
|
||||
/** The studio's own settings, a page each, saved as they change. */
|
||||
export function SettingsDialog({ open, onOpenChange, views, theme }: SettingsDialogProps): React.JSX.Element {
|
||||
const [page, setPage] = useState<PageId>('appearance')
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent
|
||||
aria-describedby={undefined}
|
||||
onOpenAutoFocus={(event) => {
|
||||
event.preventDefault()
|
||||
;(event.currentTarget as HTMLElement).focus()
|
||||
}}
|
||||
className="flex h-[min(600px,85vh)] gap-0 overflow-hidden p-0 sm:max-w-[860px]">
|
||||
<nav className="flex w-52 shrink-0 flex-col gap-0.5 border-r bg-background p-2">
|
||||
<DialogTitle className="px-2 pt-1.5 pb-2.5 text-[13px] font-semibold">Settings</DialogTitle>
|
||||
{STUDIO_PAGES.map((link) => (
|
||||
<PageButton key={link.id} link={link} chosen={page === link.id} onChoose={setPage} />
|
||||
))}
|
||||
<div className="flex-1" />
|
||||
<PageButton link={ABOUT_PAGE} chosen={page === ABOUT_PAGE.id} onChoose={setPage} />
|
||||
</nav>
|
||||
{page === 'appearance' && <AppearancePage theme={theme} />}
|
||||
{page === 'keymap' && <KeymapPage views={views} />}
|
||||
{page === 'graphics' && <GraphicsPage />}
|
||||
{page === 'about' && <AboutPage />}
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
|
||||
function PageButton({ link, chosen, onChoose }: { link: PageLink; chosen: boolean; onChoose(page: PageId): void }): React.JSX.Element {
|
||||
return (
|
||||
<button
|
||||
className={cn(
|
||||
'flex h-7 w-full items-center gap-2 rounded-md px-2 text-left outline-none focus-visible:focused [&_svg]:size-4',
|
||||
chosen ? 'bg-selection' : 'hover:bg-accent'
|
||||
)}
|
||||
aria-current={chosen ? 'page' : undefined}
|
||||
onClick={() => onChoose(link.id)}
|
||||
>
|
||||
{link.icon}
|
||||
{link.label}
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
function AppearancePage({ theme }: { theme: Theme }): React.JSX.Element {
|
||||
const [scale, chooseScale] = useUiScale()
|
||||
return (
|
||||
<SettingsPage title="Appearance" description="How the studio looks.">
|
||||
<SettingGroup>
|
||||
<SettingRow label="Theme" detail="System follows the desktop's light or dark setting">
|
||||
<Choice value={theme.choice} options={Object.keys(THEME_LABELS) as ThemeChoice[]} label={(choice) => THEME_LABELS[choice]} onChange={theme.choose} />
|
||||
</SettingRow>
|
||||
<SettingRow label="UI scale" detail="The size of text and controls">
|
||||
{scale !== null && <Choice value={scale} options={[...UI_SCALES]} label={(choice) => `${Math.round(choice * PERCENT)}%`} onChange={chooseScale} />}
|
||||
</SettingRow>
|
||||
</SettingGroup>
|
||||
</SettingsPage>
|
||||
)
|
||||
}
|
||||
|
||||
function useUiScale(): [UiScale | null, (scale: UiScale) => void] {
|
||||
const [scale, setScale] = useState<UiScale | null>(null)
|
||||
useEffect(() => {
|
||||
void window.studio.uiScale().then(setScale)
|
||||
}, [])
|
||||
const choose = (next: UiScale): void => {
|
||||
setScale(next)
|
||||
window.studio.setUiScale(next)
|
||||
}
|
||||
return [scale, choose]
|
||||
}
|
||||
|
||||
interface ChoiceProps<T> {
|
||||
value: T
|
||||
options: T[]
|
||||
label(option: T): string
|
||||
onChange(option: T): void
|
||||
}
|
||||
|
||||
/** One of a few options, as segments with the chosen one filled. */
|
||||
function Choice<T extends string | number>({ value, options, label, onChange }: ChoiceProps<T>): React.JSX.Element {
|
||||
return (
|
||||
<ToggleGroup
|
||||
type="single"
|
||||
variant="outline"
|
||||
className="w-64"
|
||||
value={String(value)}
|
||||
onValueChange={(chosen) => {
|
||||
const option = options.find((candidate) => String(candidate) === chosen)
|
||||
if (option !== undefined) {
|
||||
onChange(option)
|
||||
}
|
||||
}}
|
||||
>
|
||||
{options.map((option) => (
|
||||
<ToggleGroupItem key={String(option)} value={String(option)}>
|
||||
{label(option)}
|
||||
</ToggleGroupItem>
|
||||
))}
|
||||
</ToggleGroup>
|
||||
)
|
||||
}
|
||||
|
||||
function GraphicsPage(): React.JSX.Element {
|
||||
const [graphics, setGraphics] = useState<GraphicsInfo | null>(null)
|
||||
useEffect(() => {
|
||||
void window.studio.graphics().then(setGraphics)
|
||||
}, [])
|
||||
return (
|
||||
<SettingsPage title="Graphics" description="The GPU the studio draws its maps and 3D views on.">
|
||||
<SettingGroup>
|
||||
{graphics !== null && !graphics.canUseDedicatedGpu && (
|
||||
<SettingRow label="GPU" detail="Choosing one needs an NVIDIA GPU with its Vulkan driver">
|
||||
<span className="text-secondary-text">System default</span>
|
||||
</SettingRow>
|
||||
)}
|
||||
{graphics !== null && graphics.canUseDedicatedGpu && (
|
||||
<SettingRow label="GPU" detail="Changing it restarts the studio">
|
||||
<Choice
|
||||
value={graphics.usesDedicatedGpu ? 'dedicated' : 'default'}
|
||||
options={['default', 'dedicated']}
|
||||
label={(choice) => (choice === 'dedicated' ? 'dGPU' : 'System default')}
|
||||
onChange={(choice) => window.studio.useDedicatedGpu(choice === 'dedicated')}
|
||||
/>
|
||||
</SettingRow>
|
||||
)}
|
||||
</SettingGroup>
|
||||
</SettingsPage>
|
||||
)
|
||||
}
|
||||
|
||||
function AboutPage(): React.JSX.Element {
|
||||
const [about, setAbout] = useState<AboutInfo | null>(null)
|
||||
useEffect(() => {
|
||||
void window.studio.about().then(setAbout)
|
||||
}, [])
|
||||
return (
|
||||
<SettingsPage title="About">
|
||||
<SettingGroup title="Iris Studio">
|
||||
<SettingRow label="Version">
|
||||
<span className="text-secondary-text tabular-nums">{about?.version}</span>
|
||||
</SettingRow>
|
||||
<SettingRow label="Electron">
|
||||
<span className="text-secondary-text tabular-nums">{about?.electron}</span>
|
||||
</SettingRow>
|
||||
<SettingRow label="Chromium">
|
||||
<span className="text-secondary-text tabular-nums">{about?.chromium}</span>
|
||||
</SettingRow>
|
||||
</SettingGroup>
|
||||
<SettingGroup title="Licences">
|
||||
<SettingRow label="IntelliJ icons" detail={intellijNotice.split('\n').slice(0, 2).join(' · ')}>
|
||||
<LicenseLink href={APACHE_LICENSE_URL}>Apache License 2.0</LicenseLink>
|
||||
</SettingRow>
|
||||
<SettingRow label="Lucide icons">
|
||||
<LicenseLink href={LUCIDE_LICENSE_URL}>ISC License</LicenseLink>
|
||||
</SettingRow>
|
||||
</SettingGroup>
|
||||
</SettingsPage>
|
||||
)
|
||||
}
|
||||
|
||||
function LicenseLink({ href, children }: { href: string; children: ReactNode }): React.JSX.Element {
|
||||
return (
|
||||
<a className="rounded-sm text-link outline-none hover:underline focus-visible:focused" href={href} target="_blank" rel="noreferrer">
|
||||
{children}
|
||||
</a>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
import type { ReactNode } from 'react'
|
||||
import { ScrollArea } from '@/components/ui/scroll-area'
|
||||
|
||||
interface SettingsPageProps {
|
||||
title: string
|
||||
description?: string
|
||||
/** Stays above the scrolling settings, such as a filter. */
|
||||
toolbar?: ReactNode
|
||||
/** Stays below the scrolling settings. */
|
||||
footer?: ReactNode
|
||||
children: ReactNode
|
||||
}
|
||||
|
||||
/** One page of the settings: its title and what it is for, over its settings. */
|
||||
export function SettingsPage({ title, description, toolbar, footer, children }: SettingsPageProps): React.JSX.Element {
|
||||
return (
|
||||
<section className="flex min-w-0 flex-1 flex-col">
|
||||
<header className="border-b px-6 pt-5 pb-4 pr-14">
|
||||
<h2 className="text-[15px] font-semibold">{title}</h2>
|
||||
{description !== undefined && <p className="mt-1 text-muted-foreground">{description}</p>}
|
||||
</header>
|
||||
{toolbar !== undefined && <div className="flex items-center gap-2 px-6 pt-4">{toolbar}</div>}
|
||||
<ScrollArea className="min-h-0 flex-1">
|
||||
<div className="flex flex-col gap-5 px-6 py-4">{children}</div>
|
||||
</ScrollArea>
|
||||
{footer !== undefined && <footer className="flex h-11 shrink-0 items-center gap-2 border-t px-6">{footer}</footer>}
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
/** Settings that belong together, under a heading when the page has more than one group. */
|
||||
export function SettingGroup({ title, children }: { title?: string; children: ReactNode }): React.JSX.Element {
|
||||
return (
|
||||
<section>
|
||||
{title !== undefined && <h3 className="mb-1 text-[12px] font-semibold text-muted-foreground">{title}</h3>}
|
||||
{children}
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
interface SettingRowProps {
|
||||
label: string
|
||||
detail?: string
|
||||
children: ReactNode
|
||||
}
|
||||
|
||||
/** A setting's name, with what it does below it, and its control on the right. */
|
||||
export function SettingRow({ label, detail, children }: SettingRowProps): React.JSX.Element {
|
||||
return (
|
||||
<div className="flex min-h-10 items-center gap-6 py-1">
|
||||
<div className="min-w-0 flex-1">
|
||||
<div>{label}</div>
|
||||
{detail !== undefined && <div className="text-[12px] text-muted-foreground">{detail}</div>}
|
||||
</div>
|
||||
<div className="flex shrink-0 items-center">{children}</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,167 +0,0 @@
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog'
|
||||
import { cn } from '@/lib/utils'
|
||||
import type { GraphicsInfo } from '../../../shared/bridge'
|
||||
import type { ViewInfo } from '../bridge/types'
|
||||
import { chordOf, chordText, chordsOf, chordsText, clashesWith, defaultChords, shortcutRows, type ShortcutGroup, type ShortcutRow } from './shortcuts'
|
||||
import { shortcutStore, useBindings } from './useBindings'
|
||||
|
||||
interface ShortcutSettingsProps {
|
||||
open: boolean
|
||||
onOpenChange(open: boolean): void
|
||||
views: ViewInfo[]
|
||||
}
|
||||
|
||||
interface Note {
|
||||
text: string
|
||||
warning: boolean
|
||||
}
|
||||
|
||||
const GROUPS: ShortcutGroup[] = ['Views', 'Everywhere', 'Map', 'Node editor']
|
||||
const RECORDING_TEXT = 'Press a key…'
|
||||
const NO_KEYS_TEXT = 'None'
|
||||
|
||||
/** Every shortcut with its keys, rebound by clicking its keys and pressing the new one. Changes are saved at once. */
|
||||
export function ShortcutSettings({ open, onOpenChange, views }: ShortcutSettingsProps): React.JSX.Element {
|
||||
const bindings = useBindings()
|
||||
const rows = useMemo(() => shortcutRows(views), [views])
|
||||
const [recording, setRecording] = useState<ShortcutRow | null>(null)
|
||||
const [note, setNote] = useState<Note | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) {
|
||||
setRecording(null)
|
||||
}
|
||||
}, [open])
|
||||
|
||||
useEffect(() => {
|
||||
if (recording === null) {
|
||||
return
|
||||
}
|
||||
const record = (event: KeyboardEvent): void => {
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
const chord = chordOf(event)
|
||||
if (chord === null) {
|
||||
return
|
||||
}
|
||||
const clashes = clashesWith(recording, chord, rows, shortcutStore.snapshot())
|
||||
shortcutStore.rebind(recording.id, [chord])
|
||||
setRecording(null)
|
||||
setNote(
|
||||
clashes.length === 0
|
||||
? { text: `${recording.label} is now ${chordText(chord)}`, warning: false }
|
||||
: { text: `${chordText(chord)} is also ${clashes.map((clash) => clash.label).join(', ')}`, warning: true }
|
||||
)
|
||||
}
|
||||
window.addEventListener('keydown', record, true)
|
||||
return () => window.removeEventListener('keydown', record, true)
|
||||
}, [recording, rows])
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="max-w-[560px] bg-card">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="text-[15px]">Settings</DialogTitle>
|
||||
<DialogDescription>Click a shortcut's keys, then press the new key. Esc can be chosen too; click the keys again to cancel.</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="flex max-h-[60vh] flex-col gap-3 overflow-y-auto pr-1">
|
||||
<GraphicsSection />
|
||||
{GROUPS.map((group) => (
|
||||
<section key={group}>
|
||||
<h3 className="mb-1 text-[11px] font-semibold text-muted-foreground">{group}</h3>
|
||||
{rows
|
||||
.filter((row) => row.group === group)
|
||||
.map((row) => (
|
||||
<ShortcutRowView
|
||||
key={row.id}
|
||||
row={row}
|
||||
keys={chordsOf(row.id, bindings)}
|
||||
changed={bindings[row.id] !== undefined}
|
||||
recording={recording?.id === row.id}
|
||||
onRecord={() => setRecording((current) => (current?.id === row.id ? null : row))}
|
||||
onReset={() => {
|
||||
setRecording(null)
|
||||
shortcutStore.reset(row.id)
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</section>
|
||||
))}
|
||||
</div>
|
||||
<DialogFooter className="items-center sm:justify-between">
|
||||
<span className={cn('min-w-0 flex-1 truncate text-[12px]', note?.warning ? 'text-warning' : 'text-secondary-text')}>{note?.text}</span>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => {
|
||||
setRecording(null)
|
||||
setNote(null)
|
||||
shortcutStore.resetAll()
|
||||
}}
|
||||
>
|
||||
Reset all
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
|
||||
/** The GPU choice, shown only where there is an NVIDIA GPU to choose. Changing it restarts the studio. */
|
||||
function GraphicsSection(): React.JSX.Element | null {
|
||||
const [graphics, setGraphics] = useState<GraphicsInfo | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
void window.studio.graphics().then(setGraphics)
|
||||
}, [])
|
||||
|
||||
if (graphics === null || !graphics.canUseDedicatedGpu) {
|
||||
return null
|
||||
}
|
||||
const dedicated = graphics.usesDedicatedGpu
|
||||
return (
|
||||
<section>
|
||||
<h3 className="mb-1 text-[11px] font-semibold text-muted-foreground">Graphics</h3>
|
||||
<div className="flex items-center gap-2 py-0.5">
|
||||
<span className="min-w-0 flex-1 truncate text-secondary-text">Draw with the NVIDIA GPU (restarts)</span>
|
||||
<Button variant="outline" size="xs" className="w-36" onClick={() => window.studio.useDedicatedGpu(!dedicated)}>
|
||||
{dedicated ? 'On' : 'Off'}
|
||||
</Button>
|
||||
<span className="w-14" />
|
||||
</div>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
interface ShortcutRowViewProps {
|
||||
row: ShortcutRow
|
||||
keys: string[]
|
||||
changed: boolean
|
||||
recording: boolean
|
||||
onRecord(): void
|
||||
onReset(): void
|
||||
}
|
||||
|
||||
function ShortcutRowView({ row, keys, changed, recording, onRecord, onReset }: ShortcutRowViewProps): React.JSX.Element {
|
||||
return (
|
||||
<div className="flex items-center gap-2 py-0.5">
|
||||
<span className="min-w-0 flex-1 truncate text-secondary-text" title={row.label}>
|
||||
{row.label}
|
||||
</span>
|
||||
<Button variant="outline" size="xs" className={cn('w-36', recording && 'border-ring')} onClick={onRecord} title="Click, then press the new key">
|
||||
{recording ? RECORDING_TEXT : keys.length === 0 ? NO_KEYS_TEXT : chordsText(keys)}
|
||||
</Button>
|
||||
<Button
|
||||
variant="link"
|
||||
size="xs"
|
||||
className={cn('w-14 text-link', !changed && 'invisible')}
|
||||
onClick={onReset}
|
||||
title={chordsText(defaultChords(row.id)) || NO_KEYS_TEXT}
|
||||
>
|
||||
Default
|
||||
</Button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
import type { ReactNode } from 'react'
|
||||
import { Blocks, Mountain, PawPrint, SquareDashed, SunMoon } from 'lucide-react'
|
||||
import { Blocks, Mountain, PawPrint, SquareDashed } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Kbd } from '@/components/ui/kbd'
|
||||
import { Separator } from '@/components/ui/separator'
|
||||
import { Toggle } from '@/components/ui/toggle'
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'
|
||||
import type { ThemeChoice } from '../../../shared/bridge'
|
||||
import type { WorldInfo } from '../bridge/types'
|
||||
import { Glyph } from './Glyph'
|
||||
import type { StudioToggles } from './MapStudio'
|
||||
@@ -14,16 +13,13 @@ import { useKeyText } from './useBindings'
|
||||
|
||||
interface StudioToolbarProps {
|
||||
world: WorldInfo
|
||||
theme: { choice: ThemeChoice; next: () => void }
|
||||
onHelp(): void
|
||||
onSettings(): void
|
||||
onDisconnect(): void
|
||||
}
|
||||
|
||||
const THEME_NAMES: Record<ThemeChoice, string> = { system: 'Theme: system', light: 'Theme: light', dark: 'Theme: dark' }
|
||||
|
||||
/** The window's bar: the world the studio is connected to, which leads back to the world list, and the studio's own buttons. */
|
||||
export function StudioToolbar({ world, theme, onHelp, onSettings, onDisconnect }: StudioToolbarProps): React.JSX.Element {
|
||||
export function StudioToolbar({ world, onHelp, onSettings, onDisconnect }: StudioToolbarProps): React.JSX.Element {
|
||||
return (
|
||||
<header className="flex h-10 shrink-0 items-center gap-1 px-1.5">
|
||||
<IconHint hint="Back to the world list">
|
||||
@@ -37,9 +33,6 @@ export function StudioToolbar({ world, theme, onHelp, onSettings, onDisconnect }
|
||||
</Button>
|
||||
</IconHint>
|
||||
<div className="flex-1" />
|
||||
<MainToolbarButton hint={THEME_NAMES[theme.choice]} onClick={theme.next}>
|
||||
<SunMoon className="size-5" />
|
||||
</MainToolbarButton>
|
||||
<MainToolbarButton action="help" hint="Show every mouse and key shortcut" onClick={onHelp}>
|
||||
<Glyph glyph="help" large />
|
||||
</MainToolbarButton>
|
||||
|
||||
@@ -3,7 +3,6 @@ import type { ThemeChoice } from '../../../shared/bridge'
|
||||
|
||||
const STORAGE_KEY = 'iris-studio.theme'
|
||||
const DARK_QUERY = '(prefers-color-scheme: dark)'
|
||||
const ORDER: ThemeChoice[] = ['system', 'light', 'dark']
|
||||
|
||||
function storedChoice(): ThemeChoice {
|
||||
const stored = localStorage.getItem(STORAGE_KEY)
|
||||
@@ -15,8 +14,13 @@ function apply(choice: ThemeChoice): void {
|
||||
document.documentElement.classList.toggle('dark', dark)
|
||||
}
|
||||
|
||||
export interface Theme {
|
||||
choice: ThemeChoice
|
||||
choose(choice: ThemeChoice): void
|
||||
}
|
||||
|
||||
/** The light or dark look, following the system unless chosen; the choice outlives the window. */
|
||||
export function useTheme(): { choice: ThemeChoice; next: () => void } {
|
||||
export function useTheme(): Theme {
|
||||
const [choice, setChoice] = useState<ThemeChoice>(storedChoice)
|
||||
|
||||
useEffect(() => {
|
||||
@@ -29,5 +33,5 @@ export function useTheme(): { choice: ThemeChoice; next: () => void } {
|
||||
return () => media.removeEventListener('change', follow)
|
||||
}, [choice])
|
||||
|
||||
return { choice, next: () => setChoice(ORDER[(ORDER.indexOf(choice) + 1) % ORDER.length]) }
|
||||
return { choice, choose: setChoice }
|
||||
}
|
||||
@@ -11,6 +11,22 @@ export type StoredShortcuts = Record<string, string[]>
|
||||
|
||||
export type ThemeChoice = 'system' | 'light' | 'dark'
|
||||
|
||||
/** How large the studio draws its text and controls, as a zoom factor of the window. */
|
||||
export const UI_SCALES = [0.9, 1, 1.1, 1.25] as const
|
||||
export type UiScale = (typeof UI_SCALES)[number]
|
||||
export const DEFAULT_UI_SCALE: UiScale = 1
|
||||
|
||||
export function isUiScale(value: unknown): value is UiScale {
|
||||
return UI_SCALES.includes(value as UiScale)
|
||||
}
|
||||
|
||||
/** The studio's version and the runtime it is built on. */
|
||||
export interface AboutInfo {
|
||||
version: string
|
||||
electron: string
|
||||
chromium: string
|
||||
}
|
||||
|
||||
export interface GraphicsInfo {
|
||||
/** Whether this machine has an NVIDIA GPU the studio can be asked to draw on. */
|
||||
canUseDedicatedGpu: boolean
|
||||
@@ -31,6 +47,10 @@ export interface StudioHost {
|
||||
graphics(): Promise<GraphicsInfo>
|
||||
/** Saves the choice and restarts the studio, which only picks its GPU when it starts. */
|
||||
useDedicatedGpu(dedicated: boolean): void
|
||||
uiScale(): Promise<UiScale>
|
||||
/** Saves the scale and applies it to the window at once. */
|
||||
setUiScale(scale: UiScale): void
|
||||
about(): Promise<AboutInfo>
|
||||
}
|
||||
|
||||
const LINK_PROTOCOL = 'iris-studio:'
|
||||
|
||||
Reference in new issue
Block a user