Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/features/library/changes-tab.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { useState } from "react"
import { toast } from "sonner"
import { Button } from "@/components/ui/button"
import { Dialog } from "@/components/ui/dialog"
import { useT } from "@/i18n"
import { openUrl } from "@/lib/api"
import { run, useStore } from "@/lib/store"
import type { Project } from "@/lib/types"
import { githubVersionLinks } from "@/lib/version-links"

export function ChangesTab({ project: p }: { project: Project }) {
const t = useT()
const busy = useStore((s) => !!s.snap?.job.running || (s.snap?.active_builds ?? 0) > 0)
const [confirm, setConfirm] = useState(false)
const links = p.kind === "git" && !p.listing.nuked ? githubVersionLinks(p.web_url, p.built, p.update) : null
const value = (sha: string | null) => sha || t("library.details.versionUnknown")
const browse = (url: string) => void openUrl(url).catch((error) => toast.error(String(error)))
return (
<section className="max-w-[760px] space-y-4">
<h2 className="font-semibold">{t("library.tabs.changes")}</h2>
<dl className="space-y-3 rounded-xl border border-line p-4 text-body">
<div><dt className="text-fg-3">{t("library.changes.installed")}</dt><dd className="break-all font-mono">{value(p.built)}</dd></div>
<div><dt className="text-fg-3">{t("library.changes.available")}</dt><dd className="break-all font-mono">{p.update ? value(p.update) : t("library.changes.noUpdate")}</dd></div>
<div><dt className="text-fg-3">{t("library.changes.previous")}</dt><dd className="break-all font-mono">{p.previous_build === null ? "—" : value(p.previous_build)}</dd></div>
</dl>
<div className="flex flex-wrap gap-2">
{p.kind === "git" && !p.listing.nuked && <Button disabled={p.checking || busy} onClick={() => void run({ type: "check_repo", repo: p.repo })}>{t("library.menu.checkUpdates")}</Button>}
{links?.compare && <Button onClick={() => browse(links.compare!)}>{t("library.changes.compare")}</Button>}
{links && <Button variant="ghost" onClick={() => browse(links.releases)}>{t("library.changes.releases")}</Button>}
{p.kind === "git" && p.previous_build !== null && <Button variant="ghost" disabled={busy} onClick={() => setConfirm(true)}>{t("library.note.restore")}</Button>}
</div>
<p className="text-caption text-fg-3">{t("library.changes.hint")}</p>
<Dialog open={confirm} onOpenChange={setConfirm} title={t("library.changes.confirm")} description={t("library.changes.restoreHint")} footer={
<>
<Button variant="primary" disabled={busy} onClick={() => { setConfirm(false); void run({ type: "rollback", repo: p.repo }) }}>{t("common.confirm")}</Button>
<Button variant="ghost" onClick={() => setConfirm(false)}>{t("common.cancel")}</Button>
</>
} />
</section>
)
}
8 changes: 6 additions & 2 deletions src/features/library/project-tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { Project } from "@/lib/types"
import { cn } from "@/lib/utils"
import { ActivityTab } from "./activity-tab"
import { GraphicsTab } from "./graphics-tab"
import { ChangesTab } from "./changes-tab"
import { LaunchTab } from "./launch-tab"
import { NotesTab } from "./notes-tab"
import { OverviewTab } from "./overview-tab"
Expand All @@ -15,6 +16,7 @@ const TABS = [
{ id: "overview", labelKey: "library.tabs.overview" },
{ id: "graphics", labelKey: "library.tabs.graphics" },
{ id: "launch", labelKey: "library.tabs.launch" },
{ id: "changes", labelKey: "library.tabs.changes" },
{ id: "notes", labelKey: "library.tabs.notes" },
{ id: "activity", labelKey: "library.tabs.activity" },
] as const satisfies readonly { id: ProjectTab; labelKey: Key }[]
Expand All @@ -29,7 +31,7 @@ export function ProjectTabs({ project }: { project: Project }) {
const running = useStore((s) => s.snap?.job.running || (s.snap?.active_builds ?? 0) > 0)
const screenshot = useStore((s) => s.screenshot)
const listRef = useRef<HTMLDivElement>(null)
const hidden = screenshot && (tab === "launch" || tab === "notes" || tab === "activity")
const hidden = screenshot && (tab === "launch" || tab === "notes" || tab === "activity" || tab === "changes")
// Arrow keys move between tabs and open them (the WAI-ARIA tabs pattern, automatic activation).
const onKey = (e: React.KeyboardEvent) => {
const i = TABS.findIndex((x) => x.id === tab)
Expand All @@ -42,7 +44,7 @@ export function ProjectTabs({ project }: { project: Project }) {
}
return (
<div className="max-w-[1280px] px-10 pb-16">
<div ref={listRef} role="tablist" aria-label={t("library.tabs.label")} onKeyDown={onKey} className="flex gap-8 border-b border-line">
<div ref={listRef} role="tablist" aria-label={t("library.tabs.label")} onKeyDown={onKey} className="flex flex-wrap gap-x-8 border-b border-line">
{TABS.map((x) => (
<button
key={x.id}
Expand Down Expand Up @@ -82,6 +84,8 @@ export function ProjectTabs({ project }: { project: Project }) {
<GraphicsTab project={project} />
) : tab === "launch" ? (
<LaunchTab project={project} />
) : tab === "changes" ? (
<ChangesTab project={project} />
) : tab === "notes" ? (
<NotesTab project={project} />
) : (
Expand Down
12 changes: 12 additions & 0 deletions src/i18n/messages/en/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export default {
dontShow: "Don't show this again",
},
tabs: {
changes: "Changes",
label: "Project",
overview: "Overview",
graphics: "Graphics",
Expand All @@ -80,6 +81,17 @@ export default {
running: "Running",
hidden: "Hidden in Screenshot mode.",
},
changes: {
installed: "Installed commit",
available: "Available update",
previous: "Previous build",
noUpdate: "No update offered",
compare: "Compare commits on GitHub",
releases: "Releases and changelog",
hint: "Links open GitHub without installing anything. Commit history may be unavailable for other hosts or local builds.",
confirm: "Restore previous build?",
restoreHint: "This swaps the installed and previous build. It does not restore a saved game.",
},
overview: {
newBuild: "A new build is out",
versionHidden: "Version hidden",
Expand Down
12 changes: 12 additions & 0 deletions src/i18n/messages/es/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export default {
dontShow: "No volver a mostrar esto",
},
tabs: {
changes: "Cambios",
label: "Proyecto",
overview: "Resumen",
graphics: "Gráficos",
Expand All @@ -77,6 +78,17 @@ export default {
running: "En ejecución",
hidden: "Oculto en el modo captura.",
},
changes: {
installed: "Commit instalado",
available: "Actualización disponible",
previous: "Compilación anterior",
noUpdate: "No hay actualizaciones ofrecidas",
compare: "Comparar commits en GitHub",
releases: "Versiones y registro de cambios",
hint: "Los enlaces abren GitHub sin instalar nada. El historial puede no estar disponible para otros servidores o compilaciones locales.",
confirm: "¿Restaurar la compilación anterior?",
restoreHint: "Esto intercambia la compilación instalada y la anterior. No restaura una partida guardada.",
},
overview: {
newBuild: "Hay una nueva compilación disponible",
versionHidden: "Versión oculta",
Expand Down
12 changes: 12 additions & 0 deletions src/i18n/messages/fr/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export default {
dontShow: "Ne plus afficher ce message",
},
tabs: {
changes: "Modifications",
label: "Projet",
overview: "Aperçu",
graphics: "Graphismes",
Expand All @@ -77,6 +78,17 @@ export default {
running: "En cours",
hidden: "Masqué en mode capture d’écran.",
},
changes: {
installed: "Commit installé",
available: "Mise à jour disponible",
previous: "Build précédent",
noUpdate: "Aucune mise à jour proposée",
compare: "Comparer les commits sur GitHub",
releases: "Versions et journal des modifications",
hint: "Les liens ouvrent GitHub sans rien installer. L’historique peut être indisponible pour les autres hébergeurs ou les builds locaux.",
confirm: "Restaurer le build précédent ?",
restoreHint: "Cela échange le build installé et le précédent, sans restaurer de sauvegarde.",
},
overview: {
newBuild: "Un nouveau build est disponible",
versionHidden: "Version masquée",
Expand Down
12 changes: 12 additions & 0 deletions src/i18n/messages/ru/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export default {
dontShow: "Больше не показывать",
},
tabs: {
changes: "Изменения",
label: "Проект",
overview: "Обзор",
graphics: "Графика",
Expand All @@ -80,6 +81,17 @@ export default {
running: "Выполняется",
hidden: "Скрыто в режиме скриншотов.",
},
changes: {
installed: "Установленный коммит",
available: "Доступное обновление",
previous: "Предыдущая сборка",
noUpdate: "Обновление не предложено",
compare: "Сравнить коммиты на GitHub",
releases: "Релизы и список изменений",
hint: "Ссылки открывают GitHub без установки. История может быть недоступна для других хостингов или локальных сборок.",
confirm: "Восстановить предыдущую сборку?",
restoreHint: "Установленная и предыдущая сборки поменяются местами. Игровые сохранения не восстанавливаются.",
},
overview: {
newBuild: "Вышла новая сборка",
versionHidden: "Версия скрыта",
Expand Down
12 changes: 12 additions & 0 deletions src/i18n/messages/zh-CN/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export default {
dontShow: "不再显示",
},
tabs: {
changes: "变更",
label: "项目",
overview: "概览",
graphics: "图形",
Expand All @@ -77,6 +78,17 @@ export default {
running: "运行中",
hidden: "截图模式下不显示。",
},
changes: {
installed: "已安装的提交",
available: "可用更新",
previous: "上一个构建版本",
noUpdate: "暂无可用更新",
compare: "在 GitHub 上比较提交",
releases: "发布版本与变更记录",
hint: "链接只打开 GitHub,不会安装任何内容。其他托管平台或本地构建版本可能没有提交历史。",
confirm: "还原上一个构建版本?",
restoreHint: "这会交换已安装版本和上一个构建版本,不会还原游戏存档。",
},
overview: {
newBuild: "有新的构建版本",
versionHidden: "已隐藏版本",
Expand Down
12 changes: 12 additions & 0 deletions src/i18n/messages/zh-TW/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export default {
dontShow: "不再顯示",
},
tabs: {
changes: "變更",
label: "專案",
overview: "總覽",
graphics: "圖形",
Expand All @@ -77,6 +78,17 @@ export default {
running: "執行中",
hidden: "截圖模式下不顯示。",
},
changes: {
installed: "已安裝的提交",
available: "可用更新",
previous: "上一個建置版本",
noUpdate: "暫無可用更新",
compare: "在 GitHub 上比較提交",
releases: "發布版本與變更記錄",
hint: "連結只開啟 GitHub,不會安裝任何內容。其他託管平台或本機建置版本可能沒有提交歷史。",
confirm: "還原上一個建置版本?",
restoreHint: "這會交換已安裝版本和上一個建置版本,不會還原遊戲存檔。",
},
overview: {
newBuild: "有新的建置版本",
versionHidden: "已隱藏版本",
Expand Down
2 changes: 1 addition & 1 deletion src/lib/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { act as send, getBackend } from "./api"
import type { Action, PlayChoice, Project, Snapshot } from "./types"

export type View = "library" | "settings"
export type ProjectTab = "overview" | "graphics" | "launch" | "notes" | "activity"
export type ProjectTab = "overview" | "graphics" | "launch" | "notes" | "activity" | "changes"

export type Dialog =
| { kind: "import" }
Expand Down
21 changes: 21 additions & 0 deletions src/lib/version-links.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { describe, expect, it } from "vitest"
import { githubVersionLinks } from "./version-links"

describe("githubVersionLinks", () => {
it("compares installed and offered commits", () => {
expect(githubVersionLinks("https://github.com/example/project", "1234567", "abcdef0")).toEqual({
releases: "https://github.com/example/project/releases",
compare: "https://github.com/example/project/compare/1234567...abcdef0",
})
})
it("does not compare unknown, equal or invalid versions", () => {
for (const [a, b] of [[null, "abcdef0"], ["local", "abcdef0"], ["1234567", "1234567"], ["1234567", "../other"]]) {
expect(githubVersionLinks("https://github.com/example/project", a, b)?.compare).toBeNull()
}
})
it("rejects non-GitHub links and non-repository paths", () => {
for (const url of [null, "https://github.com.evil.example/a/b", "http://github.com/a/b", "https://github.com/a/b/issues", "https://user@github.com/a/b"]) {
expect(githubVersionLinks(url, "1234567", "abcdef0")).toBeNull()
}
})
})
25 changes: 25 additions & 0 deletions src/lib/version-links.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/** Only link to a genuine GitHub repository and validated commit IDs.
* Custom hosts and local/ZIP builds do not have a known GitHub history.
*/
export function githubVersionLinks(
webUrl: string | null,
built: string | null,
update: string | null,
) {
if (!webUrl) return null
let url: URL
try {
url = new URL(webUrl)
} catch {
return null
}
if (url.origin !== "https://github.com" || url.username || url.password || url.search || url.hash) return null
const path = url.pathname.replace(/\/$/, "").replace(/\.git$/, "")
if (!/^\/[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(path)) return null
const root = url.origin + path
const valid = (sha: string | null): sha is string => !!sha && /^[a-f0-9]{7,40}$/i.test(sha)
return {
releases: root + "/releases",
compare: valid(built) && valid(update) && built !== update ? root + "/compare/" + built + "..." + update : null,
}
}