1
0
mirror of https://github.com/mamoe/mirai.git synced 2025-03-25 06:50:09 +08:00

rename to mirai-core-utils-barcode; change to jvm module

This commit is contained in:
Karlatemp 2022-06-14 17:19:16 +08:00
parent d12fb34576
commit 1cff5c093b
No known key found for this signature in database
GPG Key ID: BA173CA2B9956C59
12 changed files with 37 additions and 152 deletions
mirai-core-api/src/jvmMain/kotlin/utils
mirai-core-utils-addition
mirai-core-utils-barcode
mirai-core-utils/src/commonMain/kotlin
mirai-core
settings.gradle.kts

View File

@ -106,7 +106,7 @@ public object SwingSolver : LoginSolver() {
"", HyperLinkLabel(url, "设备锁验证", title),
"URL", JTextField(url),
).also { components ->
val qr = PlatformImageUtil.generateQRCode(url, 300, 300)
val qr = BarcodeSupport.generateQRCode(url, 300, 300)
if (qr != null) {
components.add("")
components.add(JLabel(ImageIcon(qr)))

View File

@ -1,77 +0,0 @@
/*
* Copyright 2019-2022 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
plugins {
kotlin("multiplatform")
// id("kotlinx-atomicfu")
kotlin("plugin.serialization")
id("me.him188.kotlin-jvm-blocking-bridge")
id("me.him188.kotlin-dynamic-delegation")
`maven-publish`
}
description = "mirai-core utilities additions"
kotlin {
explicitApi()
if (isAndroidSDKAvailable) {
jvm("android") {
attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.androidJvm)
// publishAllLibraryVariants()
}
} else {
printAndroidNotInstalled()
}
jvm("common") {
attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.common)
}
jvm("jvm")
sourceSets {
val commonMain by getting {
dependencies {
implementation(project(":mirai-core-utils"))
}
}
val commonTest by getting {
dependencies {
}
}
if (isAndroidSDKAvailable) {
val androidMain by getting {
dependencies {
compileOnly(`android-runtime`)
implementation(`zxing-core`)
}
}
}
val jvmMain by getting {
dependencies {
implementation(`zxing-javase`)
}
}
val jvmTest by getting {
dependencies {
runtimeOnly(files("build/classes/kotlin/jvm/test")) // classpath is not properly set by IDE
}
}
}
}
configureMppPublishing()

View File

@ -1,48 +0,0 @@
/*
* Copyright 2019-2022 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/
package net.mamoe.mirai.utils.addition
import android.graphics.Bitmap
import com.google.zxing.BarcodeFormat
import com.google.zxing.WriterException
import com.google.zxing.common.BitMatrix
import com.google.zxing.qrcode.QRCodeWriter
import net.mamoe.mirai.utils.PlatformImage
import net.mamoe.mirai.utils.PlatformImageUtil
public class PlatformImageUtilImpl : PlatformImageUtil {
override val available: Boolean get() = true
override fun generateQRCode(content: String, width: Int, height: Int): PlatformImage? {
val bitMatrix: BitMatrix = try {
QRCodeWriter().encode(
content,
BarcodeFormat.QR_CODE,
width,
height
)
} catch (e: WriterException) {
throw RuntimeException(e)
}
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565)
for (x in 0 until width) {
for (y in 0 until height) {
bitmap.setPixel(
x, y, if (bitMatrix[x, y]) {
0x000000
} else {
0xFFFFFF
}
)
}
}
return bitmap
}
}

View File

@ -1,10 +0,0 @@
/*
* Copyright 2019-2022 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/
package net.mamoe.mirai.utils.addition

View File

@ -1,11 +1,11 @@
# mirai-core-utils-addition
# mirai-core-utils-barcode
mirai 内部的一些扩展工具, 提供一些扩展支持. 如在 `UnsafeDeviceVerify` 中显示二维码 等.
### 在 mcl 中安装
```shell
./mcl --update-package net.mamoe:mirai-core-utils-addition --type core --channel beta
./mcl --update-package net.mamoe:mirai-core-utils-barcode --type core --channel beta
```
-------

View File

@ -7,4 +7,23 @@
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/
package net.mamoe.mirai.utils.addition
plugins {
kotlin("jvm")
kotlin("plugin.serialization")
`maven-publish`
}
description = "mirai-core utilities barcode support"
kotlin {
explicitApi()
}
dependencies {
implementation(project(":mirai-core-utils"))
implementation(`zxing-javase`)
}
configurePublishing("mirai-core-utils-barcode")

View File

@ -7,7 +7,7 @@
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/
package net.mamoe.mirai.utils.addition
package net.mamoe.mirai.utils.barcode
import com.google.zxing.BarcodeFormat
import com.google.zxing.WriterException
@ -15,9 +15,9 @@ import com.google.zxing.client.j2se.MatrixToImageWriter
import com.google.zxing.common.BitMatrix
import com.google.zxing.qrcode.QRCodeWriter
import net.mamoe.mirai.utils.PlatformImage
import net.mamoe.mirai.utils.PlatformImageUtil
import net.mamoe.mirai.utils.BarcodeSupport
public class PlatformImageUtilImpl : PlatformImageUtil {
public class BarcodeSupportImpl : BarcodeSupport {
override val available: Boolean get() = true
override fun generateQRCode(content: String, width: Int, height: Int): PlatformImage? {

View File

@ -7,4 +7,4 @@
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/
package net.mamoe.mirai.utils.addition
package net.mamoe.mirai.utils.barcode

View File

@ -8,13 +8,14 @@
*/
@file:JvmMultifileClass
@file:JvmName("MiraiUtils")
package net.mamoe.mirai.utils
public expect class PlatformImage
public interface PlatformImageUtil {
public interface BarcodeSupport {
public val available: Boolean
/**
@ -26,17 +27,17 @@ public interface PlatformImageUtil {
height: Int
): PlatformImage?
public companion object INSTANCE : PlatformImageUtil by initService()
public companion object INSTANCE : BarcodeSupport by initService()
}
private fun initService(): PlatformImageUtil {
private fun initService(): BarcodeSupport {
return loadServiceOrNull(
PlatformImageUtil::class,
"net.mamoe.mirai.utils.addition.PlatformImageUtilImpl"
) ?: DummyPIU
BarcodeSupport::class,
"net.mamoe.mirai.utils.barcode.BarcodeSupportImpl"
) ?: DummyBSI
}
private object DummyPIU : PlatformImageUtil {
private object DummyBSI : BarcodeSupport {
override val available: Boolean get() = false
override fun generateQRCode(content: String, width: Int, height: Int): PlatformImage? = null
}

View File

@ -102,7 +102,7 @@ kotlin {
val jvmTest by getting {
dependencies {
api(`kotlinx-coroutines-debug`)
api(project(":mirai-core-utils-addition"))
api(project(":mirai-core-utils-barcode"))
// implementation("net.mamoe:mirai-login-solver-selenium:1.0-dev-14")
}
}

View File

@ -28,7 +28,7 @@ fun includeProject(projectPath: String, dir: String? = null) {
}
includeProject(":mirai-core-utils")
includeProject(":mirai-core-utils-addition")
includeProject(":mirai-core-utils-barcode")
includeProject(":mirai-core-api")
includeProject(":mirai-core")
includeProject(":mirai-core-all")