Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add proxy support #106

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion src/components/settings/settings_window.gd
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ func _prepare_settings():
SettingCheckbox,
tr("Will check only stable Godots releases.")
)),
SettingChangeObserved(SettingCfg(
"network/http_proxy/host",
Config.HTTP_PROXY_HOST,
SettingText,
tr("Host")
)),
SettingChangeObserved(SettingCfg(
"network/http_proxy/port",
Config.HTTP_PROXY_PORT,
SettingPort,
tr("Port")
)),
]


Expand Down Expand Up @@ -331,7 +343,10 @@ class SettingText extends Setting:
CompInit.SIZE_FLAGS_HORIZONTAL_EXPAND_FILL(),
CompInit.CUSTOM(func(this: LineEdit):
self.on_value_changed(func(new_value):
this.text = new_value
# don't update text if the user is interacting
# this prevents the caret from going to postition 0
if not this.has_focus():
this.text = new_value
)
this.text_changed.connect(func(new_text):
_value = new_text
Expand All @@ -345,6 +360,40 @@ class SettingText extends Setting:
control.add_to(target)


class SettingPort extends Setting:
func add_control(target):
var timer = CompRefs.Simple.new()
var control = Comp.new(HBoxContainer, [
Comp.new(Timer).ref(timer).on_init(
func(this: Timer): this.timeout.connect(self.notify_changed)
),
CompSettingNameContainer.new(self),
CompSettingPanelContainer.new(_tooltip, [
Comp.new(SpinBox).on_init([
CompInit.TOOLTIP_TEXT(_tooltip),
CompInit.ADD_THEME_STYLEBOX_OVERRIDE("focus", StyleBoxEmpty.new()),
CompInit.SIZE_FLAGS_HORIZONTAL_EXPAND_FILL(),
CompInit.CUSTOM(func(this: SpinBox):
# set valid port range
this.min_value = 0
this.max_value = 65535
self.on_value_changed(func(new_value):
this.value = new_value
)
this.value_changed.connect(func(new_text):
_value = new_text
(timer.value as Timer).start(1)
)
pass\
),
# set value after so it fits within range
CompInit.VALUE(self._value)
])
])
])
control.add_to(target)


class SettingFilePath extends Setting:
func add_control(target):
var file_dialog = CompRefs.Simple.new()
Expand Down
18 changes: 18 additions & 0 deletions src/config.gd
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,24 @@ var GLOBAL_CUSTOM_COMMANDS_EDITORS = ConfigFileValue.new(
set(_v): _readonly()


var HTTP_PROXY_HOST = ConfigFileValue.new(
_cfg_auto_save,
"network",
"http_proxy_host",
""
):
set(_v): _readonly()


var HTTP_PROXY_PORT = ConfigFileValue.new(
_cfg_auto_save,
"network",
"http_proxy_port",
8080
):
set(_v): _readonly()


func _enter_tree() -> void:
DirAccess.make_dir_absolute(ProjectSettings.globalize_path(DEFAULT_VERSIONS_PATH))
DirAccess.make_dir_absolute(ProjectSettings.globalize_path(DEFAULT_DOWNLOADS_PATH))
Expand Down
10 changes: 10 additions & 0 deletions src/http_client.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ extends Node

func async_http_get(url, headers=[], download_file=null):
var http_request = HTTPRequest.new()
var proxy_host = Config.HTTP_PROXY_HOST.ret().strip_edges()
if not proxy_host.is_empty():
http_request.set_http_proxy(
proxy_host,
Config.HTTP_PROXY_PORT.ret()
)
http_request.set_https_proxy(
proxy_host,
Config.HTTP_PROXY_PORT.ret()
)
add_child(http_request)
var response = await async_http_get_using(http_request, url, headers, download_file)
http_request.queue_free()
Expand Down
4 changes: 4 additions & 0 deletions src/objects/node_component/comp_init.gd
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ static func TEXT(t):
return func(c): c.text = c.tr(str(t))


static func VALUE(v):
return func(c): c.value = v


static func CUSTOM(callback):
return callback

Expand Down