source: launchers/macosx/obj-cpp/AppDelegate.h @ c8490a3

Last change on this file since c8490a3 was c8490a3, checked in by meeh <meeh@…>, 2 years ago

Starting to get stable and usable. Basically everything is based on callbacks.

  • Property mode set to 100644
File size: 5.4 KB
Line 
1#ifndef __APPDELEGATE_H__
2#define __APPDELEGATE_H__
3
4#include <algorithm>
5#include <string>
6#include <memory>
7
8#include <Cocoa/Cocoa.h>
9
10#include "StatusItemButton.h"
11#include "JavaHelper.h"
12#include "RouterTask.h"
13#include "neither/maybe.hpp"
14#include "optional.hpp"
15#include "subprocess.hpp"
16#include <glob.h>
17#include <vector>
18
19
20#define DEF_I2P_VERSION "0.9.35"
21#define APPDOMAIN "net.i2p.launcher"
22#define NSAPPDOMAIN @APPDOMAIN
23#define CFAPPDOMAIN CFSTR(APPDOMAIN)
24#define APP_IDSTR @"I2P Launcher"
25
26
27using namespace neither;
28
29using maybeAnRouterRunner = std::experimental::optional<RouterTask*>;
30
31
32extern JvmListSharedPtr gRawJvmList;
33
34// DO NOT ACCESS THIS GLOBAL VARIABLE DIRECTLY.
35static std::mutex globalRouterStatusMutex;
36static maybeAnRouterRunner globalRouterStatus = maybeAnRouterRunner{};
37
38maybeAnRouterRunner getGlobalRouterObject();
39void setGlobalRouterObject(RouterTask* newRouter);
40
41@class ExtractMetaInfo;
42@interface ExtractMetaInfo : NSObject
43@property (strong) NSString* i2pBase;
44@property (strong) NSString* javaBinary;
45@property (strong) NSString* zipFile;
46@property (strong) NSString* jarFile;
47@end
48
49inline void sendUserNotification(NSString* title, NSString* informativeText, NSImage* contentImage = NULL, bool makeSound = false) {
50  NSUserNotification *userNotification = [[[NSUserNotification alloc] init] autorelease];
51
52  userNotification.title = title;
53  userNotification.informativeText = informativeText;
54  if (contentImage != NULL) userNotification.contentImage = contentImage;
55  if (makeSound) userNotification.soundName = NSUserNotificationDefaultSoundName;
56
57  [[NSUserNotificationCenter defaultUserNotificationCenter] scheduleNotification:userNotification];
58};
59
60inline std::vector<std::string> globVector(const std::string& pattern){
61    glob_t glob_result;
62    glob(pattern.c_str(),GLOB_TILDE,NULL,&glob_result);
63    std::vector<std::string> files;
64    for(unsigned int i=0;i<glob_result.gl_pathc;++i){
65        files.push_back(std::string(glob_result.gl_pathv[i]));
66    }
67    globfree(&glob_result);
68    return files;
69}
70
71@interface MenuBarCtrl : NSObject <StatusItemButtonDelegate, NSMenuDelegate>
72@property BOOL enableLogging;
73@property BOOL enableVerboseLogging;
74@property (strong) NSMenu *menu;
75@property (strong) StatusItemButton* statusBarButton;
76@property (strong) NSUserDefaults *userPreferences;
77@property (strong, nonatomic) NSImage * image;
78@property (strong, nonatomic) NSStatusItem *statusItem;
79// Event handlers
80- (void) statusItemButtonLeftClick: (StatusItemButton *) button;
81- (void) statusItemButtonRightClick: (StatusItemButton *) button;
82- (void) statusBarImageBtnClicked;
83- (void) btnPressedAction:(id)sender;
84- (void) menuWillOpen:(NSMenu *)menu;
85
86- (void) openRouterConsoleBtnHandler: (NSMenuItem *) menuItem;
87- (void) startJavaRouterBtnHandler: (NSMenuItem *) menuItem;
88- (void) restartJavaRouterBtnHandler: (NSMenuItem *) menuItem;
89- (void) stopJavaRouterBtnHandler: (NSMenuItem *) menuItem;
90- (void) quitWrapperBtnHandler: (NSMenuItem *) menuItem;
91// Methods
92- (MenuBarCtrl *) init;
93- (void) dealloc;
94- (NSMenu *) createStatusBarMenu;
95@end
96
97@protocol MenuBarCtrlDelegate
98- (void) menuBarCtrlStatusChanged: (BOOL) active;
99@end
100
101@interface AppDelegate : NSObject <NSUserNotificationCenterDelegate, NSApplicationDelegate> {
102@public
103  //NSImageView *imageCell;
104}
105@property (strong) MenuBarCtrl *menuBarCtrl;
106@property (strong) NSUserDefaults *userPreferences;
107@property BOOL enableLogging;
108@property BOOL enableVerboseLogging;
109@property (copy) NSImage *contentImage NS_AVAILABLE(10_9, NA);
110- (void)extractI2PBaseDir:(ExtractMetaInfo *)metaInfo completion:(void(^)(BOOL success, NSError *error))completion;
111- (void)startupI2PRouter:(ExtractMetaInfo *)metaInfo;
112- (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
113- (void)applicationWillTerminate:(NSNotification *)aNotification;
114- (void)setApplicationDefaultPreferences;
115- (void)userChooseJavaHome;
116- (AppDelegate *)initWithArgc:(int)argc argv:(const char **)argv;
117- (NSString *)userSelectJavaHome:(JvmListPtr)rawJvmList;
118- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center
119                               shouldPresentNotification:(NSUserNotification *)notification;
120@end
121
122
123/*
124
125
126@implementation CNSStatusBarCtrl
127-(id)initWithSysTray:(I2PCtrlSysIcon *)sys
128{
129  self = [super init];
130  if (self) {
131    item = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength] retain];
132    menu = 0;
133    systray = sys;
134    imageCell = [[NSImageView alloc] initWithParent:self];
135    [item setView: imageCell];
136    [item setHidden: NO];
137    CFShow(CFSTR("CNSStatusBarCtrl::initWithSysTray executed"));
138  }
139  return self;
140}
141-(NSStatusItem*)item {
142    return item;
143}
144-(void)dealloc {
145  [[NSStatusBar systemStatusBar] removeStatusItem:item];
146  [[NSNotificationCenter defaultCenter] removeObserver:imageCell];
147  [imageCell release];
148  [item release];
149  [super dealloc];
150}
151@end
152
153
154class CSystemTrayIcon
155{
156public:
157  CSystemTrayIcon(I2PCtrlSysIcon *sys)
158  {
159    item = [[CNSStatusBarCtrl alloc] initWithSysTray:sys];
160    [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:item];
161    const int menuHeight = [[NSStatusBar systemStatusBar] thickness];
162    printf("menuHeight: %d\n", menuHeight);
163    [[[item item] view] setHidden: NO];
164  }
165  ~CSystemTrayIcon()
166  {
167    [[[item item] view] setHidden: YES];
168    [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:nil];
169    [item release];
170  }
171  CNSStatusBarCtrl *item;
172};
173*/
174
175
176#endif
Note: See TracBrowser for help on using the repository browser.