Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Dialogs/Composer/Dialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ public class Tuba.Dialogs.Composer.Dialog : Adw.Dialog {
Adw.BreakpointConditionLengthType.MAX_WIDTH,
400, Adw.LengthUnit.SP
);
var breakpoint = new Adw.Breakpoint (condition);
var breakpoint = new Adw.Breakpoint (condition.copy());
breakpoint.add_setter (this, "is-narrow", true);
add_breakpoint (breakpoint);

Expand Down
41 changes: 41 additions & 0 deletions src/Services/Helpers/Video.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
public class Tuba.Helper.Video {
private static Soup.Session session;
private static Soup.Cache cache;

public static void clear_cache () {
new Helper.Video ();
cache.clear ();
}

public static void flush_cache () {
new Helper.Video ();
cache.flush ();
cache.dump ();
}

static construct {
cache = new Soup.Cache (
GLib.Path.build_path (GLib.Path.DIR_SEPARATOR_S, Tuba.cache_path, "soup", "videos"),
Soup.CacheType.SINGLE_USER
);
cache.load ();
cache.set_max_size (1024 * 1024 * 100 * 2);

session = new Soup.Session.with_options ("max-conns", 64, "max-conns-per-host", 64) {
user_agent = @"$(Build.NAME)/$(Build.VERSION) libsoup/$(Soup.get_major_version()).$(Soup.get_minor_version()).$(Soup.get_micro_version()) ($(Soup.MAJOR_VERSION).$(Soup.MINOR_VERSION).$(Soup.MICRO_VERSION))" // vala-lint=line-length
};
session.add_feature (cache);
}

public static async InputStream request (string? url) throws Oopsie {
if (url == null || url == "") throw new Tuba.Oopsie.INTERNAL ("No url provided");
new Helper.Video ();

var download_msg = new Soup.Message ("GET", url);
try {
return yield session.send_async (download_msg, 0, null);
} catch (Error e) {
throw new Tuba.Oopsie.INTERNAL (@"Failed to get video at \"$url\": $(e.message)");
}
}
}
1 change: 1 addition & 0 deletions src/Services/Helpers/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ sources += files(
'Blurhash.vala',
'Entity.vala',
'Image.vala',
'Video.vala',
)
2 changes: 1 addition & 1 deletion src/Views/Admin/Pages/Accounts.vala
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class Tuba.Views.Admin.Page.Accounts : Views.Admin.Page.Base {
Adw.BreakpointConditionLengthType.MAX_WIDTH,
450, Adw.LengthUnit.SP
);
var breakpoint = new Adw.Breakpoint (condition);
var breakpoint = new Adw.Breakpoint (condition.copy());
breakpoint.add_setter (revealer_box, "halign", Gtk.Align.FILL);
breakpoint.add_setter (entry_box_1, "orientation", Gtk.Orientation.VERTICAL);
breakpoint.add_setter (entry_box_2, "orientation", Gtk.Orientation.VERTICAL);
Expand Down
13 changes: 10 additions & 3 deletions src/Views/MediaViewer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -1051,9 +1051,16 @@ public class Tuba.Views.MediaViewer : Gtk.Widget, Gtk.Buildable, Adw.Swipeable {
add_todo_item (item);
#else
if (stream) {
File file = File.new_for_uri (url);
video.set_file (file);
add_todo_item (item);
Helper.Video.request.begin (url, (obj, res) => {
try {
video.set_media_stream (Gtk.MediaFile.for_input_stream (Helper.Video.request.end (res)));
add_todo_item (item);
} catch (Oopsie e) {
warning (e.message);
var dlg = app.inform (_("Error"), e.message);
dlg.present (app.main_window);
}
});
} else if (!as_is) {
download_video.begin (url, (obj, res) => {
try {
Expand Down
2 changes: 1 addition & 1 deletion src/Views/TabbedBase.vala
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public class Tuba.Views.TabbedBase : Views.Base {

if (this.current_breakpoint != null) remove_breakpoint (this.current_breakpoint);
this.small = true;
var breakpoint = new Adw.Breakpoint (condition);
var breakpoint = new Adw.Breakpoint (condition.copy());
breakpoint.add_setter (this, "title-stack-page-visible", true);
breakpoint.add_setter (switcher_bar, "reveal", true);
add_breakpoint (breakpoint);
Expand Down
4 changes: 1 addition & 3 deletions src/Widgets/Attachment/Box.vala
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,12 @@ public class Tuba.Widgets.Attachment.Box : Adw.Bin {
is_main = attachment_widgets[i].entity.url == url;

var paintable = attachment_widgets[i].pic.paintable;
var stream = false;

#if GSTREAMER
if (attachment_widgets[i].media_kind == Tuba.Attachment.MediaType.AUDIO) {
if (paintable == null) {
paintable = this.audio_fallback_paintable;
}
stream = true;
}
#endif

Expand All @@ -187,7 +185,7 @@ public class Tuba.Widgets.Attachment.Box : Adw.Bin {
attachment_widgets[i].pic.alternative_text,
null,
attachment_widgets[i].entity.blurhash,
stream,
true,
is_main,
is_main == null
);
Expand Down
Loading