Commit missing SharePlugin source
I seem to have forgotten to add my patched version of the SharePlugin in
commit 7f06f39f7e, so here it is.
			
			
This commit is contained in:
		
							parent
							
								
									3ab6348084
								
							
						
					
					
						commit
						529dee2577
					
				|  | @ -0,0 +1,80 @@ | ||||||
|  | # | ||||||
|  | # © 2024-present https://github.com/cengiz-pz | ||||||
|  | # | ||||||
|  | 
 | ||||||
|  | @tool | ||||||
|  | class_name Share | ||||||
|  | extends Node | ||||||
|  | 
 | ||||||
|  | const PLUGIN_SINGLETON_NAME: String = "SharePlugin" | ||||||
|  | const MIME_TYPE_TEXT: String = "text/plain" | ||||||
|  | const MIME_TYPE_IMAGE: String = "image/*" | ||||||
|  | 
 | ||||||
|  | @onready var _temp_image_path: String = OS.get_user_data_dir() + "/tmp_share_img_path.png" | ||||||
|  | 
 | ||||||
|  | var _plugin_singleton: Object | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | func _ready() -> void: | ||||||
|  | 	if OS.get_name() == "Android": | ||||||
|  | 		_update_plugin() | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | func _notification(a_what: int) -> void: | ||||||
|  | 	if a_what == NOTIFICATION_APPLICATION_RESUMED: | ||||||
|  | 		_update_plugin() | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | func _update_plugin() -> void: | ||||||
|  | 	if _plugin_singleton == null: | ||||||
|  | 		if Engine.has_singleton(PLUGIN_SINGLETON_NAME): | ||||||
|  | 			_plugin_singleton = Engine.get_singleton(PLUGIN_SINGLETON_NAME) | ||||||
|  | 		else: | ||||||
|  | 			printerr("%s singleton not found!" % PLUGIN_SINGLETON_NAME) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | func share_text(a_title: String, a_subject: String, a_content: String) -> void: | ||||||
|  | 	if _plugin_singleton != null: | ||||||
|  | 		_plugin_singleton.share( | ||||||
|  | 			SharedData.new() | ||||||
|  | 				.set_title(a_title) | ||||||
|  | 				.set_subject(a_subject) | ||||||
|  | 				.set_content(a_content) | ||||||
|  | 				.set_mime_type(MIME_TYPE_TEXT) | ||||||
|  | 				.get_raw_data() | ||||||
|  | 		) | ||||||
|  | 	else: | ||||||
|  | 		printerr("%s plugin not initialized" % PLUGIN_SINGLETON_NAME) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | func share_image(a_path: String, a_title: String, a_subject: String, a_content: String) -> void: | ||||||
|  | 	share_file(a_path, MIME_TYPE_IMAGE, a_title, a_subject, a_content) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | func share_texture(a_texture: Texture2D, a_title: String, a_subject: String, a_content: String) -> void: | ||||||
|  | 	var __image: Image = a_texture.get_image() | ||||||
|  | 	__image.save_png(_temp_image_path) | ||||||
|  | 	share_file(_temp_image_path, MIME_TYPE_IMAGE, a_title, a_subject, a_content) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | func share_viewport(a_viewport: Viewport, a_title: String, a_subject: String, a_content: String, a_flip_y: bool = false) -> void: | ||||||
|  | 	var __image: Image = a_viewport.get_texture().get_image() | ||||||
|  | 	if a_flip_y: | ||||||
|  | 		__image.flip_y() | ||||||
|  | 	__image.save_png(_temp_image_path) | ||||||
|  | 	share_file(_temp_image_path, MIME_TYPE_IMAGE, a_title, a_subject, a_content) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | func share_file(a_path: String, a_mime_type: String, a_title: String, a_subject: String, a_content: String) -> void: | ||||||
|  | 	if _plugin_singleton != null: | ||||||
|  | 		_plugin_singleton.share( | ||||||
|  | 			SharedData.new() | ||||||
|  | 				.set_title(a_title) | ||||||
|  | 				.set_subject(a_subject) | ||||||
|  | 				.set_content(a_content) | ||||||
|  | 				.set_mime_type(a_mime_type) | ||||||
|  | 				.set_file_path(a_path) | ||||||
|  | 				.get_raw_data() | ||||||
|  | 		) | ||||||
|  | 	else: | ||||||
|  | 		printerr("%s plugin not initialized" % PLUGIN_SINGLETON_NAME) | ||||||
|  | @ -0,0 +1,65 @@ | ||||||
|  | # | ||||||
|  | # © 2024-present https://github.com/cengiz-pz | ||||||
|  | # | ||||||
|  | 
 | ||||||
|  | @tool | ||||||
|  | extends EditorPlugin | ||||||
|  | 
 | ||||||
|  | const PLUGIN_NODE_TYPE_NAME = "Share" | ||||||
|  | const PLUGIN_PARENT_NODE_TYPE = "Node" | ||||||
|  | const PLUGIN_NAME: String = "SharePlugin" | ||||||
|  | const PLUGIN_VERSION: String = "3.0" | ||||||
|  | const PLUGIN_PACKAGE: String = "org.godotengine.plugin.android.share" | ||||||
|  | const PLUGIN_DEPENDENCIES: Array = [ "androidx.appcompat:appcompat:1.7.0" ] | ||||||
|  | 
 | ||||||
|  | const PROVIDER_TAG = """ | ||||||
|  | <provider android:name="%s.ShareFileProvider" | ||||||
|  | 		android:exported="false" | ||||||
|  | 		android:authorities="%s.sharefileprovider" | ||||||
|  | 		android:grantUriPermissions="true"> | ||||||
|  | 	<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_provider_paths"/> | ||||||
|  | </provider> | ||||||
|  | """ | ||||||
|  | 
 | ||||||
|  | var export_plugin: AndroidExportPlugin | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | func _enter_tree() -> void: | ||||||
|  | 	add_custom_type(PLUGIN_NODE_TYPE_NAME, PLUGIN_PARENT_NODE_TYPE, preload("Share.gd"), preload("icon.png")) | ||||||
|  | 	export_plugin = AndroidExportPlugin.new() | ||||||
|  | 	add_export_plugin(export_plugin) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | func _exit_tree() -> void: | ||||||
|  | 	remove_custom_type(PLUGIN_NODE_TYPE_NAME) | ||||||
|  | 	remove_export_plugin(export_plugin) | ||||||
|  | 	export_plugin = null | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | class AndroidExportPlugin extends EditorExportPlugin: | ||||||
|  | 	var _plugin_name = PLUGIN_NAME | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 	func _supports_platform(platform: EditorExportPlatform) -> bool: | ||||||
|  | 		if platform is EditorExportPlatformAndroid: | ||||||
|  | 			return true | ||||||
|  | 		return false | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 	func _get_android_libraries(platform: EditorExportPlatform, debug: bool) -> PackedStringArray: | ||||||
|  | 		if debug: | ||||||
|  | 			return PackedStringArray(["%s/bin/debug/%s-%s-debug.aar" % [_plugin_name, _plugin_name, PLUGIN_VERSION]]) | ||||||
|  | 		else: | ||||||
|  | 			return PackedStringArray(["%s/bin/release/%s-%s-release.aar" % [_plugin_name, _plugin_name, PLUGIN_VERSION]]) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 	func _get_name() -> String: | ||||||
|  | 		return _plugin_name | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 	func _get_android_dependencies(platform: EditorExportPlatform, debug: bool) -> PackedStringArray: | ||||||
|  | 		return PackedStringArray(PLUGIN_DEPENDENCIES) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 	func _get_android_manifest_application_element_contents(platform: EditorExportPlatform, debug: bool) -> String: | ||||||
|  | 		return PROVIDER_TAG % [PLUGIN_PACKAGE, get_option("package/unique_name")] | ||||||
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							|  | @ -0,0 +1,34 @@ | ||||||
|  | [remap] | ||||||
|  | 
 | ||||||
|  | importer="texture" | ||||||
|  | type="CompressedTexture2D" | ||||||
|  | uid="uid://cm4eejjdmpyec" | ||||||
|  | path="res://.godot/imported/icon.png-cbd45f0ce843eb69e82e7474c8559974.ctex" | ||||||
|  | metadata={ | ||||||
|  | "vram_texture": false | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | [deps] | ||||||
|  | 
 | ||||||
|  | source_file="res://addons/SharePlugin/icon.png" | ||||||
|  | dest_files=["res://.godot/imported/icon.png-cbd45f0ce843eb69e82e7474c8559974.ctex"] | ||||||
|  | 
 | ||||||
|  | [params] | ||||||
|  | 
 | ||||||
|  | compress/mode=0 | ||||||
|  | compress/high_quality=false | ||||||
|  | compress/lossy_quality=0.7 | ||||||
|  | compress/hdr_compression=1 | ||||||
|  | compress/normal_map=0 | ||||||
|  | compress/channel_pack=0 | ||||||
|  | mipmaps/generate=false | ||||||
|  | mipmaps/limit=-1 | ||||||
|  | roughness/mode=0 | ||||||
|  | roughness/src_normal="" | ||||||
|  | process/fix_alpha_border=true | ||||||
|  | process/premult_alpha=false | ||||||
|  | process/normal_map_invert_y=false | ||||||
|  | process/hdr_as_srgb=false | ||||||
|  | process/hdr_clamp_exposure=false | ||||||
|  | process/size_limit=0 | ||||||
|  | detect_3d/compress_to=1 | ||||||
|  | @ -0,0 +1,47 @@ | ||||||
|  | # | ||||||
|  | # © 2024-present https://github.com/cengiz-pz | ||||||
|  | # | ||||||
|  | 
 | ||||||
|  | class_name SharedData | ||||||
|  | extends RefCounted | ||||||
|  | 
 | ||||||
|  | const DATA_KEY_TITLE = "title" | ||||||
|  | const DATA_KEY_SUBJECT = "subject" | ||||||
|  | const DATA_KEY_CONTENT = "content" | ||||||
|  | const DATA_KEY_FILE_PATH = "file_path" | ||||||
|  | const DATA_KEY_MIME_TYPE = "mime_type" | ||||||
|  | 
 | ||||||
|  | var _data: Dictionary | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | func _init() -> void: | ||||||
|  | 	_data = {} | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | func set_title(a_title: String) -> SharedData: | ||||||
|  | 	_data[DATA_KEY_TITLE] = a_title | ||||||
|  | 	return self | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | func set_subject(a_subject: String) -> SharedData: | ||||||
|  | 	_data[DATA_KEY_SUBJECT] = a_subject | ||||||
|  | 	return self | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | func set_content(a_content: String) -> SharedData: | ||||||
|  | 	_data[DATA_KEY_CONTENT] = a_content | ||||||
|  | 	return self | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | func set_file_path(a_file_path: String) -> SharedData: | ||||||
|  | 	_data[DATA_KEY_FILE_PATH] = a_file_path | ||||||
|  | 	return self | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | func set_mime_type(a_mime_type: String) -> SharedData: | ||||||
|  | 	_data[DATA_KEY_MIME_TYPE] = a_mime_type | ||||||
|  | 	return self | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | func get_raw_data() -> Dictionary: | ||||||
|  | 	return _data | ||||||
|  | @ -0,0 +1,10 @@ | ||||||
|  | ; | ||||||
|  | ; © 2024-present https://github.com/cengiz-pz | ||||||
|  | ; | ||||||
|  | [plugin] | ||||||
|  | 
 | ||||||
|  | name="Share" | ||||||
|  | description="Allow sharing of text or images with other apps" | ||||||
|  | author="Cengiz" | ||||||
|  | version="3.0" | ||||||
|  | script="ShareExportPlugin.gd" | ||||||
		Loading…
	
		Reference in New Issue