source: launchers/macosx/AppDelegate.h @ e2d2264

Last change on this file since e2d2264 was 7dbf568, checked in by meeh <meeh@…>, 22 months ago

OSX Launcher: Refactor deployment code to own file, + code cleanups.

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