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:
2018-10-12 11:37:08 +02:00
parent bc0ac5d893
commit 7708f3dc74
13 changed files with 208 additions and 20 deletions

View File

@@ -4,6 +4,33 @@
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>ppi</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>pp-icon-square</string>
<key>CFBundleTypeIconFiles</key>
<array/>
<key>CFBundleTypeMIMETypes</key>
<array/>
<key>CFBundleTypeName</key>
<string>PanoPainter Image</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSIsAppleDefaultForType</key>
<true/>
<key>LSItemContentTypes</key>
<array>
<string>public.panorama-image</string>
</array>
<key>LSTypeIsPackage</key>
<integer>0</integer>
</dict>
</array>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIconFile</key>
@@ -30,5 +57,67 @@
<string>Copyright © 2018 OmixLab Ltd. All rights reserved.</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
</array>
<key>UTTypeDescription</key>
<string>PanoPainter Image</string>
<key>UTTypeIconFile</key>
<string>pp-icon-square</string>
<key>UTTypeIconFiles</key>
<array/>
<key>UTTypeIdentifier</key>
<string>public.panorama-image</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>com.apple.ostype</key>
<array>
<string>****</string>
</array>
<key>public.filename-extension</key>
<array>
<string>ppi</string>
</array>
<key>public.mime-type</key>
<array>
<string>image/ppi</string>
</array>
</dict>
</dict>
</array>
<key>UTImportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
</array>
<key>UTTypeDescription</key>
<string>PanoPainter Image</string>
<key>UTTypeIconFile</key>
<string>pp-icon-square</string>
<key>UTTypeIdentifier</key>
<string>com.panopainter.image</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>com.apple.ostype</key>
<array>
<string>****</string>
</array>
<key>public.filename-extension</key>
<array>
<string>ppi</string>
</array>
<key>public.mime-type</key>
<array>
<string>image/ppi</string>
</array>
</dict>
</dict>
</array>
</dict>
</plist>

View File

@@ -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];

View File

@@ -9,13 +9,14 @@
@interface Controller : NSWindowController<NSWindowDelegate>
@end
@interface View : NSOpenGLView
@interface View : NSOpenGLView<NSSharingServiceDelegate>
{
@public Window* wnd;
CVDisplayLinkRef dl;
NSOpenGLContext* glctx;
_CGLContextObject* cgl;
bool gl_ready;
@public NSString* file2open;
}
- (void)close;
- (void)terminateGL;
@@ -24,4 +25,5 @@
- (void)async_swap;
- (std::string)pick_file:(NSArray<NSString*>*)types;
- (std::string)pick_dir;
- (void)share_file:(NSString*)file_path;
@end