Browse Source

Improve CSPasteboardDelegate compatibility with Swift

osy 3 năm trước cách đây
mục cha
commit
efb56207de

+ 6 - 6
Sources/CocoaSpice/CSSession.m

@@ -19,8 +19,8 @@
 #import <spice-client.h>
 #import <spice/vd_agent.h>
 
-const NSNotificationName CSPasteboardChangedNotification = @"CSPasteboardChangedNotification";
-const NSNotificationName CSPasteboardRemovedNotification = @"CSPasteboardRemovedNotification";
+const NSNotificationName kCSPasteboardChangedNotification = @"CSPasteboardChangedNotification";
+const NSNotificationName kCSPasteboardRemovedNotification = @"CSPasteboardRemovedNotification";
 
 @interface CSSession ()
 
@@ -274,12 +274,12 @@ static void cs_channel_destroy(SpiceSession *session, SpiceChannel *channel,
     if (self = [super init]) {
         [[NSNotificationCenter defaultCenter] addObserver:self
                                                  selector:@selector(pasteboardDidChange:)
-                                                     name:CSPasteboardChangedNotification
+                                                     name:kCSPasteboardChangedNotification
                                                    object:nil];
         
         [[NSNotificationCenter defaultCenter] addObserver:self
                                                  selector:@selector(pasteboardDidRemove:)
-                                                     name:CSPasteboardRemovedNotification
+                                                     name:kCSPasteboardRemovedNotification
                                                    object:nil];
         self.shareClipboard = YES;
     }
@@ -320,11 +320,11 @@ static void cs_channel_destroy(SpiceSession *session, SpiceChannel *channel,
     g_object_unref(self.session);
     self.session = NULL;
     [[NSNotificationCenter defaultCenter] removeObserver:self
-                                                    name:CSPasteboardChangedNotification
+                                                    name:kCSPasteboardChangedNotification
                                                   object:nil];
     
     [[NSNotificationCenter defaultCenter] removeObserver:self
-                                                    name:CSPasteboardRemovedNotification
+                                                    name:kCSPasteboardRemovedNotification
                                                   object:nil];
 }
 

+ 6 - 4
Sources/CocoaSpice/include/CSPasteboardDelegate.h

@@ -35,10 +35,10 @@ typedef NS_ENUM(NSInteger, CSPasteboardType) {
 };
 
 /// Notification posted when pasteboard changes
-extern const NSNotificationName _Nonnull CSPasteboardChangedNotification;
+extern const NSNotificationName _Nonnull kCSPasteboardChangedNotification;
 
 /// Notification posted when an item is removed from the pasteboard
-extern const NSNotificationName _Nonnull CSPasteboardRemovedNotification;
+extern const NSNotificationName _Nonnull kCSPasteboardRemovedNotification;
 
 NS_ASSUME_NONNULL_BEGIN
 
@@ -53,7 +53,8 @@ NS_ASSUME_NONNULL_BEGIN
 
 /// Get pasteboard data from system
 /// @param type Pasteboard type
-- (NSData *)dataForType:(CSPasteboardType)type;
+/// @returns data or nil if data is not found or is not of correct type
+- (nullable NSData *)dataForType:(CSPasteboardType)type;
 
 /// Sets pasteboard data in system
 /// @param data Pasteboard data
@@ -61,7 +62,8 @@ NS_ASSUME_NONNULL_BEGIN
 - (void)setData:(NSData *)data forType:(CSPasteboardType)type;
 
 /// Gets a string type pasteboard item from system
-- (NSString *)string;
+/// @returns string or nil if string is not found or is not of correct type
+- (nullable NSString *)string;
 
 /// Sets a string type pasteboard item to system
 /// @param string Pasteboard data