Files
CreatBotKlipperScreen/ks_includes/sdbus_reg.py
zkk 5988acd55b 增加注册码测试功能
Squashed commit of the following:

commit d7698fd423
Merge: d6fcc79a bc36533e
Author: zkk <1007518571@qq.com>
Date:   Mon Mar 10 15:13:20 2025 +0800

    Merge commit 'bc36533ef7266c49c2ef8d9429fca1bc3fadf6f0' into release

commit bc36533ef7
Author: zkk <1007518571@qq.com>
Date:   Mon Mar 10 14:23:56 2025 +0800

    注册码增加测试功能

commit d6fcc79a20
Merge: 69bcfa4b 7f6d43be
Author: zkk <1007518571@qq.com>
Date:   Tue Mar 4 16:08:21 2025 +0800

    Merge commit '7f6d43be7085f8d9e5a236e684303fa2fdc7688b' into release

commit 7f6d43be70
Author: zkk <1007518571@qq.com>
Date:   Tue Mar 4 16:07:27 2025 +0800

    新增图标文件,修复更改主题图标不更新的问题

commit 69bcfa4bd0
Merge: 2dba9f8e 964a81c3
Author: zkk <1007518571@qq.com>
Date:   Mon Mar 3 15:25:49 2025 +0800

    Merge commit '964a81c37cd165b9f8df20db87fd915ba03d10b5' into release

commit 964a81c37c
Author: zkk <1007518571@qq.com>
Date:   Fri Feb 28 16:27:57 2025 +0800

    状态栏增加网络连接图标

commit 9c99cd9125
Author: zkk <1007518571@qq.com>
Date:   Fri Feb 28 16:20:52 2025 +0800

    修复网络页面IP更新不及时的问题

commit 842a616c25
Author: zkk <1007518571@qq.com>
Date:   Tue Feb 25 14:53:31 2025 +0800

    注册码功能的实现

commit 2dba9f8ee2
Merge: 03cd3722 18f05cc5
Author: zkk <1007518571@qq.com>
Date:   Fri Feb 14 15:21:36 2025 +0800

    Merge commit '18f05cc52dfb7889853a4f84aad975309ab7dbbe' into release

commit 18f05cc52d
Author: zkk <1007518571@qq.com>
Date:   Wed Feb 5 10:59:00 2025 +0800

    修复连接不了未加密网络的旧问题

commit 025a26209c
Author: zkk <1007518571@qq.com>
Date:   Fri Jan 24 15:48:52 2025 +0800

    重构网络页面,解决卡顿问题

commit fdc851c4e6
Author: zkk <1007518571@qq.com>
Date:   Fri Jan 24 15:13:41 2025 +0800

    优化菜单页面的点击效果和增加列表风格属性

commit e6cfa87420
Author: zkk <1007518571@qq.com>
Date:   Tue Jan 21 15:11:28 2025 +0800

    优化进入工厂模式的方式为10s内点击5次

commit 03cd37229e
Merge: cf7cafef adcbaa17
Author: zkk <1007518571@qq.com>
Date:   Fri Jan 17 14:38:18 2025 +0800

    Merge commit 'adcbaa1795bffedc3000bc9e59eabba04d946dd4' into release

commit adcbaa1795
Author: zkk <1007518571@qq.com>
Date:   Tue Jan 14 15:34:10 2025 +0800

    实现探针偏移值校准保存前范围检测,避免保存错误值无法启动问题

commit cf7cafefbc
Merge: dc3478b4 8d259cea
Author: zkk <1007518571@qq.com>
Date:   Tue Jan 7 17:26:59 2025 +0800

    Merge commit '8d259ceadd5026cecc1dc61224d91aef4f3877b4' into release

commit 8d259ceadd
Author: zkk <1007518571@qq.com>
Date:   Tue Jan 7 17:15:46 2025 +0800

    实现 打印中恢复喷头温度 提示语的翻译

commit dd11c9683c
Author: zkk <1007518571@qq.com>
Date:   Tue Jan 7 16:52:04 2025 +0800

    优化单个喷头时不显示喷头偏移菜单

commit c3ec7a81bb
Author: zkk <1007518571@qq.com>
Date:   Fri Jan 3 17:52:24 2025 +0800

    修复屏幕耗材检测显示偶尔不准确的问题

commit 413bf6fc4a
Author: zkk <1007518571@qq.com>
Date:   Fri Jan 3 15:00:54 2025 +0800

    修复耗材检测弹窗异常问题

commit dc3478b48c
Merge: 02c7556c 3bfc1aa7
Author: zkk <1007518571@qq.com>
Date:   Thu Jan 2 11:18:07 2025 +0800

    Merge commit '3bfc1aa714e282d74b801155d830377ca58d8f59' into release

commit 3bfc1aa714
Author: zkk <1007518571@qq.com>
Date:   Thu Jan 2 11:17:15 2025 +0800

    修复移轴页面移轴功能失效问题

commit 02c7556cda
Merge: 6bfa42e0 991003e6
Author: zkk <1007518571@qq.com>
Date:   Tue Dec 31 15:07:54 2024 +0800

    Merge commit '991003e6cbea335eca73d3783aa1837059614724' into release

commit 991003e6cb
Author: zkk <1007518571@qq.com>
Date:   Tue Dec 31 15:03:34 2024 +0800

    优化完整 简体中文和繁体中文的翻译

commit 1a177e90d0
Author: zkk <1007518571@qq.com>
Date:   Tue Dec 31 14:10:03 2024 +0800

    优化排除对象的英文语法错误

commit e8d509cb6c
Author: zkk <1007518571@qq.com>
Date:   Fri Dec 27 16:40:52 2024 +0800

    优化耗材检测显示内容

commit 1b7670485a
Author: zkk <1007518571@qq.com>
Date:   Fri Dec 27 14:56:25 2024 +0800

    完善断料自动切头功能描述

commit ecc0c3dd16
Author: zkk <1007518571@qq.com>
Date:   Fri Dec 27 13:40:01 2024 +0800

    实现弹窗翻译功能

commit bc6d60fa18
Author: zkk <1007518571@qq.com>
Date:   Fri Dec 27 09:53:16 2024 +0800

    优化不合理名称和不合理大小写

commit 2e650926bd
Author: zkk <1007518571@qq.com>
Date:   Thu Dec 26 15:06:11 2024 +0800

    修复10寸屏幕偏移值微调页面出界问题

commit c481b551f7
Author: zkk <1007518571@qq.com>
Date:   Wed Dec 25 15:28:26 2024 +0800

    优化移轴设置页面没有返回按钮的问题

commit 2b3c9936bd
Author: zkk <1007518571@qq.com>
Date:   Wed Dec 25 10:05:04 2024 +0800

    删除移动设置页面中轴反转的选项

commit 5e37d59497
Author: zkk <1007518571@qq.com>
Date:   Wed Dec 25 09:05:03 2024 +0800

    优化选择语言标题

commit 5214c3697b
Author: zkk <1007518571@qq.com>
Date:   Tue Dec 24 10:57:41 2024 +0800

    增加设置hostname功能

commit 3709a7465c
Author: zkk <1007518571@qq.com>
Date:   Tue Dec 24 10:43:46 2024 +0800

    增加工厂设置中打包模式

commit 0c2a2618be
Author: zkk <1007518571@qq.com>
Date:   Mon Dec 23 16:25:37 2024 +0800

    实现恢复出厂设置功能

commit e3a38f8561
Author: zkk <1007518571@qq.com>
Date:   Mon Dec 23 15:48:17 2024 +0800

    一点格式化

commit 4e9e452e8b
Author: zkk <1007518571@qq.com>
Date:   Sat Dec 21 14:20:22 2024 +0800

    优化探针偏移值校准时如果当前激活为第一个喷头时不会重复激活喷头

commit 3b85e8e8d5
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 882850dbde
Author: zkk <1007518571@qq.com>
Date:   Wed Dec 18 17:21:16 2024 +0800

    补充双喷头偏移校准页面二维码图片

commit 10ec2029eb
Author: ruipeng <1041589370@qq.com>
Date:   Wed Dec 18 17:17:18 2024 +0800

    增加自动切换喷头开关选项

commit 3d6eed9d95
Author: zkk <1007518571@qq.com>
Date:   Mon Dec 16 16:33:34 2024 +0800

    喷头偏移值校准功能的实现

commit 40ecbb3ea4
Author: zkk <1007518571@qq.com>
Date:   Fri Dec 13 09:20:00 2024 +0800

    z探针校准时指定默认激活工具头为第一个头

commit bce3caa409
Author: zkk <1007518571@qq.com>
Date:   Fri Dec 13 09:19:19 2024 +0800

    优化z探针校准时候移动过慢问题

commit 6bfa42e036
Merge: 1a87ced3 4f3aa9aa
Author: zkk <1007518571@qq.com>
Date:   Thu Dec 12 10:33:58 2024 +0800

    Merge commit '4f3aa9aa4c581ae9e7a740bd37f9e80ba064c27f' into release

commit 4f3aa9aa4c
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 1a69b5180d
Author: ruipeng <1041589370@qq.com>
Date:   Wed Dec 11 11:44:36 2024 +0800

    新增D600pro2、D1000的V0版机型

commit e3fd413d62
Author: zkk <1007518571@qq.com>
Date:   Tue Dec 10 14:34:13 2024 +0800

    修复打印时没有修改z偏移值 仍提示保存z偏移的按钮的bug

commit 594fb668fe
Author: zkk <1007518571@qq.com>
Date:   Tue Dec 10 14:25:04 2024 +0800

    设置自适应调平选项默认为关闭状态

commit 1a87ced3f5
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/sdbus_reg.py   resolved by d7698fd423 version
#	panels/license.py   resolved by d7698fd423 version
2025-03-10 15:14:32 +08:00

186 lines
6.2 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 test_registration(self, val: str) -> bool:
raise NotImplementedError
@dbus_method_async(result_signature="b")
async def add_registration_time(self) -> bool:
raise NotImplementedError
@dbus_method_async(result_signature="b")
async def minus_registration_time(self) -> 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 test_registration(self, code: str) -> bool:
async def _reset():
return await self.registration_interface.proxy.test_registration(code)
return self._async_call(_reset, default=False)
def add_registration_time(self) -> bool:
async def _add():
return await self.registration_interface.proxy.add_registration_time()
return self._async_call(_add, default=False)
def minus_registration_time(self) -> bool:
async def _minus():
return await self.registration_interface.proxy.minus_registration_time()
return self._async_call(_minus, 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