source: launchers/macosx/SBridge.h @ 1a00f73

Last change on this file since 1a00f73 was b25dec1, checked in by meeh <meeh@…>, 22 months ago

OSX Launcher: some changes to the Swift↔Objective-C bridge

  • Property mode set to 100644
File size: 1.8 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#import "RouterTask.h"
13
14#ifdef __cplusplus
15#include <memory>
16#include <future>
17#include <glob.h>
18#include <string>
19#include <vector>
20#include "include/fn.h"
21//std::future<int> startupRouter(NSString* javaBin, NSArray<NSString*>* arguments, NSString* i2pBaseDir, RouterProcessStatus* routerStatus = nil);
22
23
24namespace osx {
25  inline void openUrl(NSString* url)
26  {
27    [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString: url]];
28  }
29}
30
31inline std::vector<std::string> globVector(const std::string& pattern){
32  glob_t glob_result;
33  glob(pattern.c_str(),GLOB_TILDE,NULL,&glob_result);
34  std::vector<std::string> files;
35  for(unsigned int i=0;i<glob_result.gl_pathc;++i){
36    files.push_back(std::string(glob_result.gl_pathv[i]));
37  }
38  globfree(&glob_result);
39  return files;
40}
41
42inline std::string buildClassPathForObjC(std::string basePath)
43{
44  NSBundle *launcherBundle = [NSBundle mainBundle];
45  auto jarList = globVector(basePath+std::string("/lib/*.jar"));
46 
47  std::string classpathStrHead = "-classpath";
48  std::string classpathStr = "";
49  classpathStr += [[launcherBundle pathForResource:@"launcher" ofType:@"jar"] UTF8String];
50  std::string prefix(basePath);
51  prefix += "/lib/";
52  for_each(jarList, [&classpathStr](std::string str){ classpathStr += std::string(":") + str; });
53  return classpathStr;
54}
55
56#endif
57
58
59@interface SBridge : NSObject
60@property (nonatomic, assign) I2PRouterTask* currentRouterInstance;
61- (NSString*) buildClassPath:(NSString*)i2pPath;
62- (void) startupI2PRouter:(NSString*)i2pRootPath;
63- (void) openUrl:(NSString*)url;
64+ (void) logProxy:(int)level formattedMsg:(NSString*)formattedMsg;
65+ (instancetype)sharedInstance; // this makes it a singleton
66@end
Note: See TracBrowser for help on using the repository browser.