source: launchers/macosx/RouterTask.h @ 7615b92

Last change on this file since 7615b92 was 7615b92, checked in by meeh <meeh@…>, 2 years ago

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
  • Property mode set to 100644
File size: 1.8 KB
Line 
1#pragma once
2
3#include <dispatch/dispatch.h>
4#include <functional>
5#include <memory>
6#include <string>
7#include <vector>
8
9#include <Cocoa/Cocoa.h>
10#import <AppKit/AppKit.h>
11
12#include "optional.hpp"
13#include "subprocess.hpp"
14
15
16@class RTaskOptions;
17@interface RTaskOptions : NSObject
18@property (strong) NSString* binPath;
19@property (strong) NSArray<NSString *>* arguments;
20@property (strong) NSString* i2pBaseDir;
21@end
22
23@class I2PRouterTask;
24@interface I2PRouterTask : NSObject
25@property (strong) NSTask* routerTask;
26@property (strong) NSUserDefaults *userPreferences;
27@property (strong) NSFileHandle *readLogHandle;
28@property (strong) NSMutableData *totalLogData;
29@property (strong) NSPipe *processPipe;
30@property (strong) NSFileHandle *input;
31@property (atomic) BOOL isRouterRunning;
32@property (atomic) BOOL userRequestedRestart;
33- (instancetype) initWithOptions : (RTaskOptions*) options;
34- (int) execute;
35- (void) requestShutdown;
36- (void) requestRestart;
37- (BOOL) isRunning;
38- (int) getPID;
39- (void)routerStdoutData:(NSNotification *)notification;
40@end
41
42
43
44using namespace subprocess;
45
46class JavaRunner;
47
48typedef std::function<void(void)> fp_t;
49typedef std::function<void(JavaRunner *ptr)> fp_proc_t;
50
51
52
53/**
54 *
55 * class JavaRunner
56 *
57 **/
58class JavaRunner
59{
60public:
61  // copy fn
62  JavaRunner(std::string& javaBin, std::string& arguments, std::string& i2pBaseDir, const fp_proc_t& executingFn, const fp_t& cb);
63  ~JavaRunner() = default;
64
65  static const std::vector<NSString*> defaultStartupFlags;
66  static const std::vector<std::string> defaultFlagsForExtractorJob;
67
68  void requestRouterShutdown();
69
70  std::experimental::optional<std::future<int> > execute();
71  std::shared_ptr<Popen> javaProcess;
72  std::string javaBinaryPath;
73  std::string javaRouterArgs;
74  std::string execLine;
75  std::string _i2pBaseDir;
76private:
77  const fp_proc_t& executingFn;
78  const fp_t& exitCallbackFn;
79};
80
81
Note: See TracBrowser for help on using the repository browser.