diff --git a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/HyperLinkLabel.kt b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/HyperLinkLabel.kt new file mode 100644 index 000000000..af6e2b881 --- /dev/null +++ b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/HyperLinkLabel.kt @@ -0,0 +1,26 @@ +package net.mamoe.mirai.utils + +import java.awt.Desktop +import java.awt.event.MouseAdapter +import java.awt.event.MouseEvent +import java.net.URI +import javax.swing.JLabel + +/** + * 构造方法中url指代用户需要点击的链接, text为显示的提示内容 + */ +internal class HyperLinkLabel constructor(url: String, text: String) : JLabel() { + init { + super.setText("$text"); + addMouseListener(object : MouseAdapter() { + + override fun mouseClicked(e: MouseEvent) { + try { + Desktop.getDesktop().browse(URI(url)) + } catch (ex: Exception) { + ex.printStackTrace() + } + } + }) + } +} diff --git a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/LoginSolver.swing.jvm.kt b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/LoginSolver.swing.jvm.kt index aff36078f..b67bb6702 100644 --- a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/LoginSolver.swing.jvm.kt +++ b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/LoginSolver.swing.jvm.kt @@ -38,18 +38,14 @@ public object SwingSolver : LoginSolver() { public override suspend fun onSolveUnsafeDeviceLoginVerify(bot: Bot, url: String): String? { return openWindow("Mirai UnsafeDeviceLoginVerify(${bot.id})") { - JLabel( - """ + JLabel(""" 需要进行账户安全认证
该账户有[设备锁]/[不常用登录地点]/[不常用设备登录]的问题
完成以下账号认证即可成功登录|理论本认证在mirai每个账户中最多出现1次
- 请将该链接在QQ浏览器中打开并完成认证
- 成功后请关闭该窗口
- 这步操作将在后续的版本中优化 - """.trimIndent() - ).last() - JTextField(url).append() + 成功后请关闭该窗口 + """.trimIndent()).append() + HyperLinkLabel(url, "设备锁验证").last() } } } \ No newline at end of file