mirror of
https://github.com/mamoe/mirai.git
synced 2024-12-31 07:29:45 +08:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
fb2f437a21
@ -16,6 +16,12 @@ mirai 欢迎一切形式的代码贡献。你可以通过以下几种途径向 m
|
||||
|
||||
### 能做什么?
|
||||
|
||||
#### 分支
|
||||
|
||||
- `master`: 最新稳定版
|
||||
- `1.x`: 1.x 现有版本的开发
|
||||
- `dev`: 2.0 重构版本的开发
|
||||
|
||||
**请基于 `master` 分支进行文档修改; 基于 `dev` 分支进行其他修改 (否则你的修改可能被关闭或不会立即合并)**
|
||||
|
||||
- 代码优化: 优化任何功能设计或实现, 或是引入一个新的设计(请先通过 issue 与维护者达成共识)
|
||||
|
@ -118,6 +118,7 @@ subprojects {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
val shadowJarMd5 = tasks.register("shadowJarMd5") {
|
||||
dependsOn("shadowJvmJar")
|
||||
|
||||
@ -140,6 +141,7 @@ subprojects {
|
||||
tasks.getByName("publish").dependsOn(this)
|
||||
tasks.getByName("bintrayUpload").dependsOn(this)
|
||||
}.get()
|
||||
*/
|
||||
|
||||
val githubUpload by tasks.creating {
|
||||
group = "mirai"
|
||||
|
@ -73,6 +73,7 @@ inline fun Project.setupPublishing(
|
||||
|
||||
// afterEvaluate {
|
||||
|
||||
/*
|
||||
val shadowJar = tasks.filterIsInstance<ShadowJar>().firstOrNull() ?: return//@afterEvaluate
|
||||
|
||||
tasks.register("shadowJarMd5") {
|
||||
@ -97,6 +98,7 @@ inline fun Project.setupPublishing(
|
||||
tasks.getByName("publish").dependsOn(this)
|
||||
tasks.getByName("bintrayUpload").dependsOn(this)
|
||||
}
|
||||
*/
|
||||
|
||||
if (Bintray.isBintrayAvailable(project)) {
|
||||
bintray {
|
||||
@ -136,11 +138,13 @@ inline fun Project.setupPublishing(
|
||||
publications {
|
||||
register("mavenJava", MavenPublication::class) {
|
||||
from(components["java"])
|
||||
/*
|
||||
afterEvaluate {
|
||||
for (file in tasks.getByName("shadowJarMd5").outputs.files) {
|
||||
artifact(provider { file })
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
groupId = rootProject.group.toString()
|
||||
this.artifactId = artifactId
|
||||
|
@ -123,10 +123,12 @@ afterEvaluate {
|
||||
|
||||
case 'jvm':
|
||||
it.artifactId = isKotlin137x ? "$variantName" : "$variantName-jvm"
|
||||
/*
|
||||
def files = tasks.getByName("shadowJarMd5").outputs.files + tasks.getByName("shadowJvmJar").outputs.files
|
||||
for (f in files) {
|
||||
artifact f
|
||||
}
|
||||
*/
|
||||
break
|
||||
|
||||
case 'js':
|
||||
|
@ -328,9 +328,12 @@ internal object MessageSvcPbGetMsg : OutgoingPacketFactory<MessageSvcPbGetMsg.Re
|
||||
if (!bot.firstLoginSucceed) {
|
||||
return@mapNotNull null
|
||||
}
|
||||
|
||||
friend.lastMessageSequence.loop {
|
||||
if (friend.lastMessageSequence.compareAndSet(it, msg.msgHead.msgSeq)) {
|
||||
if (friend.lastMessageSequence.compareAndSet(
|
||||
it,
|
||||
msg.msgHead.msgSeq
|
||||
) && msg.contentHead?.autoReply != 1
|
||||
) {
|
||||
return@mapNotNull FriendMessageEvent(
|
||||
friend,
|
||||
msg.toMessageChain(bot, groupIdOrZero = 0, onlineSource = true),
|
||||
|
@ -95,7 +95,7 @@ public class StandardCharImageLoginSolver(
|
||||
if (img == null) {
|
||||
logger.info("无法创建字符图片. 请查看文件")
|
||||
} else {
|
||||
logger.info(img.createCharImg())
|
||||
logger.info("\n" + img.createCharImg())
|
||||
}
|
||||
} catch (throwable: Throwable) {
|
||||
logger.info("创建字符图片时出错($throwable)。请查看文件")
|
||||
|
@ -16,25 +16,66 @@ package net.mamoe.mirai.utils
|
||||
import kotlinx.coroutines.CompletableDeferred
|
||||
import java.awt.BorderLayout
|
||||
import java.awt.Desktop
|
||||
import java.awt.Dimension
|
||||
import java.awt.Toolkit
|
||||
import java.awt.event.KeyEvent
|
||||
import java.awt.event.KeyListener
|
||||
import java.awt.event.WindowAdapter
|
||||
import java.awt.event.WindowEvent
|
||||
import java.awt.image.BufferedImage
|
||||
import java.io.File
|
||||
import javax.imageio.ImageIO
|
||||
import javax.swing.JFrame
|
||||
import javax.swing.JTextField
|
||||
import javax.swing.SwingUtilities
|
||||
|
||||
// 隔离类代码
|
||||
@Suppress("DEPRECATION")
|
||||
internal object WindowHelperJvm {
|
||||
internal val isDesktopSupported: Boolean =
|
||||
kotlin.runCatching {
|
||||
System.getProperty("mirai.no-desktop") === null && Desktop.isDesktopSupported()
|
||||
}.getOrElse {
|
||||
internal val isDesktopSupported: Boolean = kotlin.run {
|
||||
if (System.getProperty("mirai.no-desktop") === null) {
|
||||
kotlin.runCatching {
|
||||
Class.forName("java.awt.Desktop")
|
||||
Class.forName("java.awt.Toolkit")
|
||||
}.onFailure { return@run false } // Android OS
|
||||
kotlin.runCatching {
|
||||
Toolkit.getDefaultToolkit()
|
||||
}.onFailure { // AWT Error, #270
|
||||
return@run false
|
||||
}
|
||||
kotlin.runCatching {
|
||||
Desktop.isDesktopSupported().also { stat ->
|
||||
if (stat) {
|
||||
MiraiLogger.info(
|
||||
"""
|
||||
Mirai 正在使用桌面环境,
|
||||
如果你正在使用SSH, 或无法访问桌面等,
|
||||
请将 `mirai.no-desktop` 添加到 JVM 系统属性中 (-Dmirai.no-desktop)
|
||||
然后重启 Mirai
|
||||
""".trimIndent()
|
||||
)
|
||||
MiraiLogger.info(
|
||||
"""
|
||||
Mirai using DesktopCaptcha System.
|
||||
If you are running on SSH, cannot access desktop or more.
|
||||
Please add `mirai.no-desktop` to JVM properties (-Dmirai.no-desktop)
|
||||
Then restart mirai
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
}
|
||||
}.getOrElse {
|
||||
// Should not happen
|
||||
MiraiLogger.warning("Exception in checking desktop support.", it)
|
||||
false
|
||||
}
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class WindowInitialzier(private val initializer: WindowInitialzier.(JFrame) -> Unit) {
|
||||
internal class WindowInitializer(private val initializer: WindowInitializer.(JFrame) -> Unit) {
|
||||
private lateinit var frame0: JFrame
|
||||
val frame: JFrame get() = frame0
|
||||
fun java.awt.Component.append() {
|
||||
@ -51,12 +92,20 @@ internal class WindowInitialzier(private val initializer: WindowInitialzier.(JFr
|
||||
}
|
||||
}
|
||||
|
||||
internal suspend fun openWindow(title: String = "", initializer: WindowInitialzier.(JFrame) -> Unit = {}): String {
|
||||
return openWindow(title, WindowInitialzier(initializer))
|
||||
internal val windowIcon: BufferedImage? by lazy {
|
||||
WindowHelperJvm::class.java.getResourceAsStream("project-mirai.png")?.use {
|
||||
ImageIO.read(it)
|
||||
}
|
||||
}
|
||||
|
||||
internal suspend fun openWindow(title: String = "", initializer: WindowInitialzier = WindowInitialzier {}): String {
|
||||
internal suspend fun openWindow(title: String = "", initializer: WindowInitializer.(JFrame) -> Unit = {}): String {
|
||||
return openWindow(title, WindowInitializer(initializer))
|
||||
}
|
||||
|
||||
internal suspend fun openWindow(title: String = "", initializer: WindowInitializer = WindowInitializer {}): String {
|
||||
val frame = JFrame()
|
||||
frame.iconImage = windowIcon
|
||||
frame.minimumSize = Dimension(228, 62) // From Windows 10
|
||||
val value = JTextField()
|
||||
val def = CompletableDeferred<String>()
|
||||
value.addKeyListener(object : KeyListener {
|
||||
@ -89,9 +138,9 @@ internal suspend fun openWindow(title: String = "", initializer: WindowInitialzi
|
||||
frame.title = title
|
||||
frame.isVisible = true
|
||||
|
||||
val result = def.await().trim()
|
||||
SwingUtilities.invokeLater {
|
||||
frame.dispose()
|
||||
return def.await().trim().also {
|
||||
SwingUtilities.invokeLater {
|
||||
frame.dispose()
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 38 KiB |
Loading…
Reference in New Issue
Block a user