Files
i2p.i2p/launchers/macosx/SBridge.h

68 lines
1.9 KiB
C
Raw Normal View History

//
// SBridge.h
// I2PLauncher
//
// Created by Mikal Villa on 18/09/2018.
// Copyright © 2018 The I2P Project. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
#import "RouterTask.h"
#ifdef __cplusplus
#include <memory>
#include <future>
#include <glob.h>
#include <string>
#include <vector>
#include "include/fn.h"
//std::future<int> startupRouter(NSString* javaBin, NSArray<NSString*>* arguments, NSString* i2pBaseDir, RouterProcessStatus* routerStatus = nil);
namespace osx {
inline void openUrl(NSString* url)
{
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString: url]];
}
}
inline std::vector<std::string> globVector(const std::string& pattern){
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;
}
inline std::string buildClassPathForObjC(std::string basePath)
{
NSBundle *launcherBundle = [NSBundle mainBundle];
auto jarList = globVector(basePath+std::string("/lib/*.jar"));
std::string classpathStrHead = "-classpath";
std::string classpathStr = "";
classpathStr += [[launcherBundle pathForResource:@"launcher" ofType:@"jar"] UTF8String];
std::string prefix(basePath);
prefix += "/lib/";
for_each(jarList, [&classpathStr](std::string str){ classpathStr += std::string(":") + str; });
return classpathStr;
}
#endif
@interface SBridge : NSObject
@property (nonatomic, assign) I2PRouterTask* currentRouterInstance;
- (NSString*) buildClassPath:(NSString*)i2pPath;
- (void) startupI2PRouter:(NSString*)i2pRootPath;
- (void) openUrl:(NSString*)url;
+ (void) logProxy:(int)level formattedMsg:(NSString*)formattedMsg;
+ (void) sendUserNotification:(NSString*)title formattedMsg:(NSString*)formattedMsg;
+ (instancetype)sharedInstance; // this makes it a singleton
@end