In the development of PyQt6 software, there may be a requirement for an “About” interface to have a button and functionality for “Update in XX Store”.For example, as shown below (using WeChat as an example):Assuming we want to update WeChat in the Deepin StoreAssuming we want to update WeChat in the Spark Application StoreFor users, clicking to navigate to the software detail page for updates is indeed convenient. How do we call this? How is the code written?-> Update in Deepin StoreBefore that, let me introduce a command: dbus-send
dbus-send is a command-line tool used to send messages to D-Bus, allowing different applications and services to interact through message passing.
The basic syntax of the dbus-send command is as follows:
dbus-send [–system | –session | –bus=ADDRESS] [–dest=NAME] [–print-reply] [–reply-timeout=MSEC] [–type=TYPE] OBJECT_PATH INTERFACE.MEMBER [CONTENTS…]
This command allows different applications and services to interact through message passing.But what does this have to do with “navigating to the Linux Software Store”? The following command will clarify:
dbus-send --session --print-reply=literal --dest=com.home.appstore.client /com/home/appstore/client com.home.appstore.client.openBusinessUri string:'app_detail_info/com.tencent.wechat'
In simpler terms, this dbus-send command invokes the Deepin Application Store and navigates to the WeChat detail page.-> Update in Spark Application StoreHow do we navigate to the Spark Application Store?Those who use the Spark Application Store know that each software detail page has a shareable link:
After clicking copy, it looks like this:spk://store/chat/wechatGiven that the launch command is spark-store, combining it with the link gives us:
spark-store spk://store/chat/wechat
Executing the above command in the terminal will achieve the navigation effect!What about other application detail pages? Just replace the corresponding package name and spk link.-> How to write the code?In Python, call the subprocess module, and then let subprocess.Popen execute the previously mentioned command↓
subprocess.Popen(['dbus-send', '--session', '--print-reply=literal', '--dest=com.home.appstore.client', '/com/home/appstore/client', 'com.home.appstore.client.openBusinessUri', 'string:''app_detail_info/包名'''])
This code invokes the Deepin Application Store detail page, replacing “包名” with the actual package name of the application.
subprocess.Popen(['spark-store', 'spk分享链接'])
This code invokes the Spark Application Store detail page, replacing “spk分享链接” with the copied link starting with spk://.For non-Deepin distributions or distributions without the Spark Application Store installed, this code will not work. You can only use try…except… to handle exceptions.