Skip to content

Commit b56188d

Browse files
ferdymercurydpiparo
authored andcommitted
[core] print URL to terminal if web browser could not be opened
Fixes #22496 (cherry picked from commit 295249a)
1 parent 2f27255 commit b56188d

1 file changed

Lines changed: 16 additions & 13 deletions

File tree

core/base/src/TApplication.cxx

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,8 @@ TApplication::EExitOnException TApplication::ExitOnException(TApplication::EExit
622622
/// The function generates and executes a command that loads the Doxygen URL in
623623
/// a browser. It works for Mac, Windows and Linux. In the case of Linux, the
624624
/// function also checks if the DISPLAY is set. If it isn't, a warning message
625-
/// and the URL will be displayed on the terminal.
625+
/// and the URL will be displayed on the terminal. In all OS, if the system command
626+
/// fails, the URL will be also displayed on the terminal.
626627
///
627628
/// \param[in] url web page to be displayed in a browser
628629

@@ -634,26 +635,28 @@ void TApplication::OpenInBrowser(const TString &url)
634635
TString cMac("open ");
635636
// We generate the full command and execute it.
636637
cMac.Append(url);
637-
gSystem->Exec(cMac);
638+
auto res = gSystem->Exec(cMac);
638639
#elif defined(R__WIN32)
639640
// Command for opening a browser on Windows.
640641
TString cWindows("start \"\" ");
641642
cWindows.Append(url);
642-
gSystem->Exec(cWindows);
643+
auto res = gSystem->Exec(cWindows);
643644
#else
644-
// Command for opening a browser in Linux.
645+
// For Linux we check first if the DISPLAY is set.
646+
if (!gSystem->Getenv("DISPLAY")) {
647+
// The user will have a warning and the URL in the terminal.
648+
Warning("OpenInBrowser", "The $DISPLAY is not set! Please manually open (e.g. Ctrl-click) %s\n", url.Data());
649+
return;
650+
}
651+
// Command for opening a browser in Linux. Since the DISPLAY is set, it will open the browser.
645652
TString cLinux("xdg-open ");
646-
// For Linux we check if the DISPLAY is set.
647-
if (gSystem->Getenv("DISPLAY")) {
648-
// If the DISPLAY is set it will open the browser.
649-
cLinux.Append(url);
650-
gSystem->Exec(cLinux);
651-
} else {
652-
// Else the user will have a warning and the URL in the terminal.
653-
Warning("OpenInBrowser", "The $DISPLAY is not set! Please open (e.g. Ctrl-click) %s\n", url.Data());
653+
cLinux.Append(url);
654+
auto res = gSystem->Exec(cLinux);
655+
#endif
656+
if (res != EXIT_SUCCESS) {
657+
Warning("OpenInBrowser", "Could not automatically open web browser (e.g. due to missing X11)! Please manually open (e.g. Ctrl-click) %s\n", url.Data());
654658
return;
655659
}
656-
#endif
657660
Info("OpenInBrowser", "A new tab should have opened in your browser.");
658661
}
659662

0 commit comments

Comments
 (0)