2020-11-14 14:13:00 -08:00
|
|
|
#include "mainwindow.h"
|
2020-12-06 16:15:31 -08:00
|
|
|
#include "ipfs.h"
|
2021-02-27 15:25:25 -08:00
|
|
|
#include "project_config.h"
|
|
|
|
#include <iostream>
|
2020-11-28 14:47:34 -08:00
|
|
|
#include <gtkmm/application.h>
|
2020-11-12 16:54:34 -08:00
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2021-02-27 15:25:25 -08:00
|
|
|
// Any arguments provided?
|
|
|
|
if (argc > 1)
|
|
|
|
{
|
|
|
|
int opt;
|
|
|
|
while ((opt = getopt(argc, argv, ":v")) != EOF) // -v is optional
|
|
|
|
switch (opt)
|
|
|
|
{
|
|
|
|
case 'v':
|
|
|
|
// Display version, and directly exit the program.
|
|
|
|
std::cout << "DWeb Browser " << PROJECT_VER << std::endl;
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
case '?': // Unknown
|
|
|
|
fprintf(stderr, "Usuage: browser [-v] \nDecentralized Web Browser\n\nOptions are:\n -v : output version information and exit\n\n");
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-12 12:46:41 -08:00
|
|
|
pid_t child_pid = fork();
|
|
|
|
if (child_pid == 0)
|
|
|
|
{
|
|
|
|
// Run by child process
|
|
|
|
printf("INFO: Starting IPFS daemon.\n");
|
2021-03-01 13:28:58 -08:00
|
|
|
return IPFS::startIPFSDaemon();
|
2021-02-12 12:46:41 -08:00
|
|
|
}
|
|
|
|
else if (child_pid > 0)
|
|
|
|
{
|
|
|
|
// Parent process (child_pid is PID of child)
|
|
|
|
auto app = Gtk::Application::create(argc, argv, "org.melroy.browser");
|
2020-12-06 16:15:31 -08:00
|
|
|
|
2021-02-12 12:46:41 -08:00
|
|
|
MainWindow window;
|
|
|
|
int exitCode = app->run(window);
|
|
|
|
// Kill also the child
|
|
|
|
kill(child_pid, SIGTERM);
|
|
|
|
return exitCode;
|
|
|
|
}
|
|
|
|
else // PID < 0, error
|
|
|
|
{
|
|
|
|
printf("ERROR: fork failed.\n");
|
|
|
|
}
|
2020-11-12 16:54:34 -08:00
|
|
|
}
|