mirror of
https://github.com/SerenityOS/serenity
synced 2026-05-05 22:52:10 +02:00
LibDesktop+TaskBar: Propagate errors from AppFile::spawn and friends
Returning a boolean tells us nothing about why the spawn failed.
This commit is contained in:
committed by
Andrew Kaster
parent
416eb74fa5
commit
dccd1cd348
@@ -169,22 +169,19 @@ Vector<ByteString> AppFile::launcher_protocols() const
|
||||
return protocols;
|
||||
}
|
||||
|
||||
bool AppFile::spawn(ReadonlySpan<StringView> arguments) const
|
||||
ErrorOr<void> AppFile::spawn(ReadonlySpan<StringView> arguments) const
|
||||
{
|
||||
if (!is_valid())
|
||||
return false;
|
||||
return Error::from_string_literal("AppFile is invalid");
|
||||
|
||||
auto pid = Core::Process::spawn(executable(), arguments, working_directory());
|
||||
if (pid.is_error())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
TRY(Core::Process::spawn(executable(), arguments, working_directory()));
|
||||
return {};
|
||||
}
|
||||
|
||||
bool AppFile::spawn_with_escalation(ReadonlySpan<StringView> user_arguments) const
|
||||
ErrorOr<void> AppFile::spawn_with_escalation(ReadonlySpan<StringView> user_arguments) const
|
||||
{
|
||||
if (!is_valid())
|
||||
return false;
|
||||
return Error::from_string_literal("AppFile is invalid");
|
||||
|
||||
StringView exe;
|
||||
Vector<StringView, 2> args;
|
||||
@@ -207,18 +204,15 @@ bool AppFile::spawn_with_escalation(ReadonlySpan<StringView> user_arguments) con
|
||||
}
|
||||
args.extend(Vector(user_arguments));
|
||||
|
||||
auto pid = Core::Process::spawn(exe, args.span(),
|
||||
working_directory().is_empty() ? Core::StandardPaths::home_directory() : working_directory());
|
||||
if (pid.is_error())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
TRY(Core::Process::spawn(exe, args.span(),
|
||||
working_directory().is_empty() ? Core::StandardPaths::home_directory() : working_directory()));
|
||||
return {};
|
||||
}
|
||||
|
||||
void AppFile::spawn_with_escalation_or_show_error(GUI::Window& window, ReadonlySpan<StringView> arguments) const
|
||||
{
|
||||
if (!spawn_with_escalation(arguments))
|
||||
GUI::MessageBox::show_error(&window, ByteString::formatted("Failed to spawn {} with escalation", executable()));
|
||||
if (auto result = spawn_with_escalation(arguments); result.is_error())
|
||||
GUI::MessageBox::show_error(&window, ByteString::formatted("Failed to spawn {} with escalation: {}", executable(), result.error()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -44,8 +44,8 @@ public:
|
||||
Vector<ByteString> launcher_mime_types() const;
|
||||
Vector<ByteString> launcher_file_types() const;
|
||||
Vector<ByteString> launcher_protocols() const;
|
||||
bool spawn(ReadonlySpan<StringView> arguments = {}) const;
|
||||
bool spawn_with_escalation(ReadonlySpan<StringView> arguments = {}) const;
|
||||
ErrorOr<void> spawn(ReadonlySpan<StringView> arguments = {}) const;
|
||||
ErrorOr<void> spawn_with_escalation(ReadonlySpan<StringView> arguments = {}) const;
|
||||
void spawn_with_escalation_or_show_error(GUI::Window&, ReadonlySpan<StringView> arguments = {}) const;
|
||||
|
||||
private:
|
||||
|
||||
@@ -386,8 +386,8 @@ void TaskbarWindow::wm_event(GUI::WMEvent& event)
|
||||
break;
|
||||
}
|
||||
case GUI::Event::WM_SuperSpaceKeyPressed: {
|
||||
if (!m_assistant_app_file->spawn())
|
||||
warnln("failed to spawn 'Assistant' when requested via Super+Space");
|
||||
if (auto result = m_assistant_app_file->spawn(); result.is_error())
|
||||
warnln("Failed to spawn 'Assistant' when requested via Super+Space: {}", result.error());
|
||||
break;
|
||||
}
|
||||
case GUI::Event::WM_SuperDKeyPressed: {
|
||||
|
||||
Reference in New Issue
Block a user