2018-06-30 13:10:06 +00:00
|
|
|
#ifndef __APPDELEGATE_H__
|
|
|
|
#define __APPDELEGATE_H__
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <string>
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include <Cocoa/Cocoa.h>
|
|
|
|
|
2018-07-24 16:26:40 +00:00
|
|
|
#include "RouterTask.h"
|
2018-06-30 13:10:06 +00:00
|
|
|
#include "StatusItemButton.h"
|
|
|
|
#include "JavaHelper.h"
|
2018-07-13 06:30:16 +00:00
|
|
|
#include "neither/maybe.hpp"
|
|
|
|
#include "optional.hpp"
|
|
|
|
#include "subprocess.hpp"
|
|
|
|
#include <glob.h>
|
|
|
|
#include <vector>
|
|
|
|
|
2018-07-13 09:11:46 +00:00
|
|
|
|
|
|
|
#define DEF_I2P_VERSION "0.9.35"
|
|
|
|
#define APPDOMAIN "net.i2p.launcher"
|
|
|
|
#define NSAPPDOMAIN @APPDOMAIN
|
|
|
|
#define CFAPPDOMAIN CFSTR(APPDOMAIN)
|
|
|
|
#define APP_IDSTR @"I2P Launcher"
|
|
|
|
|
|
|
|
|
2018-07-13 06:30:16 +00:00
|
|
|
using namespace neither;
|
2018-06-30 13:10:06 +00:00
|
|
|
|
2018-07-24 16:26:40 +00:00
|
|
|
@class ExtractMetaInfo;
|
|
|
|
using maybeAnRouterRunner = std::experimental::optional<I2PRouterTask*>;
|
2018-07-13 09:11:46 +00:00
|
|
|
|
2018-07-24 16:26:40 +00:00
|
|
|
std::vector<std::string> buildClassPath(std::string basePath);
|
2018-07-13 09:11:46 +00:00
|
|
|
|
2018-06-30 13:10:06 +00:00
|
|
|
extern JvmListSharedPtr gRawJvmList;
|
|
|
|
|
2018-07-13 06:30:16 +00:00
|
|
|
// DO NOT ACCESS THIS GLOBAL VARIABLE DIRECTLY.
|
2018-07-13 09:11:46 +00:00
|
|
|
static std::mutex globalRouterStatusMutex;
|
|
|
|
static maybeAnRouterRunner globalRouterStatus = maybeAnRouterRunner{};
|
2018-07-24 16:26:40 +00:00
|
|
|
static bool isRuterRunning = false;
|
2018-07-13 09:11:46 +00:00
|
|
|
|
|
|
|
maybeAnRouterRunner getGlobalRouterObject();
|
2018-07-24 16:26:40 +00:00
|
|
|
void setGlobalRouterObject(I2PRouterTask* newRouter);
|
|
|
|
bool getGlobalRouterIsRunning();
|
|
|
|
void setGlobalRouterIsRunning(bool running);
|
2018-07-13 09:11:46 +00:00
|
|
|
|
|
|
|
@interface ExtractMetaInfo : NSObject
|
2018-07-24 16:26:40 +00:00
|
|
|
@property (copy) NSString* i2pBase;
|
|
|
|
@property (copy) NSString* javaBinary;
|
|
|
|
@property (copy) NSString* zipFile;
|
|
|
|
@property (copy) NSString* jarFile;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@class I2PStatusMenu;
|
|
|
|
@interface I2PStatusMenu : NSMenu
|
|
|
|
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem;
|
2018-07-13 09:11:46 +00:00
|
|
|
@end
|
2018-07-13 06:30:16 +00:00
|
|
|
|
2018-07-13 09:11:46 +00:00
|
|
|
inline void sendUserNotification(NSString* title, NSString* informativeText, NSImage* contentImage = NULL, bool makeSound = false) {
|
|
|
|
NSUserNotification *userNotification = [[[NSUserNotification alloc] init] autorelease];
|
2018-07-13 06:30:16 +00:00
|
|
|
|
2018-07-13 09:11:46 +00:00
|
|
|
userNotification.title = title;
|
|
|
|
userNotification.informativeText = informativeText;
|
|
|
|
if (contentImage != NULL) userNotification.contentImage = contentImage;
|
|
|
|
if (makeSound) userNotification.soundName = NSUserNotificationDefaultSoundName;
|
2018-07-13 06:30:16 +00:00
|
|
|
|
2018-07-13 09:11:46 +00:00
|
|
|
[[NSUserNotificationCenter defaultUserNotificationCenter] scheduleNotification:userNotification];
|
|
|
|
};
|
2018-07-13 06:30:16 +00:00
|
|
|
|
2018-07-13 09:11:46 +00:00
|
|
|
inline std::vector<std::string> globVector(const std::string& pattern){
|
2018-07-13 06:30:16 +00:00
|
|
|
glob_t glob_result;
|
|
|
|
glob(pattern.c_str(),GLOB_TILDE,NULL,&glob_result);
|
|
|
|
std::vector<std::string> files;
|
|
|
|
for(unsigned int i=0;i<glob_result.gl_pathc;++i){
|
|
|
|
files.push_back(std::string(glob_result.gl_pathv[i]));
|
|
|
|
}
|
|
|
|
globfree(&glob_result);
|
|
|
|
return files;
|
|
|
|
}
|
|
|
|
|
2018-07-24 16:26:40 +00:00
|
|
|
inline std::string getDefaultBaseDir()
|
|
|
|
{
|
|
|
|
// Figure out base directory
|
|
|
|
const char* pathFromHome = "/Users/%s/Library/I2P";
|
|
|
|
auto username = getenv("USER");
|
|
|
|
char buffer[strlen(pathFromHome)+strlen(username)];
|
|
|
|
sprintf(buffer, pathFromHome, username);
|
|
|
|
std::string i2pBaseDir(buffer);
|
|
|
|
return i2pBaseDir;
|
|
|
|
}
|
|
|
|
|
2018-06-30 13:10:06 +00:00
|
|
|
@interface MenuBarCtrl : NSObject <StatusItemButtonDelegate, NSMenuDelegate>
|
|
|
|
@property BOOL enableLogging;
|
|
|
|
@property BOOL enableVerboseLogging;
|
2018-07-24 16:26:40 +00:00
|
|
|
@property (strong) I2PStatusMenu *menu;
|
2018-06-30 13:10:06 +00:00
|
|
|
@property (strong) StatusItemButton* statusBarButton;
|
|
|
|
@property (strong) NSUserDefaults *userPreferences;
|
|
|
|
@property (strong, nonatomic) NSImage * image;
|
|
|
|
@property (strong, nonatomic) NSStatusItem *statusItem;
|
|
|
|
// Event handlers
|
|
|
|
- (void) statusItemButtonLeftClick: (StatusItemButton *) button;
|
|
|
|
- (void) statusItemButtonRightClick: (StatusItemButton *) button;
|
|
|
|
- (void) statusBarImageBtnClicked;
|
|
|
|
- (void) btnPressedAction:(id)sender;
|
2018-07-24 16:26:40 +00:00
|
|
|
- (void) menuWillOpen:(I2PStatusMenu *)menu;
|
2018-06-30 13:10:06 +00:00
|
|
|
|
2018-07-13 09:11:46 +00:00
|
|
|
- (void) openRouterConsoleBtnHandler: (NSMenuItem *) menuItem;
|
2018-06-30 13:10:06 +00:00
|
|
|
- (void) startJavaRouterBtnHandler: (NSMenuItem *) menuItem;
|
|
|
|
- (void) restartJavaRouterBtnHandler: (NSMenuItem *) menuItem;
|
|
|
|
- (void) stopJavaRouterBtnHandler: (NSMenuItem *) menuItem;
|
|
|
|
- (void) quitWrapperBtnHandler: (NSMenuItem *) menuItem;
|
|
|
|
// Methods
|
|
|
|
- (MenuBarCtrl *) init;
|
|
|
|
- (void) dealloc;
|
2018-07-24 16:26:40 +00:00
|
|
|
- (I2PStatusMenu *) createStatusBarMenu;
|
2018-06-30 13:10:06 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@protocol MenuBarCtrlDelegate
|
|
|
|
- (void) menuBarCtrlStatusChanged: (BOOL) active;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface AppDelegate : NSObject <NSUserNotificationCenterDelegate, NSApplicationDelegate> {
|
|
|
|
@public
|
|
|
|
//NSImageView *imageCell;
|
|
|
|
}
|
|
|
|
@property (strong) MenuBarCtrl *menuBarCtrl;
|
|
|
|
@property (strong) NSUserDefaults *userPreferences;
|
|
|
|
@property BOOL enableLogging;
|
|
|
|
@property BOOL enableVerboseLogging;
|
2018-07-24 16:26:40 +00:00
|
|
|
@property ExtractMetaInfo *metaInfo;
|
2018-07-13 09:11:46 +00:00
|
|
|
@property (copy) NSImage *contentImage NS_AVAILABLE(10_9, NA);
|
2018-07-24 16:26:40 +00:00
|
|
|
- (void)extractI2PBaseDir:(void(^)(BOOL success, NSError *error))completion;
|
|
|
|
- (void)startupI2PRouter;
|
2018-06-30 13:10:06 +00:00
|
|
|
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
|
|
|
|
- (void)applicationWillTerminate:(NSNotification *)aNotification;
|
|
|
|
- (void)setApplicationDefaultPreferences;
|
|
|
|
- (void)userChooseJavaHome;
|
|
|
|
- (AppDelegate *)initWithArgc:(int)argc argv:(const char **)argv;
|
|
|
|
- (NSString *)userSelectJavaHome:(JvmListPtr)rawJvmList;
|
2018-07-13 06:30:16 +00:00
|
|
|
- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center
|
|
|
|
shouldPresentNotification:(NSUserNotification *)notification;
|
2018-06-30 13:10:06 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|