source: launchers/macosx/AppDelegate.h @ eca5805

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

OSX Launcher: make deployer an property so it's not deleted in mid-extract by GC.

  • Property mode set to 100644
File size: 3.2 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#include "SBridge.h"
17
18
19#include "RouterTask.h"
20
21#include "version.h"
22
23@class SwiftMainDelegate;
24@class I2PDeployer;
25
26@protocol SwiftMainDelegateProto
27- (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
28@end
29
30
31@class ExtractMetaInfo;
32
33@interface ExtractMetaInfo : NSObject
34@property (copy) NSString* i2pBase;
35@property (copy) NSString* javaBinary;
36@property (copy) NSString* zipFile;
37@property (copy) NSString* jarFile;
38@end
39
40
41#ifdef __cplusplus
42
43inline const char* RealHomeDirectory() {
44  struct passwd *pw = getpwuid(getuid());
45  assert(pw);
46  return pw->pw_dir;
47}
48
49inline std::string getDefaultBaseDir()
50{
51  // Figure out base directory
52  auto homeDir = RealHomeDirectory();
53  const char* pathFromHome = "%s/Library/I2P";
54  char buffer[strlen(homeDir)+strlen(pathFromHome)];
55  sprintf(buffer, pathFromHome, homeDir);
56  std::string i2pBaseDir(buffer);
57  return i2pBaseDir;
58}
59
60inline std::string getDefaultLogDir()
61{
62  // Figure out log directory
63  auto homeDir = RealHomeDirectory();
64  const char* pathFromHome = "%s/Library/Logs/I2P";
65  char buffer[strlen(homeDir)+strlen(pathFromHome)];
66  sprintf(buffer, pathFromHome, homeDir);
67  std::string i2pBaseDir(buffer);
68  return i2pBaseDir;
69}
70
71inline void sendUserNotification(NSString* title, NSString* informativeText, bool makeSound = false) {
72  NSUserNotification *userNotification = [[NSUserNotification alloc] init];
73 
74  userNotification.title = title;
75  userNotification.informativeText = informativeText;
76  NSBundle *launcherBundle = [NSBundle mainBundle];
77  auto resPath = [launcherBundle resourcePath];
78  auto stdResPath = std::string([resPath UTF8String]);
79  stdResPath += "/AppImage.png";
80  auto nsString = [[NSString alloc] initWithUTF8String:(const char*)stdResPath.c_str()];
81  NSImage *appImage = [[NSImage alloc] initWithContentsOfFile:nsString];
82  userNotification.contentImage = appImage;
83  if (makeSound) userNotification.soundName = NSUserNotificationDefaultSoundName;
84 
85  [[NSUserNotificationCenter defaultUserNotificationCenter] scheduleNotification:userNotification];
86};
87
88#endif
89
90@interface AppDelegate : NSObject <NSUserNotificationCenterDelegate, NSApplicationDelegate>
91@property BOOL enableLogging;
92@property BOOL enableVerboseLogging;
93@property (assign) SwiftMainDelegate *swiftRuntime;
94@property (assign) NSUserDefaults *userPreferences;
95@property (assign) ExtractMetaInfo *metaInfo;
96@property (assign) I2PDeployer *deployer;
97@property (copy) NSImage *contentImage NS_AVAILABLE(10_9, NA);
98
99- (void) extractI2PBaseDir:(void(^)(BOOL success, NSError *error))completion;
100- (void) awakeFromNib;
101- (void) applicationDidFinishLaunching:(NSNotification *)aNotification;
102- (void) applicationWillTerminate:(NSNotification *)aNotification;
103- (void) setApplicationDefaultPreferences;
104- (AppDelegate *) initWithArgc:(int)argc argv:(const char **)argv;
105- (BOOL) userNotificationCenter:(NSUserNotificationCenter *)center
106                               shouldPresentNotification:(NSUserNotification *)notification;
107@end
108
109
110
111
112#endif
Note: See TracBrowser for help on using the repository browser.