mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
Ladybird: Refactor navigating to url on startup
These changes will prevent duplication of code later when there will also be the possibility to navigate to the homepage url as defined in the settings on startup.
This commit is contained in:
parent
65cf562a71
commit
abf8dd96de
Notes:
sideshowbarker
2024-07-17 20:33:50 +09:00
Author: https://github.com/martinfalisse Commit: https://github.com/SerenityOS/serenity/commit/abf8dd96de Pull-request: https://github.com/SerenityOS/serenity/pull/16947 Reviewed-by: https://github.com/linusg
1 changed files with 10 additions and 7 deletions
|
@ -75,11 +75,14 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
args_parser.add_option(dump_layout_tree, "Dump layout tree and exit", "dump-layout-tree", 'd');
|
||||
args_parser.parse(arguments);
|
||||
|
||||
URL url = raw_url;
|
||||
if (Core::File::exists(raw_url))
|
||||
url = URL::create_with_file_scheme(Core::File::real_path_for(raw_url));
|
||||
else if (!url.is_valid())
|
||||
url = DeprecatedString::formatted("http://{}", raw_url);
|
||||
auto get_formatted_url = [&](StringView const& raw_url) -> URL {
|
||||
URL url = raw_url;
|
||||
if (Core::File::exists(raw_url))
|
||||
url = URL::create_with_file_scheme(Core::File::real_path_for(raw_url));
|
||||
else if (!url.is_valid())
|
||||
url = DeprecatedString::formatted("http://{}", raw_url);
|
||||
return url;
|
||||
};
|
||||
|
||||
if (dump_layout_tree) {
|
||||
WebContentView view({});
|
||||
|
@ -92,7 +95,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
app.quit();
|
||||
};
|
||||
|
||||
view.load(url);
|
||||
view.load(get_formatted_url(raw_url));
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
|
@ -107,7 +110,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
window.resize(800, 600);
|
||||
window.show();
|
||||
|
||||
if (url.is_valid())
|
||||
if (auto url = get_formatted_url(raw_url); url.is_valid())
|
||||
window.view().load(url);
|
||||
|
||||
return app.exec();
|
||||
|
|
Loading…
Reference in a new issue