Inhibit suspend on file upload/download
This commit is contained in:
parent
9214e31b98
commit
1159a169b0
|
@ -15,6 +15,8 @@ public interface Application : GLib.Application {
|
|||
public abstract StreamInteractor stream_interactor { get; set; }
|
||||
public abstract Plugins.Registry plugin_registry { get; set; }
|
||||
public abstract SearchPathGenerator? search_path_generator { get; set; }
|
||||
public abstract uint inhibit_app(string reason);
|
||||
public abstract void uninhibit_app(uint cookie);
|
||||
|
||||
internal static string print_xmpp;
|
||||
|
||||
|
|
|
@ -250,6 +250,9 @@ public class FileManager : StreamInteractionModule, Object {
|
|||
|
||||
OutputStream os = file.create(FileCreateFlags.REPLACE_DESTINATION);
|
||||
file_transfer.cancellable.reset();
|
||||
|
||||
uint inhibit_cookie = Application.get_default()
|
||||
.inhibit_app("Ongoing file download");
|
||||
uint8[] buffer = new uint8[1024];
|
||||
ssize_t read;
|
||||
while ((read = yield input_stream.read_async(buffer, Priority.LOW, file_transfer.cancellable)) > 0) {
|
||||
|
@ -259,6 +262,7 @@ public class FileManager : StreamInteractionModule, Object {
|
|||
buffer.length = 1024;
|
||||
}
|
||||
yield input_stream.close_async(Priority.LOW, file_transfer.cancellable);
|
||||
Application.get_default().uninhibit_app(inhibit_cookie);
|
||||
yield os.close_async(Priority.LOW, file_transfer.cancellable);
|
||||
file_transfer.path = file.get_basename();
|
||||
file_transfer.input_stream = yield file.read_async();
|
||||
|
|
|
@ -342,5 +342,20 @@ public class Dino.Ui.Application : Gtk.Application, Dino.Application {
|
|||
});
|
||||
dialog.present();
|
||||
}
|
||||
}
|
||||
|
||||
private uint inhibit_app(string reason) {
|
||||
uint inhibit_cookie = inhibit(window, SUSPEND, reason);
|
||||
|
||||
if (inhibit_cookie == 0) {
|
||||
warning("suspend inhibit request failed or unsupported");
|
||||
}
|
||||
|
||||
return inhibit_cookie;
|
||||
}
|
||||
|
||||
private void uninhibit_app(uint inhibit_cookie) {
|
||||
if (inhibit_cookie != 0) {
|
||||
uninhibit(inhibit_cookie);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -125,16 +125,23 @@ public class HttpFileSender : FileSender, Object {
|
|||
foreach (var entry in file_send_data.headers.entries) {
|
||||
put_message.request_headers.append(entry.key, entry.value);
|
||||
}
|
||||
|
||||
uint inhibit_cookie = 0;
|
||||
try {
|
||||
inhibit_cookie = Application.get_default()
|
||||
.inhibit_app("Ongoing file upload");
|
||||
#if SOUP_3_0
|
||||
yield session.send_async(put_message, GLib.Priority.LOW, file_transfer.cancellable);
|
||||
#else
|
||||
yield session.send_async(put_message, file_transfer.cancellable);
|
||||
#endif
|
||||
Application.get_default().uninhibit_app(inhibit_cookie);
|
||||
|
||||
if (put_message.status_code < 200 || put_message.status_code >= 300) {
|
||||
throw new FileSendError.UPLOAD_FAILED("HTTP status code %s".printf(put_message.status_code.to_string()));
|
||||
}
|
||||
} catch (Error e) {
|
||||
Application.get_default().uninhibit_app(inhibit_cookie);
|
||||
throw new FileSendError.UPLOAD_FAILED("HTTP upload error: %s".printf(e.message));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue