mirror of
https://github.com/venera-app/venera.git
synced 2025-09-26 23:47:23 +00:00
Implement writeImageToClipboard
on macOS.
This commit is contained in:
@@ -15,8 +15,11 @@ Future<void> writeImageToClipboard(Uint8List imageBytes) async {
|
|||||||
"data": Uint8List.view(data!.buffer)
|
"data": Uint8List.view(data!.buffer)
|
||||||
});
|
});
|
||||||
image.dispose();
|
image.dispose();
|
||||||
|
} else if (Platform.isMacOS) {
|
||||||
|
await channel.invokeMethod("writeImageToClipboard", {
|
||||||
|
"data": imageBytes,
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
// TODO: Implement for other platforms
|
|
||||||
throw UnsupportedError("Clipboard image is not supported on this platform");
|
throw UnsupportedError("Clipboard image is not supported on this platform");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -38,6 +38,31 @@ class AppDelegate: FlutterAppDelegate {
|
|||||||
result(FlutterMethodNotImplemented)
|
result(FlutterMethodNotImplemented)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let clipboardChannel = FlutterMethodChannel(name: "venera/clipboard", binaryMessenger: controller.engine.binaryMessenger)
|
||||||
|
|
||||||
|
clipboardChannel.setMethodCallHandler { (call, result) in
|
||||||
|
switch call.method {
|
||||||
|
case "writeImageToClipboard":
|
||||||
|
guard let arguments = call.arguments as? [String: Any],
|
||||||
|
let data = arguments["data"] as? FlutterStandardTypedData else {
|
||||||
|
result(FlutterError(code: "INVALID_ARGUMENTS", message: "Invalid arguments", details: nil))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
guard let image = NSImage(data: data.data) else {
|
||||||
|
result(FlutterError(code: "INVALID_IMAGE", message: "Could not create image from data", details: nil))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let pasteboard = NSPasteboard.general
|
||||||
|
pasteboard.clearContents()
|
||||||
|
pasteboard.writeObjects([image])
|
||||||
|
result(true)
|
||||||
|
default:
|
||||||
|
result(FlutterMethodNotImplemented)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDirectoryPath() {
|
func getDirectoryPath() {
|
||||||
|
Reference in New Issue
Block a user