From 2c2a1ac2bc24da95873c526d0199ec781ec89742 Mon Sep 17 00:00:00 2001 From: jeffser Date: Sun, 30 Jun 2024 22:12:46 -0600 Subject: [PATCH] Verify if image can be used when pasting it --- src/window.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/window.py b/src/window.py index 352b391..85d99a9 100644 --- a/src/window.py +++ b/src/window.py @@ -1383,12 +1383,15 @@ Generate a title following these rules: try: texture = clipboard.read_texture_finish(result) if texture: - pixbuf = Gdk.pixbuf_get_from_texture(texture) - if not os.path.exists('/tmp/alpaca/images/'): - os.makedirs('/tmp/alpaca/images/') - image_name = self.generate_numbered_name('image.png', os.listdir('/tmp/alpaca/images')) - pixbuf.savev('/tmp/alpaca/images/{}'.format(image_name), "png", [], []) - self.attach_file('/tmp/alpaca/images/{}'.format(image_name), 'image') + if self.verify_if_image_can_be_used(): + pixbuf = Gdk.pixbuf_get_from_texture(texture) + if not os.path.exists('/tmp/alpaca/images/'): + os.makedirs('/tmp/alpaca/images/') + image_name = self.generate_numbered_name('image.png', os.listdir('/tmp/alpaca/images')) + pixbuf.savev('/tmp/alpaca/images/{}'.format(image_name), "png", [], []) + self.attach_file('/tmp/alpaca/images/{}'.format(image_name), 'image') + else: + self.show_toast('error', 8, self.main_overlay) except Exception as e: 'huh' def on_clipboard_paste(self, textview):