add share button and implement AirDrop share in OSX, update info.plist to set on Mac OS the default app for PPI, on iOS include the Documents/Inbox subfolder used to store the received files from AirDrop
This commit is contained in:
@@ -21,6 +21,9 @@ std::deque<std::packaged_task<void()>> tasklist;
|
||||
std::mutex task_mutex;
|
||||
|
||||
@implementation View
|
||||
{
|
||||
NSSharingService *airdrop_service;
|
||||
}
|
||||
- (void)async_lock
|
||||
{
|
||||
CGLLockContext([glctx CGLContextObj]);
|
||||
@@ -81,8 +84,39 @@ std::mutex task_mutex;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
- (void)share_file:(NSString*)file_path
|
||||
{
|
||||
NSURL *url = [NSURL fileURLWithPath:file_path];
|
||||
NSArray *objectsToShare = @[url];
|
||||
//
|
||||
// UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
|
||||
//
|
||||
// // Exclude all activities except AirDrop.
|
||||
// NSArray *excludedActivities = @[UIActivityTypePostToTwitter, UIActivityTypePostToFacebook,
|
||||
// UIActivityTypePostToWeibo,
|
||||
// UIActivityTypeMessage, UIActivityTypeMail,
|
||||
// UIActivityTypePrint, UIActivityTypeCopyToPasteboard,
|
||||
// UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll,
|
||||
// UIActivityTypeAddToReadingList, UIActivityTypePostToFlickr,
|
||||
// UIActivityTypePostToVimeo, UIActivityTypePostToTencentWeibo];
|
||||
// controller.excludedActivityTypes = excludedActivities;
|
||||
//
|
||||
// // Present the controller
|
||||
// [self presentViewController:controller animated:YES completion:nil];
|
||||
[airdrop_service performWithItems:objectsToShare];
|
||||
}
|
||||
- (NSWindow *)sharingService:(NSSharingService *)sharingService sourceWindowForShareItems:(NSArray *)items sharingContentScope:(NSSharingContentScope *)sharingContentScope
|
||||
{
|
||||
return self.window;
|
||||
}
|
||||
- (NSView *)anchoringViewForSharingService:(NSSharingService *)sharingService showRelativeToRect:(NSRect *)positioningRect preferredEdge:(NSRectEdge *)preferredEdge
|
||||
{
|
||||
return self;
|
||||
}
|
||||
- (instancetype)initWithFrame:(NSRect)frameRect
|
||||
{
|
||||
airdrop_service = [NSSharingService sharingServiceNamed:NSSharingServiceNameSendViaAirDrop];
|
||||
airdrop_service.delegate = self;
|
||||
gl_ready = false;
|
||||
NSOpenGLPixelFormatAttribute attrs[] =
|
||||
{
|
||||
@@ -134,6 +168,12 @@ std::mutex task_mutex;
|
||||
App::I.init();
|
||||
CGLUnlockContext([[self openGLContext] CGLContextObj]);
|
||||
gl_ready = true;
|
||||
|
||||
if ([file2open length] > 0)
|
||||
{
|
||||
LOG("open file %s", [file2open UTF8String]);
|
||||
App::I.open_document([file2open UTF8String]);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)terminateGL
|
||||
@@ -428,6 +468,7 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
|
||||
Window* window;
|
||||
Controller* controller;
|
||||
View* view;
|
||||
NSString* file2open;
|
||||
}
|
||||
@end @implementation AppOSX
|
||||
- (instancetype)init
|
||||
@@ -437,6 +478,13 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
|
||||
[self setDelegate:self];
|
||||
return self;
|
||||
}
|
||||
- (BOOL)application:(NSApplication *)sender openFile:(NSString *)filename
|
||||
{
|
||||
LOG("open file %s", [filename UTF8String]);
|
||||
//App::I.open_document([filename UTF8String]);
|
||||
file2open = filename;
|
||||
return YES;
|
||||
}
|
||||
- (void)applicationWillTerminate:(NSNotification *)notification
|
||||
{
|
||||
[view terminateGL];
|
||||
@@ -458,9 +506,10 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
|
||||
NSRect r = NSMakeRect(0, 0, App::I.width, App::I.height);
|
||||
|
||||
view = [[View alloc] initWithFrame:r];
|
||||
view->file2open = file2open;
|
||||
controller = [[Controller alloc] initWithWindow:window];
|
||||
App::I.osx_view = view;
|
||||
|
||||
|
||||
auto style = NSTitledWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask|NSClosableWindowMask;
|
||||
window = [[Window alloc] initWithContentRect:r styleMask:style backing:NSBackingStoreBuffered defer:NO];
|
||||
[window setDelegate:controller];
|
||||
@@ -471,7 +520,7 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
|
||||
[window setAcceptsMouseMovedEvents:true];
|
||||
[window makeFirstResponder:view];
|
||||
view->wnd = window;
|
||||
|
||||
|
||||
auto menubar = [NSMenu new];
|
||||
auto appMenuItem = [NSMenuItem new];
|
||||
[menubar addItem:appMenuItem];
|
||||
|
||||
Reference in New Issue
Block a user