From 6aca04cddb345adf815ca110bf0894af0b7a9fff Mon Sep 17 00:00:00 2001 From: Ly-sec Date: Sun, 30 Nov 2025 10:54:20 +0100 Subject: [PATCH] AboutTab: add git commit if using -git version --- Assets/Translations/de.json | 3 + Assets/Translations/en.json | 3 + Assets/Translations/es.json | 3 + Assets/Translations/fr.json | 3 + Assets/Translations/ja.json | 3 + Assets/Translations/nl.json | 3 + Assets/Translations/pt.json | 3 + Assets/Translations/ru.json | 3 + Assets/Translations/tr.json | 3 + Assets/Translations/uk-UA.json | 3 + Assets/Translations/zh-CN.json | 3 + Modules/Panels/Settings/Tabs/AboutTab.qml | 118 ++++++++++++++++++++++ 12 files changed, 151 insertions(+) diff --git a/Assets/Translations/de.json b/Assets/Translations/de.json index f2689154..70eff142 100644 --- a/Assets/Translations/de.json +++ b/Assets/Translations/de.json @@ -791,6 +791,9 @@ }, "noctalia": { "download-latest": "Neueste Version herunterladen", + "git-commit": "Git-Commit:", + "git-commit-copy": "Commit-Hash kopieren", + "git-commit-loading": "Lädt...", "installed-version": "Installierte Version:", "latest-version": "Neueste Version:", "section": { diff --git a/Assets/Translations/en.json b/Assets/Translations/en.json index 7ed6dfd3..c1bad06b 100644 --- a/Assets/Translations/en.json +++ b/Assets/Translations/en.json @@ -791,6 +791,9 @@ }, "noctalia": { "download-latest": "Download latest release", + "git-commit": "Git commit:", + "git-commit-copy": "Copy commit hash", + "git-commit-loading": "Loading...", "installed-version": "Installed version:", "latest-version": "Latest version:", "section": { diff --git a/Assets/Translations/es.json b/Assets/Translations/es.json index c48eb2d4..4a4c2dfb 100644 --- a/Assets/Translations/es.json +++ b/Assets/Translations/es.json @@ -791,6 +791,9 @@ }, "noctalia": { "download-latest": "Descargar la última versión", + "git-commit": "Commit de Git:", + "git-commit-copy": "Copiar hash del commit", + "git-commit-loading": "Cargando...", "installed-version": "Versión instalada:", "latest-version": "Última versión:", "section": { diff --git a/Assets/Translations/fr.json b/Assets/Translations/fr.json index 15163092..aa23424c 100644 --- a/Assets/Translations/fr.json +++ b/Assets/Translations/fr.json @@ -791,6 +791,9 @@ }, "noctalia": { "download-latest": "Télécharger la dernière version", + "git-commit": "Commit Git :", + "git-commit-copy": "Copier le hash du commit", + "git-commit-loading": "Chargement...", "installed-version": "Version installée :", "latest-version": "Dernière version :", "section": { diff --git a/Assets/Translations/ja.json b/Assets/Translations/ja.json index 128ef7b1..69d6db83 100644 --- a/Assets/Translations/ja.json +++ b/Assets/Translations/ja.json @@ -791,6 +791,9 @@ }, "noctalia": { "download-latest": "最新版をダウンロード", + "git-commit": "Gitコミット:", + "git-commit-copy": "コミットハッシュをコピー", + "git-commit-loading": "読み込み中...", "installed-version": "現在のバージョン:", "latest-version": "最新のバージョン:", "section": { diff --git a/Assets/Translations/nl.json b/Assets/Translations/nl.json index 96685262..87e010cc 100644 --- a/Assets/Translations/nl.json +++ b/Assets/Translations/nl.json @@ -791,6 +791,9 @@ }, "noctalia": { "download-latest": "Nieuwste release downloaden", + "git-commit": "Git commit:", + "git-commit-copy": "Commit hash kopiëren", + "git-commit-loading": "Laden...", "installed-version": "Geïnstalleerde versie:", "latest-version": "Nieuwste versie:", "section": { diff --git a/Assets/Translations/pt.json b/Assets/Translations/pt.json index 9bc700ab..9aea8add 100644 --- a/Assets/Translations/pt.json +++ b/Assets/Translations/pt.json @@ -791,6 +791,9 @@ }, "noctalia": { "download-latest": "Baixar a versão mais recente", + "git-commit": "Commit Git:", + "git-commit-copy": "Copiar hash do commit", + "git-commit-loading": "Carregando...", "installed-version": "Versão instalada:", "latest-version": "Última versão:", "section": { diff --git a/Assets/Translations/ru.json b/Assets/Translations/ru.json index d9cfb7ba..cff9d09f 100644 --- a/Assets/Translations/ru.json +++ b/Assets/Translations/ru.json @@ -791,6 +791,9 @@ }, "noctalia": { "download-latest": "Скачать последний выпуск", + "git-commit": "Git коммит:", + "git-commit-copy": "Скопировать хеш коммита", + "git-commit-loading": "Загрузка...", "installed-version": "Установленная версия:", "latest-version": "Последняя версия:", "section": { diff --git a/Assets/Translations/tr.json b/Assets/Translations/tr.json index 6fb0a700..0541b48a 100644 --- a/Assets/Translations/tr.json +++ b/Assets/Translations/tr.json @@ -791,6 +791,9 @@ }, "noctalia": { "download-latest": "En son sürümü indir", + "git-commit": "Git commit:", + "git-commit-copy": "Commit hash'ini kopyala", + "git-commit-loading": "Yükleniyor...", "installed-version": "Yüklü sürüm:", "latest-version": "En son sürüm:", "section": { diff --git a/Assets/Translations/uk-UA.json b/Assets/Translations/uk-UA.json index 91260301..d78f4a2c 100644 --- a/Assets/Translations/uk-UA.json +++ b/Assets/Translations/uk-UA.json @@ -791,6 +791,9 @@ }, "noctalia": { "download-latest": "Завантажити останній реліз", + "git-commit": "Git коміт:", + "git-commit-copy": "Скопіювати хеш коміту", + "git-commit-loading": "Завантаження...", "installed-version": "Встановлена версія:", "latest-version": "Остання версія:", "section": { diff --git a/Assets/Translations/zh-CN.json b/Assets/Translations/zh-CN.json index 858a60d2..287c16de 100644 --- a/Assets/Translations/zh-CN.json +++ b/Assets/Translations/zh-CN.json @@ -791,6 +791,9 @@ }, "noctalia": { "download-latest": "下载最新版本", + "git-commit": "Git提交:", + "git-commit-copy": "复制提交哈希", + "git-commit-loading": "加载中...", "installed-version": "已安装版本:", "latest-version": "最新版本:", "section": { diff --git a/Modules/Panels/Settings/Tabs/AboutTab.qml b/Modules/Panels/Settings/Tabs/AboutTab.qml index 75d843cd..af1a1495 100644 --- a/Modules/Panels/Settings/Tabs/AboutTab.qml +++ b/Modules/Panels/Settings/Tabs/AboutTab.qml @@ -14,11 +14,98 @@ ColumnLayout { property string latestVersion: GitHubService.latestVersion property string currentVersion: UpdateService.currentVersion property var contributors: GitHubService.contributors + property string gitCommitHash: "" readonly property int topContributorsCount: 20 + readonly property bool isGitVersion: root.currentVersion.endsWith("-git") || root.hasArchGitVersion() + + property int _gitSearchDepth: 0 + readonly property int _maxGitSearchDepth: 5 spacing: Style.marginL + Component.onCompleted: { + if (root.isGitVersion) { + // First try to extract from Arch package version format (e.g., 3.4.0.r112.g3f00bec8-1) + var archHash = root.extractCommitFromArchVersion(); + if (archHash) { + root.gitCommitHash = archHash; + } else { + // Fall back to git command for git-cloned installations + fetchGitCommit(); + } + } + } + + function hasArchGitVersion() { + // Check if version matches Arch package format: X.Y.Z.rN.gHASH-REV + // Pattern: version.r.g- + return /\.r\d+\.g[0-9a-fA-F]+-/.test(root.currentVersion); + } + + function extractCommitFromArchVersion() { + // Extract commit hash from Arch package version format + // Format: 3.4.0.r112.g3f00bec8-1 or v3.4.0.r112.g3f00bec8-1 + // We want to extract the hash after ".g" and before "-" + var match = root.currentVersion.match(/\.g([0-9a-fA-F]+)-/i); + if (match && match[1]) { + // Return first 7 characters (short hash) + return match[1].substring(0, 7); + } + return ""; + } + + function fetchGitCommit() { + // Try to find git repository starting from shellDir and going up + var searchDir = Quickshell.shellDir || ""; + if (!searchDir) { + Logger.w("AboutTab", "Cannot determine shell directory, skipping git commit fetch"); + return; + } + + // Reset search depth + root._gitSearchDepth = 0; + + // Try current directory first, then parent directories + gitCommitProcess.workingDirectory = searchDir; + gitCommitProcess.running = true; + } + + Process { + id: gitCommitProcess + command: ["git", "rev-parse", "HEAD"] + running: false + + onExited: function (exitCode) { + if (exitCode === 0) { + var commitHash = stdout.text.trim(); + if (commitHash) { + // Show short hash (first 7 characters) + root.gitCommitHash = commitHash.substring(0, 7); + Logger.d("AboutTab", "Git commit hash:", root.gitCommitHash); + } + } else { + // If git command fails, try parent directory (up to max depth) + if (root._gitSearchDepth < root._maxGitSearchDepth) { + var currentDir = gitCommitProcess.workingDirectory || ""; + var parentDir = currentDir.split("/").slice(0, -1).join("/"); + if (parentDir && parentDir !== currentDir && parentDir.length > 0) { + root._gitSearchDepth++; + gitCommitProcess.workingDirectory = parentDir; + gitCommitProcess.running = true; + } else { + Logger.d("AboutTab", "Could not find git repository"); + } + } else { + Logger.d("AboutTab", "Could not find git repository (max search depth reached)"); + } + } + } + + stdout: StdioCollector {} + stderr: StdioCollector {} + } + NHeader { label: I18n.tr("settings.about.noctalia.section.label") description: I18n.tr("settings.about.noctalia.section.description") @@ -54,6 +141,37 @@ ColumnLayout { color: Color.mOnSurface font.weight: Style.fontWeightBold } + + // Git commit hash (only shown for -git versions) + NText { + visible: root.isGitVersion + text: I18n.tr("settings.about.noctalia.git-commit") + color: Color.mOnSurface + } + + RowLayout { + visible: root.isGitVersion + spacing: Style.marginXS + + NText { + text: root.gitCommitHash || I18n.tr("settings.about.noctalia.git-commit-loading") + color: Color.mOnSurface + font.weight: Style.fontWeightBold + font.family: "monospace" + } + + NIconButton { + visible: root.gitCommitHash !== "" + icon: "clipboard-copy" + tooltipText: I18n.tr("settings.about.noctalia.git-commit-copy") + baseSize: Style.baseWidgetSize * 0.7 + onClicked: { + if (root.gitCommitHash) { + Quickshell.execDetached(["sh", "-c", `echo -n "${root.gitCommitHash}" | wl-copy`]); + } + } + } + } } // Update button