source: launchers/macosx/AppDelegate.h @ 5ed701d

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

Mac OS X Launcher: more cleanup and some bugfixes.

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