source: launchers/macosx/SBridge.h @ e8decff5

Last change on this file since e8decff5 was e8decff5, checked in by meeh <meeh@…>, 20 months ago

Mac OS X Launcher: more cleanup and some bugfixes.

  • Property mode set to 100644
File size: 1.6 KB
Line 
1//
2//  SBridge.h
3//  I2PLauncher
4//
5//  Created by Mikal Villa on 18/09/2018.
6//  Copyright © 2018 The I2P Project. All rights reserved.
7//
8
9#import <Foundation/Foundation.h>
10#import <Cocoa/Cocoa.h>
11
12#ifdef __cplusplus
13#include <memory>
14#include <future>
15#include <glob.h>
16#include <string>
17#include <vector>
18#include "include/fn.h"
19std::future<int> startupRouter(NSString* javaBin, NSArray<NSString*>* arguments, NSString* i2pBaseDir);
20
21
22namespace osx {
23  inline void openUrl(NSString* url)
24  {
25    [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString: url]];
26  }
27}
28
29inline std::vector<std::string> globVector(const std::string& pattern){
30  glob_t glob_result;
31  glob(pattern.c_str(),GLOB_TILDE,NULL,&glob_result);
32  std::vector<std::string> files;
33  for(unsigned int i=0;i<glob_result.gl_pathc;++i){
34    files.push_back(std::string(glob_result.gl_pathv[i]));
35  }
36  globfree(&glob_result);
37  return files;
38}
39
40inline std::string buildClassPathForObjC(std::string basePath)
41{
42  NSBundle *launcherBundle = [NSBundle mainBundle];
43  auto jarList = globVector(basePath+std::string("/lib/*.jar"));
44 
45  std::string classpathStrHead = "-classpath";
46  std::string classpathStr = "";
47  classpathStr += [[launcherBundle pathForResource:@"launcher" ofType:@"jar"] UTF8String];
48  std::string prefix(basePath);
49  prefix += "/lib/";
50  for_each(jarList, [&classpathStr](std::string str){ classpathStr += std::string(":") + str; });
51  return classpathStr;
52}
53
54#endif
55
56@interface SBridge : NSObject
57- (NSString*) buildClassPath:(NSString*)i2pPath;
58- (void) startupI2PRouter:(NSString*)i2pRootPath javaBinPath:(NSString*)javaBinPath;
59- (void) openUrl:(NSString*)url;
60@end
Note: See TracBrowser for help on using the repository browser.