@@ -14,9 +14,11 @@ var app_data_dir: String
1414var tree : Tree
1515var devices_btn : OptionButton
1616var dock_menu_button : MenuButton
17+ var status_label : Label
1718
1819var current_device : String
1920var show_all := false
21+ var is_busy := false
2022
2123enum ContextMenu {
2224 NEW_FILE ,
@@ -81,11 +83,16 @@ func _setup_ui() -> void:
8183 tree .item_collapsed .connect (_on_item_collapsed )
8284 tree .item_mouse_selected .connect (_on_item_mouse_selected )
8385 add_child (tree )
86+
87+ status_label = Label .new ()
88+ status_label .text = "Ready"
89+ status_label .add_theme_color_override ("font_color" , Color (0.6 , 0.6 , 0.6 ))
90+ add_child (status_label )
8491
8592
8693func _on_item_mouse_selected (pos : Vector2 , mouse_button_index : int ) -> void :
8794 if mouse_button_index == MOUSE_BUTTON_RIGHT :
88- create_context_menu ()
95+ _create_context_menu ()
8996
9097
9198func _on_dock_menu_item_pressed (id : int ) -> void :
@@ -229,7 +236,7 @@ func _show_file_dialog(remote_path: String, is_uploading: bool, is_dir: bool = f
229236 file_dialog .file_mode = FileDialog .FILE_MODE_SAVE_FILE
230237 file_dialog .title = "Save file as..."
231238 file_dialog .current_file = remote_path .get_file ()
232- file_dialog .file_selected .connect (_pull_single_file .bind (remote_path ))
239+ file_dialog .file_selected .connect (_pull_file .bind (remote_path ))
233240
234241 add_child (file_dialog )
235242 file_dialog .popup_file_dialog ()
@@ -312,6 +319,24 @@ func _dialog_visibility_changed(dialog: Window) -> void:
312319
313320# ADB Handling--------------------------------------------------------------------------------------
314321
322+ func _execute_threaded (callable : Callable , status_msg : String ) -> void :
323+ if is_busy : return
324+ _update_status (status_msg , true )
325+
326+ WorkerThreadPool .add_task (func ():
327+ callable .call ()
328+ call_deferred ("_update_status" , "Ready" , false )
329+ )
330+
331+
332+ func _update_status (msg : String , busy : bool ) -> void :
333+ is_busy = busy
334+ status_label .text = msg
335+ status_label .add_theme_color_override ("font_color" , Color (1 , 0.8 , 0.3 ) if busy else Color (0.6 , 0.6 , 0.6 ))
336+ process_mode = Node .PROCESS_MODE_DISABLED if busy else Node .PROCESS_MODE_INHERIT
337+ modulate = Color (1 , 1 , 1 , 0.5 ) if busy else Color (1 , 1 , 1 , 1 )
338+
339+
315340func _run_adb (p_args : PackedStringArray ) -> String :
316341 var args : PackedStringArray = []
317342 if not current_device .is_empty ():
@@ -353,7 +378,19 @@ func _list_dir(path: String) -> Array:
353378 return files
354379
355380
381+ func _pull_file (local_path : String , remote_path : String ) -> void :
382+ _execute_threaded (func ():
383+ _pull_file_internal (local_path , remote_path )
384+ , "Pulling: " + remote_path .get_file ())
385+
386+
356387func _pull_dir (local_path : String , remote_path : String ) -> void :
388+ _execute_threaded (func ():
389+ _pull_dir_internal (local_path , remote_path )
390+ , "Pulling Directory: " + remote_path .get_file ())
391+
392+
393+ func _pull_dir_internal (local_path : String , remote_path : String ) -> void :
357394 if not remote_path .begins_with (app_data_dir ):
358395 _run_adb (["pull" , remote_path , local_path ])
359396 return
@@ -378,10 +415,10 @@ func _pull_dir(local_path: String, remote_path: String) -> void:
378415 if is_dir :
379416 _pull_dir (item_local_path , item_remote_path )
380417 else :
381- _pull_single_file (item_local_path , item_remote_path )
418+ _pull_file_internal (item_local_path , item_remote_path )
382419
383420
384- func _pull_single_file (local_path : String , remote_path : String ) -> void :
421+ func _pull_file_internal (local_path : String , remote_path : String ) -> void :
385422 if not remote_path .begins_with (app_data_dir ):
386423 _run_adb (["pull" , remote_path , local_path ])
387424 return
@@ -398,36 +435,31 @@ func _pull_single_file(local_path: String, remote_path: String) -> void:
398435
399436
400437func _push (local_path : String , remote_path : String ) -> void :
401- if not remote_path .begins_with (app_data_dir ):
402- _run_adb (["push" , local_path , remote_path ])
403- return
404-
405- # special handling for app's private data dir
406- var temp_name = "temp_" + str (Time .get_ticks_usec ())
407- var temp_path = PULL_PUSH_TEMP .path_join (temp_name )
408-
409- _run_adb (["push" , local_path , temp_path ])
410-
411- var source_name = local_path .get_file ()
412- var exact_remote_path = remote_path .path_join (source_name )
413-
414- var cp_cmd = "cp -r '%s ' '%s '" % [temp_path , exact_remote_path ]
415- _run_adb (["shell" , "run-as" , package_name , cp_cmd ])
416- _run_adb (["shell" , "rm" , "-rf" , temp_path ])
417-
418- # Finally refresh the tree view to show newly uploaded file
419- _on_dir_expanded (tree .get_selected (), true )
438+ _execute_threaded (func ():
439+ if not remote_path .begins_with (app_data_dir ):
440+ _run_adb (["push" , local_path , remote_path ])
441+ else :
442+ var temp_name = "temp_" + str (Time .get_ticks_usec ())
443+ var temp_path = PULL_PUSH_TEMP .path_join (temp_name )
444+ _run_adb (["push" , local_path , temp_path ])
445+ var exact_remote_path = remote_path .path_join (local_path .get_file ())
446+ var cp_cmd = "cp -r '%s ' '%s '" % [temp_path , exact_remote_path ]
447+ _run_adb (["shell" , "run-as" , package_name , cp_cmd ])
448+ _run_adb (["shell" , "rm" , "-rf" , temp_path ])
449+
450+ call_deferred ("_on_dir_expanded" , tree .get_selected (), true )
451+ , "Uploading: " + local_path .get_file ())
420452
421453
422454func _delete (remote_path : String ) -> void :
423- var delete_cmd = "rm -r ' %s '" % remote_path
424- if remote_path . begins_with ( app_data_dir ):
425- _run_adb ([ "shell" , "run-as" , package_name , delete_cmd ])
426- else :
427- _run_adb ([ "shell" , delete_cmd ])
428-
429- # Finally refresh the tree view
430- _on_dir_expanded ( tree . get_selected (). get_parent (), true )
455+ _execute_threaded ( func ():
456+ var delete_cmd = "rm -r ' %s '" % remote_path
457+ if remote_path . begins_with ( app_data_dir ):
458+ _run_adb ([ "shell" , "run-as" , package_name , delete_cmd ])
459+ else :
460+ _run_adb ([ "shell" , delete_cmd ])
461+ call_deferred ( "_on_dir_expanded" , tree . get_selected (). get_parent (), true )
462+ , "Deleting: " + remote_path . get_file () )
431463
432464
433465func _create_file_or_directory (path : String , creating_dir : bool ) -> void :
@@ -457,7 +489,7 @@ func _get_icon_for_ext(path: String) -> String:
457489 _ : return "File"
458490
459491
460- func create_context_menu () -> void :
492+ func _create_context_menu () -> void :
461493 var item = tree .get_selected ()
462494 if not item : return
463495
0 commit comments