How can I use the "size_changed" signal in Viewport Mode?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Ly97

In my project, I want to be able to resize the cursor sprite when the player resizes the game window. And for all of my projects, I always used this code:

extends Node

var sprite = preload("res://cursor.png")
var normal_window_size := Vector2(ProjectSettings.get_setting("display/window/size/width"), ProjectSettings.get_setting("display/window/size/height"))

func _ready() -> void:
	get_viewport.connect("size_changed", self, "cursor_update")
	cursor_update()

func cursor_update():
	print("cursor resized!")
	var current_window_size = OS.window_size
	var scale_multiple = min(floor(current_window_size.x / normal_window_size.x), floor(current_window_size.y / normal_window_size.y)) + 1
	
	var img = sprite.get_data()
	img.resize(sprite.get_width()*scale_multiple, sprite.get_height()*scale_multiple, Image.INTERPOLATE_NEAREST)
	var imgtex := ImageTexture.new()
	imgtex.create_from_image(img)
	
	Input.set_custom_mouse_cursor(imgtex, Input.CURSOR_ARROW, Vector2(0, 0))

But the thing is that all of these projects were on 2D mode, and I tried the same code in another project that used the Viewport mode and it didn’t work. The code also did not work both in Godot 3.5.x and Godot 4.x

So… Is there any other way to detect when the player resizes the window with the Viewport window mode?