Skip to content

A lightweight Clip Studio Paint alternative with real-time multiplayer collaborative drawing. Built with Tauri and React.

12.3 KB
Raw Blame
import React, { useEffect, useState } from 'react';
import {
  Bug,
  Check,
  Copy,
  ExternalLink,
  Info,
  RefreshCw,
  X,
} from 'lucide-react';
import { version as APP_VERSION } from '../../package.json';
import { isTauriEnvironment } from '../hooks/useMultiplayer';
import { updaterService } from '../services/updaterService';
import { useUiStore } from '../stores';
import { useUpdaterStore } from '../stores/useUpdaterStore';
import type { ChromeStyle } from '../types/appearance';
import {
  GITHUB_ISSUES_URL,
  GITHUB_LICENSE_URL,
  openExternalUrl,
} from '../utils/externalLinks';
import { getChangelogForVersion } from '../utils/changelog';
import { ChangelogBox } from './ChangelogBox';
import { COMMUNITY_LINKS } from './SocialIcons';
import { isImeComposing, useI18n } from '../i18n';

export interface AboutModalProps {
  isOpen: boolean;
  onClose: () => void;
  showToast?: (msg: string) => void;
}

export const AboutModal: React.FC<AboutModalProps> = ({
  isOpen,
  onClose,
  showToast,
}) => {
  const { t, td } = useI18n();
  const isDesktopTauri = isTauriEnvironment();
  const runtimeAppVersion = useUpdaterStore((s) => s.currentVersion);
  const chromeStyle: ChromeStyle = useUiStore(
    (s) => s.appSettings.appearance?.chromeStyle ?? 'hairline'
  );
  const [copied, setCopied] = useState(false);

  useEffect(() => {
    if (isOpen && isDesktopTauri) {
      void updaterService.resolveCurrentVersion();
    }
  }, [isOpen, isDesktopTauri]);

  useEffect(() => {
    if (!isOpen) {
      setCopied(false);
      return;
    }

    const handleKeyDown = (e: KeyboardEvent) => {
      if (isImeComposing(e)) return;
      if (e.key === 'Escape') {
        e.preventDefault();
        onClose();
      }
    };

    window.addEventListener('keydown', handleKeyDown);
    return () => window.removeEventListener('keydown', handleKeyDown);
  }, [isOpen, onClose]);

  useEffect(() => {
    if (!copied) return;
    const timer = window.setTimeout(() => setCopied(false), 1800);
    return () => window.clearTimeout(timer);
  }, [copied]);

  if (!isOpen) {
    return null;
  }

  const version = runtimeAppVersion || APP_VERSION;
  const changelogEntry = getChangelogForVersion(version) ?? getChangelogForVersion();
  const rawEnvLabel = isDesktopTauri ? 'Desktop' : 'Web';
  const envLabel = t(rawEnvLabel);
  const buildInfo = `Ink Studio v${version} (${rawEnvLabel})`;

  const handleCopyVersion = async () => {
    try {
      await navigator.clipboard.writeText(buildInfo);
      setCopied(true);
      showToast?.(t('Copied version info'));
    } catch {
      showToast?.(t('Failed to copy version info'));
    }
  };

  const handleCheckUpdates = () => {
    onClose();
    updaterService.openUpdateModal();
    const st = useUpdaterStore.getState().status;
    if (st !== 'downloading' && st !== 'ready') {
      void updaterService.checkForUpdates({ silent: false });
    }
  };

  const linkButtonChrome =
    chromeStyle === 'flat'
      ? 'group ui-icon-stroke inline-flex items-center gap-1.5 h-[var(--ui-control-height)] px-2.5 rounded-ui-sm bg-ui-control/80 hover:bg-ui-control-hover border border-ui-subtle hover:border-ui-default text-[11px] text-ui-secondary hover:text-ui-primary transition-colors cursor-pointer focus:outline-none focus-visible:border-ui-focus'
      : chromeStyle === 'islands'
        ? 'group ui-icon-stroke inline-flex items-center gap-1.5 h-[var(--ui-control-height)] px-2.5 rounded-ui-md bg-ui-panel hover:bg-ui-control-hover border border-ui-default hover:border-ui-strong shadow-xs text-[11px] text-ui-secondary hover:text-ui-primary transition-colors cursor-pointer focus:outline-none focus-visible:border-ui-focus'
        : 'group ui-icon-stroke inline-flex items-center gap-1.5 h-[var(--ui-control-height)] px-2.5 rounded-ui-sm bg-ui-control hover:bg-ui-control-hover border border-ui-default hover:border-ui-strong text-[11px] text-ui-secondary hover:text-ui-primary transition-colors cursor-pointer focus:outline-none focus-visible:border-ui-focus';

  return (
    <div
      role="dialog"
      aria-modal="true"
      aria-labelledby="about-modal-title"
      data-testid="about-modal"
      data-chrome-style={chromeStyle}
      className="fixed inset-0 z-50 flex items-center justify-center bg-ui-overlay p-4 select-none"
      onClick={onClose}
    >
      <div
        onClick={(e) => e.stopPropagation()}
        className="bg-ui-panel rounded-ui-lg shadow-ui-popover w-full max-w-lg max-h-[85vh] flex flex-col overflow-hidden text-xs text-ui-primary border border-ui-default"
      >
        {/* Header */}
        <div className="h-10 px-4 flex items-center justify-between bg-ui-header border-b border-ui-subtle shrink-0">
          <div className="flex items-center gap-2">
            <Info className="w-3.5 h-3.5 text-ui-accent" />
            <span id="about-modal-title" className="text-xs font-medium text-ui-primary">
              {t('About Ink Studio')}
            </span>
          </div>
          <button
            type="button"
            onClick={onClose}
            className="w-6 h-6 rounded-ui-sm flex items-center justify-center text-ui-muted hover:text-ui-primary hover:bg-ui-control-hover transition-colors cursor-pointer"
            title={t('Close (Esc)')}
            aria-label={t('Close about dialog')}
          >
            <X className="w-3.5 h-3.5" />
          </button>
        </div>

        {/* Body */}
        <div className="p-5 space-y-4 overflow-y-auto min-h-0">
          {/* App identity */}
          <div className="flex items-center gap-3.5">
            <div className="w-12 h-12 rounded-ui-md bg-ui-header border border-ui-subtle flex items-center justify-center shrink-0">
              <img
                src="/app-icon.png"
                alt="Ink Studio"
                className="w-8 h-8 object-contain"
              />
            </div>
            <div className="min-w-0">
              <div className="flex items-center gap-2">
                <h2 className="text-sm font-semibold text-ui-primary">Ink Studio</h2>
                <span className="font-ui-mono tabular-nums text-[10px] px-1.5 py-0.5 rounded-ui-xs bg-ui-header border border-ui-subtle text-ui-secondary">
                  v{version}
                </span>
              </div>
              <p className="text-[11px] text-ui-muted mt-0.5">
                {t("Drawing software that doesn't charge you rent.")}
              </p>
            </div>
          </div>

          {/* Description */}
          <div className="space-y-2 text-[11px] text-ui-secondary leading-relaxed select-text">
            <p>
              {t("Built by Sora because paying a monthly subscription just to draw lines on a screen got old. It opens PSD and CSP files, loads .sut brushes, handles layers, manga tools, and multiplayer, and mostly behaves itself when you aren't looking.")}
            </p>
            <p className="text-ui-muted">
              {t('No accounts, no telemetry, no forced AI slop, no cloud launcher eating your RAM. Hit Ctrl+S anyway. All software is held together by spite and duct tape.')}
            </p>
          </div>

          {/* Build metadata */}
          <div className="bg-ui-header rounded-ui-md border border-ui-subtle divide-y divide-ui-subtle text-[11px]">
            <div className="px-3 py-2 flex items-center justify-between gap-2">
              <span className="text-ui-muted">{t('Build')}</span>
              <div className="flex items-center gap-2">
                <span className="font-ui-mono tabular-nums text-ui-primary select-text">
                  v{version} · {envLabel}
                </span>
                <button
                  type="button"
                  onClick={() => void handleCopyVersion()}
                  className="inline-flex items-center gap-1 px-1.5 py-0.5 rounded-ui-xs bg-ui-control hover:bg-ui-control-hover border border-ui-subtle text-[10px] text-ui-secondary hover:text-ui-primary transition-colors cursor-pointer"
                  title={t('Copy version info')}
                >
                  {copied ? (
                    <>
                      <Check className="w-3 h-3 text-ui-success" />
                      <span className="text-ui-success">{t('Copied')}</span>
                    </>
                  ) : (
                    <>
                      <Copy className="w-3 h-3" />
                      <span>{t('Copy')}</span>
                    </>
                  )}
                </button>
              </div>
            </div>

            <div className="px-3 py-2 flex items-center justify-between gap-2">
              <span className="text-ui-muted">{t('License')}</span>
              <button
                type="button"
                onClick={() => void openExternalUrl(GITHUB_LICENSE_URL)}
                className="inline-flex items-center gap-1 text-ui-primary hover:text-ui-accent transition-colors cursor-pointer"
              >
                <span>GNU GPL v3.0</span>
                <ExternalLink className="w-3 h-3 opacity-70" />
              </button>
            </div>

            <div className="px-3 py-2 flex items-center justify-between gap-2">
              <span className="text-ui-muted">{t('Stack')}</span>
              <span className="font-ui-mono text-ui-secondary">
                {isDesktopTauri ? 'Tauri · Rust · React · WebGL' : 'React · TypeScript · WebGL'}
              </span>
            </div>
          </div>

          {/* What's New / Changelog */}
          {changelogEntry && (
            <div className="space-y-1.5">
              <div className="flex items-center justify-between">
                <span className="text-[11px] font-medium text-ui-primary tabular-nums">
                  {t("What's New in v{version}", { version: changelogEntry.version })}
                </span>
              </div>
              <ChangelogBox entry={changelogEntry} maxHeightClass="max-h-40" />
            </div>
          )}

          {/* Links & actions */}
          <div
            data-testid="about-community-links"
            className="flex flex-wrap items-center gap-2"
          >
            {COMMUNITY_LINKS.map((link) => (
              <a
                key={link.id}
                href={link.url}
                target="_blank"
                rel="noopener noreferrer"
                data-testid={`about-link-${link.id}`}
                title={td(link.title)}
                onClick={(e) => {
                  e.preventDefault();
                  void openExternalUrl(link.url);
                }}
                className={linkButtonChrome}
              >
                {link.renderIcon('w-3.5 h-3.5 text-ui-icon-muted group-hover:text-ui-primary transition-colors shrink-0')}
                <span>{td(link.label)}</span>
              </a>
            ))}

            <a
              href={GITHUB_ISSUES_URL}
              target="_blank"
              rel="noopener noreferrer"
              data-testid="about-link-issues"
              title={t('Report a bug or request a feature on GitHub')}
              onClick={(e) => {
                e.preventDefault();
                void openExternalUrl(GITHUB_ISSUES_URL);
              }}
              className={linkButtonChrome}
            >
              <Bug className="w-3.5 h-3.5 text-ui-icon-muted group-hover:text-ui-primary transition-colors shrink-0" />
              <span>{t('Report a Bug')}</span>
            </a>

            {isDesktopTauri && (
              <button
                type="button"
                onClick={handleCheckUpdates}
                className={linkButtonChrome}
              >
                <RefreshCw className="w-3.5 h-3.5 text-ui-icon-muted group-hover:text-ui-primary transition-colors shrink-0" />
                <span>{t('Updates')}</span>
              </button>
            )}
          </div>
        </div>

        {/* Footer */}
        <div className="px-4 py-2.5 bg-ui-header flex items-center justify-between gap-3 border-t border-ui-subtle">
          <span className="text-[10px] text-ui-muted">
            {t('© 2026 Sora · Provided as-is, no warranty.')}
          </span>
          <button
            type="button"
            onClick={onClose}
            className="px-3.5 py-1.5 rounded-ui-sm bg-ui-accent text-ui-accent-contrast hover:opacity-90 font-medium transition-opacity cursor-pointer"
          >
            {t('Close')}
          </button>
        </div>
      </div>
    </div>
  );
};