From 6f501504cf5edad151bbb1990b99d2c82d9640ce Mon Sep 17 00:00:00 2001 From: Loup-Garou911XD Date: Mon, 22 Apr 2024 21:31:22 +0530 Subject: [PATCH 01/11] Added function for getting changelog --- index.json | 1 + plugin_manager.py | 42 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/index.json b/index.json index 8e02d1c1..b7e105b5 100644 --- a/index.json +++ b/index.json @@ -1,6 +1,7 @@ { "plugin_manager_url": "https://github.com/bombsquad-community/plugin-manager/{content_type}/{tag}/plugin_manager.py", "versions": { + "1.0.17": null, "1.0.16": { "api_version": 8, "commit_sha": "0839999", diff --git a/plugin_manager.py b/plugin_manager.py index 77256f05..2f926312 100644 --- a/plugin_manager.py +++ b/plugin_manager.py @@ -31,7 +31,7 @@ from threading import Thread import logging -PLUGIN_MANAGER_VERSION = "1.0.16" +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 @@ class Dummy: _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"], } @@ -1283,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: @@ -1313,6 +1316,38 @@ async def setup_index(self): 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 @@ -1355,10 +1390,14 @@ def cleanup(self): 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"] @@ -2283,6 +2322,7 @@ def save_settings_button(self): 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() From 9df1ed9cd1d0ffc4d3be766c334e31919cd7b02f Mon Sep 17 00:00:00 2001 From: Loup-Garou911XD Date: Mon, 22 Apr 2024 16:02:08 +0000 Subject: [PATCH 02/11] [ci] auto-format --- plugin_manager.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/plugin_manager.py b/plugin_manager.py index 2f926312..d096e9cb 100644 --- a/plugin_manager.py +++ b/plugin_manager.py @@ -1320,15 +1320,15 @@ 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 - ), + 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: + + async def setup_changelog(self, version=None) -> None: if version is None: version = PLUGIN_MANAGER_VERSION while self._changelog_setup_in_progress: @@ -1346,7 +1346,6 @@ async def setup_changelog(self, version = None) -> None: 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. @@ -1395,7 +1394,7 @@ async def refresh(self): def set_index_global_cache(self, index): _CACHE["index"] = index - def set_changelog_global_cache(self,changelog): + def set_changelog_global_cache(self, changelog): _CACHE["changelog"] = changelog def unset_index_global_cache(self): From 5fd39258faf832cc60f3302ea3ff054051822cb2 Mon Sep 17 00:00:00 2001 From: Loup-Garou911XD Date: Mon, 22 Apr 2024 16:02:09 +0000 Subject: [PATCH 03/11] [ci] apply-version-metadata --- index.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/index.json b/index.json index b7e105b5..e29c6dd5 100644 --- a/index.json +++ b/index.json @@ -1,7 +1,12 @@ { "plugin_manager_url": "https://github.com/bombsquad-community/plugin-manager/{content_type}/{tag}/plugin_manager.py", "versions": { - "1.0.17": null, + "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", From 942893573718539607f73b32d4e4de7798108475 Mon Sep 17 00:00:00 2001 From: Loup-Garou911XD Date: Mon, 22 Apr 2024 21:40:17 +0530 Subject: [PATCH 04/11] Added CHANGELOG entry --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57c6fbec..cbd5d06c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## 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 From 7b61d12cbee3ece48d17a1bd8afa51dc5767cbfc Mon Sep 17 00:00:00 2001 From: Loup <90267658+Loup-Garou911XD@users.noreply.github.com> Date: Mon, 22 Apr 2024 23:13:13 +0530 Subject: [PATCH 05/11] Update release.yml to run only on main branch --- .github/workflows/release.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d8eb2b29..429aa3a0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,6 +2,8 @@ name: Create Release on: push: + branches: + - main paths: - index.json From c69d60f9148d31e44ead916aad9797e42d935604 Mon Sep 17 00:00:00 2001 From: Vishal Date: Tue, 23 Apr 2024 00:17:03 +0530 Subject: [PATCH 06/11] testing --- plugin_manager.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin_manager.py b/plugin_manager.py index d096e9cb..9f480dbb 100644 --- a/plugin_manager.py +++ b/plugin_manager.py @@ -8,6 +8,7 @@ import _bascenev1 from bauiv1lib import popup, confirm + import urllib.request import http.client import socket From f194499f97598d6281ac7dc82f270cbaf4bc6538 Mon Sep 17 00:00:00 2001 From: Vishal Date: Tue, 23 Apr 2024 01:49:42 +0530 Subject: [PATCH 07/11] Adding ChangeLog Window. --- plugin_manager.py | 92 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 89 insertions(+), 3 deletions(-) diff --git a/plugin_manager.py b/plugin_manager.py index 9f480dbb..a915d7ab 100644 --- a/plugin_manager.py +++ b/plugin_manager.py @@ -8,7 +8,6 @@ import _bascenev1 from bauiv1lib import popup, confirm - import urllib.request import http.client import socket @@ -896,6 +895,73 @@ async def update(self): bui.getsound('error').play() +class ChangelogWindow(popup.PopupWindow): + def __init__(self, origin_widget): + self.scale_origin = origin_widget.get_screen_space_center() + bui.getsound('swish').play() + s = 1.65 if _uiscale is babase.UIScale.SMALL else 1.39 if _uiscale is babase.UIScale.MEDIUM else 1.67 + width = 400 * s + height = width * 0.5 + color = (1, 1, 1) + text_scale = 0.7 * s + self._transition_out = 'out_scale' + transition = 'in_scale' + + self._root_widget = bui.containerwidget(size=(width, height), + on_outside_click_call=self._back, + transition=transition, + scale=(1.5 if _uiscale is babase.UIScale.SMALL else 1.5 + if _uiscale is babase.UIScale.MEDIUM else 1.0), + scale_origin_stack_offset=self.scale_origin) + + bui.textwidget(parent=self._root_widget, + position=(width * 0.49, height * 0.87), size=(0, 0), + h_align='center', v_align='center', text='ChangeLog', + scale=text_scale * 1.25, color=bui.app.ui_v1.title_color, + maxwidth=width * 0.9) + + back_button = bui.buttonwidget( + parent=self._root_widget, + position=(width * 0.1, height * 0.8), + size=(60, 60), + scale=0.8, + label=babase.charstr(babase.SpecialChar.BACK), + # autoselect=True, + button_type='backSmall', + on_activate_call=self._back) + + bui.containerwidget(edit=self._root_widget, cancel_button=back_button) + + bui.textwidget(parent=self._root_widget, + position=(width * 0.49, height * 0.72), size=(0, 0), + h_align='center', v_align='center', text=PLUGIN_MANAGER_VERSION, + scale=text_scale * 1.1, color=color, + maxwidth=width * 0.9) + + bui.buttonwidget( + parent=self._root_widget, + position=(width * 0.7, height * 0.72 - 20), + size=(140, 60), + scale=0.8, + label='Full ChangeLog', + button_type='square', + on_activate_call=lambda: bui.open_url(REPOSITORY_URL + '/blob/main/CHANGELOG.md')) + + logs = _CACHE['changelog'].split('\n') + loop_height = height * 0.62 + for log in logs: + bui.textwidget(parent=self._root_widget, + position=(width * 0.05, loop_height), size=(0, 0), + h_align='left', v_align='top', text=log, + scale=text_scale, color=color, + maxwidth=width * 0.9) + loop_height -= 35 + + def _back(self) -> None: + bui.getsound('swish').play() + bui.containerwidget(edit=self._root_widget, transition='out_scale') + + class AuthorsWindow(popup.PopupWindow): def __init__(self, authors_info, origin_widget): self.authors_info = authors_info @@ -1038,7 +1104,8 @@ async def draw_ui(self): size=(len(text)*14, 20), label='', texture=bui.gettexture("empty"), - on_activate_call=lambda: AuthorsWindow(self.plugin.info["authors"], self._root_widget)) + on_activate_call=lambda: + AuthorsWindow(self.plugin.info["authors"], self._root_widget)) bui.textwidget(parent=self._root_widget, position=(width * 0.49 - (len(text)*14/2), pos - 10), size=(len(text)*14, 20), @@ -1345,7 +1412,6 @@ async def setup_changelog(self, version=None) -> None: 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): @@ -1779,6 +1845,7 @@ async def draw_index(self): self.draw_category_selection_button(post_label="All") self.draw_refresh_icon() self.draw_settings_icon() + await self.plugin_manager.setup_changelog() with self.exception_handler(): await self.plugin_manager.setup_index() bui.textwidget(edit=self._plugin_manager_status_text, @@ -2171,6 +2238,25 @@ async def draw_ui(self): maxwidth=width * 0.9) pos -= 20 + self._changelog_button = bui.buttonwidget(parent=self._root_widget, + position=((width * 0.2) - button_size[0] / 2 - 5, + pos), + size=(80, 30), + on_activate_call=lambda: + ChangelogWindow(self._root_widget), + textcolor=b_text_color, + button_type='square', + label='') + bui.textwidget(parent=self._root_widget, + position=((width * 0.2) - button_size[0] / 2, pos), + size=(70, 30), + scale=0.6, + h_align='center', + v_align='center', + text='ChangeLog', + color=b_text_color, + draw_controller=self._changelog_button, + ) self._save_button = bui.buttonwidget(parent=self._root_widget, position=((width * 0.82) - button_size[0] / 2, pos), size=(73, 35), From 71b20d2ab3d375e0b3215c96ce69bce59446bb72 Mon Sep 17 00:00:00 2001 From: vishal332008 Date: Mon, 22 Apr 2024 20:20:07 +0000 Subject: [PATCH 08/11] [ci] auto-format --- plugin_manager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin_manager.py b/plugin_manager.py index a915d7ab..72e8c0a6 100644 --- a/plugin_manager.py +++ b/plugin_manager.py @@ -1104,7 +1104,7 @@ async def draw_ui(self): size=(len(text)*14, 20), label='', texture=bui.gettexture("empty"), - on_activate_call=lambda: + on_activate_call=lambda: AuthorsWindow(self.plugin.info["authors"], self._root_widget)) bui.textwidget(parent=self._root_widget, position=(width * 0.49 - (len(text)*14/2), pos - 10), From d9d5a4ff138c0f4c001ac143fd60e5c1ad8060e1 Mon Sep 17 00:00:00 2001 From: Vishal Date: Tue, 23 Apr 2024 01:51:37 +0530 Subject: [PATCH 09/11] Updating changelog.md and index.json --- CHANGELOG.md | 2 +- index.json | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cbd5d06c..068f59af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ### 1.0.17 (22-04-2024) -- Added function for getting changelog +- Added ChangeLog Window to view latest changes. ### 1.0.16 (22-04-2024) diff --git a/index.json b/index.json index e29c6dd5..8e02d1c1 100644 --- a/index.json +++ b/index.json @@ -1,12 +1,6 @@ { "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", From 02530f050e64890f81a3e7beeaa6f39e867cd22a Mon Sep 17 00:00:00 2001 From: Loup-Garou911XD Date: Tue, 23 Apr 2024 02:31:25 +0530 Subject: [PATCH 10/11] Fix class instance not created --- index.json | 1 + plugin_manager.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/index.json b/index.json index 8e02d1c1..b7e105b5 100644 --- a/index.json +++ b/index.json @@ -1,6 +1,7 @@ { "plugin_manager_url": "https://github.com/bombsquad-community/plugin-manager/{content_type}/{tag}/plugin_manager.py", "versions": { + "1.0.17": null, "1.0.16": { "api_version": 8, "commit_sha": "0839999", diff --git a/plugin_manager.py b/plugin_manager.py index 72e8c0a6..bea4f696 100644 --- a/plugin_manager.py +++ b/plugin_manager.py @@ -2408,7 +2408,7 @@ def save_settings_button(self): async def update(self, to_version=None, commit_sha=None): try: await self._plugin_manager.update(to_version, commit_sha) - PluginManager.setup_changelog() + await self._plugin_manager.setup_changelog() except MD5CheckSumFailed: bui.screenmessage("MD5 checksum failed during plugin manager update", color=(1, 0, 0)) bui.getsound('error').play() From 9385a859f282ec8200a2e92bd348f12050fe35d2 Mon Sep 17 00:00:00 2001 From: Loup-Garou911XD Date: Mon, 22 Apr 2024 21:02:25 +0000 Subject: [PATCH 11/11] [ci] apply-version-metadata --- index.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/index.json b/index.json index b7e105b5..bae80468 100644 --- a/index.json +++ b/index.json @@ -1,7 +1,12 @@ { "plugin_manager_url": "https://github.com/bombsquad-community/plugin-manager/{content_type}/{tag}/plugin_manager.py", "versions": { - "1.0.17": null, + "1.0.17": { + "api_version": 8, + "commit_sha": "02530f0", + "released_on": "22-04-2024", + "md5sum": "b5f3902046731ae4cc5bc88586203238" + }, "1.0.16": { "api_version": 8, "commit_sha": "0839999",