Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit bb0f4be

Browse files
committed
hasStrings on mac
1 parent 169b22c commit bb0f4be

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

shell/platform/darwin/macos/framework/Source/FlutterViewController.mm

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,14 @@ - (NSDictionary*)getClipboardData:(NSString*)format;
173173
*/
174174
- (void)setClipboardData:(NSDictionary*)data;
175175

176+
/**
177+
* Returns true iff the clipboard contains nonempty string data.
178+
*
179+
* See also:
180+
* * https://developer.apple.com/documentation/uikit/uipasteboard/1829416-hasstrings
181+
*/
182+
- (NSDictionary*)clipboardHasStrings;
183+
176184
@end
177185

178186
#pragma mark - FlutterViewController implementation.
@@ -505,6 +513,8 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
505513
} else if ([call.method isEqualToString:@"Clipboard.setData"]) {
506514
[self setClipboardData:call.arguments];
507515
result(nil);
516+
} else if ([call.method isEqualToString:@"Clipboard.hasStrings"]) {
517+
result([self clipboardHasStrings]);
508518
} else {
509519
result(FlutterMethodNotImplemented);
510520
}
@@ -527,13 +537,24 @@ - (NSDictionary*)getClipboardData:(NSString*)format {
527537

528538
- (void)setClipboardData:(NSDictionary*)data {
529539
NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
530-
NSString* text = data[@"text"];
540+
NSString *text = data[@"text"];
531541
if (text && ![text isEqual:[NSNull null]]) {
532542
[pasteboard clearContents];
533543
[pasteboard setString:text forType:NSPasteboardTypeString];
534544
}
535545
}
536546

547+
- (NSDictionary*)clipboardHasStrings {
548+
NSDictionary* data = [self getClipboardData:[NSString stringWithFormat:@"%s", kTextPlainFormat]];
549+
NSString* string = data[@"text"];
550+
BOOL hasStrings = string.length > 0;
551+
return @{@"value" : @(hasStrings)};
552+
/*
553+
UIPasteboard* pasteboard = [UIPasteboard generalPasteboard];
554+
return @{@"value" : @(pasteboard.hasStrings)};
555+
*/
556+
}
557+
537558
#pragma mark - FlutterViewReshapeListener
538559

539560
/**

0 commit comments

Comments
 (0)