Skip to content
This repository has been archived by the owner on May 10, 2019. It is now read-only.

Commit

Permalink
Clean up and handle errors
Browse files Browse the repository at this point in the history
  • Loading branch information
bleakgrey committed Mar 14, 2018
1 parent c4c6441 commit d7385c1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
26 changes: 19 additions & 7 deletions src/Utils.vala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
public class Utils{

private static const string dir = "/tmp/Transporter";
private const string dir = "/tmp/Transporter";
private static string zip = null;

public static string get_send_path(string[] uris){
Expand All @@ -25,7 +25,7 @@ public class Utils{
else if(uris.length == 1 && dirs == 1)
return paths[0];
else
return get_temp_path(paths);
return get_archive_path(paths);
}

public static bool is_directory(string path){
Expand All @@ -43,14 +43,23 @@ public class Utils{
return "directory" in stdout;
}

private static string get_temp_path(string[] paths){
// magic-wormhole doesn't support multiple file sending or
// when directory contains symlinks to other directories.
//
// That's why we have to create an archive.
private static string get_archive_path(string[] paths){
info ("Preparing zip file at: "+dir);
clean_temp();

//Create temp folder
zip = "Transfer-" + new GLib.DateTime.now_local ().to_unix ().to_string ();
var zip_path = "%s/%s".printf(dir, zip);
Process.spawn_command_line_sync ("mkdir " + dir);
try{
Process.spawn_command_line_sync ("mkdir " + dir);
}
catch(GLib.SpawnError e){
warning(e.message);
}

//Create symlinks for each file
foreach (string path in paths) {
Expand All @@ -76,9 +85,12 @@ public class Utils{
}

public static void clean_temp(){
if(dir != null && dir != "/"){
info("Cleaning up temporary files");
Process.spawn_command_line_async ("rm -rf /tmp/Transporter");
info("Cleaning up temporary files");
try{
Process.spawn_command_line_sync ("rm -rf "+dir);
}
catch(GLib.SpawnError e){
warning(e.message);
}
}

Expand Down
26 changes: 22 additions & 4 deletions src/View/DropView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class DropView : Gtk.Box {
};
private const string DRAG_TEXT = _("Drag files and folders here");
private const string DROP_TEXT = _("Drop to send");
private const string PREPARE_TEXT = _("Preparing files...");

private Gtk.Label title;

Expand Down Expand Up @@ -68,14 +69,31 @@ public class DropView : Gtk.Box {

private void on_drag_data_received (Gdk.DragContext drag_context, int x, int y, Gtk.SelectionData data, uint info, uint time){
Gtk.drag_finish (drag_context, true, false, time);
title.label = _("One moment...");

var path = Utils.get_send_path (data.get_uris ());
var display = window.get_display ();
var display = window.get_display ();
var clipboard = Gtk.Clipboard.get_for_display (display, Gdk.SELECTION_CLIPBOARD);
window.prevScreen();
window.addScreen (new SendView (window, clipboard));
window.wormhole.send (path);
title.label = PREPARE_TEXT;

var uris = data.get_uris ();
try{
if(Thread.supported ()){
new Thread<bool>.try ("PackThread", () => {
var path = Utils.get_send_path (uris);
wormhole.send (path);
return false;
});
}
else{
var path = Utils.get_send_path (uris);
wormhole.send (path);
}
}
catch(Error e){
warning(e.message);
wormhole.errored(e.message, _("Internal Error"), true);
}
}

}

0 comments on commit d7385c1

Please sign in to comment.