Ignore:
Timestamp:
Jul 24, 2018 4:26:40 PM (2 years ago)
Author:
meeh <meeh@…>
Branches:
master
Children:
7338282b
Parents:
2ee1a21
Message:

Code changes:

  • Port check to see if i2p is already running.
  • All buttons in the menu should work now.
  • Rewrote some C++ to Objective-C, which fits better with the integration.
  • Misc cleanup.
  • Made the launch of router repeatable.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • launchers/macosx/obj-cpp/AppDelegate.h

    r2ee1a21 rf9fbc76  
    88#include <Cocoa/Cocoa.h>
    99
     10#include "RouterTask.h"
    1011#include "StatusItemButton.h"
    1112#include "JavaHelper.h"
    12 #include "RouterTask.h"
    1313#include "neither/maybe.hpp"
    1414#include "optional.hpp"
     
    2727using namespace neither;
    2828
    29 using maybeAnRouterRunner = std::experimental::optional<RouterTask*>;
     29@class ExtractMetaInfo;
     30using maybeAnRouterRunner = std::experimental::optional<I2PRouterTask*>;
    3031
     32std::vector<std::string> buildClassPath(std::string basePath);
    3133
    3234extern JvmListSharedPtr gRawJvmList;
     
    3537static std::mutex globalRouterStatusMutex;
    3638static maybeAnRouterRunner globalRouterStatus = maybeAnRouterRunner{};
     39static bool isRuterRunning = false;
    3740
    3841maybeAnRouterRunner getGlobalRouterObject();
    39 void setGlobalRouterObject(RouterTask* newRouter);
     42void setGlobalRouterObject(I2PRouterTask* newRouter);
     43bool getGlobalRouterIsRunning();
     44void setGlobalRouterIsRunning(bool running);
    4045
    41 @class ExtractMetaInfo;
    4246@interface ExtractMetaInfo : NSObject
    43 @property (strong) NSString* i2pBase;
    44 @property (strong) NSString* javaBinary;
    45 @property (strong) NSString* zipFile;
    46 @property (strong) NSString* jarFile;
     47@property (copy) NSString* i2pBase;
     48@property (copy) NSString* javaBinary;
     49@property (copy) NSString* zipFile;
     50@property (copy) NSString* jarFile;
     51@end
     52
     53@class I2PStatusMenu;
     54@interface I2PStatusMenu : NSMenu
     55- (BOOL)validateMenuItem:(NSMenuItem *)menuItem;
    4756@end
    4857
     
    6978}
    7079
     80inline std::string getDefaultBaseDir()
     81{
     82  // Figure out base directory
     83  const char* pathFromHome = "/Users/%s/Library/I2P";
     84  auto username = getenv("USER");
     85  char buffer[strlen(pathFromHome)+strlen(username)];
     86  sprintf(buffer, pathFromHome, username);
     87  std::string i2pBaseDir(buffer);
     88  return i2pBaseDir;
     89}
     90
    7191@interface MenuBarCtrl : NSObject <StatusItemButtonDelegate, NSMenuDelegate>
    7292@property BOOL enableLogging;
    7393@property BOOL enableVerboseLogging;
    74 @property (strong) NSMenu *menu;
     94@property (strong) I2PStatusMenu *menu;
    7595@property (strong) StatusItemButton* statusBarButton;
    7696@property (strong) NSUserDefaults *userPreferences;
     
    82102- (void) statusBarImageBtnClicked;
    83103- (void) btnPressedAction:(id)sender;
    84 - (void) menuWillOpen:(NSMenu *)menu;
     104- (void) menuWillOpen:(I2PStatusMenu *)menu;
    85105
    86106- (void) openRouterConsoleBtnHandler: (NSMenuItem *) menuItem;
     
    92112- (MenuBarCtrl *) init;
    93113- (void) dealloc;
    94 - (NSMenu *) createStatusBarMenu;
     114- (I2PStatusMenu *) createStatusBarMenu;
    95115@end
    96116
     
    107127@property BOOL enableLogging;
    108128@property BOOL enableVerboseLogging;
     129@property ExtractMetaInfo *metaInfo;
    109130@property (copy) NSImage *contentImage NS_AVAILABLE(10_9, NA);
    110 - (void)extractI2PBaseDir:(ExtractMetaInfo *)metaInfo completion:(void(^)(BOOL success, NSError *error))completion;
    111 - (void)startupI2PRouter:(ExtractMetaInfo *)metaInfo;
     131- (void)extractI2PBaseDir:(void(^)(BOOL success, NSError *error))completion;
     132- (void)startupI2PRouter;
    112133- (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
    113134- (void)applicationWillTerminate:(NSNotification *)aNotification;
     
    121142
    122143
    123 /*
    124 
    125 
    126 @implementation CNSStatusBarCtrl
    127 -(id)initWithSysTray:(I2PCtrlSysIcon *)sys
    128 {
    129   self = [super init];
    130   if (self) {
    131     item = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength] retain];
    132     menu = 0;
    133     systray = sys;
    134     imageCell = [[NSImageView alloc] initWithParent:self];
    135     [item setView: imageCell];
    136     [item setHidden: NO];
    137     CFShow(CFSTR("CNSStatusBarCtrl::initWithSysTray executed"));
    138   }
    139   return self;
    140 }
    141 -(NSStatusItem*)item {
    142     return item;
    143 }
    144 -(void)dealloc {
    145   [[NSStatusBar systemStatusBar] removeStatusItem:item];
    146   [[NSNotificationCenter defaultCenter] removeObserver:imageCell];
    147   [imageCell release];
    148   [item release];
    149   [super dealloc];
    150 }
    151 @end
    152 
    153 
    154 class CSystemTrayIcon
    155 {
    156 public:
    157   CSystemTrayIcon(I2PCtrlSysIcon *sys)
    158   {
    159     item = [[CNSStatusBarCtrl alloc] initWithSysTray:sys];
    160     [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:item];
    161     const int menuHeight = [[NSStatusBar systemStatusBar] thickness];
    162     printf("menuHeight: %d\n", menuHeight);
    163     [[[item item] view] setHidden: NO];
    164   }
    165   ~CSystemTrayIcon()
    166   {
    167     [[[item item] view] setHidden: YES];
    168     [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:nil];
    169     [item release];
    170   }
    171   CNSStatusBarCtrl *item;
    172 };
    173 */
    174 
    175 
    176144#endif
Note: See TracChangeset for help on using the changeset viewer.