import React from 'react' import { openURL } from 'renderer/viewer/lib/simpleUtils' import { haveDirectoryPicker } from '../utils' import { ConnectOptions } from '../connect' import styles from './mainMenu.module.css' import Button from './Button' import ButtonWithTooltip from './ButtonWithTooltip' import { pixelartIcons } from './PixelartIcon' import useLongPress from './useLongPress' type Action = (e: React.MouseEvent) => void interface Props { connectToServerAction?: Action singleplayerAction?: Action optionsAction?: Action githubAction?: Action linksButton?: JSX.Element openFileAction?: Action mapsProvider?: string versionStatus?: string versionTitle?: string onVersionStatusClick?: () => void bottomRightLinks?: string versionText?: string onVersionTextClick?: () => void } const httpsRegex = /^https?:\/\// export default ({ connectToServerAction, mapsProvider, singleplayerAction, optionsAction, githubAction, linksButton, openFileAction, versionText, onVersionTextClick, versionStatus, versionTitle, onVersionStatusClick, bottomRightLinks }: Props) => { if (!bottomRightLinks?.trim()) bottomRightLinks = undefined // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion const linksParsed = bottomRightLinks?.split(/;|\n/g).map(l => { const parts = l.split(':') return [parts[0], parts.slice(1).join(':')] }) as Array<[string, string]> | undefined const singleplayerLongPress = useLongPress( () => { window.location.href = window.location.pathname + '?sp=1' }, () => singleplayerAction?.(null as any), { delay: 500 } ) const versionLongPress = useLongPress( () => { const buildDate = process.env.BUILD_VERSION ? new Date(process.env.BUILD_VERSION) : null alert(`BUILD INFO:\n${buildDate?.toLocaleString() || 'Development build'}`) }, () => onVersionTextClick?.(), ) const connectToServerLongPress = useLongPress( () => { if (process.env.NODE_ENV === 'development') { // Connect to :25565 const origin = window.location.hostname const connectOptions: ConnectOptions = { server: `${origin}:25565`, username: 'test', } dispatchEvent(new CustomEvent('connect', { detail: connectOptions })) } }, () => connectToServerAction?.(null as any), { delay: 500 } ) return (
Prismarine is a beautiful block
Connect to server
Singleplayer mapsProvider && openURL(httpsRegex.test(mapsProvider) ? mapsProvider : 'https://' + mapsProvider, false)} />
GitHub {linksButton}
{versionText} Prismarine Web Client {versionStatus}
{linksParsed?.map(([name, link], i, arr) => { if (!link.startsWith('http')) link = `https://${link}` return
{name} {i < arr.length - 1 && ยท}
})}
A Minecraft client in the browser!
) }