|
6 | 6 | #include "util/binary.h"
|
7 | 7 | #include "util/path.h"
|
8 | 8 | #include "util/stringUtils.h"
|
| 9 | +#include "util/debug.h" |
9 | 10 |
|
10 | 11 | const char* ffDetectWMPlugin(FF_MAYBE_UNUSED FFstrbuf* pluginName)
|
11 | 12 | {
|
12 | 13 | return "Not supported on this platform";
|
13 | 14 | }
|
14 | 15 |
|
15 |
| -static bool extractHyprlandVersion(const char* line, FF_MAYBE_UNUSED uint32_t len, void *userdata) |
| 16 | +static bool extractHyprlandVersion(const char* line, uint32_t len, void *userdata) |
16 | 17 | {
|
| 18 | + if (line[0] != 'v') return true; |
| 19 | + ++line; --len; |
17 | 20 | int count = 0;
|
18 |
| - sscanf(line, " version: bump to v%*d.%*d.%*d%n", &count); |
| 21 | + sscanf(line, "%*d.%*d.%*d%n", &count); |
19 | 22 | if (count == 0) return true;
|
20 | 23 |
|
21 |
| - // SUPER hacky and doesn't work for development versions |
22 |
| - uint32_t prefixLen = (uint32_t) strlen(" version: bump to v"); // version bump commit message |
23 |
| - ffStrbufSetNS((FFstrbuf*) userdata, len - prefixLen, line + prefixLen); |
| 24 | + ffStrbufSetNS((FFstrbuf*) userdata, len, line); |
24 | 25 | return false;
|
25 | 26 | }
|
26 | 27 |
|
27 | 28 | static const char* getHyprland(FFstrbuf* result)
|
28 | 29 | {
|
29 |
| - FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate(); |
30 |
| - const char* error = ffFindExecutableInPath("Hyprland", &path); |
31 |
| - if (error) return "Failed to find Hyprland executable path"; |
| 30 | + FF_DEBUG("Detecting Hyprland version"); |
| 31 | + FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate(); |
| 32 | + |
| 33 | + FF_DEBUG("Checking for " FASTFETCH_TARGET_DIR_USR "/include/hyprland/src/version.h" " file"); |
| 34 | + if (ffReadFileBuffer(FASTFETCH_TARGET_DIR_USR "/include/hyprland/src/version.h", &buffer)) |
| 35 | + { |
| 36 | + FF_DEBUG("Found version.h file, extracting version"); |
| 37 | + if (ffStrbufSubstrAfterFirstS(&buffer, "\n#define GIT_TAG ")) |
| 38 | + { |
| 39 | + ffStrbufSubstrAfterFirstC(&buffer, '"'); |
| 40 | + ffStrbufSubstrBeforeFirstC(&buffer, '"'); |
| 41 | + FF_DEBUG("Extracted version from version.h: %s", buffer.chars); |
| 42 | + return NULL; |
| 43 | + } |
| 44 | + FF_DEBUG("Failed to extract version from version.h"); |
| 45 | + ffStrbufClear(&buffer); |
| 46 | + } |
| 47 | + else |
| 48 | + { |
| 49 | + FF_DEBUG("version.h file not found, trying Hyprland executable"); |
| 50 | + } |
32 | 51 |
|
33 |
| - ffBinaryExtractStrings(path.chars, extractHyprlandVersion, result, (uint32_t) strlen(" version: bump to v0.0.0")); |
34 |
| - if (result->length > 0) return NULL; |
| 52 | + const char* error = ffFindExecutableInPath("Hyprland", &buffer); |
| 53 | + if (error) { |
| 54 | + FF_DEBUG("Error finding Hyprland executable: %s", error); |
| 55 | + return "Failed to find Hyprland executable path"; |
| 56 | + } |
| 57 | + FF_DEBUG("Found Hyprland executable at: %s", buffer.chars); |
| 58 | + |
| 59 | + ffBinaryExtractStrings(buffer.chars, extractHyprlandVersion, result, (uint32_t) strlen("v0.0.0")); |
| 60 | + if (result->length > 0) { |
| 61 | + FF_DEBUG("Extracted version from binary strings: %s", result->chars); |
| 62 | + return NULL; |
| 63 | + } |
| 64 | + FF_DEBUG("Failed to extract version from binary strings, trying --version option"); |
35 | 65 |
|
36 | 66 | if (ffProcessAppendStdOut(result, (char* const[]){
|
37 |
| - path.chars, |
| 67 | + buffer.chars, |
38 | 68 | "--version",
|
39 | 69 | NULL
|
40 | 70 | }) == NULL)
|
41 |
| - { // Hyprland 0.46.2 built from branch v0.46.2-b at... long and multi line |
42 |
| - ffStrbufSubstrAfterFirstC(result, ' '); |
43 |
| - ffStrbufSubstrBeforeFirstC(result, ' '); |
| 71 | + { |
| 72 | + // Hyprland 0.48.1 built from branch at commit 29e2e59... |
| 73 | + // Date: ... |
| 74 | + // Tag: v0.48.1, commits: 5937 |
| 75 | + // ... |
| 76 | + |
| 77 | + FF_DEBUG("Raw version output: %s", result->chars); |
| 78 | + // Use tag if available |
| 79 | + if (ffStrbufSubstrAfterFirstS(result, "\nTag: v")) |
| 80 | + { |
| 81 | + ffStrbufSubstrBeforeFirstC(result, ','); |
| 82 | + FF_DEBUG("Extracted version from Tag: %s", result->chars); |
| 83 | + } |
| 84 | + else |
| 85 | + { |
| 86 | + ffStrbufSubstrAfterFirstC(result, ' '); |
| 87 | + ffStrbufSubstrBeforeFirstC(result, ' '); |
| 88 | + FF_DEBUG("Extracted version from output: %s", result->chars); |
| 89 | + } |
44 | 90 | return NULL;
|
45 | 91 | }
|
| 92 | + FF_DEBUG("Failed to run Hyprland --version command"); |
46 | 93 |
|
47 | 94 | return "Failed to run command `Hyprland --version`";
|
48 | 95 | }
|
|
0 commit comments