Skip to content

Commit

Permalink
GD-609: Rework on GdUnit4 update notification (#612)
Browse files Browse the repository at this point in the history
# Why
We want to be notified in a smarter way instead of popup a window after
some seconds

# What
Complete restructure the way to notify.
If a new version found, the console is showing an animated notification.
Moved the update window into the setting dialog as a new tab.
Improved the release node visualization by made some improvements to
render HTML into bbcode

* notify on console and settings tab

![image](https://github.com/user-attachments/assets/7f81508c-7134-430d-b266-bc34de69d9bf)
* run the update

![image](https://github.com/user-attachments/assets/1b918e69-cd12-4893-9313-121e9a4e8918)
  • Loading branch information
MikeSchulze authored Dec 12, 2024
1 parent 2ec28a1 commit 8d4d66c
Show file tree
Hide file tree
Showing 22 changed files with 684 additions and 496 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ icon.png.import
*.gd.uid
*.cs.uid
*.json.uid
*.txt.uid

# Mono-specific ignores
.mono/
Expand Down
26 changes: 12 additions & 14 deletions addons/gdUnit4/plugin.gd
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
@tool
extends EditorPlugin

const GdUnitTools := preload ("res://addons/gdUnit4/src/core/GdUnitTools.gd")
const GdUnitTestDiscoverGuard := preload ("res://addons/gdUnit4/src/core/discovery/GdUnitTestDiscoverGuard.gd")
const GdUnitTools := preload("res://addons/gdUnit4/src/core/GdUnitTools.gd")
const GdUnitTestDiscoverGuard := preload("res://addons/gdUnit4/src/core/discovery/GdUnitTestDiscoverGuard.gd")
const GdUnitConsole := preload("res://addons/gdUnit4/src/ui/GdUnitConsole.gd")


var _gd_inspector: Control
var _gd_console: Control
var _gd_console: GdUnitConsole
var _guard: GdUnitTestDiscoverGuard


Expand All @@ -19,23 +20,20 @@ func _enter_tree() -> void:
prints("GdUnit4 plugin requires a minimum of Godot 4.2.x Version!")
return
GdUnitSettings.setup()
# install the GdUnit inspector
_gd_inspector = load("res://addons/gdUnit4/src/ui/GdUnitInspector.tscn").instantiate()
# Install the GdUnit Inspector
_gd_inspector = (load("res://addons/gdUnit4/src/ui/GdUnitInspector.tscn") as PackedScene).instantiate()
add_control_to_dock(EditorPlugin.DOCK_SLOT_LEFT_UR, _gd_inspector)
# install the GdUnit Console
_gd_console = load("res://addons/gdUnit4/src/ui/GdUnitConsole.tscn").instantiate()
@warning_ignore("return_value_discarded")
add_control_to_bottom_panel(_gd_console, "gdUnitConsole")
prints("Loading GdUnit4 Plugin success")
if GdUnitSettings.is_update_notification_enabled():
var update_tool: Node = load("res://addons/gdUnit4/src/update/GdUnitUpdateNotify.tscn").instantiate()
Engine.get_main_loop().root.add_child.call_deferred(update_tool)
# Install the GdUnit Console
_gd_console = (load("res://addons/gdUnit4/src/ui/GdUnitConsole.tscn") as PackedScene).instantiate()
var control := add_control_to_bottom_panel(_gd_console, "gdUnitConsole")
await _gd_console.setup_update_notification(control)
if GdUnit4CSharpApiLoader.is_mono_supported():
prints("GdUnit4Net version '%s' loaded." % GdUnit4CSharpApiLoader.version())
# connect to be notified for script changes to be able to discover new tests
# Connect to be notified for script changes to be able to discover new tests
_guard = GdUnitTestDiscoverGuard.new()
@warning_ignore("return_value_discarded")
resource_saved.connect(_on_resource_saved)
prints("Loading GdUnit4 Plugin success")


func _exit_tree() -> void:
Expand Down
33 changes: 33 additions & 0 deletions addons/gdUnit4/src/ui/GdUnitConsole.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@tool
extends Control

const GdUnitUpdateClient = preload("res://addons/gdUnit4/src/update/GdUnitUpdateClient.gd")
const TITLE = "gdUnit4 ${version} Console"

@onready var header := $VBoxContainer/Header
Expand Down Expand Up @@ -104,6 +105,38 @@ func line_number(report: GdUnitReport) -> String:
return str(report._line_number) if report._line_number != -1 else "<n/a>"


func setup_update_notification(control: Button) -> void:
if not GdUnitSettings.is_update_notification_enabled():
print_message("The search for updates is deactivated.", Color.CORNFLOWER_BLUE)
return

println_message("Searching for updates.", Color.CORNFLOWER_BLUE)
var update_client := GdUnitUpdateClient.new()
add_child(update_client)
var response :GdUnitUpdateClient.HttpResponse = await update_client.request_latest_version()
if response.status() != 200:
println_message("Information cannot be retrieved from GitHub!", Color.INDIAN_RED)
println_message("Error: %s" % response.response(), Color.INDIAN_RED)
return
var latest_version := update_client.extract_latest_version(response)
if not latest_version.is_greater(GdUnit4Version.current()):
println_message("GdUnit4 is up-to-date.", Color.FOREST_GREEN)
return

println_message("A new update is available %s" % latest_version, Color.YELLOW)
println_message("Open the GdUnit4 settings and check the update tab.", Color.YELLOW)

control.icon = GdUnitUiTools.get_icon("Notification", Color.YELLOW)
var tween :=create_tween()
tween.tween_property(control, "self_modulate", Color.VIOLET, .2).set_trans(Tween.TransitionType.TRANS_LINEAR)
tween.tween_property(control, "self_modulate", Color.YELLOW, .2).set_trans(Tween.TransitionType.TRANS_BOUNCE)
tween.parallel()
tween.tween_property(control, "scale", Vector2.ONE*1.05, .4).set_trans(Tween.TransitionType.TRANS_LINEAR)
tween.tween_property(control, "scale", Vector2.ONE, .4).set_trans(Tween.TransitionType.TRANS_BOUNCE)
tween.set_loops(-1)
tween.play()


func _on_gdunit_event(event: GdUnitEvent) -> void:
match event.type():
GdUnitEvent.INIT:
Expand Down
8 changes: 6 additions & 2 deletions addons/gdUnit4/src/ui/parts/InspectorToolBar.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ signal stop_pressed()
@onready var _button_run: Button = %run
@onready var _button_run_debug: Button = %debug
@onready var _button_stop: Button = %stop
@onready var settings_dlg := preload("res://addons/gdUnit4/src/ui/settings/GdUnitSettingsDialog.tscn").instantiate()



const SETTINGS_SHORTCUT_MAPPING := {
Expand All @@ -35,7 +35,7 @@ func _ready() -> void:
GdUnitSignals.instance().gdunit_settings_changed.connect(_on_gdunit_settings_changed)
init_buttons()
init_shortcuts(command_handler)
EditorInterface.get_base_control().add_child(settings_dlg)



func init_buttons() -> void:
Expand Down Expand Up @@ -94,6 +94,10 @@ func _on_wiki_pressed() -> void:


func _on_btn_tool_pressed() -> void:
var settings_dlg: Window = EditorInterface.get_base_control().find_child("GdUnitSettingsDialog", false, false)
if settings_dlg == null:
settings_dlg = preload("res://addons/gdUnit4/src/ui/settings/GdUnitSettingsDialog.tscn").instantiate()
EditorInterface.get_base_control().add_child(settings_dlg, true)
settings_dlg.popup_centered_ratio(.60)


Expand Down
27 changes: 20 additions & 7 deletions addons/gdUnit4/src/ui/settings/GdUnitSettingsDialog.gd
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,24 @@ const GdUnitUpdateClient = preload ("res://addons/gdUnit4/src/update/GdUnitUpdat
@onready var _properties_report: Node = % "report-content"
@onready var _input_capture: GdUnitInputCapture = %GdUnitInputCapture
@onready var _property_error: Window = % "propertyError"
@onready var _tab_container: TabContainer = %Properties
@onready var _update_tab: = %Update

var _font_size: float


func _ready() -> void:
set_name("GdUnitSettingsDialog")
# initialize for testing
if not Engine.is_editor_hint():
GdUnitSettings.setup()
GdUnit4Version.init_version_label(_version_label)
_font_size = GdUnitFonts.init_fonts(_version_label)
@warning_ignore("return_value_discarded")
about_to_popup.connect(_do_setup_properties)


# do setup the dialog with given settings
func _do_setup_properties() -> void:
setup_properties(_properties_common, GdUnitSettings.COMMON_SETTINGS)
setup_properties(_properties_ui, GdUnitSettings.UI_SETTINGS)
setup_properties(_properties_report, GdUnitSettings.REPORT_SETTINGS)
setup_properties(_properties_shortcuts, GdUnitSettings.SHORTCUT_SETTINGS)
check_for_update()


func _sort_by_key(left: GdUnitProperty, right: GdUnitProperty) -> bool:
Expand Down Expand Up @@ -85,7 +83,6 @@ func setup_properties(properties_parent: Node, property_category: String) -> voi
reset_btn.icon = _get_btn_icon("Reload")
reset_btn.disabled = property.value() == property.default()
grid.add_child(reset_btn)
min_size_ += reset_btn.size.x

# property type specific input element
var input: Node = _create_input_element(property, reset_btn)
Expand All @@ -100,6 +97,7 @@ func setup_properties(properties_parent: Node, property_category: String) -> voi
grid.add_child(info)
if min_size_overall < min_size_:
min_size_overall = min_size_

for controls: Array in [labels, inputs, info_labels]:
var _size: float = controls.map(func(c: Control) -> float: return c.size.x).max()
min_size_overall += _size
Expand Down Expand Up @@ -217,6 +215,21 @@ func rescan(update_scripts:=false) -> void:
EditorInterface.get_resource_filesystem().update_script_classes()


func check_for_update() -> void:
if not GdUnitSettings.is_update_notification_enabled():
return
var response :GdUnitUpdateClient.HttpResponse = await _update_client.request_latest_version()
if response.status() != 200:
printerr("Latest version information cannot be retrieved from GitHub!")
printerr("Error: %s" % response.response())
return
var latest_version := _update_client.extract_latest_version(response)
if latest_version.is_greater(GdUnit4Version.current()):
var tab_index := _tab_container.get_tab_idx_from_control(_update_tab)
_tab_container.set_tab_button_icon(tab_index, GdUnitUiTools.get_icon("Notification", Color.YELLOW))
_tab_container.set_tab_tooltip(tab_index, "An new update is available.")


func _on_btn_report_bug_pressed() -> void:
@warning_ignore("return_value_discarded")
OS.shell_open("https://github.com/MikeSchulze/gdUnit4/issues/new?assignees=MikeSchulze&labels=bug&projects=projects%2F5&template=bug_report.yml&title=GD-XXX%3A+Describe+the+issue+briefly")
Expand Down
180 changes: 53 additions & 127 deletions addons/gdUnit4/src/ui/settings/GdUnitSettingsDialog.tscn

Large diffs are not rendered by default.

Loading

0 comments on commit 8d4d66c

Please sign in to comment.