diff --git a/studio/src/main/index.ts b/studio/src/main/index.ts index 749351ccb..f0cc00802 100644 --- a/studio/src/main/index.ts +++ b/studio/src/main/index.ts @@ -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 { } } -/** 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 { try { const settings: unknown = JSON.parse(readFileSync(settingsPath(), 'utf8')) - return typeof settings === 'object' && settings !== null && (settings as Record)[DEDICATED_GPU_KEY] === true + return typeof settings === 'object' && settings !== null && !Array.isArray(settings) ? (settings as Record) : {} } 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): 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) diff --git a/studio/src/preload/index.ts b/studio/src/preload/index.ts index 684dc4516..1a18bf23b 100644 --- a/studio/src/preload/index.ts +++ b/studio/src/preload/index.ts @@ -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) diff --git a/studio/src/renderer/src/studio/KeymapSettings.tsx b/studio/src/renderer/src/studio/KeymapSettings.tsx new file mode 100644 index 000000000..a6a5cf53c --- /dev/null +++ b/studio/src/renderer/src/studio/KeymapSettings.tsx @@ -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(null) + const [note, setNote] = useState(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 ( + + + setFilter(event.target.value)} /> + + } + footer={ + <> + {note?.text} + + + } + > + {shown.length === 0 &&

No shortcut matches

} + {GROUPS.map((group) => { + const groupRows = shown.filter((row) => row.group === group) + if (groupRows.length === 0) { + return null + } + return ( + + {groupRows.map((row) => ( + setRecording((current) => (current?.id === row.id ? null : row))} + onReset={() => { + setRecording(null) + shortcutStore.reset(row.id) + }} + /> + ))} + + ) + })} +
+ ) +} + +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 ( +
+ + {row.label} + + + +
+ ) +} diff --git a/studio/src/renderer/src/studio/MapStudio.tsx b/studio/src/renderer/src/studio/MapStudio.tsx index 8da67c1ce..f88381ba9 100644 --- a/studio/src/renderer/src/studio/MapStudio.tsx +++ b/studio/src/renderer/src/studio/MapStudio.tsx @@ -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 (
- setHelpOpen(true)} onSettings={() => setSettingsOpen(true)} onDisconnect={onDisconnect} /> + setHelpOpen(true)} onSettings={() => setSettingsOpen(true)} onDisconnect={onDisconnect} />
@@ -324,7 +324,7 @@ export function MapStudio({ client, world, theme, onDisconnect }: MapStudioProps - +
) } diff --git a/studio/src/renderer/src/studio/SettingsDialog.tsx b/studio/src/renderer/src/studio/SettingsDialog.tsx new file mode 100644 index 000000000..e17512d42 --- /dev/null +++ b/studio/src/renderer/src/studio/SettingsDialog.tsx @@ -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: }, + { id: 'keymap', label: 'Keymap', icon: }, + { id: 'graphics', label: 'Graphics', icon: } +] +const ABOUT_PAGE: PageLink = { id: 'about', label: 'About', icon: } + +const THEME_LABELS: Record = { 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('appearance') + return ( + + { + event.preventDefault() + ;(event.currentTarget as HTMLElement).focus() + }} + className="flex h-[min(600px,85vh)] gap-0 overflow-hidden p-0 sm:max-w-[860px]"> + + {page === 'appearance' && } + {page === 'keymap' && } + {page === 'graphics' && } + {page === 'about' && } + + + ) +} + +function PageButton({ link, chosen, onChoose }: { link: PageLink; chosen: boolean; onChoose(page: PageId): void }): React.JSX.Element { + return ( + + ) +} + +function AppearancePage({ theme }: { theme: Theme }): React.JSX.Element { + const [scale, chooseScale] = useUiScale() + return ( + + + + THEME_LABELS[choice]} onChange={theme.choose} /> + + + {scale !== null && `${Math.round(choice * PERCENT)}%`} onChange={chooseScale} />} + + + + ) +} + +function useUiScale(): [UiScale | null, (scale: UiScale) => void] { + const [scale, setScale] = useState(null) + useEffect(() => { + void window.studio.uiScale().then(setScale) + }, []) + const choose = (next: UiScale): void => { + setScale(next) + window.studio.setUiScale(next) + } + return [scale, choose] +} + +interface ChoiceProps { + 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({ value, options, label, onChange }: ChoiceProps): React.JSX.Element { + return ( + { + const option = options.find((candidate) => String(candidate) === chosen) + if (option !== undefined) { + onChange(option) + } + }} + > + {options.map((option) => ( + + {label(option)} + + ))} + + ) +} + +function GraphicsPage(): React.JSX.Element { + const [graphics, setGraphics] = useState(null) + useEffect(() => { + void window.studio.graphics().then(setGraphics) + }, []) + return ( + + + {graphics !== null && !graphics.canUseDedicatedGpu && ( + + System default + + )} + {graphics !== null && graphics.canUseDedicatedGpu && ( + + (choice === 'dedicated' ? 'dGPU' : 'System default')} + onChange={(choice) => window.studio.useDedicatedGpu(choice === 'dedicated')} + /> + + )} + + + ) +} + +function AboutPage(): React.JSX.Element { + const [about, setAbout] = useState(null) + useEffect(() => { + void window.studio.about().then(setAbout) + }, []) + return ( + + + + {about?.version} + + + {about?.electron} + + + {about?.chromium} + + + + + Apache License 2.0 + + + ISC License + + + + ) +} + +function LicenseLink({ href, children }: { href: string; children: ReactNode }): React.JSX.Element { + return ( + + {children} + + ) +} diff --git a/studio/src/renderer/src/studio/SettingsLayout.tsx b/studio/src/renderer/src/studio/SettingsLayout.tsx new file mode 100644 index 000000000..66d9081fd --- /dev/null +++ b/studio/src/renderer/src/studio/SettingsLayout.tsx @@ -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 ( +
+
+

{title}

+ {description !== undefined &&

{description}

} +
+ {toolbar !== undefined &&
{toolbar}
} + +
{children}
+
+ {footer !== undefined &&
{footer}
} +
+ ) +} + +/** 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 ( +
+ {title !== undefined &&

{title}

} + {children} +
+ ) +} + +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 ( +
+
+
{label}
+ {detail !== undefined &&
{detail}
} +
+
{children}
+
+ ) +} diff --git a/studio/src/renderer/src/studio/ShortcutSettings.tsx b/studio/src/renderer/src/studio/ShortcutSettings.tsx deleted file mode 100644 index 474470daa..000000000 --- a/studio/src/renderer/src/studio/ShortcutSettings.tsx +++ /dev/null @@ -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(null) - const [note, setNote] = useState(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 ( - - - - Settings - Click a shortcut's keys, then press the new key. Esc can be chosen too; click the keys again to cancel. - -
- - {GROUPS.map((group) => ( -
-

{group}

- {rows - .filter((row) => row.group === group) - .map((row) => ( - setRecording((current) => (current?.id === row.id ? null : row))} - onReset={() => { - setRecording(null) - shortcutStore.reset(row.id) - }} - /> - ))} -
- ))} -
- - {note?.text} - - -
-
- ) -} - -/** 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(null) - - useEffect(() => { - void window.studio.graphics().then(setGraphics) - }, []) - - if (graphics === null || !graphics.canUseDedicatedGpu) { - return null - } - const dedicated = graphics.usesDedicatedGpu - return ( -
-

Graphics

-
- Draw with the NVIDIA GPU (restarts) - - -
-
- ) -} - -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 ( -
- - {row.label} - - - -
- ) -} diff --git a/studio/src/renderer/src/studio/StudioToolbar.tsx b/studio/src/renderer/src/studio/StudioToolbar.tsx index cad8a03b4..f39eaedfc 100644 --- a/studio/src/renderer/src/studio/StudioToolbar.tsx +++ b/studio/src/renderer/src/studio/StudioToolbar.tsx @@ -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 = { 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 (
@@ -37,9 +33,6 @@ export function StudioToolbar({ world, theme, onHelp, onSettings, onDisconnect }
- - - diff --git a/studio/src/renderer/src/studio/theme.ts b/studio/src/renderer/src/studio/theme.ts index 2302a2cca..416d13d25 100644 --- a/studio/src/renderer/src/studio/theme.ts +++ b/studio/src/renderer/src/studio/theme.ts @@ -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(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 } } diff --git a/studio/src/shared/bridge.ts b/studio/src/shared/bridge.ts index 31448d371..bb73ad405 100644 --- a/studio/src/shared/bridge.ts +++ b/studio/src/shared/bridge.ts @@ -11,6 +11,22 @@ export type StoredShortcuts = Record 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 /** Saves the choice and restarts the studio, which only picks its GPU when it starts. */ useDedicatedGpu(dedicated: boolean): void + uiScale(): Promise + /** Saves the scale and applies it to the window at once. */ + setUiScale(scale: UiScale): void + about(): Promise } const LINK_PROTOCOL = 'iris-studio:'