From 87d14d4ef2e06f7dfeeb66aa2fac74fef2e58cc6 Mon Sep 17 00:00:00 2001 From: Gerasim Troeglazov <3dEyes@gmail.com> Date: Sun, 6 Apr 2025 10:13:00 +1000 Subject: Add simple launcher app diff --git a/tools/haiku-launcher/launcher.cpp b/tools/haiku-launcher/launcher.cpp new file mode 100644 index 0000000..86a9f22 --- /dev/null +++ b/tools/haiku-launcher/launcher.cpp @@ -0,0 +1,111 @@ +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class BrowserLauncherApp : public BApplication { + public: + BrowserLauncherApp(const char *signature, int argc, char **argv); + ~BrowserLauncherApp() {}; + + virtual void RefsReceived(BMessage *pmsg); + virtual void ArgvRecieved(int32 argc, char**argv); + virtual void ReadyToRun(); + BString GetBinPath(void); + + private: + BString fCommandLine; +}; + +BrowserLauncherApp::BrowserLauncherApp(const char *signature, int argc, char **argv) + : BApplication(signature) +{ + ArgvRecieved(argc, argv); +} + +BString +BrowserLauncherApp::GetBinPath(void) +{ + BPath binPath; + + image_info info; + int32 cookie = 0; + + while (get_next_image_info(B_CURRENT_TEAM, &cookie, &info) == B_OK) { + if (info.type == B_APP_IMAGE) { + binPath.SetTo(info.name); + binPath.GetParent(&binPath); + break; + } + } + + binPath.Append("Iceweasel"); + + return binPath.Path(); +} + +void +BrowserLauncherApp::RefsReceived(BMessage *pmsg) +{ + fCommandLine = GetBinPath(); + + entry_ref ref; + for (int32 i = 0; pmsg->FindRef("refs", i, &ref) == B_OK; i++) { + BPath file = BPath(&ref); + fCommandLine += " \""; + fCommandLine += file.Path(); + fCommandLine += "\""; + } + + BString url; + for (int32 i = 0; pmsg->FindString("url", i, &url) == B_OK; i++) { + fCommandLine += " \""; + fCommandLine += url; + fCommandLine += "\""; + } + + fCommandLine += " &"; +} + +void +BrowserLauncherApp::ArgvRecieved(int32 argc, char**argv) +{ + BMessage message(B_REFS_RECEIVED); + for (int i = 1; i < argc; i++) { + const char* url = argv[i]; + BEntry entry(argv[i], true); + BPath path; + if (entry.Exists() && entry.GetPath(&path) == B_OK) + url = path.Path(); + message.AddString("url", url); + } + RefsReceived(&message); +} + +void +BrowserLauncherApp::ReadyToRun() +{ + if (!fCommandLine.IsEmpty()) + system(fCommandLine.String()); + + Quit(); +} + +int main(int argc, char **argv) +{ + BrowserLauncherApp application("application/x-vnd.iceweasel-launcher", argc, argv); + application.Run(); + return 0; +} + + -- 2.48.1