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

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

Fixed a load of issues related to my "sync" approach, and Mac OSX's "async" API.

  • Property mode set to 100644
File size: 4.2 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
19using namespace neither;
20
21extern JvmListSharedPtr gRawJvmList;
22
23// DO NOT ACCESS THIS GLOBAL VARIABLE DIRECTLY.
24maybeAnRouterRunner globalRouterStatus = maybeAnRouterRunner{};
25
26maybeAnRouterRunner getGlobalRouterObject()
27{
28    std::lock_guard<std::mutex> lock(globalRouterStatusMutex);
29    return globalRouterStatus;
30}
31
32void setGlobalRouterObject(RouterTask* newRouter)
33{
34    std::lock_guard<std::mutex> lock(globalRouterStatusMutex);
35    globalRouterStatus.emplace(newRouter);
36}
37
38
39
40std::vector<std::string> globVector(const std::string& pattern){
41    glob_t glob_result;
42    glob(pattern.c_str(),GLOB_TILDE,NULL,&glob_result);
43    std::vector<std::string> files;
44    for(unsigned int i=0;i<glob_result.gl_pathc;++i){
45        files.push_back(std::string(glob_result.gl_pathv[i]));
46    }
47    globfree(&glob_result);
48    return files;
49}
50
51@interface MenuBarCtrl : NSObject <StatusItemButtonDelegate, NSMenuDelegate>
52@property BOOL enableLogging;
53@property BOOL enableVerboseLogging;
54@property (strong) NSMenu *menu;
55@property (strong) StatusItemButton* statusBarButton;
56@property (strong) NSUserDefaults *userPreferences;
57@property (strong, nonatomic) NSImage * image;
58@property (strong, nonatomic) NSStatusItem *statusItem;
59// Event handlers
60- (void) statusItemButtonLeftClick: (StatusItemButton *) button;
61- (void) statusItemButtonRightClick: (StatusItemButton *) button;
62- (void) statusBarImageBtnClicked;
63- (void) btnPressedAction:(id)sender;
64- (void) menuWillOpen:(NSMenu *)menu;
65
66- (void) startJavaRouterBtnHandler: (NSMenuItem *) menuItem;
67- (void) restartJavaRouterBtnHandler: (NSMenuItem *) menuItem;
68- (void) stopJavaRouterBtnHandler: (NSMenuItem *) menuItem;
69- (void) quitWrapperBtnHandler: (NSMenuItem *) menuItem;
70// Methods
71- (MenuBarCtrl *) init;
72- (void) dealloc;
73- (NSMenu *) createStatusBarMenu;
74@end
75
76@protocol MenuBarCtrlDelegate
77- (void) menuBarCtrlStatusChanged: (BOOL) active;
78@end
79
80@interface AppDelegate : NSObject <NSUserNotificationCenterDelegate, NSApplicationDelegate> {
81@public
82  //NSImageView *imageCell;
83}
84@property (strong) MenuBarCtrl *menuBarCtrl;
85@property (strong) NSUserDefaults *userPreferences;
86@property BOOL enableLogging;
87@property BOOL enableVerboseLogging;
88- (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
89- (void)applicationWillTerminate:(NSNotification *)aNotification;
90- (void)setApplicationDefaultPreferences;
91- (void)userChooseJavaHome;
92- (AppDelegate *)initWithArgc:(int)argc argv:(const char **)argv;
93- (NSString *)userSelectJavaHome:(JvmListPtr)rawJvmList;
94- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center
95                               shouldPresentNotification:(NSUserNotification *)notification;
96@end
97
98
99/*
100
101
102@implementation CNSStatusBarCtrl
103-(id)initWithSysTray:(I2PCtrlSysIcon *)sys
104{
105  self = [super init];
106  if (self) {
107    item = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength] retain];
108    menu = 0;
109    systray = sys;
110    imageCell = [[NSImageView alloc] initWithParent:self];
111    [item setView: imageCell];
112    [item setHidden: NO];
113    CFShow(CFSTR("CNSStatusBarCtrl::initWithSysTray executed"));
114  }
115  return self;
116}
117-(NSStatusItem*)item {
118    return item;
119}
120-(void)dealloc {
121  [[NSStatusBar systemStatusBar] removeStatusItem:item];
122  [[NSNotificationCenter defaultCenter] removeObserver:imageCell];
123  [imageCell release];
124  [item release];
125  [super dealloc];
126}
127@end
128
129
130class CSystemTrayIcon
131{
132public:
133  CSystemTrayIcon(I2PCtrlSysIcon *sys)
134  {
135    item = [[CNSStatusBarCtrl alloc] initWithSysTray:sys];
136    [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:item];
137    const int menuHeight = [[NSStatusBar systemStatusBar] thickness];
138    printf("menuHeight: %d\n", menuHeight);
139    [[[item item] view] setHidden: NO];
140  }
141  ~CSystemTrayIcon()
142  {
143    [[[item item] view] setHidden: YES];
144    [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:nil];
145    [item release];
146  }
147  CNSStatusBarCtrl *item;
148};
149*/
150
151
152#endif
Note: See TracBrowser for help on using the repository browser.