Image Message Identify QRCode Notification

This commit is contained in:
Jeason Lee 2019-10-18 10:34:44 +08:00
parent 83b5eac8d6
commit 58ea444d1a
8 changed files with 15 additions and 1 deletions

View File

@ -19,3 +19,4 @@
"Tweak.MessageMenuItem.CopyLink" = "Copy Link"; "Tweak.MessageMenuItem.CopyLink" = "Copy Link";
"Tweak.MessageMenuItem.OpenInBrowser" = "Open In Browser"; "Tweak.MessageMenuItem.OpenInBrowser" = "Open In Browser";
"Tweak.MessageMenuItem.IdentifyQRCode" = "Identify QRCode"; "Tweak.MessageMenuItem.IdentifyQRCode" = "Identify QRCode";
"Tweak.MessageMenuItem.IdentifyQRCodeNotification" = "The result of the recognition has been copied to the pasteboard";

View File

@ -19,3 +19,4 @@
"Tweak.MessageMenuItem.CopyLink" = "复制链接"; "Tweak.MessageMenuItem.CopyLink" = "复制链接";
"Tweak.MessageMenuItem.OpenInBrowser" = "使用浏览器打开"; "Tweak.MessageMenuItem.OpenInBrowser" = "使用浏览器打开";
"Tweak.MessageMenuItem.IdentifyQRCode" = "识别二维码"; "Tweak.MessageMenuItem.IdentifyQRCode" = "识别二维码";
"Tweak.MessageMenuItem.IdentifyQRCodeNotification" = "识别结果已复制到粘贴板";

View File

@ -19,3 +19,4 @@
"Tweak.MessageMenuItem.CopyLink" = "複製鏈接"; "Tweak.MessageMenuItem.CopyLink" = "複製鏈接";
"Tweak.MessageMenuItem.OpenInBrowser" = "使用瀏覽器打開"; "Tweak.MessageMenuItem.OpenInBrowser" = "使用瀏覽器打開";
"Tweak.MessageMenuItem.IdentifyQRCode" = "識別QRCode"; "Tweak.MessageMenuItem.IdentifyQRCode" = "識別QRCode";
"Tweak.MessageMenuItem.IdentifyQRCodeNotification" = "識別結果已復製到粘貼板";

View File

@ -247,7 +247,18 @@ static void __attribute__((constructor)) tweak(void) {
CIQRCodeFeature *result = results.firstObject; CIQRCodeFeature *result = results.firstObject;
NSString *content = result.messageString; NSString *content = result.messageString;
if (content.length) { if (content.length) {
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:content]]; NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
[pasteboard clearContents];
[pasteboard setString:content forType:NSStringPboardType];
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:({
NSUserNotification *notification = [[NSUserNotification alloc] init];
notification.informativeText = [NSBundle.tweakBundle localizedStringForKey:@"Tweak.MessageMenuItem.IdentifyQRCodeNotification"];
notification;
})];
NSURL *url = [NSURL URLWithString:content];
if ([url.scheme containsString:@"http"]) {
[[NSWorkspace sharedWorkspace] openURL:url];
}
} }
} }
} }