Only update preview if the file is a valid image

This commit is contained in:
Romain Vigier
2020-08-03 22:56:02 +02:00
parent 886ea9ed09
commit 86b821f514
2 changed files with 11 additions and 5 deletions
+10 -4
View File
@@ -455,8 +455,11 @@ const Preferences = class {
this.settings.connect('changed::background-day', () => updateBackgroundsBackgroundsDayBackgroundButtonUri());
backgroundsBackgroundsDayBackgroundButton.connect('update-preview', () => {
const file = backgroundsBackgroundsDayBackgroundButton.get_preview_filename();
const pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(file, 256, 256);
dayBackgroundPreview.set_from_pixbuf(pixbuf);
const allowedContentTypes = ['image/jpeg', 'image/png', 'image/tiff'];
if (allowedContentTypes.includes(Gio.content_type_guess(file, null)[0])) {
const pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(file, 256, 256);
dayBackgroundPreview.set_from_pixbuf(pixbuf);
}
});
backgroundsBackgroundsDayBackgroundButton.connect('file-set', () => {
this.settings.set_string('background-day', backgroundsBackgroundsDayBackgroundButton.get_uri());
@@ -471,8 +474,11 @@ const Preferences = class {
this.settings.connect('changed::background-night', () => updateBackgroundsBackgroundsNightBackgroundButtonUri());
backgroundsBackgroundsNightBackgroundButton.connect('update-preview', () => {
const file = backgroundsBackgroundsNightBackgroundButton.get_preview_filename();
const pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(file, 256, 256);
nightBackgroundPreview.set_from_pixbuf(pixbuf);
const allowedContentTypes = ['image/jpeg', 'image/png', 'image/tiff'];
if (allowedContentTypes.includes(Gio.content_type_guess(file, null)[0])) {
const pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(file, 256, 256);
nightBackgroundPreview.set_from_pixbuf(pixbuf);
}
});
backgroundsBackgroundsNightBackgroundButton.connect('file-set', () => {
this.settings.set_string('background-night', backgroundsBackgroundsNightBackgroundButton.get_uri());
+1 -1
View File
@@ -20,7 +20,7 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="pixel_size">256</property>
<property name="icon_name">image-loading</property>
<property name="icon_name">image-missing</property>
<property name="icon_size">0</property>
</object>
<object class="GtkDialog" id="ondemand_keyboard_shortcut_dialog">