Adding all new code, removed a lot obsolete code and fixed import paths etc.

Mac OS X launcher:
* UI built on Swift
  * Why?
    * Apple seems to on purpose make it harder to get into Objective-C these days
    * Swift is compiled to native code, but has easiness of Javascript in programming
    * Perfect for the OS X UI, many guides & tutorials as well
* "Backend" in Objective-C++ / C++14
  * Why?
    * Originally written in Objective-C / C++14 with C++17 backports
    * Only for backend because of the time the development takes
    *

Short summary of features:

* Java
  * It can detect java from:
    * JAVA_HOME environment variable
    * "Internet Plug-Ins" Apple stuff
    * By the /usr/libexec/java_home binary helper
  * It can unpack a new version of I2P
    * Unpacks to ~/Library/I2P
    * Can check currently unpacked version in ~/Library/I2P via i2p.jar's "net.i2p.CoreVersion"

  * User Interface (a popover, see https://youtu.be/k8L3lQ5rUq0 for example of this concept)
    * Router control tab view
      * It can start the router
      * It can stop the router
      * It can detect already running router, then avoid fireing up one
      * It can show basic information about the router state & version
    * Log view tab (not yet done)
  * While left-click triggers popover, right-click draws a minimal context menu
This commit is contained in:
meeh
2018-09-18 15:36:38 +00:00
parent 1bddf5527a
commit 7615b9236b
47 changed files with 1735 additions and 41 deletions

View File

@@ -0,0 +1,42 @@
#pragma once
#include <CoreFoundation/CoreFoundation.h>
#include <unistd.h>
#include <sys/event.h>
#include "neither/either.hpp"
#include "AppDelegate.h"
using callbackType = void (CFFileDescriptorRef, CFOptionFlags, void *);
using HandleFunction = std::function<void(int)>;
static void noteProcDeath(CFFileDescriptorRef fdref, CFOptionFlags callBackTypes, void *info) {
struct kevent kev;
int fd = CFFileDescriptorGetNativeDescriptor(fdref);
kevent(fd, NULL, 0, &kev, 1, NULL);
// take action on death of process here
NSLog(@"process with pid '%u' died\n", (unsigned int)kev.ident);
sendUserNotification(APP_IDSTR, @"The I2P router has stopped.");
CFFileDescriptorInvalidate(fdref);
CFRelease(fdref); // the CFFileDescriptorRef is no longer of any use in this example
}
// one argument, an integer pid to watch, required
int watchPid(int pid, callbackType callback = noteProcDeath) {
int fd = kqueue();
struct kevent kev;
EV_SET(&kev, pid, EVFILT_PROC, EV_ADD|EV_ENABLE, NOTE_EXIT, 0, NULL);
kevent(fd, &kev, 1, NULL, 0, NULL);
CFFileDescriptorRef fdref = CFFileDescriptorCreate(kCFAllocatorDefault, fd, true, callback, NULL);
CFFileDescriptorEnableCallBacks(fdref, kCFFileDescriptorReadCallBack);
CFRunLoopSourceRef source = CFFileDescriptorCreateRunLoopSource(kCFAllocatorDefault, fdref, 0);
CFRunLoopAddSource(CFRunLoopGetMain(), source, kCFRunLoopDefaultMode);
CFRelease(source);
/*
seconds
The length of time to run the run loop. If 0, only one pass is made through the run loop before returning;
if multiple sources or timers are ready to fire immediately, only one (possibly two if one is a version
0 source) will be fired, regardless of the value of returnAfterSourceHandled.
*/
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, false);
return 0;
}

View File

@@ -0,0 +1,59 @@
#pragma once
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <errno.h>
typedef struct sockaddr *sad; /* A necesary dummy typedef */
int port_check(int portNum=7657)
{
int sock; /* Socket that will be bind */
struct sockaddr_in sin; /* Address Structure */
/* Create the socket */
/* PF_INET is the option for make a TCP socket.
You can try "man socket" for more info */
sock = socket( PF_INET, SOCK_STREAM, 0 );
/* The socket creation failed */
if ( 0 > sock ) {
perror( "socket" );
return ( -1 );
}
/* Address */
sin.sin_family = AF_INET;
sin.sin_port = htons( portNum ); /* htons() convert the number
to big endian */
sin.sin_addr.s_addr = INADDR_ANY;
/* We bind the socket to the port PORT to check if
the port is in use */
if ( 0 > bind( sock, (sad)&sin, sizeof( sin ) ) ) {
/* Bind failed, now we can check if the address is
in use */
if ( EADDRINUSE == errno ) {
/* We put the code necesary to manage this case */
printf( "The TCP port %d is in use.\n", portNum );
}
else
/* If the error were other than EADDRINUSE, we print it */
perror( "bind" );
return 1;
}
/* If we arrive to this point, the port weren't in use and
we have it attached to our program. We can close
the socket or use it */
close( sock ); /* Close the socket */
return 0;
}