Skip to content

Commit

Permalink
Merge pull request #193 from brostosjoined/main
Browse files Browse the repository at this point in the history
Loop error fix and backward compability support
  • Loading branch information
rikkolovescats authored Oct 6, 2023
2 parents d73e81b + c50e986 commit eb4e0e5
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 21 deletions.
6 changes: 6 additions & 0 deletions index.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
"plugin_manager_url": "https://github.com/bombsquad-community/plugin-manager/{content_type}/{tag}/plugin_manager.py",
"versions": {
"1.0.3": {
"api_version": 8,
"commit_sha": "2a5ce50",
"released_on": "06-10-2023",
"md5sum": "d8e6267b2eae6fc21efd77bbb47c0a07"
},
"1.0.2": {
"api_version": 8,
"commit_sha": "818ec65",
Expand Down
75 changes: 54 additions & 21 deletions plugin_manager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# ba_meta require api 8
from babase._meta import EXPORT_CLASS_NAME_SHORTCUTS
from baenv import TARGET_BALLISTICA_BUILD
import babase
import _babase
import bauiv1 as bui
Expand Down Expand Up @@ -28,20 +29,52 @@
from threading import Thread
import logging

_env = _babase.env()
_uiscale = bui.app.ui_v1.uiscale


PLUGIN_MANAGER_VERSION = "1.0.2"
PLUGIN_MANAGER_VERSION = "1.0.3"
REPOSITORY_URL = "https://github.com/bombsquad-community/plugin-manager"
# Current tag can be changed to "staging" or any other branch in
# plugin manager repo for testing purpose.
CURRENT_TAG = "main"


if TARGET_BALLISTICA_BUILD < 21282:
# These attributes have been deprecated as of 1.7.27. For more info see:
# https://github.com/efroemling/ballistica/blob/master/CHANGELOG.md#1727-build-21282-api-8-2023-08-30
# Adding a compatibility layer here so older builds still work fine.
class Dummy:
pass

babase.app.env = Dummy()

babase.app.env.build_number = babase.app.build_number
babase.app.env.device_name = babase.app.device_name
babase.app.env.config_file_path = babase.app.config_file_path
babase.app.env.version = babase.app.version
babase.app.env.debug_build = babase.app.debug_build
babase.app.env.test_build = babase.app.test_build
babase.app.env.data_directory = babase.app.data_directory
babase.app.env.python_directory_user = babase.app.python_directory_user
babase.app.env.python_directory_app = babase.app.python_directory_app
babase.app.env.python_directory_app_site = babase.app.python_directory_app_site
babase.app.env.api_version = babase.app.api_version
babase.app.env.on_tv = babase.app.on_tv
babase.app.env.vr_mode = babase.app.vr_mode
babase.app.env.toolbar_test = babase.app.toolbar_test
babase.app.env.arcade_mode = babase.app.arcade_mode
babase.app.env.headless_mode = babase.app.arcade_mode
babase.app.env.demo_mode = babase.app.demo_mode
babase.app.env.protocl_version = babase.app.protocol_version


_env = _babase.env()
_uiscale = bui.app.ui_v1.uiscale

INDEX_META = "{repository_url}/{content_type}/{tag}/index.json"
HEADERS = {
"User-Agent": _env["legacy_user_agent_string"],
}
PLUGIN_DIRECTORY = _env["python_directory_user"]
loop = babase._asyncio._asyncio_event_loop


def _regexp_friendly_class_name_shortcut(string): return string.replace(".", "\\.")
Expand All @@ -68,6 +101,7 @@ def _regexp_friendly_class_name_shortcut(string): return string.replace(".", "\\
}
DISCORD_URL = "https://ballistica.net/discord"


_CACHE = {}


Expand Down Expand Up @@ -100,7 +134,6 @@ def send_network_request(request):


async def async_send_network_request(request):
loop = asyncio.get_event_loop()
response = await loop.run_in_executor(None, send_network_request, request)
return response

Expand Down Expand Up @@ -129,7 +162,7 @@ def stream_network_response_to_file(request, file, md5sum=None, retries=3):


async def async_stream_network_response_to_file(request, file, md5sum=None, retries=3):
loop = asyncio.get_event_loop()

content = await loop.run_in_executor(
None,
stream_network_response_to_file,
Expand All @@ -156,6 +189,9 @@ class DNSBlockWorkaround:
Such as Jio, a pretty popular ISP in India has a DNS block on
raw.githubusercontent.com (sigh..).
References:
* https://github.com/orgs/community/discussions/42655
Usage:
-----
>>> import urllib.request
Expand Down Expand Up @@ -537,7 +573,7 @@ async def get_content(self):
if self._content is None:
if not self.is_installed:
raise PluginNotInstalled("Plugin is not available locally.")
loop = asyncio.get_event_loop()

self._content = await loop.run_in_executor(None, self._get_content)
return self._content

Expand Down Expand Up @@ -669,7 +705,7 @@ def set_version(self, version):

async def set_content(self, content):
if not self._content:
loop = asyncio.get_event_loop()

await loop.run_in_executor(None, self._set_content, content)
self._content = content
return self
Expand Down Expand Up @@ -808,7 +844,7 @@ def latest_compatible_version(self):
break
if self._latest_compatible_version is None:
raise NoCompatibleVersion(
f"{self.name} has no version compatible with API {babase.app.api_version}."
f"{self.name} has no version compatible with API {babase.app.env.api_version}."
)
return self._latest_compatible_version

Expand Down Expand Up @@ -855,7 +891,7 @@ def __init__(self, plugin, origin_widget, button_callback=lambda: None):
self.plugin = plugin
self.button_callback = button_callback
self.scale_origin = origin_widget.get_screen_space_center()
loop = asyncio.get_event_loop()

loop.create_task(self.draw_ui())

def get_description(self, minimum_character_offset=40):
Expand Down Expand Up @@ -1107,7 +1143,7 @@ async def asyncio_handler(fn, self, *args, **kwargs):

def wrapper(self, *args, **kwargs):
self._ok()
loop = asyncio.get_event_loop()

if asyncio.iscoroutinefunction(fn):
loop.create_task(asyncio_handler(fn, self, *args, **kwargs))
else:
Expand Down Expand Up @@ -1369,8 +1405,6 @@ def __init__(self, origin_widget):
# autoselect=True,
description="Add Source")

loop = asyncio.get_event_loop()

bui.buttonwidget(parent=self._root_widget,
position=(330, 28),
size=(37, 37),
Expand Down Expand Up @@ -1475,7 +1509,7 @@ def _update_custom_sources_widget(self):
on_activate_call=self.show_sources_window)

def popup_menu_selected_choice(self, window, choice):
loop = asyncio.get_event_loop()

loop.create_task(self._asyncio_callback(choice))

def popup_menu_closing(self, window):
Expand All @@ -1497,7 +1531,6 @@ def __init__(self, transition: str = "in_right", origin_widget: bui.Widget = Non
self.selected_category = None
self.plugins_in_current_view = {}

loop = asyncio.get_event_loop()
loop.create_task(self.draw_index())

self._width = (700 if _uiscale is babase.UIScale.SMALL
Expand Down Expand Up @@ -1692,7 +1725,7 @@ def draw_search_bar(self):
description=filter_txt)
self._last_filter_text = None
self._last_filter_plugins = []
loop = asyncio.get_event_loop()

loop.create_task(self.process_search_term())

async def process_search_term(self):
Expand Down Expand Up @@ -1751,7 +1784,7 @@ def draw_refresh_icon(self):
500 if _uiscale is babase.UIScale.MEDIUM else 510)
refresh_pos_y = (180 if _uiscale is babase.UIScale.SMALL else
108 if _uiscale is babase.UIScale.MEDIUM else 120)
loop = asyncio.get_event_loop()

controller_button = bui.buttonwidget(parent=self._root_widget,
# autoselect=True,
position=(refresh_pos_x, refresh_pos_y),
Expand Down Expand Up @@ -1908,7 +1941,7 @@ def __init__(self, plugin_manager, origin_widget):
self._plugin_manager = plugin_manager
self.scale_origin = origin_widget.get_screen_space_center()
self.settings = babase.app.config["Community Plugin Manager"]["Settings"].copy()
loop = asyncio.get_event_loop()

loop.create_task(self.draw_ui())

async def draw_ui(self):
Expand Down Expand Up @@ -2028,7 +2061,7 @@ async def draw_ui(self):
plugin_manager_update_available = False
if plugin_manager_update_available:
text_color = (0.75, 0.2, 0.2)
loop = asyncio.get_event_loop()

button_size = (95 * s, 32 * s)
update_button_label = f'Update to v{plugin_manager_update_available[0]}'
self._update_button = bui.buttonwidget(parent=self._root_widget,
Expand Down Expand Up @@ -2073,7 +2106,7 @@ async def draw_ui(self):
size=(0, 0),
h_align='center',
v_align='center',
text=f'API Version: {babase.app.api_version}',
text=f'API Version: {babase.app.env.api_version}',
scale=text_scale * 0.7,
color=(0.4, 0.8, 1),
maxwidth=width * 0.95)
Expand Down Expand Up @@ -2483,5 +2516,5 @@ def on_app_running(self) -> None:
DNSBlockWorkaround.apply()
asyncio.set_event_loop(babase._asyncio._asyncio_event_loop)
startup_tasks = StartupTasks()
loop = asyncio.get_event_loop()

loop.create_task(startup_tasks.execute())

0 comments on commit eb4e0e5

Please sign in to comment.