mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2025-12-05 21:15:38 -05:00
DMS Version Formatting
This commit is contained in:
@@ -2,6 +2,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/AvengeMedia/DankMaterialShell/core/internal/log"
|
"github.com/AvengeMedia/DankMaterialShell/core/internal/log"
|
||||||
@@ -152,7 +154,55 @@ var pluginsUninstallCmd = &cobra.Command{
|
|||||||
|
|
||||||
func runVersion(cmd *cobra.Command, args []string) {
|
func runVersion(cmd *cobra.Command, args []string) {
|
||||||
printASCII()
|
printASCII()
|
||||||
fmt.Printf("%s\n", Version)
|
fmt.Printf("%s\n", formatVersion(Version))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Git builds: dms (git) v0.6.2-XXXX
|
||||||
|
// Stable releases: dms v0.6.2
|
||||||
|
func formatVersion(version string) string {
|
||||||
|
// Arch/Debian/Ubuntu/OpenSUSE git format: 0.6.2+git2264.c5c5ce84
|
||||||
|
re := regexp.MustCompile(`^([\d.]+)\+git(\d+)\.`)
|
||||||
|
if matches := re.FindStringSubmatch(version); matches != nil {
|
||||||
|
return fmt.Sprintf("dms (git) v%s-%s", matches[1], matches[2])
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fedora COPR git format: 0.0.git.2267.d430cae9
|
||||||
|
re = regexp.MustCompile(`^[\d.]+\.git\.(\d+)\.`)
|
||||||
|
if matches := re.FindStringSubmatch(version); matches != nil {
|
||||||
|
baseVersion := getBaseVersion()
|
||||||
|
return fmt.Sprintf("dms (git) v%s-%s", baseVersion, matches[1])
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stable release format: 0.6.2
|
||||||
|
re = regexp.MustCompile(`^([\d.]+)$`)
|
||||||
|
if matches := re.FindStringSubmatch(version); matches != nil {
|
||||||
|
return fmt.Sprintf("dms v%s", matches[1])
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("dms %s", version)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getBaseVersion() string {
|
||||||
|
paths := []string{
|
||||||
|
"/usr/share/quickshell/dms/VERSION",
|
||||||
|
"/usr/local/share/quickshell/dms/VERSION",
|
||||||
|
"/etc/xdg/quickshell/dms/VERSION",
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, path := range paths {
|
||||||
|
if content, err := os.ReadFile(path); err == nil {
|
||||||
|
ver := strings.TrimSpace(string(content))
|
||||||
|
ver = strings.TrimPrefix(ver, "v")
|
||||||
|
if re := regexp.MustCompile(`^([\d.]+)`); re.MatchString(ver) {
|
||||||
|
if matches := re.FindStringSubmatch(ver); matches != nil {
|
||||||
|
return matches[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback
|
||||||
|
return "0.6.2"
|
||||||
}
|
}
|
||||||
|
|
||||||
func startDebugServer() error {
|
func startDebugServer() error {
|
||||||
|
|||||||
@@ -165,12 +165,24 @@ Item {
|
|||||||
text: {
|
text: {
|
||||||
if (!SystemUpdateService.shellVersion) return "dms";
|
if (!SystemUpdateService.shellVersion) return "dms";
|
||||||
|
|
||||||
// Git versioning to show ex: "dms v0.6.2-2223"
|
|
||||||
let version = SystemUpdateService.shellVersion;
|
let version = SystemUpdateService.shellVersion;
|
||||||
let match = version.match(/^([\d.]+)\+git(\d+)\./);
|
|
||||||
|
|
||||||
|
// Debian/Ubuntu/OpenSUSE git format: 0.6.2+git2264.c5c5ce84
|
||||||
|
let match = version.match(/^([\d.]+)\+git(\d+)\./);
|
||||||
if (match) {
|
if (match) {
|
||||||
return `dms v${match[1]}-${match[2]}`;
|
return `dms (git) v${match[1]}-${match[2]}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fedora COPR git format: 0.0.git.2267.d430cae9
|
||||||
|
match = version.match(/^[\d.]+\.git\.(\d+)\./);
|
||||||
|
if (match) {
|
||||||
|
return `dms (git) v0.6.2-${match[1]}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stable release format: 0.6.2
|
||||||
|
match = version.match(/^([\d.]+)$/);
|
||||||
|
if (match) {
|
||||||
|
return `dms v${match[1]}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return `dms ${version}`;
|
return `dms ${version}`;
|
||||||
|
|||||||
Reference in New Issue
Block a user