Skip to content

Commit

Permalink
Merge pull request #109 from Poing-Studios/request-agent
Browse files Browse the repository at this point in the history
Request agent
  • Loading branch information
gumaciel authored Nov 11, 2023
2 parents 0ad47f8 + 3238e2c commit f133c21
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 20 deletions.
37 changes: 20 additions & 17 deletions addons/admob/admob.gd
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

@tool
class_name AdMobEditorPlugin
extends EditorPlugin

var http_request_downloader := HTTPRequest.new()
Expand All @@ -34,8 +34,8 @@ var godot_version := "v" + str(Engine.get_version_info().major) + "." + str(Engi
var plugin_version := get_plugin_version()

var version_support := {
"android": "v3.0.0",
"ios": "v3.0.0"
"android": "v3.0.2",
"ios": "v3.0.2"
}

enum Items {
Expand All @@ -44,7 +44,21 @@ enum Items {
GitHub
}


class PoingAdMobEditorExportPlugin extends EditorExportPlugin:
const CFG_FILE_PATH := "res://addons/admob/plugin.cfg"

func _export_begin(features: PackedStringArray, is_debug: bool, path: String, flags: int) -> void:
var file = FileAccess.open(CFG_FILE_PATH, FileAccess.READ)
if file:
print("Exporting Poing AdMob '.cfg' file")
add_file(CFG_FILE_PATH, file.get_buffer(file.get_length()), false)
file.close()

var _exporter := PoingAdMobEditorExportPlugin.new()
func _enter_tree():
add_export_plugin(_exporter)

setup_timer()
create_download_directories()
_request_version_support()
Expand Down Expand Up @@ -80,11 +94,12 @@ func _enter_tree():
add_tool_submenu_item("AdMob Download Manager", popup)

func _exit_tree():
remove_export_plugin(_exporter)
remove_tool_menu_item("AdMob Download Manager")


func _request_version_support():
var url = "https://raw.githubusercontent.com/Poing-Studios/godot-admob-versions/" + plugin_version + "/versions.json"
var url = "https://raw.githubusercontent.com/Poing-Studios/godot-admob-versions/" + get_plugin_version() + "/versions.json"
var http_request = HTTPRequest.new()
http_request.request_completed.connect(_on_version_support_request_completed)
add_child(http_request)
Expand Down Expand Up @@ -161,19 +176,7 @@ func _on_popupmenu_id_pressed(id : int):
var path_directory = ProjectSettings.globalize_path(default_download_path)
OS.shell_open(str("file://", path_directory))
Items.GitHub:
OS.shell_open("https://github.com/Poing-Studios/godot-admob-plugin/tree/" + plugin_version)


func get_plugin_version() -> String:
var plugin_config_file := ConfigFile.new()
var version: String = ""

if plugin_config_file.load("res://addons/admob/plugin.cfg") == OK:
version = plugin_config_file.get_value("plugin", "version")
else:
printerr("Failed to load plugin.cfg")

return version
OS.shell_open("https://github.com/Poing-Studios/godot-admob-plugin/tree/" + get_plugin_version())

func show_download_percent(url_download: String = ""):
if not url_download.is_empty():
Expand Down
2 changes: 1 addition & 1 deletion addons/admob/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
name="AdMob"
description="The AdMob Plugin for Android and iOS."
author="Poing Studios"
version="v3.0.0"
version="v3.0.1"
script="admob.gd"
4 changes: 3 additions & 1 deletion addons/admob/src/api/core/AdRequest.gd
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ var extras : Dictionary
func convert_to_dictionary() -> Dictionary:
return {
"mediation_extras" : _transform_mediation_extras_to_dictionary(),
"extras" : extras
"extras" : extras,
"google_request_agent" : "Godot-PoingStudios-"+PoingAdMobVersionHelper.version_formated
}

func _transform_mediation_extras_to_dictionary() -> Dictionary:
Expand All @@ -41,3 +42,4 @@ func _transform_mediation_extras_to_dictionary() -> Dictionary:
"extras" : extra.extras
}
return mediation_extras_dictionary

46 changes: 46 additions & 0 deletions addons/admob/version_helper.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# MIT License

# Copyright (c) 2023-present Poing Studios

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

class_name PoingAdMobVersionHelper
extends Object

static var version_formated : String = _get_plugin_version_formated() :
set(value):
version_formated = _get_plugin_version_formated()

static func _get_plugin_version_formated() -> String:
var plugin_config_file := ConfigFile.new()
var version: String = "v3.0.1" #redundancy

if plugin_config_file.load("res://addons/admob/plugin.cfg") == OK:
version = plugin_config_file.get_value("plugin", "version")
else:
push_error("Failed to load plugin.cfg")

var pattern = RegEx.new()
pattern.compile("(?:v)?(\\d+\\.\\d+\\.\\d+)")

var matchs := pattern.search(version)
if matchs != null:
version = matchs.get_string(1)
return version

2 changes: 1 addition & 1 deletion project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ config={

config/name="AdMobAddon"
run/main_scene="res://addons/admob/sample/Main.tscn"
config/features=PackedStringArray("4.1", "GL Compatibility")
config/features=PackedStringArray("4.2", "GL Compatibility")
config/icon="res://addons/admob/assets/icon-76.png"

[display]
Expand Down

0 comments on commit f133c21

Please sign in to comment.