Merge pull request #267 from Loup-Garou911XD/main

Added function for getting changelog
This commit is contained in:
Vishal 2024-04-22 22:53:59 +05:30 committed by GitHub
commit b487cddacf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 94 additions and 34 deletions

View file

@ -1,5 +1,13 @@
## Plugin Manager (dd-mm-yyyy)
### 1.0.17 (22-04-2024)
- Added function for getting changelog
### 1.0.16 (22-04-2024)
- Fix for error caused when disable button was missing
### 1.0.15 (22-04-2024)
- Plugins can now be viewed in A-Z and Z-A order.

View file

@ -1,6 +1,18 @@
{
"plugin_manager_url": "https://github.com/bombsquad-community/plugin-manager/{content_type}/{tag}/plugin_manager.py",
"versions": {
"1.0.17": {
"api_version": 8,
"commit_sha": "9df1ed9",
"released_on": "22-04-2024",
"md5sum": "c080fc19435f37ed34a9519f33656e85"
},
"1.0.16": {
"api_version": 8,
"commit_sha": "0839999",
"released_on": "22-04-2024",
"md5sum": "f9f3f7d3ff9fcbeee7ae01c8dc1a4ab8"
},
"1.0.15": {
"api_version": 8,
"commit_sha": "fd170eb",

View file

@ -31,7 +31,7 @@ from datetime import datetime
from threading import Thread
import logging
PLUGIN_MANAGER_VERSION = "1.0.15"
PLUGIN_MANAGER_VERSION = "1.0.17"
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.
@ -71,6 +71,7 @@ _env = _babase.env()
_uiscale = bui.app.ui_v1.uiscale
INDEX_META = "{repository_url}/{content_type}/{tag}/index.json"
CHANGELOG_META = "{repository_url}/{content_type}/{tag}/CHANGELOG.md"
HEADERS = {
"User-Agent": _env["legacy_user_agent_string"],
}
@ -1095,7 +1096,7 @@ class PluginWindow(popup.PopupWindow):
button1_action = self.install
if to_draw_button1:
button1 = bui.buttonwidget(parent=self._root_widget,
selected_btn = bui.buttonwidget(parent=self._root_widget,
position=(
width * (
0.1 if self.plugin.is_installed and has_update else
@ -1110,7 +1111,7 @@ class PluginWindow(popup.PopupWindow):
label=button1_label)
if self.plugin.is_installed:
bui.buttonwidget(parent=self._root_widget,
selected_btn = bui.buttonwidget(parent=self._root_widget,
position=(width * (0.4 if has_update else 0.55), pos),
size=button_size,
on_activate_call=button2_action,
@ -1121,7 +1122,7 @@ class PluginWindow(popup.PopupWindow):
label=button2_label)
if has_update:
button1 = bui.buttonwidget(parent=self._root_widget,
selected_btn = bui.buttonwidget(parent=self._root_widget,
position=(width * 0.7, pos),
size=button_size,
on_activate_call=button3_action,
@ -1131,9 +1132,10 @@ class PluginWindow(popup.PopupWindow):
button_type='square',
text_scale=1,
label=button3_label)
bui.containerwidget(edit=self._root_widget,
on_cancel_call=self._cancel,
selected_child=button1)
selected_child=selected_btn)
open_pos_x = (390 if _uiscale is babase.UIScale.SMALL else
450 if _uiscale is babase.UIScale.MEDIUM else 440)
@ -1282,9 +1284,11 @@ class PluginManager:
def __init__(self):
self.request_headers = HEADERS
self._index = _CACHE.get("index", {})
self._changelog = _CACHE.get("changelog", {})
self.categories = {}
self.module_path = sys.modules[__name__].__file__
self._index_setup_in_progress = False
self._changelog_setup_in_progress = False
async def get_index(self):
if not self._index:
@ -1312,6 +1316,37 @@ class PluginManager:
await self.setup_plugin_categories(index)
self._index_setup_in_progress = False
async def get_changelog(self) -> str:
if not self._changelog:
request = urllib.request.Request(CHANGELOG_META.format(
repository_url=REPOSITORY_URL,
content_type="raw",
tag=CURRENT_TAG
),
headers=self.request_headers)
response = await async_send_network_request(request)
self._changelog = response.read().decode()
return self._changelog
async def setup_changelog(self, version=None) -> None:
if version is None:
version = PLUGIN_MANAGER_VERSION
while self._changelog_setup_in_progress:
# Avoid making multiple network calls to the same resource in parallel.
# Rather wait for the previous network call to complete.
await asyncio.sleep(0.1)
self._changelog_setup_in_progress = not bool(self._changelog)
full_changelog = await self.get_changelog()
pattern = rf"### {version} \(\d\d-\d\d-\d{{4}}\)\n(.*?)(?=### \d+\.\d+\.\d+|\Z)"
matches = re.findall(pattern, full_changelog, re.DOTALL)
if matches:
changelog = matches[0].strip()
else:
changelog = f"Changelog entry for version {version} not found."
self.set_changelog_global_cache(changelog)
print(changelog)
self._changelog_setup_in_progress = False
async def setup_plugin_categories(self, plugin_index):
# A hack to have the "All" category show at the top.
self.categories["All"] = None
@ -1354,10 +1389,14 @@ class PluginManager:
async def refresh(self):
self.cleanup()
await self.setup_index()
await self.setup_changelog()
def set_index_global_cache(self, index):
_CACHE["index"] = index
def set_changelog_global_cache(self, changelog):
_CACHE["changelog"] = changelog
def unset_index_global_cache(self):
try:
del _CACHE["index"]
@ -2282,6 +2321,7 @@ class PluginManagerSettingsWindow(popup.PopupWindow):
async def update(self, to_version=None, commit_sha=None):
try:
await self._plugin_manager.update(to_version, commit_sha)
PluginManager.setup_changelog()
except MD5CheckSumFailed:
bui.screenmessage("MD5 checksum failed during plugin manager update", color=(1, 0, 0))
bui.getsound('error').play()