source: launchers/macosx/AppDelegate.h @ e046418f

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

Cleaning up the code base, remove dead code and failed attempts.

  • Property mode set to 100644
File size: 3.7 KB
Line 
1#ifndef __APPDELEGATE_H__
2#define __APPDELEGATE_H__
3
4
5#include <string.h>
6#include <memory.h>
7
8#ifdef __cplusplus
9#include <unistd.h>
10#include <sys/types.h>
11#include <pwd.h>
12#include <assert.h>
13#endif
14
15#include <Cocoa/Cocoa.h>
16
17
18#include "RouterTask.h"
19#include "JavaHelper.h"
20
21
22#define DEF_I2P_VERSION "0.9.36"
23#define APPDOMAIN "net.i2p.launcher"
24#define NSAPPDOMAIN @APPDOMAIN
25#define CFAPPDOMAIN CFSTR(APPDOMAIN)
26#define APP_IDSTR @"I2P Launcher"
27
28@class SwiftMainDelegate;
29
30@protocol SwiftMainDelegateProto
31- (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
32@end
33
34
35@class ExtractMetaInfo;
36
37
38
39@interface ExtractMetaInfo : NSObject
40@property (copy) NSString* i2pBase;
41@property (copy) NSString* javaBinary;
42@property (copy) NSString* zipFile;
43@property (copy) NSString* jarFile;
44@end
45
46
47#ifdef __cplusplus
48
49inline const char* RealHomeDirectory() {
50  struct passwd *pw = getpwuid(getuid());
51  assert(pw);
52  return pw->pw_dir;
53}
54
55inline std::string getDefaultBaseDir()
56{
57  // Figure out base directory
58  auto homeDir = RealHomeDirectory();
59  const char* pathFromHome = "%s/Library/I2P";
60  char buffer[strlen(homeDir)+strlen(pathFromHome)];
61  sprintf(buffer, pathFromHome, homeDir);
62  std::string i2pBaseDir(buffer);
63  return i2pBaseDir;
64}
65
66inline void sendUserNotification(NSString* title, NSString* informativeText, NSImage* contentImage = NULL, bool makeSound = false) {
67  NSUserNotification *userNotification = [[NSUserNotification alloc] init];
68 
69  userNotification.title = title;
70  userNotification.informativeText = informativeText;
71  NSBundle *launcherBundle = [NSBundle mainBundle];
72  auto resPath = [launcherBundle resourcePath];
73  auto stdResPath = std::string([resPath UTF8String]);
74  stdResPath += "/AppImage.png";
75  auto nsString = [[NSString alloc] initWithUTF8String:(const char*)stdResPath.c_str()];
76  NSImage *appImage = [[NSImage alloc] initWithContentsOfFile:nsString];
77  userNotification.contentImage = appImage;
78  if (makeSound) userNotification.soundName = NSUserNotificationDefaultSoundName;
79 
80  [[NSUserNotificationCenter defaultUserNotificationCenter] scheduleNotification:userNotification];
81};
82
83using maybeAnRouterRunner = I2PRouterTask*;
84
85std::vector<std::string> buildClassPath(std::string basePath);
86
87extern JvmListSharedPtr gRawJvmList;
88
89// DO NOT ACCESS THIS GLOBAL VARIABLE DIRECTLY.
90static std::mutex globalRouterStatusMutex;
91static maybeAnRouterRunner globalRouterStatus = maybeAnRouterRunner{};
92static bool isRuterRunning = false;
93
94maybeAnRouterRunner getGlobalRouterObject();
95void setGlobalRouterObject(I2PRouterTask* newRouter);
96bool getGlobalRouterIsRunning();
97void setGlobalRouterIsRunning(bool running);
98
99#include "SBridge.h"
100
101#endif
102
103@class MenuBarCtrl;
104
105@interface AppDelegate : NSObject <NSUserNotificationCenterDelegate, NSApplicationDelegate> {
106@public
107  //NSImageView *imageCell;
108}
109@property BOOL enableLogging;
110@property BOOL enableVerboseLogging;
111@property (assign) SwiftMainDelegate *swiftRuntime;
112@property (assign) NSUserDefaults *userPreferences;
113@property (assign) ExtractMetaInfo *metaInfo;
114@property (copy) NSImage *contentImage NS_AVAILABLE(10_9, NA);
115
116- (void) extractI2PBaseDir:(void(^)(BOOL success, NSError *error))completion;
117- (void) awakeFromNib;
118- (void) applicationDidFinishLaunching:(NSNotification *)aNotification;
119- (void) applicationWillTerminate:(NSNotification *)aNotification;
120- (void) setApplicationDefaultPreferences;
121- (void) userChooseJavaHome;
122- (AppDelegate *) initWithArgc:(int)argc argv:(const char **)argv;
123#ifdef __cplusplus
124- (void) startupI2PRouter;
125- (NSString *) userSelectJavaHome:(JvmListPtr)rawJvmList;
126#endif
127- (BOOL) userNotificationCenter:(NSUserNotificationCenter *)center
128                               shouldPresentNotification:(NSUserNotification *)notification;
129@end
130
131
132
133
134#endif
Note: See TracBrowser for help on using the repository browser.