mirror of
https://github.com/dmunozv04/iSponsorBlockTV.git
synced 2025-12-06 11:56:45 +03:00
Merge pull request #334 from desofity/trust-system-proxy-by-default
Added proxy support
This commit is contained in:
@@ -20,5 +20,6 @@
|
||||
{"id": "",
|
||||
"name": ""
|
||||
}
|
||||
]
|
||||
],
|
||||
"use_proxy": false
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import aiohttp
|
||||
from . import api_helpers, ytlounge
|
||||
|
||||
# Constants for user input prompts
|
||||
USE_PROXY_PROMPT = "Do you want to use system-wide proxy? (y/N)"
|
||||
ATVS_REMOVAL_PROMPT = (
|
||||
"Do you want to remove the legacy 'atvs' entry (the app won't start with it present)? (y/N) "
|
||||
)
|
||||
@@ -45,8 +46,8 @@ def get_yn_input(prompt):
|
||||
return None
|
||||
|
||||
|
||||
async def create_web_session():
|
||||
return aiohttp.ClientSession()
|
||||
async def create_web_session(use_proxy):
|
||||
return aiohttp.ClientSession(trust_env=use_proxy)
|
||||
|
||||
|
||||
async def pair_device(web_session: aiohttp.ClientSession):
|
||||
@@ -75,8 +76,12 @@ async def pair_device(web_session: aiohttp.ClientSession):
|
||||
|
||||
def main(config, debug: bool) -> None:
|
||||
print("Welcome to the iSponsorBlockTV cli setup wizard")
|
||||
|
||||
choice = get_yn_input(USE_PROXY_PROMPT)
|
||||
config.use_proxy = choice == "y"
|
||||
|
||||
loop = asyncio.get_event_loop_policy().get_event_loop()
|
||||
web_session = loop.run_until_complete(create_web_session())
|
||||
web_session = loop.run_until_complete(create_web_session(config.use_proxy))
|
||||
if debug:
|
||||
loop.set_debug(True)
|
||||
asyncio.set_event_loop(loop)
|
||||
|
||||
@@ -44,6 +44,7 @@ class Config:
|
||||
self.minimum_skip_length = 1
|
||||
self.auto_play = True
|
||||
self.join_name = "iSponsorBlockTV"
|
||||
self.use_proxy = False
|
||||
self.__load()
|
||||
|
||||
def validate(self):
|
||||
|
||||
@@ -172,9 +172,11 @@ async def main_async(config, debug, http_tracing):
|
||||
trace_config.on_response_chunk_received.append(tracer.on_response_chunk_received)
|
||||
trace_config.on_request_end.append(tracer.on_request_end)
|
||||
trace_config.on_request_exception.append(tracer.on_request_exception)
|
||||
web_session = aiohttp.ClientSession(connector=tcp_connector, trace_configs=[trace_config])
|
||||
web_session = aiohttp.ClientSession(
|
||||
trust_env=config.use_proxy, connector=tcp_connector, trace_configs=[trace_config]
|
||||
)
|
||||
else:
|
||||
web_session = aiohttp.ClientSession(connector=tcp_connector)
|
||||
web_session = aiohttp.ClientSession(trust_env=config.use_proxy, connector=tcp_connector)
|
||||
|
||||
api_helper = api_helpers.ApiHelper(config, web_session)
|
||||
for i in config.devices:
|
||||
|
||||
@@ -383,3 +383,9 @@ MigrationScreen {
|
||||
padding: 1;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
/* Use Proxy */
|
||||
#useproxy-container{
|
||||
padding: 1;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
@@ -233,7 +233,7 @@ class AddDevice(ModalWithClickExit):
|
||||
def __init__(self, config, **kwargs) -> None:
|
||||
super().__init__(**kwargs)
|
||||
self.config = config
|
||||
self.web_session = aiohttp.ClientSession()
|
||||
self.web_session = aiohttp.ClientSession(trust_env=config.use_proxy)
|
||||
self.api_helper = api_helpers.ApiHelper(config, self.web_session)
|
||||
self.devices_discovered_dial = []
|
||||
|
||||
@@ -382,7 +382,7 @@ class AddChannel(ModalWithClickExit):
|
||||
def __init__(self, config, **kwargs) -> None:
|
||||
super().__init__(**kwargs)
|
||||
self.config = config
|
||||
web_session = aiohttp.ClientSession()
|
||||
web_session = aiohttp.ClientSession(trust_env=config.use_proxy)
|
||||
self.api_helper = api_helpers.ApiHelper(config, web_session)
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
@@ -890,6 +890,37 @@ class AutoPlayManager(Vertical):
|
||||
self.config.auto_play = event.checkbox.value
|
||||
|
||||
|
||||
class UseProxyManager(Vertical):
|
||||
"""Manager for proxy use, allows enabling/disabling use of proxy."""
|
||||
|
||||
def __init__(self, config, **kwargs) -> None:
|
||||
super().__init__(**kwargs)
|
||||
self.config = config
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Label("Use proxy", classes="title")
|
||||
yield Label(
|
||||
"This feature allows application to use system proxy,"
|
||||
" if it is set in environment variables."
|
||||
" This parameter will be passed in all [i]aiohttp.ClientSession[/i]"
|
||||
' calls. For further information, see "[i]trust_env[/i]" section at'
|
||||
" [link='https://docs.aiohttp.org/en/stable/client_reference.html']"
|
||||
"aiohttp documentation[/link].",
|
||||
classes="subtitle",
|
||||
id="useproxy-subtitle",
|
||||
)
|
||||
with Horizontal(id="useproxy-container"):
|
||||
yield Checkbox(
|
||||
value=self.config.use_proxy,
|
||||
id="useproxy-switch",
|
||||
label="Use proxy",
|
||||
)
|
||||
|
||||
@on(Checkbox.Changed, "#useproxy-switch")
|
||||
def changed_skip(self, event: Checkbox.Changed):
|
||||
self.config.use_proxy = event.checkbox.value
|
||||
|
||||
|
||||
class ISponsorBlockTVSetupMainScreen(Screen):
|
||||
TITLE = "iSponsorBlockTV"
|
||||
SUB_TITLE = "Setup Wizard"
|
||||
@@ -926,6 +957,7 @@ class ISponsorBlockTVSetupMainScreen(Screen):
|
||||
)
|
||||
yield ApiKeyManager(config=self.config, id="api-key-manager", classes="container")
|
||||
yield AutoPlayManager(config=self.config, id="autoplay-manager", classes="container")
|
||||
yield UseProxyManager(config=self.config, id="useproxy-manager", classes="container")
|
||||
|
||||
def on_mount(self) -> None:
|
||||
if self.check_for_old_config_entries():
|
||||
|
||||
Reference in New Issue
Block a user