From 651621da0dbdc14cf7263b3570970732bffbe692 Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Tue, 28 May 2024 12:25:46 +0200 Subject: [PATCH] Extensions: Tooltips and disable poll message for Check for Updates This includes checks for offline-mode. Co-authored by Pablo Vazquez. --- .../addons_core/bl_pkg/bl_extension_ops.py | 47 ++++++++--- .../editors/space_userpref/userpref_ops.cc | 81 ++++++++++++++++--- 2 files changed, 109 insertions(+), 19 deletions(-) diff --git a/scripts/addons_core/bl_pkg/bl_extension_ops.py b/scripts/addons_core/bl_pkg/bl_extension_ops.py index be46ef2df8e..b1c4a4f6170 100644 --- a/scripts/addons_core/bl_pkg/bl_extension_ops.py +++ b/scripts/addons_core/bl_pkg/bl_extension_ops.py @@ -1029,8 +1029,9 @@ class BlPkgRepoSync(Operator, _BlPkgCmdMixIn): class BlPkgRepoSyncAll(Operator, _BlPkgCmdMixIn): + """Refresh the list of extensions for all the remote repositories""" bl_idname = "bl_pkg.repo_sync_all" - bl_label = "Ext Repo Sync All" + bl_label = "Check for Updates" __slots__ = _BlPkgCmdMixIn.cls_slots use_active_only: BoolProperty( @@ -1038,14 +1039,28 @@ class BlPkgRepoSyncAll(Operator, _BlPkgCmdMixIn): description="Only sync the active repository", ) + @classmethod + def poll(cls, context): + if not bpy.app.online_access: + if bpy.app.online_access_override: + cls.poll_message_set( + "Online access required to check for updates. Launch Blender without --offline-mode") + else: + cls.poll_message_set( + "Online access required to check for updates. Enable online access in System preferences") + return False + + repos_all = extension_repos_read(use_active_only=False) + if not len(repos_all): + cls.poll_message_set("No repositories available") + return False + + return True + def exec_command_iter(self, is_modal): use_active_only = self.use_active_only repos_all = extension_repos_read(use_active_only=use_active_only) - if not repos_all: - self.report({'INFO'}, "No repositories to sync") - return None - for repo_item in repos_all: if not os.path.exists(repo_item.directory): try: @@ -1098,6 +1113,7 @@ class BlPkgRepoSyncAll(Operator, _BlPkgCmdMixIn): class BlPkgPkgUpgradeAll(Operator, _BlPkgCmdMixIn): + """Upgrade all the extensions to their latest version for all the remote repositories""" bl_idname = "bl_pkg.pkg_upgrade_all" bl_label = "Ext Package Upgrade All" __slots__ = _BlPkgCmdMixIn.cls_slots + ( @@ -1109,6 +1125,23 @@ class BlPkgPkgUpgradeAll(Operator, _BlPkgCmdMixIn): description="Only sync the active repository", ) + @classmethod + def poll(cls, context): + if not bpy.app.online_access: + if bpy.app.online_access_override: + cls.poll_message_set("Online access required to install updates. Launch Blender without --offline-mode") + else: + cls.poll_message_set( + "Online access required to install updates. Enable online access in System preferences") + return False + + repos_all = extension_repos_read(use_active_only=False) + if not len(repos_all): + cls.poll_message_set("No repositories available") + return False + + return True + def exec_command_iter(self, is_modal): from . import repo_cache_store self._repo_directories = set() @@ -1119,10 +1152,6 @@ class BlPkgPkgUpgradeAll(Operator, _BlPkgCmdMixIn): repos_all = extension_repos_read(use_active_only=use_active_only) repo_directory_supset = [repo_entry.directory for repo_entry in repos_all] if use_active_only else None - if not repos_all: - self.report({'INFO'}, "No repositories to upgrade") - return None - # NOTE: Unless we have a "clear-cache" operator - there isn't a great place to apply cache-clearing. # So when cache is disabled simply clear all cache before performing an update. # Further, individual install & remove operation will manage the cache diff --git a/source/blender/editors/space_userpref/userpref_ops.cc b/source/blender/editors/space_userpref/userpref_ops.cc index a43cc09e6b4..bba1a360d69 100644 --- a/source/blender/editors/space_userpref/userpref_ops.cc +++ b/source/blender/editors/space_userpref/userpref_ops.cc @@ -23,6 +23,7 @@ #include "BKE_callbacks.hh" #include "BKE_context.hh" +#include "BKE_global.hh" #include "BKE_main.hh" #include "BKE_preferences.h" @@ -580,16 +581,77 @@ static void PREFERENCES_OT_extension_repo_add(wmOperatorType *ot) /** \name Generic Extension Repository Utilities * \{ */ -static bool preferences_extension_repo_remote_active_enabled_poll(bContext *C) +static bool preferences_extension_check_for_updates_enabled_poll(bContext *C) { const bUserExtensionRepo *repo = BKE_preferences_extension_repo_find_index( &U, U.active_extension_repo); - if (repo == nullptr || (repo->flag & USER_EXTENSION_REPO_FLAG_DISABLED) || - !(repo->flag & USER_EXTENSION_REPO_FLAG_USE_REMOTE_URL)) - { - CTX_wm_operator_poll_msg_set(C, "An enabled remote repository must be selected"); + + if ((G.f & G_FLAG_INTERNET_ALLOW) == 0) { + if ((G.f & G_FLAG_INTERNET_OVERRIDE_PREF_OFFLINE) != 0) { + CTX_wm_operator_poll_msg_set( + C, "Online access required to check for updates. Launch Blender without --offline-mode"); + } + else { + CTX_wm_operator_poll_msg_set(C, + "Online access required to check for updates. Enable online " + "access in System preferences"); + } return false; } + + if (repo == nullptr) { + CTX_wm_operator_poll_msg_set(C, "No repositories available"); + return false; + } + + if ((repo->flag & USER_EXTENSION_REPO_FLAG_USE_REMOTE_URL) == 0) { + CTX_wm_operator_poll_msg_set(C, "Local repositories do not require refreshing"); + return false; + } + + if ((repo->flag & USER_EXTENSION_REPO_FLAG_DISABLED) != 0) { + CTX_wm_operator_poll_msg_set(C, "Active repository is disabled"); + return false; + } + + return true; +} + +static bool preferences_extension_install_updates_enabled_poll(bContext *C) +{ + const bUserExtensionRepo *repo = BKE_preferences_extension_repo_find_index( + &U, U.active_extension_repo); + + if ((G.f & G_FLAG_INTERNET_ALLOW) == 0) { + if ((G.f & G_FLAG_INTERNET_OVERRIDE_PREF_OFFLINE) != 0) { + CTX_wm_operator_poll_msg_set( + C, "Online access required to install updates. Launch Blender without --offline-mode"); + } + else { + CTX_wm_operator_poll_msg_set(C, + "Online access required to install updates. Enable online " + "access in System preferences"); + } + return false; + } + + if (repo == nullptr) { + CTX_wm_operator_poll_msg_set(C, "No repositories available"); + return false; + } + + if ((repo->flag & USER_EXTENSION_REPO_FLAG_USE_REMOTE_URL) == 0) { + CTX_wm_operator_poll_msg_set(C, + "Local repositories do not require manual update. Reload scripts " + "or restart Blender to see any updates"); + return false; + } + + if ((repo->flag & USER_EXTENSION_REPO_FLAG_DISABLED) != 0) { + CTX_wm_operator_poll_msg_set(C, "Active repository is disabled"); + return false; + } + return true; } @@ -755,10 +817,10 @@ static void PREFERENCES_OT_extension_repo_sync(wmOperatorType *ot) { ot->name = "Check for Updates"; ot->idname = "PREFERENCES_OT_extension_repo_sync"; - ot->description = "Synchronize the active extension repository with its remote URL"; + ot->description = "Refresh the list of extensions for the active repository"; ot->exec = preferences_extension_repo_sync_exec; - ot->poll = preferences_extension_repo_remote_active_enabled_poll; + ot->poll = preferences_extension_check_for_updates_enabled_poll; ot->flag = OPTYPE_INTERNAL; } @@ -781,10 +843,9 @@ static void PREFERENCES_OT_extension_repo_upgrade(wmOperatorType *ot) { ot->name = "Install Available Updates for Repository"; ot->idname = "PREFERENCES_OT_extension_repo_upgrade"; - ot->description = "Update any outdated extensions for the active extension repository"; - + ot->description = "Upgrade all the extensions to their latest version for the active repository"; ot->exec = preferences_extension_repo_upgrade_exec; - ot->poll = preferences_extension_repo_remote_active_enabled_poll; + ot->poll = preferences_extension_install_updates_enabled_poll; ot->flag = OPTYPE_INTERNAL; }