Skip to content

Commit

Permalink
feat: [cast]Update QR with url
Browse files Browse the repository at this point in the history
Set the product url into QR code, and parse it by new way.

Log: Update QR with url.
  • Loading branch information
re2zero committed Nov 21, 2024
1 parent c02ae81 commit 9050e04
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ android {
// 无痛修改包名:https://www.jianshu.com/p/17327e191d2e
applicationId 'com.deepin.assistant'
versionCode 11
versionName "1.0.0"
versionName "1.0.2"

// 仅保留中文语种的资源
resConfigs 'zh'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,13 +378,17 @@ class HomeActivity : AppActivity(), NavigationAdapter.OnNavigationListener {

resultCodeFromScan?.let {
try {
val decodedBytes = Base64.decode(it, Base64.DEFAULT)
var mark = it.substringAfter("mark=")
if (mark.isNullOrEmpty()) {
mark = it // without mark=, back to old.
}
val decodedBytes = Base64.decode(mark, Base64.DEFAULT)
// 处理成功解码的字节
val decodedString = String(decodedBytes)

// 按照"&"分割字符串
val parameters = decodedString.split("&")
if (parameters.size == 3) {
if (parameters.size >= 3) {
// 创建一个存储解析结果的 Map
val resultMap = mutableMapOf<String, String>()

Expand All @@ -402,6 +406,7 @@ class HomeActivity : AppActivity(), NavigationAdapter.OnNavigationListener {
val ip = resultMap["host"]
val portString = resultMap["port"]
val pin = resultMap["pin"]
val pv = resultMap["pv"] // protocol version

// 将 port 转换为 Int,如果失败默认为 0
val port = portString?.toIntOrNull() ?: 0
Expand Down
8 changes: 6 additions & 2 deletions src/lib/cooperation/core/net/helper/phonehelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ inline constexpr char Kconnect[] { ":/icons/deepin/builtin/texts/connect_18px.sv
inline constexpr char Kdisconnect[] { ":/icons/deepin/builtin/texts/disconnect_18px.svg" };
#endif

inline constexpr char KprotocolVer[] { "1.0.0" };
inline constexpr char KdownloadUrl[] { "https://www.chinauos.com/resource/assistant" };

PhoneHelper::PhoneHelper(QObject *parent)
: QObject(parent), m_viewSize(0, 0)
{
Expand Down Expand Up @@ -158,12 +161,13 @@ int PhoneHelper::notifyMessage(const QString &message, QStringList actions)

void PhoneHelper::generateQRCode(const QString &ip, const QString &port, const QString &pin)
{
QString combined = QString("host=%1&port=%2&pin=%3").arg(ip).arg(port).arg(pin);
QString combined = QString("host=%1&port=%2&pin=%3&pv=%4").arg(ip).arg(port).arg(pin).arg(KprotocolVer);

QByteArray byteArray = combined.toUtf8();
QByteArray base64 = byteArray.toBase64();
QString qrContent = QString("%1?mark=%2").arg(KdownloadUrl).arg(QString::fromUtf8(base64));

emit setQRCode(base64);
emit setQRCode(qrContent);
}

void PhoneHelper::resetScreenMirroringWindow()
Expand Down

0 comments on commit 9050e04

Please sign in to comment.