Last active
January 3, 2023 22:14
-
-
Save SuddenDevelopment/0947f2a5c6a4d0e145299c8d45d77894 to your computer and use it in GitHub Desktop.
blender addon version check and message update
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1. include this version file | |
# 2. put a json file online format = { "version": "1.4.0", "message": "upgrade for these new features" } | |
# 3. point to the url in version.py | |
# 4. register a prop to show the ui message bpy.types.WindowManager.flex_update = bpy.props.StringProperty(name="Info", default="") | |
# 5. point to that property name in version.py | |
# 6. setup the UI to ue that property if populated | |
#if bpy.context.window_manager.flex_update != "": | |
# box = layout.box() | |
# row = box.row(align=True) | |
# row.alignment = 'EXPAND' | |
# row.label(icon="INFO", text=bpy.context.window_manager.KEY_message) | |
# row = box.row() | |
# row.operator( | |
# 'wm.url_open', text="Product Page", icon="URL").url = config.bl_info['website'] | |
import bpy | |
import requests | |
import json | |
URL = 'https://anthonyaragues.com/stopmotion_checky.json' | |
PROP = 'KEY_message' | |
def getIntVersion(strVersion): | |
# expects blinfo as a string str(bl_info["version"]) | |
strVersion = strVersion.replace(",", ".").replace(")", "").replace("(", "") | |
return int(strVersion.replace(".", "").replace(" ", "")) | |
def show_message(msg, bl_info): | |
print(f'{bl_info["name"]}: {msg}') | |
try: | |
# set as window manager because scene isnt there yet and window is more appropriate level | |
setattr(bpy.context.window_manager, PROP, msg) | |
except: | |
pass | |
def check_version(bl_info): | |
# example response | |
# { "version": "1.4.0", "message": "upgrade for these new features" } | |
objResponse = requests.get(URL) | |
if objResponse.status_code == 200: | |
objVersion = json.loads(objResponse.text) | |
intCurrent = getIntVersion(objVersion["version"]) | |
intInstalled = getIntVersion(str(bl_info["version"])) | |
if intCurrent > intInstalled: | |
show_message(objVersion["message"], bl_info) | |
else: | |
show_message("couldn't check version", bl_info) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment