mirror of
https://github.com/RGBCube/serenity
synced 2025-05-18 21:25:07 +00:00
Help: Handle external links
Links which do not have the "file" protocol (most commonly links to external websites - http and https) are now not treated as file paths anymore but instead handled by Desktop::Launcher. The same applies to files outside of /usr/share/man. Fixes #2727.
This commit is contained in:
parent
787673b743
commit
87465f7c54
2 changed files with 28 additions and 6 deletions
|
@ -7,4 +7,4 @@ set(SOURCES
|
||||||
)
|
)
|
||||||
|
|
||||||
serenity_bin(Help)
|
serenity_bin(Help)
|
||||||
target_link_libraries(Help LibWeb LibMarkdown LibGUI)
|
target_link_libraries(Help LibWeb LibMarkdown LibGUI LibDesktop)
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include <AK/ByteBuffer.h>
|
#include <AK/ByteBuffer.h>
|
||||||
#include <AK/URL.h>
|
#include <AK/URL.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
|
#include <LibDesktop/Launcher.h>
|
||||||
#include <LibGUI/AboutDialog.h>
|
#include <LibGUI/AboutDialog.h>
|
||||||
#include <LibGUI/Action.h>
|
#include <LibGUI/Action.h>
|
||||||
#include <LibGUI/Application.h>
|
#include <LibGUI/Application.h>
|
||||||
|
@ -58,7 +59,7 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
auto app = GUI::Application::construct(argc, argv);
|
auto app = GUI::Application::construct(argc, argv);
|
||||||
|
|
||||||
if (pledge("stdio shared_buffer accept rpath", nullptr) < 0) {
|
if (pledge("stdio shared_buffer accept rpath unix", nullptr) < 0) {
|
||||||
perror("pledge");
|
perror("pledge");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -73,6 +74,11 @@ int main(int argc, char* argv[])
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (unveil("/tmp/portal/launch", "rw") < 0) {
|
||||||
|
perror("unveil");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
unveil(nullptr, nullptr);
|
unveil(nullptr, nullptr);
|
||||||
|
|
||||||
auto app_icon = GUI::Icon::default_icon("app-help");
|
auto app_icon = GUI::Icon::default_icon("app-help");
|
||||||
|
@ -159,10 +165,27 @@ int main(int argc, char* argv[])
|
||||||
model->update_section_node_on_toggle(index, open);
|
model->update_section_node_on_toggle(index, open);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
auto open_external = [&](auto& url) {
|
||||||
|
if (!Desktop::Launcher::open(url)) {
|
||||||
|
GUI::MessageBox::show(
|
||||||
|
String::format("The link to '%s' could not be opened.", url.to_string().characters()),
|
||||||
|
"Failed to open link",
|
||||||
|
GUI::MessageBox::Type::Error,
|
||||||
|
GUI::MessageBox::InputType::OK,
|
||||||
|
window);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
page_view.on_link_click = [&](auto& url, auto&, unsigned) {
|
page_view.on_link_click = [&](auto& url, auto&, unsigned) {
|
||||||
char* current_path = strdup(history.current().characters());
|
if (url.protocol() != "file") {
|
||||||
char* path = realpath(url.path().characters(), nullptr);
|
open_external(url);
|
||||||
free(current_path);
|
return;
|
||||||
|
}
|
||||||
|
auto path = Core::File::real_path_for(url.path());
|
||||||
|
if (!path.starts_with("/usr/share/man/")) {
|
||||||
|
open_external(url);
|
||||||
|
return;
|
||||||
|
}
|
||||||
auto tree_view_index = model->index_from_path(path);
|
auto tree_view_index = model->index_from_path(path);
|
||||||
if (tree_view_index.has_value()) {
|
if (tree_view_index.has_value()) {
|
||||||
dbg() << "Found path _" << path << "_ in model at index " << tree_view_index.value();
|
dbg() << "Found path _" << path << "_ in model at index " << tree_view_index.value();
|
||||||
|
@ -172,7 +195,6 @@ int main(int argc, char* argv[])
|
||||||
history.push(path);
|
history.push(path);
|
||||||
update_actions();
|
update_actions();
|
||||||
open_page(path);
|
open_page(path);
|
||||||
free(path);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
go_back_action = GUI::CommonActions::make_go_back_action([&](auto&) {
|
go_back_action = GUI::CommonActions::make_go_back_action([&](auto&) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue