Skip to content

Commit 274e8b4

Browse files
Fix Android Native File dialog and remove permissions (#80)
1 parent 6958947 commit 274e8b4

6 files changed

Lines changed: 25 additions & 26 deletions

File tree

export_presets.cfg

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,13 @@ permissions/process_outgoing_calls=false
161161
permissions/read_calendar=false
162162
permissions/read_call_log=false
163163
permissions/read_contacts=false
164-
permissions/read_external_storage=true
164+
permissions/read_external_storage=false
165165
permissions/read_frame_buffer=false
166166
permissions/read_history_bookmarks=false
167167
permissions/read_input_state=false
168168
permissions/read_logs=false
169169
permissions/read_media_audio=false
170-
permissions/read_media_images=true
170+
permissions/read_media_images=false
171171
permissions/read_media_video=false
172172
permissions/read_media_visual_user_selected=false
173173
permissions/read_phone_state=false
@@ -216,7 +216,7 @@ permissions/write_apn_settings=false
216216
permissions/write_calendar=false
217217
permissions/write_call_log=false
218218
permissions/write_contacts=false
219-
permissions/write_external_storage=true
219+
permissions/write_external_storage=false
220220
permissions/write_gservices=false
221221
permissions/write_history_bookmarks=false
222222
permissions/write_profile=false
@@ -391,13 +391,13 @@ permissions/process_outgoing_calls=false
391391
permissions/read_calendar=false
392392
permissions/read_call_log=false
393393
permissions/read_contacts=false
394-
permissions/read_external_storage=true
394+
permissions/read_external_storage=false
395395
permissions/read_frame_buffer=false
396396
permissions/read_history_bookmarks=false
397397
permissions/read_input_state=false
398398
permissions/read_logs=false
399399
permissions/read_media_audio=false
400-
permissions/read_media_images=true
400+
permissions/read_media_images=false
401401
permissions/read_media_video=false
402402
permissions/read_media_visual_user_selected=false
403403
permissions/read_phone_state=false
@@ -446,7 +446,7 @@ permissions/write_apn_settings=false
446446
permissions/write_calendar=false
447447
permissions/write_call_log=false
448448
permissions/write_contacts=false
449-
permissions/write_external_storage=true
449+
permissions/write_external_storage=false
450450
permissions/write_gservices=false
451451
permissions/write_history_bookmarks=false
452452
permissions/write_profile=false

src/config_classes/TabData.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func _sync() -> void:
145145

146146
if is_saved():
147147
# The extension is included in the presented name because it's always in the end and can't hide useless info.
148-
presented_name = svg_file_path.get_file()
148+
presented_name = Utils.get_file_name(svg_file_path, false)
149149
empty_unsaved = false
150150

151151
if OS.has_feature("web"):

src/ui_parts/editor_scene.tscn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
[gd_scene load_steps=2 format=3 uid="uid://bihwwoedqcyo8"]
1+
[gd_scene format=3 uid="uid://bihwwoedqcyo8"]
22

33
[ext_resource type="Script" uid="uid://dunoppeuubgd1" path="res://src/ui_parts/editor_scene.gd" id="1_o7lif"]
44

5-
[node name="EditorScene" type="PanelContainer"]
5+
[node name="EditorScene" type="PanelContainer" unique_id=1706058386]
66
anchors_preset = 15
77
anchor_right = 1.0
88
anchor_bottom = 1.0

src/ui_parts/good_file_dialog.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ func get_save_name() -> String:
292292
if selected_file_paths.is_empty() or selected_file_paths[0].get_extension().is_empty():
293293
return default_saved_file
294294
else:
295-
return selected_file_paths[0].get_file()
295+
return Utils.get_file_name(selected_file_paths[0], false)
296296

297297
# For optimization, only generate the visible files' images.
298298
func _setup_file_images() -> void:

src/utils/FileUtils.gd

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,6 @@ static func open_xml_export_dialog(xml: String, file_name: String) -> void:
126126
)
127127

128128
static func _finish_export(file_path: String, export_data: ImageExportData) -> void:
129-
if not (file_path.contains("/Documents/") or file_path.contains("/Download/")):
130-
OS.alert("Saving is only allowed in the Documents or Download directories.", "Save Failed")
131-
return
132129
if file_path.get_extension().is_empty():
133130
file_path += "." + export_data.format
134131

@@ -184,13 +181,6 @@ static func open_xml_import_dialog(completion_callback: Callable) -> void:
184181

185182
# On web, the completion callback can't use the full file path.
186183
static func open_custom_import_dialog(extensions: PackedStringArray, completion_callback: Callable, multi_select := false) -> void:
187-
var permission := "android.permission.READ_MEDIA_IMAGES"
188-
if Configs.current_sdk < 33:
189-
permission = "android.permission.READ_EXTERNAL_STORAGE"
190-
191-
if not OS.request_permission(permission):
192-
return
193-
194184
var extensions_with_dots := PackedStringArray()
195185
for extension in extensions:
196186
extensions_with_dots.append("." + extension)
@@ -223,9 +213,13 @@ static func open_custom_import_dialog(extensions: PackedStringArray, completion_
223213
# Preprocessing step where all files with wrong extensions are discarded.
224214
static func _start_file_import_process(file_paths: PackedStringArray, completion_callback: Callable,
225215
allowed_extensions: PackedStringArray, show_incorrect_extension_errors := true) -> void:
226-
if not show_incorrect_extension_errors:
216+
if not file_paths.is_empty() and file_paths[0].begins_with("content://"):
217+
_file_import_proceed(file_paths, completion_callback)
218+
return
219+
220+
if (not show_incorrect_extension_errors):
227221
for i in range(file_paths.size() - 1, -1, -1):
228-
if not Utils.get_lowercase_extension(file_paths[i]) in allowed_extensions:
222+
if (not Utils.get_lowercase_extension(file_paths[i]) in allowed_extensions):
229223
file_paths.remove_at(i)
230224
if not file_paths.is_empty():
231225
_file_import_proceed(file_paths, completion_callback)
@@ -251,7 +245,7 @@ allowed_extensions: PackedStringArray, show_incorrect_extension_errors := true)
251245
passed_list = incorrect_extension_file_paths
252246
else:
253247
error_text += Translator.translate("{file_name} was discarded.").format(
254-
{"file_name": incorrect_extension_file_paths[0].get_file()})
248+
{"file_name": Utils.get_file_name(incorrect_extension_file_paths[0], false)})
255249

256250
var options_dialog := OptionsDialogScene.instantiate()
257251
HandlerGUI.add_dialog(options_dialog)
@@ -284,7 +278,7 @@ static func _file_import_proceed(file_paths: PackedStringArray, completion_callb
284278
var options_dialog := OptionsDialogScene.instantiate()
285279
HandlerGUI.add_dialog(options_dialog)
286280
var error := Translator.translate("{file_name} couldn't be opened.").format(
287-
{"file_name": Utils.simplify_file_path(file_path).get_file()})
281+
{"file_name": Utils.get_file_name(Utils.simplify_file_path(file_path), false)})
288282
if not FileAccess.file_exists(file_path):
289283
error += "\n" + Translator.translate("Check if the file still exists in the selected file path.")
290284
if not file_paths.is_empty():

src/utils/Utils.gd

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,13 @@ static func is_string_upper(string: String) -> bool:
3030
static func is_string_lower(string: String) -> bool:
3131
return string.to_lower() == string
3232

33-
static func get_file_name(string: String) -> String:
34-
return string.get_file().trim_suffix("." + string.get_extension())
33+
static func get_file_name(string: String, trim_extension := true) -> String:
34+
if string.begins_with("content://"):
35+
string = string.uri_file_decode()
36+
if trim_extension:
37+
return string.get_file().trim_suffix("." + string.get_extension())
38+
else:
39+
return string.get_file()
3540

3641
static func get_lowercase_extension(string: String) -> String:
3742
return string.get_extension().to_lower()

0 commit comments

Comments
 (0)