Skip to content

Commit 9fd782a

Browse files
committed
core/desktopentry: add more logs for diagnosing why terminal isn't being chosen
1 parent d20a2e5 commit 9fd782a

1 file changed

Lines changed: 37 additions & 17 deletions

File tree

src/core/desktopentry.cpp

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -379,13 +379,19 @@ void DesktopEntry::doExec(
379379
auto found = false;
380380

381381
for (const auto& term: manager->resolvedTerminals) {
382-
// Skip if TryExec exists but the binary doesn't.
383-
if (!term.tryExec.isEmpty() && QStandardPaths::findExecutable(term.tryExec).isEmpty())
382+
if (!term.tryExec.isEmpty() && QStandardPaths::findExecutable(term.tryExec).isEmpty()) {
383+
qCWarning(logDesktopEntry) << "Terminal" << term.command.first() << "TryExec"
384+
<< term.tryExec << "not found in PATH (skipping)";
384385
continue;
386+
}
385387

386-
// Skip if command is empty or the first item (the executable) doesn't exist.
387388
if (term.command.isEmpty() || QStandardPaths::findExecutable(term.command.first()).isEmpty())
389+
{
390+
qCWarning(logDesktopEntry)
391+
<< "Terminal executable" << (term.command.isEmpty() ? "(empty)" : term.command.first())
392+
<< "not found in PATH (skipping)";
388393
continue;
394+
}
389395

390396
command = QList<QString>();
391397
command.append(term.command);
@@ -816,10 +822,19 @@ void DesktopEntryManager::onScanCompleted(const QList<ParsedDesktopEntryData>& s
816822
};
817823

818824
// Scan-time validation: structural checks only, no PATH lookups.
819-
auto isValidTerminal = [](const DesktopEntry* entry) -> bool {
820-
if (!entry->bCategories.value().contains("TerminalEmulator")) return false;
821-
if (entry->bCommand.value().isEmpty()) return false;
822-
if (!entry->terminal.execArg.has_value()) return false;
825+
auto isValidTerminal = [](const DesktopEntry* entry, auto&& log) -> bool {
826+
if (!entry->bCategories.value().contains("TerminalEmulator")) {
827+
log(entry->mId, "missing TerminalEmulator category");
828+
return false;
829+
}
830+
if (entry->bCommand.value().isEmpty()) {
831+
log(entry->mId, "has empty Exec command");
832+
return false;
833+
}
834+
if (!entry->terminal.execArg.has_value()) {
835+
log(entry->mId, "missing [X-]TerminalArgExec");
836+
return false;
837+
}
823838
return true;
824839
};
825840

@@ -843,19 +858,24 @@ void DesktopEntryManager::onScanCompleted(const QList<ParsedDesktopEntryData>& s
843858
if (configEntry.exclude || configEntry.protect) continue;
844859

845860
auto* dentry = this->byId(configEntry.id);
846-
if (!dentry || !isValidTerminal(dentry)) continue;
861+
if (!dentry) {
862+
qCWarning(logDesktopEntry)
863+
<< "Terminal" << configEntry.id
864+
<< "not found in desktop entries (instructed from xdg-terminals.list)";
865+
continue;
866+
}
867+
if (!isValidTerminal(dentry, termWarn)) continue;
847868

848869
auto command = dentry->bCommand.value();
849870
if (!configEntry.action.isEmpty()) {
850-
auto found = false;
851-
for (auto* action: dentry->actions()) {
852-
if (action->mId == configEntry.action) {
853-
command = action->bCommand.value();
854-
found = true;
855-
break;
856-
}
871+
auto actions = dentry->actions();
872+
auto action = std::ranges::find(actions, configEntry.action, &DesktopAction::mId);
873+
if (action == actions.end()) {
874+
qCWarning(logDesktopEntry)
875+
<< "Terminal entry" << configEntry.id << "no action named" << configEntry.action;
876+
continue;
857877
}
858-
if (!found) continue;
878+
command = (*action)->bCommand.value();
859879
}
860880

861881
addResolved(dentry, command);
@@ -870,7 +890,7 @@ void DesktopEntryManager::onScanCompleted(const QList<ParsedDesktopEntryData>& s
870890
std::ranges::sort(fallbackEntries, {}, &DesktopEntry::mId);
871891
for (auto* entry: fallbackEntries) {
872892
if (addedIds.contains(entry->mId)) continue;
873-
if (!isValidTerminal(entry)) continue;
893+
if (!isValidTerminal(entry, termDebug)) continue;
874894
if (excludedIds.contains(entry->mId) && !protectedIds.contains(entry->mId)) continue;
875895

876896
addResolved(entry, entry->bCommand.value());

0 commit comments

Comments
 (0)