mirror of
https://github.com/SteamDeckHomebrew/decky-loader.git
synced 2026-07-11 17:02:00 +00:00
Use f-strings instead of .format
This commit is contained in:
@@ -40,15 +40,15 @@ class PluginBrowser:
|
|||||||
async def _install(self, artifact, version, hash):
|
async def _install(self, artifact, version, hash):
|
||||||
name = artifact.split("/")[-1]
|
name = artifact.split("/")[-1]
|
||||||
rmtree(path.join(self.plugin_path, name), ignore_errors=True)
|
rmtree(path.join(self.plugin_path, name), ignore_errors=True)
|
||||||
self.log.info("Installing {} (Version: {})".format(artifact, version))
|
self.log.info(f"Installing {artifact} (Version: {version})")
|
||||||
async with ClientSession() as client:
|
async with ClientSession() as client:
|
||||||
url = "https://github.com/{}/archive/refs/tags/{}.zip".format(artifact, version)
|
url = f"https://github.com/{artifact}/archive/refs/tags/{version}.zip"
|
||||||
self.log.debug("Fetching {}".format(url))
|
self.log.debug(f"Fetching {url}")
|
||||||
res = await client.get(url)
|
res = await client.get(url)
|
||||||
if res.status == 200:
|
if res.status == 200:
|
||||||
self.log.debug("Got 200. Reading...")
|
self.log.debug("Got 200. Reading...")
|
||||||
data = await res.read()
|
data = await res.read()
|
||||||
self.log.debug("Read {} bytes".format(len(data)))
|
self.log.debug(f"Read {len(data)} bytes")
|
||||||
res_zip = BytesIO(data)
|
res_zip = BytesIO(data)
|
||||||
with ProcessPoolExecutor() as executor:
|
with ProcessPoolExecutor() as executor:
|
||||||
self.log.debug("Unzipping...")
|
self.log.debug("Unzipping...")
|
||||||
@@ -60,11 +60,11 @@ class PluginBrowser:
|
|||||||
hash
|
hash
|
||||||
)
|
)
|
||||||
if ret:
|
if ret:
|
||||||
self.log.info("Installed {} (Version: {})".format(artifact, version))
|
self.log.info(f"Installed {artifact} (Version: {version})")
|
||||||
else:
|
else:
|
||||||
self.log.fatal("SHA-256 Mismatch!!!! {} (Version: {})".format(artifact, version))
|
self.log.fatal(f"SHA-256 Mismatch!!!! {artifact} (Version: {version})")
|
||||||
else:
|
else:
|
||||||
self.log.fatal("Could not fetch from github. {}".format(await res.text()))
|
self.log.fatal(f"Could not fetch from github. {await res.text()}")
|
||||||
|
|
||||||
async def redirect_to_store(self, request):
|
async def redirect_to_store(self, request):
|
||||||
return web.Response(status=302, headers={"Location": self.store_url})
|
return web.Response(status=302, headers={"Location": self.store_url})
|
||||||
@@ -79,7 +79,7 @@ class PluginBrowser:
|
|||||||
self.install_requests[request_id] = PluginInstallContext(artifact, version, hash)
|
self.install_requests[request_id] = PluginInstallContext(artifact, version, hash)
|
||||||
tab = await get_tab("QuickAccess")
|
tab = await get_tab("QuickAccess")
|
||||||
await tab.open_websocket()
|
await tab.open_websocket()
|
||||||
await tab.evaluate_js("addPluginInstallPrompt('{}', '{}', '{}')".format(artifact, version, request_id))
|
await tab.evaluate_js(f"addPluginInstallPrompt('{artifact}', '{version}', '{request_id}')")
|
||||||
|
|
||||||
async def confirm_plugin_install(self, request_id):
|
async def confirm_plugin_install(self, request_id):
|
||||||
request = self.install_requests.pop(request_id)
|
request = self.install_requests.pop(request_id)
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ async def get_tabs():
|
|||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
res = await web.get("{}/json".format(BASE_ADDRESS))
|
res = await web.get(f"{BASE_ADDRESS}/json")
|
||||||
break
|
break
|
||||||
except:
|
except:
|
||||||
logger.info("Steam isn't available yet. Wait for a moment...")
|
logger.info("Steam isn't available yet. Wait for a moment...")
|
||||||
@@ -68,13 +68,13 @@ async def get_tabs():
|
|||||||
res = await res.json()
|
res = await res.json()
|
||||||
return [Tab(i) for i in res]
|
return [Tab(i) for i in res]
|
||||||
else:
|
else:
|
||||||
raise Exception("/json did not return 200. {}".format(await res.text()))
|
raise Exception(f"/json did not return 200. {await res.text()}")
|
||||||
|
|
||||||
async def get_tab(tab_name):
|
async def get_tab(tab_name):
|
||||||
tabs = await get_tabs()
|
tabs = await get_tabs()
|
||||||
tab = next((i for i in tabs if i.title == tab_name), None)
|
tab = next((i for i in tabs if i.title == tab_name), None)
|
||||||
if not tab:
|
if not tab:
|
||||||
raise ValueError("Tab {} not found".format(tab_name))
|
raise ValueError(f"Tab {tab_name} not found")
|
||||||
return tab
|
return tab
|
||||||
|
|
||||||
async def inject_to_tab(tab_name, js, run_async=False):
|
async def inject_to_tab(tab_name, js, run_async=False):
|
||||||
|
|||||||
+13
-14
@@ -84,11 +84,10 @@ class Loader:
|
|||||||
module.Plugin._plugin_directory = plugin_directory
|
module.Plugin._plugin_directory = plugin_directory
|
||||||
|
|
||||||
if not hasattr(module.Plugin, "name"):
|
if not hasattr(module.Plugin, "name"):
|
||||||
raise KeyError("Plugin {} has not defined a name".format(file))
|
raise KeyError(f"Plugin {file} has not defined a name")
|
||||||
if module.Plugin.name in self.plugins:
|
if module.Plugin.name in self.plugins:
|
||||||
if hasattr(module.Plugin, "hot_reload") and not module.Plugin.hot_reload and refresh:
|
if hasattr(module.Plugin, "hot_reload") and not module.Plugin.hot_reload and refresh:
|
||||||
self.logger.info("Plugin {} is already loaded and has requested to not be re-loaded"
|
self.logger.info(f"Plugin {module.Plugin.name} is already loaded and has requested to not be re-loaded")
|
||||||
.format(module.Plugin.name))
|
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
if hasattr(self.plugins[module.Plugin.name], "task"):
|
if hasattr(self.plugins[module.Plugin.name], "task"):
|
||||||
@@ -98,9 +97,9 @@ class Loader:
|
|||||||
if hasattr(module.Plugin, "__main"):
|
if hasattr(module.Plugin, "__main"):
|
||||||
setattr(self.plugins[module.Plugin.name], "task",
|
setattr(self.plugins[module.Plugin.name], "task",
|
||||||
self.loop.create_task(self.plugins[module.Plugin.name].__main()))
|
self.loop.create_task(self.plugins[module.Plugin.name].__main()))
|
||||||
self.logger.info("Loaded {}".format(module.Plugin.name))
|
self.logger.info(f"Loaded {module.Plugin.name}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error("Could not load {}. {}".format(file, e))
|
self.logger.error(f"Could not load {file}. {e}")
|
||||||
finally:
|
finally:
|
||||||
if refresh:
|
if refresh:
|
||||||
self.loop.create_task(self.refresh_iframe())
|
self.loop.create_task(self.refresh_iframe())
|
||||||
@@ -136,12 +135,12 @@ class Loader:
|
|||||||
with open(path.join(self.plugin_path, plugin._plugin_directory, plugin.main_view_html), 'r') as template:
|
with open(path.join(self.plugin_path, plugin._plugin_directory, plugin.main_view_html), 'r') as template:
|
||||||
template_data = template.read()
|
template_data = template.read()
|
||||||
# setup the main script, plugin, and pull in the template
|
# setup the main script, plugin, and pull in the template
|
||||||
ret = """
|
ret = f"""
|
||||||
<script src="/static/library.js"></script>
|
<script src="/static/library.js"></script>
|
||||||
<script>const plugin_name = '{}' </script>
|
<script>const plugin_name = '{plugin.name}' </script>
|
||||||
<base href="http://127.0.0.1:1337/plugins/plugin_resource/{}/">
|
<base href="http://127.0.0.1:1337/plugins/plugin_resource/{plugin.name}/">
|
||||||
{}
|
{template_data}
|
||||||
""".format(plugin.name, plugin.name, template_data)
|
"""
|
||||||
return web.Response(text=ret, content_type="text/html")
|
return web.Response(text=ret, content_type="text/html")
|
||||||
|
|
||||||
async def handle_sub_route(self, request):
|
async def handle_sub_route(self, request):
|
||||||
@@ -169,18 +168,18 @@ class Loader:
|
|||||||
inner_content = template_data
|
inner_content = template_data
|
||||||
|
|
||||||
# setup the default template
|
# setup the default template
|
||||||
ret = """
|
ret = f"""
|
||||||
<html style="height: fit-content;">
|
<html style="height: fit-content;">
|
||||||
<head>
|
<head>
|
||||||
<link rel="stylesheet" href="/static/styles.css">
|
<link rel="stylesheet" href="/static/styles.css">
|
||||||
<script src="/static/library.js"></script>
|
<script src="/static/library.js"></script>
|
||||||
<script>const plugin_name = '{name}';</script>
|
<script>const plugin_name = '{plugin.name}';</script>
|
||||||
</head>
|
</head>
|
||||||
<body style="height: fit-content; display: block;">
|
<body style="height: fit-content; display: block;">
|
||||||
{content}
|
{inner_content}
|
||||||
</body>
|
</body>
|
||||||
<html>
|
<html>
|
||||||
""".format(name=plugin.name, content=inner_content)
|
"""
|
||||||
return web.Response(text=ret, content_type="text/html")
|
return web.Response(text=ret, content_type="text/html")
|
||||||
|
|
||||||
@template('plugin_view.html')
|
@template('plugin_view.html')
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ class PluginManager:
|
|||||||
"id": 1,
|
"id": 1,
|
||||||
"method": "Runtime.evaluate",
|
"method": "Runtime.evaluate",
|
||||||
"params": {
|
"params": {
|
||||||
"expression": "resolveMethodCall({}, {})".format(call_id, dumps(response)),
|
"expression": f"resolveMethodCall({call_id}, {dumps(response)})",
|
||||||
"userGesture": True
|
"userGesture": True
|
||||||
}
|
}
|
||||||
}, receive=False)
|
}, receive=False)
|
||||||
|
|||||||
Reference in New Issue
Block a user