source: launchers/macosx/SBridge.h @ ba853a8c

Last change on this file since ba853a8c was dfcc616, checked in by meeh <meeh@…>, 22 months ago

Mac OS X Launcher: Misc changes in ObjC, forwarding sendUserNotification to Swift.

  • Property mode set to 100644
File size: 1.9 KB
RevLine 
[e046418f]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>
[e8decff5]10#import <Cocoa/Cocoa.h>
11
[3b38f5a]12#import "RouterTask.h"
13
[e8decff5]14#ifdef __cplusplus
15#include <memory>
16#include <future>
17#include <glob.h>
18#include <string>
19#include <vector>
20#include "include/fn.h"
[7a72049]21//std::future<int> startupRouter(NSString* javaBin, NSArray<NSString*>* arguments, NSString* i2pBaseDir, RouterProcessStatus* routerStatus = nil);
[e8decff5]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
[e046418f]57
[b25dec1]58
[e046418f]59@interface SBridge : NSObject
[3b38f5a]60@property (nonatomic, assign) I2PRouterTask* currentRouterInstance;
[e046418f]61- (NSString*) buildClassPath:(NSString*)i2pPath;
[b25dec1]62- (void) startupI2PRouter:(NSString*)i2pRootPath;
[e046418f]63- (void) openUrl:(NSString*)url;
[b25dec1]64+ (void) logProxy:(int)level formattedMsg:(NSString*)formattedMsg;
[dfcc616]65+ (void) sendUserNotification:(NSString*)title formattedMsg:(NSString*)formattedMsg;
[3b38f5a]66+ (instancetype)sharedInstance; // this makes it a singleton
[e046418f]67@end
Note: See TracBrowser for help on using the repository browser.