Skip to content

Commit 333c710

Browse files
authored
library: Replace Pixbufs with Textures in HTTP Image demo (#796)
1 parent 9c56539 commit 333c710

1 file changed

Lines changed: 8 additions & 11 deletions

File tree

  • src/Library/demos/HTTP Image
Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,31 @@
11
import GLib from "gi://GLib";
22
import Gdk from "gi://Gdk";
3-
import GdkPixbuf from "gi://GdkPixbuf";
43
import Gio from "gi://Gio";
54
import Soup from "gi://Soup";
65

76
// https://picsum.photos/
87
const IMAGE_URL = "https://picsum.photos/800";
98

10-
Gio._promisify(Soup.Session.prototype, "send_async", "send_finish");
119
Gio._promisify(
12-
GdkPixbuf.Pixbuf,
13-
"new_from_stream_async",
14-
"new_from_stream_finish",
10+
Soup.Session.prototype,
11+
"send_and_read_async",
12+
"send_and_read_finish",
1513
);
1614

17-
const input_stream = await getInputStream(IMAGE_URL);
18-
const pixbuf = await GdkPixbuf.Pixbuf.new_from_stream_async(input_stream, null);
19-
const texture = Gdk.Texture.new_for_pixbuf(pixbuf);
15+
const image_bytes = await getImageBytes(IMAGE_URL);
16+
const texture = Gdk.Texture.new_from_bytes(image_bytes);
2017
workbench.builder.get_object("picture").set_paintable(texture);
2118

22-
async function getInputStream(url) {
19+
async function getImageBytes(url) {
2320
const session = new Soup.Session();
2421
const message = new Soup.Message({
2522
method: "GET",
2623
uri: GLib.Uri.parse(url, GLib.UriFlags.NONE),
2724
});
28-
const input_stream = await session.send_async(message, null, null);
25+
const bytes = await session.send_and_read_async(message, null, null);
2926
const { status_code, reason_phrase } = message;
3027
if (status_code !== 200) {
3128
throw new Error(`Got ${status_code}, ${reason_phrase}`);
3229
}
33-
return input_stream;
30+
return bytes;
3431
}

0 commit comments

Comments
 (0)