Squashed commit of the following: commit 69bcfa4bd00fc1af8da8df191b6a4d86309c7d23 Merge: 2dba9f8e 964a81c3 Author: zkk <1007518571@qq.com> Date: Mon Mar 3 15:25:49 2025 +0800 Merge commit '964a81c37cd165b9f8df20db87fd915ba03d10b5' into release commit 964a81c37cd165b9f8df20db87fd915ba03d10b5 Author: zkk <1007518571@qq.com> Date: Fri Feb 28 16:27:57 2025 +0800 状态栏增加网络连接图标 commit 9c99cd91250c7aeb3d9728e540590299a1caf150 Author: zkk <1007518571@qq.com> Date: Fri Feb 28 16:20:52 2025 +0800 修复网络页面IP更新不及时的问题 commit 842a616c2558757d19b7553d23aee9f1daffdc80 Author: zkk <1007518571@qq.com> Date: Tue Feb 25 14:53:31 2025 +0800 注册码功能的实现 commit 2dba9f8ee2725847f31c891b19df6d9b81e03568 Merge: 03cd3722 18f05cc5 Author: zkk <1007518571@qq.com> Date: Fri Feb 14 15:21:36 2025 +0800 Merge commit '18f05cc52dfb7889853a4f84aad975309ab7dbbe' into release commit 18f05cc52dfb7889853a4f84aad975309ab7dbbe Author: zkk <1007518571@qq.com> Date: Wed Feb 5 10:59:00 2025 +0800 修复连接不了未加密网络的旧问题 commit 025a26209cbe15a0b7f5f1aba5166da63d6eaebf Author: zkk <1007518571@qq.com> Date: Fri Jan 24 15:48:52 2025 +0800 重构网络页面,解决卡顿问题 commit fdc851c4e66e3b872eb2564442f0c67369b9e3e2 Author: zkk <1007518571@qq.com> Date: Fri Jan 24 15:13:41 2025 +0800 优化菜单页面的点击效果和增加列表风格属性 commit e6cfa874208f8d98d0360fb073e4da15c935b202 Author: zkk <1007518571@qq.com> Date: Tue Jan 21 15:11:28 2025 +0800 优化进入工厂模式的方式为10s内点击5次 commit 03cd37229ee6c606e9814af602709d81b2c79bec Merge: cf7cafef adcbaa17 Author: zkk <1007518571@qq.com> Date: Fri Jan 17 14:38:18 2025 +0800 Merge commit 'adcbaa1795bffedc3000bc9e59eabba04d946dd4' into release commit adcbaa1795bffedc3000bc9e59eabba04d946dd4 Author: zkk <1007518571@qq.com> Date: Tue Jan 14 15:34:10 2025 +0800 实现探针偏移值校准保存前范围检测,避免保存错误值无法启动问题 commit cf7cafefbcd2274c9a481e58042d11db8cd79961 Merge: dc3478b4 8d259cea Author: zkk <1007518571@qq.com> Date: Tue Jan 7 17:26:59 2025 +0800 Merge commit '8d259ceadd5026cecc1dc61224d91aef4f3877b4' into release commit 8d259ceadd5026cecc1dc61224d91aef4f3877b4 Author: zkk <1007518571@qq.com> Date: Tue Jan 7 17:15:46 2025 +0800 实现 打印中恢复喷头温度 提示语的翻译 commit dd11c9683cb5af5407e650eea9b683b1066256c7 Author: zkk <1007518571@qq.com> Date: Tue Jan 7 16:52:04 2025 +0800 优化单个喷头时不显示喷头偏移菜单 commit c3ec7a81bbe1490b76202485d0502a4829a3cee5 Author: zkk <1007518571@qq.com> Date: Fri Jan 3 17:52:24 2025 +0800 修复屏幕耗材检测显示偶尔不准确的问题 commit 413bf6fc4a740f53d265c63abe7c51eaad483cb0 Author: zkk <1007518571@qq.com> Date: Fri Jan 3 15:00:54 2025 +0800 修复耗材检测弹窗异常问题 commit dc3478b48c7da1dbae120d1270c9ab64646d6647 Merge: 02c7556c 3bfc1aa7 Author: zkk <1007518571@qq.com> Date: Thu Jan 2 11:18:07 2025 +0800 Merge commit '3bfc1aa714e282d74b801155d830377ca58d8f59' into release commit 3bfc1aa714e282d74b801155d830377ca58d8f59 Author: zkk <1007518571@qq.com> Date: Thu Jan 2 11:17:15 2025 +0800 修复移轴页面移轴功能失效问题 commit 02c7556cdadf8de1ef3c54d2831920927cadbe30 Merge: 6bfa42e0 991003e6 Author: zkk <1007518571@qq.com> Date: Tue Dec 31 15:07:54 2024 +0800 Merge commit '991003e6cbea335eca73d3783aa1837059614724' into release commit 991003e6cbea335eca73d3783aa1837059614724 Author: zkk <1007518571@qq.com> Date: Tue Dec 31 15:03:34 2024 +0800 优化完整 简体中文和繁体中文的翻译 commit 1a177e90d09b9b9949bff2a1e3c6b12173420620 Author: zkk <1007518571@qq.com> Date: Tue Dec 31 14:10:03 2024 +0800 优化排除对象的英文语法错误 commit e8d509cb6c2883b1fadb5ab9f9ca658e61849055 Author: zkk <1007518571@qq.com> Date: Fri Dec 27 16:40:52 2024 +0800 优化耗材检测显示内容 commit 1b7670485a918cb334119175777525f768e670be Author: zkk <1007518571@qq.com> Date: Fri Dec 27 14:56:25 2024 +0800 完善断料自动切头功能描述 commit ecc0c3dd16442497e56f5f8ab3a0c6be00bd180e Author: zkk <1007518571@qq.com> Date: Fri Dec 27 13:40:01 2024 +0800 实现弹窗翻译功能 commit bc6d60fa183af50b7b16fea685139ca9d5df90ea Author: zkk <1007518571@qq.com> Date: Fri Dec 27 09:53:16 2024 +0800 优化不合理名称和不合理大小写 commit 2e650926bdba1c65baa506be1b1dd09621e8d8ea Author: zkk <1007518571@qq.com> Date: Thu Dec 26 15:06:11 2024 +0800 修复10寸屏幕偏移值微调页面出界问题 commit c481b551f777a3a6cadf7be3bfcab38448b51694 Author: zkk <1007518571@qq.com> Date: Wed Dec 25 15:28:26 2024 +0800 优化移轴设置页面没有返回按钮的问题 commit 2b3c9936bd693c8fc265d6352799f382680f4920 Author: zkk <1007518571@qq.com> Date: Wed Dec 25 10:05:04 2024 +0800 删除移动设置页面中轴反转的选项 commit 5e37d59497c54086d3f1e215cbabc03254857a58 Author: zkk <1007518571@qq.com> Date: Wed Dec 25 09:05:03 2024 +0800 优化选择语言标题 commit 5214c3697baac78bd0a465e33d6f4f3c1e30862e Author: zkk <1007518571@qq.com> Date: Tue Dec 24 10:57:41 2024 +0800 增加设置hostname功能 commit 3709a7465cc2e0d677ecc9979fb18144f7e0ec33 Author: zkk <1007518571@qq.com> Date: Tue Dec 24 10:43:46 2024 +0800 增加工厂设置中打包模式 commit 0c2a2618beb68d50601e433beef06122fb0ffd40 Author: zkk <1007518571@qq.com> Date: Mon Dec 23 16:25:37 2024 +0800 实现恢复出厂设置功能 commit e3a38f85613d53a4a063e835c34c701196010c6e Author: zkk <1007518571@qq.com> Date: Mon Dec 23 15:48:17 2024 +0800 一点格式化 commit 4e9e452e8bed4b53eaaae8f0a69142de8aa50611 Author: zkk <1007518571@qq.com> Date: Sat Dec 21 14:20:22 2024 +0800 优化探针偏移值校准时如果当前激活为第一个喷头时不会重复激活喷头 commit 3b85e8e8d59b0d4eae75f80d9e637fe9dc272cbe Merge: 882850db 10ec2029 Author: zkk <1007518571@qq.com> Date: Wed Dec 18 17:26:08 2024 +0800 Merge branch 'develop' of https://server.creatbot.com/Gitea/CreatBot/CreatBotKlipperScreen into develop commit 882850dbde648598e5f91281101d0ea01fd56d56 Author: zkk <1007518571@qq.com> Date: Wed Dec 18 17:21:16 2024 +0800 补充双喷头偏移校准页面二维码图片 commit 10ec2029eb73e66874d5a0ec492c016480641110 Author: ruipeng <1041589370@qq.com> Date: Wed Dec 18 17:17:18 2024 +0800 增加自动切换喷头开关选项 commit 3d6eed9d9526b77472ba7df29014b5768c594026 Author: zkk <1007518571@qq.com> Date: Mon Dec 16 16:33:34 2024 +0800 喷头偏移值校准功能的实现 commit 40ecbb3ea4827c9bac1aa271cccc958c94c1114a Author: zkk <1007518571@qq.com> Date: Fri Dec 13 09:20:00 2024 +0800 z探针校准时指定默认激活工具头为第一个头 commit bce3caa409618ef5bc2067865940d14a1441c0f8 Author: zkk <1007518571@qq.com> Date: Fri Dec 13 09:19:19 2024 +0800 优化z探针校准时候移动过慢问题 commit 6bfa42e036a521c8ff7db1bf8ccb65500eabb6ea Merge: 1a87ced3 4f3aa9aa Author: zkk <1007518571@qq.com> Date: Thu Dec 12 10:33:58 2024 +0800 Merge commit '4f3aa9aa4c581ae9e7a740bd37f9e80ba064c27f' into release commit 4f3aa9aa4c581ae9e7a740bd37f9e80ba064c27f Merge: e3fd413d 1a69b518 Author: zkk <1007518571@qq.com> Date: Thu Dec 12 10:30:00 2024 +0800 Merge branch 'develop' of https://server.creatbot.com/Gitea/CreatBot/CreatBotKlipperScreen into develop commit 1a69b5180de733f15550a1294a7221d6070306a0 Author: ruipeng <1041589370@qq.com> Date: Wed Dec 11 11:44:36 2024 +0800 新增D600pro2、D1000的V0版机型 commit e3fd413d6256414441e9fe653c1132b1799a5cb2 Author: zkk <1007518571@qq.com> Date: Tue Dec 10 14:34:13 2024 +0800 修复打印时没有修改z偏移值 仍提示保存z偏移的按钮的bug commit 594fb668fe94fe907c028bf65ecced43ea8660cb Author: zkk <1007518571@qq.com> Date: Tue Dec 10 14:25:04 2024 +0800 设置自适应调平选项默认为关闭状态 commit 1a87ced3f5725569a6b9a7ee5f5250044d01d852 Merge: 629416d1 6064a6e1 Author: zkk <1007518571@qq.com> Date: Fri Nov 29 10:18:32 2024 +0800 Merge branch 'develop' into release # Conflicts: # ks_includes/locales/KlipperScreen.pot resolved by 69bcfa4bd00fc1af8da8df191b6a4d86309c7d23 version # ks_includes/locales/zh_CN/LC_MESSAGES/KlipperScreen.mo resolved by 69bcfa4bd00fc1af8da8df191b6a4d86309c7d23 version # ks_includes/locales/zh_CN/LC_MESSAGES/KlipperScreen.po resolved by 69bcfa4bd00fc1af8da8df191b6a4d86309c7d23 version # ks_includes/locales/zh_TW/LC_MESSAGES/KlipperScreen.mo resolved by 69bcfa4bd00fc1af8da8df191b6a4d86309c7d23 version # ks_includes/locales/zh_TW/LC_MESSAGES/KlipperScreen.po resolved by 69bcfa4bd00fc1af8da8df191b6a4d86309c7d23 version # panels/factory_settings.py resolved by 69bcfa4bd00fc1af8da8df191b6a4d86309c7d23 version # panels/network.py resolved by 69bcfa4bd00fc1af8da8df191b6a4d86309c7d23 version
166 lines
5.6 KiB
Python
166 lines
5.6 KiB
Python
from asyncio import new_event_loop, run_coroutine_threadsafe
|
|
from threading import Thread
|
|
import ast
|
|
import logging
|
|
from typing import Optional
|
|
from sdbus import DbusInterfaceCommonAsync, dbus_method_async, dbus_property_async
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class RegistrationInterface(DbusInterfaceCommonAsync, interface_name="org.registration.interface"):
|
|
|
|
def __init__(self, bus_name: str, object_path: str):
|
|
super().__init__()
|
|
self.proxy = self.new_proxy(bus_name, object_path)
|
|
|
|
@dbus_property_async(property_signature="s")
|
|
def get_unique_id(self) -> str:
|
|
raise NotImplementedError
|
|
|
|
@dbus_property_async(property_signature="a{sv}")
|
|
def get_time_info(self) -> str:
|
|
raise NotImplementedError
|
|
|
|
@dbus_property_async(property_signature="b")
|
|
def is_active(self) -> bool:
|
|
raise NotImplementedError
|
|
|
|
@dbus_property_async(property_signature="b")
|
|
def is_trial_active(self) -> bool:
|
|
raise NotImplementedError
|
|
|
|
@dbus_method_async(input_signature="s", result_signature="b")
|
|
async def verify_activation_code(self, val: str) -> bool:
|
|
raise NotImplementedError
|
|
|
|
@dbus_method_async(input_signature="s", result_signature="b")
|
|
async def reset_registration(self, val: str) -> bool:
|
|
raise NotImplementedError
|
|
|
|
@dbus_property_async(property_signature="b")
|
|
def enabled_registration(self) -> bool:
|
|
raise NotImplementedError
|
|
|
|
|
|
class LicenseManager:
|
|
|
|
def __init__(self, bus_name: str = "org.registration.link", object_path: str = "/"):
|
|
self.loop = new_event_loop()
|
|
self.registration_interface: Optional[RegistrationInterface] = None
|
|
self.interface_valid = False
|
|
self._thread: Optional[Thread] = None
|
|
self.callback = None
|
|
|
|
try:
|
|
self.registration_interface = RegistrationInterface(bus_name, object_path)
|
|
self.interface_valid = True
|
|
logger.info("DBus connection established successfully")
|
|
except Exception as e:
|
|
logger.error(f"Failed to initialize DBus connection: {e}")
|
|
self._cleanup_resources()
|
|
return
|
|
|
|
self._thread = Thread(target=self._run_loop, daemon=True)
|
|
self._thread.start()
|
|
|
|
def _run_loop(self) -> None:
|
|
try:
|
|
self.loop.run_forever()
|
|
finally:
|
|
self.loop.close()
|
|
|
|
def _cleanup_resources(self) -> None:
|
|
if self.loop.is_running():
|
|
self.loop.call_soon_threadsafe(self.loop.stop)
|
|
if self._thread and self._thread.is_alive():
|
|
self._thread.join(timeout=1)
|
|
self.loop.close()
|
|
|
|
def is_interface_valid(self) -> bool:
|
|
return self.interface_valid
|
|
|
|
def _async_call(self, coroutine_func, default=None):
|
|
if not self.is_interface_valid():
|
|
logger.warning("Attempting to use invalid DBus interface")
|
|
return default
|
|
|
|
try:
|
|
future = run_coroutine_threadsafe(coroutine_func(), self.loop)
|
|
return future.result()
|
|
except Exception as e:
|
|
logger.error(f"DBus operation failed: {e}")
|
|
self.interface_valid = False
|
|
return default
|
|
|
|
def get_unique_id(self) -> str:
|
|
async def _get():
|
|
return await self.registration_interface.proxy.get_unique_id
|
|
|
|
return self._async_call(_get, default="")
|
|
|
|
def get_trial_time(self) -> int:
|
|
async def _get():
|
|
return await self.registration_interface.proxy.get_time_info
|
|
|
|
result = self._async_call(_get, default="{}")
|
|
try:
|
|
data_dict = ast.literal_eval(result)
|
|
return data_dict.get("trial_time", 0)
|
|
except Exception as e:
|
|
logger.error(f"Parse time info failed: {e}")
|
|
return 0
|
|
|
|
def get_total_printed_time(self) -> int:
|
|
async def _get():
|
|
return await self.registration_interface.proxy.get_time_info
|
|
|
|
result = self._async_call(_get, default="{}")
|
|
try:
|
|
data_dict = ast.literal_eval(result)
|
|
return int(data_dict.get("total_printed_time", 0))
|
|
except Exception as e:
|
|
logger.error(f"Parse time info failed: {e}")
|
|
return 0
|
|
|
|
def is_active(self) -> bool:
|
|
async def _get():
|
|
return await self.registration_interface.proxy.is_active
|
|
|
|
return self._async_call(_get, default=False)
|
|
|
|
def is_trial_active(self) -> bool:
|
|
async def _get():
|
|
return await self.registration_interface.proxy.is_trial_active
|
|
|
|
return self._async_call(_get, default=False)
|
|
|
|
def is_time_sufficient(self, required_seconds: int = 40 * 3600) -> bool:
|
|
trial_time = self.get_trial_time()
|
|
printed_time = self.get_total_printed_time()
|
|
return (trial_time - printed_time) > required_seconds
|
|
|
|
def verify_activation_code(self, code: str) -> bool:
|
|
async def _verify():
|
|
return await self.registration_interface.proxy.verify_activation_code(code)
|
|
|
|
return self._async_call(_verify, default=False)
|
|
|
|
def reset_registration(self, code: str) -> bool:
|
|
async def _reset():
|
|
return await self.registration_interface.proxy.reset_registration(code)
|
|
|
|
return self._async_call(_reset, default=False)
|
|
|
|
def enabled_registration(self) -> bool:
|
|
async def _get():
|
|
return await self.registration_interface.proxy.enabled_registration
|
|
|
|
return self._async_call(_get, default=False)
|
|
|
|
def close(self) -> None:
|
|
if self.is_interface_valid():
|
|
logger.info("Closing DBus connection...")
|
|
self._cleanup_resources()
|
|
self.interface_valid = False
|