mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-11 17:00:37 +00:00
LibDesktop: Add spawn() to AppFiles
This adds a convenience utility to AppFiles for quickly launching the apps backed by the AppFile.
This commit is contained in:
parent
cbe67ed665
commit
ae20c178b9
Notes:
sideshowbarker
2024-07-18 11:24:39 +09:00
Author: https://github.com/SpencerCDixon Commit: https://github.com/SerenityOS/serenity/commit/ae20c178b98 Pull-request: https://github.com/SerenityOS/serenity/pull/8266 Reviewed-by: https://github.com/Mandar12 Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/linusg
2 changed files with 22 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Linus Groh <linusg@serenityos.org>
|
||||
* Copyright (c) 2021, Spencer Dixon <spencercdixon@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -103,4 +104,24 @@ Vector<String> AppFile::launcher_protocols() const
|
|||
return protocols;
|
||||
}
|
||||
|
||||
bool AppFile::spawn() const
|
||||
{
|
||||
if (!is_valid())
|
||||
return false;
|
||||
|
||||
pid_t child_pid;
|
||||
const char* argv[] = { executable().characters(), nullptr };
|
||||
if ((errno = posix_spawn(&child_pid, executable().characters(), nullptr, nullptr, const_cast<char**>(argv), environ))) {
|
||||
perror("posix_spawn");
|
||||
return false;
|
||||
} else {
|
||||
if (disown(child_pid) < 0) {
|
||||
perror("disown");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ public:
|
|||
String category() const;
|
||||
Vector<String> launcher_file_types() const;
|
||||
Vector<String> launcher_protocols() const;
|
||||
bool spawn() const;
|
||||
|
||||
GUI::Icon icon() const { return GUI::FileIconProvider::icon_for_path(executable()); };
|
||||
|
||||
|
|
Loading…
Reference in a new issue