@@ -78,40 +78,30 @@ SHyprlandVersion CPluginManager::getHyprlandVersion(bool running) {
7878 else
7979 onceInstalled = true ;
8080
81- const auto HLVERCALL = running ? NHyprlandSocket::send (" /version" ) : execAndGet (" Hyprland --version" );
82- if (m_bVerbose)
83- std::println ( " {} " , verboseString ( " {} version returned: {} " , running ? " running " : " installed " , HLVERCALL) );
81+ const auto HLVERCALL = running ? NHyprlandSocket::send (" j /version" ) : execAndGet (" Hyprland --version-json " );
82+
83+ auto jsonQuery = glz::read_json<glz:: json_t >( HLVERCALL);
8484
85- if (!HLVERCALL. contains ( " Tag: " ) ) {
86- std::println (stderr, " \n {}" , failureString (" You don't seem to be running Hyprland. " ));
85+ if (!jsonQuery ) {
86+ std::println (" {}" , failureString (" failed to get the current hyprland version. Are you running hyprland? " ));
8787 return SHyprlandVersion{};
8888 }
8989
90- std::string hlcommit = HLVERCALL.substr (HLVERCALL.find (" at commit" ) + 10 );
91- hlcommit = hlcommit.substr (0 , hlcommit.find_first_of (' ' ));
92-
93- std::string hlbranch = HLVERCALL.substr (HLVERCALL.find (" from branch" ) + 12 );
94- hlbranch = hlbranch.substr (0 , hlbranch.find (" at commit " ));
95-
96- std::string hldate = HLVERCALL.substr (HLVERCALL.find (" Date: " ) + 6 );
97- hldate = hldate.substr (0 , hldate.find (' \n ' ));
98-
99- std::string hlcommits;
90+ auto hlbranch = (*jsonQuery)[" branch" ].get_string ();
91+ auto hlcommit = (*jsonQuery)[" commit" ].get_string ();
92+ auto abiHash = (*jsonQuery)[" abiHash" ].get_string ();
93+ auto hldate = (*jsonQuery)[" commit_date" ].get_string ();
94+ auto hlcommits = (*jsonQuery)[" commits" ].get_string ();
10095
101- if (HLVERCALL.contains (" commits:" )) {
102- hlcommits = HLVERCALL.substr (HLVERCALL.find (" commits:" ) + 9 );
103- hlcommits = hlcommits.substr (0 , hlcommits.find (' ' ));
104- }
105-
106- int commits = 0 ;
96+ size_t commits = 0 ;
10797 try {
108- commits = std::stoi (hlcommits);
98+ commits = std::stoull (hlcommits);
10999 } catch (...) { ; }
110100
111101 if (m_bVerbose)
112102 std::println (" {}" , verboseString (" parsed commit {} at branch {} on {}, commits {}" , hlcommit, hlbranch, hldate, commits));
113103
114- auto ver = SHyprlandVersion{hlbranch, hlcommit, hldate, commits};
104+ auto ver = SHyprlandVersion{hlbranch, hlcommit, hldate, abiHash, commits};
115105
116106 if (running)
117107 verRunning = ver;
@@ -161,7 +151,7 @@ bool CPluginManager::addNewPluginRepo(const std::string& url, const std::string&
161151 DataState::updateGlobalState (GLOBALSTATE);
162152 }
163153
164- if (GLOBALSTATE.headersHashCompiled .empty ()) {
154+ if (GLOBALSTATE.headersAbiCompiled .empty ()) {
165155 std::println (" \n {}" , failureString (" Cannot find headers in the global state. Try running hyprpm update first." ));
166156 return false ;
167157 }
@@ -444,6 +434,12 @@ eHeadersErrors CPluginManager::headersValid() {
444434 if (hash != HLVER.hash )
445435 return HEADERS_MISMATCHED;
446436
437+ // check ABI hash too
438+ const auto GLOBALSTATE = DataState::getGlobalState ();
439+
440+ if (GLOBALSTATE.headersAbiCompiled != HLVER.abiHash )
441+ return HEADERS_ABI_MISMATCH;
442+
447443 return HEADERS_OK;
448444}
449445
@@ -595,8 +591,8 @@ bool CPluginManager::updateHeaders(bool force) {
595591 progress.m_szCurrentMessage = " Done!" ;
596592 progress.print ();
597593
598- auto GLOBALSTATE = DataState::getGlobalState ();
599- GLOBALSTATE.headersHashCompiled = HLVER.hash ;
594+ auto GLOBALSTATE = DataState::getGlobalState ();
595+ GLOBALSTATE.headersAbiCompiled = HLVER.abiHash ;
600596 DataState::updateGlobalState (GLOBALSTATE);
601597
602598 std::print (" \n " );
@@ -787,8 +783,8 @@ bool CPluginManager::updatePlugins(bool forceUpdateAll) {
787783 progress.m_szCurrentMessage = " Updating global state..." ;
788784 progress.print ();
789785
790- auto GLOBALSTATE = DataState::getGlobalState ();
791- GLOBALSTATE.headersHashCompiled = HLVER.hash ;
786+ auto GLOBALSTATE = DataState::getGlobalState ();
787+ GLOBALSTATE.headersAbiCompiled = HLVER.abiHash ;
792788 DataState::updateGlobalState (GLOBALSTATE);
793789
794790 progress.m_iSteps ++;
@@ -913,9 +909,9 @@ bool CPluginManager::loadUnloadPlugin(const std::string& path, bool load) {
913909 auto state = DataState::getGlobalState ();
914910 auto HLVER = getHyprlandVersion (true );
915911
916- if (state.headersHashCompiled != HLVER.hash ) {
912+ if (state.headersAbiCompiled != HLVER.hash ) {
917913 if (load)
918- std::println (" {}" , infoString (" Running Hyprland version ({}) differs from plugin state ({}), please restart Hyprland." , HLVER.hash , state.headersHashCompiled ));
914+ std::println (" {}" , infoString (" Running Hyprland version ({}) differs from plugin state ({}), please restart Hyprland." , HLVER.hash , state.headersAbiCompiled ));
919915 return false ;
920916 }
921917
@@ -956,6 +952,7 @@ std::string CPluginManager::headerError(const eHeadersErrors err) {
956952 case HEADERS_MISMATCHED: return failureString (" Headers version mismatch. Please run hyprpm update to fix those.\n " );
957953 case HEADERS_NOT_HYPRLAND: return failureString (" It doesn't seem you are running on hyprland.\n " );
958954 case HEADERS_MISSING: return failureString (" Headers missing. Please run hyprpm update to fix those.\n " );
955+ case HEADERS_ABI_MISMATCH: return failureString (" ABI is mismatched. Please run hyprpm update to fix that.\n " );
959956 case HEADERS_DUPLICATED: {
960957 return failureString (" Headers duplicated!!! This is a very bad sign.\n "
961958 " This could be due to e.g. installing hyprland manually while a system package of hyprland is also installed.\n "
0 commit comments