mirror of
https://github.com/mamoe/mirai.git
synced 2025-04-02 13:20:14 +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` 分支进行其他修改 (否则你的修改可能被关闭或不会立即合并)**
|
**请基于 `master` 分支进行文档修改; 基于 `dev` 分支进行其他修改 (否则你的修改可能被关闭或不会立即合并)**
|
||||||
|
|
||||||
- 代码优化: 优化任何功能设计或实现, 或是引入一个新的设计(请先通过 issue 与维护者达成共识)
|
- 代码优化: 优化任何功能设计或实现, 或是引入一个新的设计(请先通过 issue 与维护者达成共识)
|
||||||
|
@ -118,6 +118,7 @@ subprojects {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
val shadowJarMd5 = tasks.register("shadowJarMd5") {
|
val shadowJarMd5 = tasks.register("shadowJarMd5") {
|
||||||
dependsOn("shadowJvmJar")
|
dependsOn("shadowJvmJar")
|
||||||
|
|
||||||
@ -140,6 +141,7 @@ subprojects {
|
|||||||
tasks.getByName("publish").dependsOn(this)
|
tasks.getByName("publish").dependsOn(this)
|
||||||
tasks.getByName("bintrayUpload").dependsOn(this)
|
tasks.getByName("bintrayUpload").dependsOn(this)
|
||||||
}.get()
|
}.get()
|
||||||
|
*/
|
||||||
|
|
||||||
val githubUpload by tasks.creating {
|
val githubUpload by tasks.creating {
|
||||||
group = "mirai"
|
group = "mirai"
|
||||||
|
@ -73,6 +73,7 @@ inline fun Project.setupPublishing(
|
|||||||
|
|
||||||
// afterEvaluate {
|
// afterEvaluate {
|
||||||
|
|
||||||
|
/*
|
||||||
val shadowJar = tasks.filterIsInstance<ShadowJar>().firstOrNull() ?: return//@afterEvaluate
|
val shadowJar = tasks.filterIsInstance<ShadowJar>().firstOrNull() ?: return//@afterEvaluate
|
||||||
|
|
||||||
tasks.register("shadowJarMd5") {
|
tasks.register("shadowJarMd5") {
|
||||||
@ -97,6 +98,7 @@ inline fun Project.setupPublishing(
|
|||||||
tasks.getByName("publish").dependsOn(this)
|
tasks.getByName("publish").dependsOn(this)
|
||||||
tasks.getByName("bintrayUpload").dependsOn(this)
|
tasks.getByName("bintrayUpload").dependsOn(this)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
if (Bintray.isBintrayAvailable(project)) {
|
if (Bintray.isBintrayAvailable(project)) {
|
||||||
bintray {
|
bintray {
|
||||||
@ -136,11 +138,13 @@ inline fun Project.setupPublishing(
|
|||||||
publications {
|
publications {
|
||||||
register("mavenJava", MavenPublication::class) {
|
register("mavenJava", MavenPublication::class) {
|
||||||
from(components["java"])
|
from(components["java"])
|
||||||
|
/*
|
||||||
afterEvaluate {
|
afterEvaluate {
|
||||||
for (file in tasks.getByName("shadowJarMd5").outputs.files) {
|
for (file in tasks.getByName("shadowJarMd5").outputs.files) {
|
||||||
artifact(provider { file })
|
artifact(provider { file })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
groupId = rootProject.group.toString()
|
groupId = rootProject.group.toString()
|
||||||
this.artifactId = artifactId
|
this.artifactId = artifactId
|
||||||
|
@ -123,10 +123,12 @@ afterEvaluate {
|
|||||||
|
|
||||||
case 'jvm':
|
case 'jvm':
|
||||||
it.artifactId = isKotlin137x ? "$variantName" : "$variantName-jvm"
|
it.artifactId = isKotlin137x ? "$variantName" : "$variantName-jvm"
|
||||||
|
/*
|
||||||
def files = tasks.getByName("shadowJarMd5").outputs.files + tasks.getByName("shadowJvmJar").outputs.files
|
def files = tasks.getByName("shadowJarMd5").outputs.files + tasks.getByName("shadowJvmJar").outputs.files
|
||||||
for (f in files) {
|
for (f in files) {
|
||||||
artifact f
|
artifact f
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
break
|
break
|
||||||
|
|
||||||
case 'js':
|
case 'js':
|
||||||
|
@ -328,9 +328,12 @@ internal object MessageSvcPbGetMsg : OutgoingPacketFactory<MessageSvcPbGetMsg.Re
|
|||||||
if (!bot.firstLoginSucceed) {
|
if (!bot.firstLoginSucceed) {
|
||||||
return@mapNotNull null
|
return@mapNotNull null
|
||||||
}
|
}
|
||||||
|
|
||||||
friend.lastMessageSequence.loop {
|
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(
|
return@mapNotNull FriendMessageEvent(
|
||||||
friend,
|
friend,
|
||||||
msg.toMessageChain(bot, groupIdOrZero = 0, onlineSource = true),
|
msg.toMessageChain(bot, groupIdOrZero = 0, onlineSource = true),
|
||||||
|
@ -95,7 +95,7 @@ public class StandardCharImageLoginSolver(
|
|||||||
if (img == null) {
|
if (img == null) {
|
||||||
logger.info("无法创建字符图片. 请查看文件")
|
logger.info("无法创建字符图片. 请查看文件")
|
||||||
} else {
|
} else {
|
||||||
logger.info(img.createCharImg())
|
logger.info("\n" + img.createCharImg())
|
||||||
}
|
}
|
||||||
} catch (throwable: Throwable) {
|
} catch (throwable: Throwable) {
|
||||||
logger.info("创建字符图片时出错($throwable)。请查看文件")
|
logger.info("创建字符图片时出错($throwable)。请查看文件")
|
||||||
|
@ -16,25 +16,66 @@ package net.mamoe.mirai.utils
|
|||||||
import kotlinx.coroutines.CompletableDeferred
|
import kotlinx.coroutines.CompletableDeferred
|
||||||
import java.awt.BorderLayout
|
import java.awt.BorderLayout
|
||||||
import java.awt.Desktop
|
import java.awt.Desktop
|
||||||
|
import java.awt.Dimension
|
||||||
|
import java.awt.Toolkit
|
||||||
import java.awt.event.KeyEvent
|
import java.awt.event.KeyEvent
|
||||||
import java.awt.event.KeyListener
|
import java.awt.event.KeyListener
|
||||||
import java.awt.event.WindowAdapter
|
import java.awt.event.WindowAdapter
|
||||||
import java.awt.event.WindowEvent
|
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.JFrame
|
||||||
import javax.swing.JTextField
|
import javax.swing.JTextField
|
||||||
import javax.swing.SwingUtilities
|
import javax.swing.SwingUtilities
|
||||||
|
|
||||||
// 隔离类代码
|
// 隔离类代码
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
internal object WindowHelperJvm {
|
internal object WindowHelperJvm {
|
||||||
internal val isDesktopSupported: Boolean =
|
internal val isDesktopSupported: Boolean = kotlin.run {
|
||||||
|
if (System.getProperty("mirai.no-desktop") === null) {
|
||||||
kotlin.runCatching {
|
kotlin.runCatching {
|
||||||
System.getProperty("mirai.no-desktop") === null && Desktop.isDesktopSupported()
|
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 {
|
}.getOrElse {
|
||||||
|
// Should not happen
|
||||||
|
MiraiLogger.warning("Exception in checking desktop support.", it)
|
||||||
false
|
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
|
private lateinit var frame0: JFrame
|
||||||
val frame: JFrame get() = frame0
|
val frame: JFrame get() = frame0
|
||||||
fun java.awt.Component.append() {
|
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 {
|
internal val windowIcon: BufferedImage? by lazy {
|
||||||
return openWindow(title, WindowInitialzier(initializer))
|
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()
|
val frame = JFrame()
|
||||||
|
frame.iconImage = windowIcon
|
||||||
|
frame.minimumSize = Dimension(228, 62) // From Windows 10
|
||||||
val value = JTextField()
|
val value = JTextField()
|
||||||
val def = CompletableDeferred<String>()
|
val def = CompletableDeferred<String>()
|
||||||
value.addKeyListener(object : KeyListener {
|
value.addKeyListener(object : KeyListener {
|
||||||
@ -89,9 +138,9 @@ internal suspend fun openWindow(title: String = "", initializer: WindowInitialzi
|
|||||||
frame.title = title
|
frame.title = title
|
||||||
frame.isVisible = true
|
frame.isVisible = true
|
||||||
|
|
||||||
val result = def.await().trim()
|
return def.await().trim().also {
|
||||||
SwingUtilities.invokeLater {
|
SwingUtilities.invokeLater {
|
||||||
frame.dispose()
|
frame.dispose()
|
||||||
}
|
}
|
||||||
return result
|
}
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
After Width: | Height: | Size: 38 KiB |
Loading…
Reference in New Issue
Block a user