From 412dc0ac1316123bcfed601c11cfcd1044524d8c Mon Sep 17 00:00:00 2001 From: "jiahua.liu" Date: Sun, 29 Mar 2020 01:07:35 +0800 Subject: [PATCH 1/6] prep for graphical wrapper --- .../graphical/MiraiConsoleGraphicalLoader.kt | 35 +++++++++++++++++++ .../mirai/console/graphical/MiraiGraphical.kt | 3 +- 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/MiraiConsoleGraphicalLoader.kt diff --git a/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/MiraiConsoleGraphicalLoader.kt b/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/MiraiConsoleGraphicalLoader.kt new file mode 100644 index 000000000..06c3fc167 --- /dev/null +++ b/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/MiraiConsoleGraphicalLoader.kt @@ -0,0 +1,35 @@ +/* + * Copyright 2020 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/master/LICENSE + */ +package net.mamoe.mirai.console.graphical + +import net.mamoe.mirai.console.pure.MiraiConsoleUIPure + +import net.mamoe.mirai.console.MiraiConsole +import tornadofx.launch +import kotlin.concurrent.thread + +class MiraiConsoleGraphicalLoader { + companion object { + internal lateinit var coreVersion :String + internal lateinit var consoleVersion: String + @JvmStatic + fun load( + coreVersion: String, + consoleVersion: String + ) { + this.coreVersion = coreVersion + this.consoleVersion = consoleVersion + Runtime.getRuntime().addShutdownHook(thread(start = false) { + MiraiConsole.stop() + }) + launch() + } + + } +} \ No newline at end of file diff --git a/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/MiraiGraphical.kt b/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/MiraiGraphical.kt index 4c8ba7351..5c2f48555 100644 --- a/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/MiraiGraphical.kt +++ b/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/MiraiGraphical.kt @@ -27,8 +27,7 @@ class MiraiGraphicalUI : App(Decorator::class, PrimaryStyleSheet::class) { override fun init() { super.init() - - MiraiConsole.start(find()) + MiraiConsole.start(find(),MiraiConsoleGraphicalLoader.coreVersion,MiraiConsoleGraphicalLoader.consoleVersion) } override fun stop() { From af48b74786fdd06a33942bdc131c9ec41927c41d Mon Sep 17 00:00:00 2001 From: "jiahua.liu" Date: Sun, 29 Mar 2020 15:58:35 +0800 Subject: [PATCH 2/6] some modify --- gradle.properties | 1 + mirai-console-graphical/build.gradle.kts | 65 +++++++++++++++++++ .../mirai/console/wrapper/ConsoleUpdater.kt | 5 ++ mirai-console/build.gradle.kts | 14 ++++ settings.gradle | 2 + 5 files changed, 87 insertions(+) diff --git a/gradle.properties b/gradle.properties index 5a5989a62..f98c58274 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,6 +4,7 @@ kotlin.code.style=official miraiVersion=0.30.0 miraiConsoleVersion=0.3.7 miraiConsoleWrapperVersion=0.1.4 +miraiConsoleGraphicalVersion = 0.0.2 kotlin.incremental.multiplatform=true kotlin.parallel.tasks.in.project=true # kotlin diff --git a/mirai-console-graphical/build.gradle.kts b/mirai-console-graphical/build.gradle.kts index 8863f725c..89080c27f 100644 --- a/mirai-console-graphical/build.gradle.kts +++ b/mirai-console-graphical/build.gradle.kts @@ -1,8 +1,13 @@ +import Versions.Publishing.bintray +import java.util.* + plugins { id("kotlinx-serialization") id("org.openjfx.javafxplugin") version "0.0.8" id("kotlin") id("java") + id("com.jfrog.bintray") + `maven-publish` } javafx { @@ -15,12 +20,37 @@ apply(plugin = "com.github.johnrengelman.shadow") version = Versions.Mirai.console +/* tasks.withType() { manifest { attributes["Main-Class"] = "net.mamoe.mirai.console.graphical.MiraiGraphicalLoader" } } + */ +val miraiConsoleGraphicalVersion: String by project.ext +version = miraiConsoleGraphicalVersion + +description = "Console Graphical Version with plugin support for mirai" +bintray { + val keyProps = Properties() + val keyFile = file("../keys.properties") + if (keyFile.exists()) keyFile.inputStream().use { keyProps.load(it) } + if (keyFile.exists()) keyFile.inputStream().use { keyProps.load(it) } + + user = keyProps.getProperty("bintrayUser") + key = keyProps.getProperty("bintrayKey") + setPublications("mavenJava") + setConfigurations("archives") + + pkg.apply { + repo = "mirai" + name = "mirai-console-graphical" + setLicenses("AGPLv3") + publicDownloadNumbers = true + vcsUrl = "https://github.com/mamoe/mirai" + } +} val kotlinVersion: String by rootProject.ext val atomicFuVersion: String by rootProject.ext @@ -54,3 +84,38 @@ dependencies { tasks.withType { kotlinOptions.jvmTarget = "1.8" } + +@Suppress("DEPRECATION") +val sourcesJar by tasks.registering(Jar::class) { + classifier = "sources" + from(sourceSets.main.get().allSource) +} + +publishing { + /* + repositories { + maven { + // change to point to your repo, e.g. http://my.org/repo + url = uri("$buildDir/repo") + } + }*/ + publications { + register("mavenJava", MavenPublication::class) { + from(components["java"]) + + groupId = rootProject.group.toString() + artifactId = "mirai-console-graphical" + version = miraiConsoleGraphicalVersion + + pom.withXml { + val root = asNode() + root.appendNode("description", description) + root.appendNode("name", project.name) + root.appendNode("url", "https://github.com/mamoe/mirai") + root.children().last() + } + + artifact(sourcesJar.get()) + } + } +} \ No newline at end of file diff --git a/mirai-console-wrapper/src/main/kotlin/net/mamoe/mirai/console/wrapper/ConsoleUpdater.kt b/mirai-console-wrapper/src/main/kotlin/net/mamoe/mirai/console/wrapper/ConsoleUpdater.kt index 02ea6ba60..c38bdde01 100644 --- a/mirai-console-wrapper/src/main/kotlin/net/mamoe/mirai/console/wrapper/ConsoleUpdater.kt +++ b/mirai-console-wrapper/src/main/kotlin/net/mamoe/mirai/console/wrapper/ConsoleUpdater.kt @@ -21,6 +21,11 @@ internal object ConsoleUpdater { "version" to "/net/mamoe/mirai-console/" ) ) + put( + CONSOLE_GRAPHICAL, mapOf( + "version" to "/net/mamoe/mirai-console-graphical/" + ) + ) } } diff --git a/mirai-console/build.gradle.kts b/mirai-console/build.gradle.kts index d91241bda..61f7331b5 100644 --- a/mirai-console/build.gradle.kts +++ b/mirai-console/build.gradle.kts @@ -1,4 +1,5 @@ import java.util.* +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { kotlin("jvm") @@ -28,6 +29,7 @@ dependencies { implementation(group = "com.alibaba", name = "fastjson", version = "1.2.62") implementation(group = "org.yaml", name = "snakeyaml", version = "1.25") implementation(group = "com.moandjiezana.toml", name = "toml4j", version = "0.7.2") + implementation(kotlin("stdlib-jdk8")) } val miraiConsoleVersion: String by project.ext @@ -87,4 +89,16 @@ publishing { artifact(sourcesJar.get()) } } +} +repositories { + maven("https://dl.bintray.com/kotlin/kotlin-eap") + mavenCentral() +} +val compileKotlin: KotlinCompile by tasks +compileKotlin.kotlinOptions { + jvmTarget = "1.8" +} +val compileTestKotlin: KotlinCompile by tasks +compileTestKotlin.kotlinOptions { + jvmTarget = "1.8" } \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 053cf61f6..8801cc958 100644 --- a/settings.gradle +++ b/settings.gradle @@ -16,6 +16,8 @@ pluginManagement { mavenCentral() maven { url "https://plugins.gradle.org/m2/" } maven { url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies" } + maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' } + maven { url 'https://plugins.gradle.org/m2/' } } } From 3cbbacfcebc28c805e8acbbdfa8c942557aabb14 Mon Sep 17 00:00:00 2001 From: "jiahua.liu" Date: Sun, 29 Mar 2020 16:02:27 +0800 Subject: [PATCH 3/6] fix class loader --- .../kotlin/net/mamoe/mirai/console/wrapper/WrapperMain.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mirai-console-wrapper/src/main/kotlin/net/mamoe/mirai/console/wrapper/WrapperMain.kt b/mirai-console-wrapper/src/main/kotlin/net/mamoe/mirai/console/wrapper/WrapperMain.kt index 1b8125a9e..7a1b9d195 100644 --- a/mirai-console-wrapper/src/main/kotlin/net/mamoe/mirai/console/wrapper/WrapperMain.kt +++ b/mirai-console-wrapper/src/main/kotlin/net/mamoe/mirai/console/wrapper/WrapperMain.kt @@ -137,7 +137,7 @@ object WrapperMain { val loader = MiraiClassLoader( CoreUpdater.getProtocolLib()!!, ConsoleUpdater.getFile()!!, - this.javaClass.classLoader + null ) loader.loadClass("net.mamoe.mirai.BotFactoryJvm") @@ -158,7 +158,7 @@ object WrapperMain { private class MiraiClassLoader( protocol: File, console: File, - parent: ClassLoader + parent: ClassLoader? ): URLClassLoader(arrayOf( protocol.toURI().toURL(), console.toURI().toURL() From d97179068f03d75b95623133e6eb7cb03449d533 Mon Sep 17 00:00:00 2001 From: "jiahua.liu" Date: Sun, 29 Mar 2020 17:09:39 +0800 Subject: [PATCH 4/6] new download link --- gradle.properties | 4 ++-- .../net/mamoe/mirai/console/wrapper/ConsoleUpdater.kt | 2 +- .../kotlin/net/mamoe/mirai/console/wrapper/CoreUpdater.kt | 2 +- .../kotlin/net/mamoe/mirai/console/wrapper/WrapperMain.kt | 8 +++++++- mirai-console/build.gradle.kts | 6 ++++++ .../main/kotlin/net/mamoe/mirai/console/MiraiConsole.kt | 8 -------- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/gradle.properties b/gradle.properties index f98c58274..7b1c7df83 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,8 +1,8 @@ # style guide kotlin.code.style=official # config -miraiVersion=0.30.0 -miraiConsoleVersion=0.3.7 +miraiVersion=0.31.0 +miraiConsoleVersion=0.3.8 miraiConsoleWrapperVersion=0.1.4 miraiConsoleGraphicalVersion = 0.0.2 kotlin.incremental.multiplatform=true diff --git a/mirai-console-wrapper/src/main/kotlin/net/mamoe/mirai/console/wrapper/ConsoleUpdater.kt b/mirai-console-wrapper/src/main/kotlin/net/mamoe/mirai/console/wrapper/ConsoleUpdater.kt index c38bdde01..71ad74dac 100644 --- a/mirai-console-wrapper/src/main/kotlin/net/mamoe/mirai/console/wrapper/ConsoleUpdater.kt +++ b/mirai-console-wrapper/src/main/kotlin/net/mamoe/mirai/console/wrapper/ConsoleUpdater.kt @@ -62,7 +62,7 @@ internal object ConsoleUpdater { ) */ MiraiDownloader.addTask( - "https://pan.jasonczc.cn/?/mirai/${getProjectName()}/${getProjectName()}-$newest.pdf", getContent("${getProjectName()}-$newest.jar") + "https://pan.jasonczc.cn/?/mirai/${getProjectName()}/${getProjectName()}-$newest.mp4", getContent("${getProjectName()}-$newest.jar") ) } } diff --git a/mirai-console-wrapper/src/main/kotlin/net/mamoe/mirai/console/wrapper/CoreUpdater.kt b/mirai-console-wrapper/src/main/kotlin/net/mamoe/mirai/console/wrapper/CoreUpdater.kt index 136e11d93..b0089d106 100644 --- a/mirai-console-wrapper/src/main/kotlin/net/mamoe/mirai/console/wrapper/CoreUpdater.kt +++ b/mirai-console-wrapper/src/main/kotlin/net/mamoe/mirai/console/wrapper/CoreUpdater.kt @@ -38,7 +38,7 @@ internal object CoreUpdater { println("Updating shadowed-core from V$current -> V$newest, this is a force update") this.getProtocolLib()?.delete() MiraiDownloader - .addTask("https://pan.jasonczc.cn/?/mirai/mirai-core-qqandroid/mirai-core-qqandroid-$newest.pdf",getContent("mirai-core-qqandroid-jvm-$newest.jar")) + .addTask("https://pan.jasonczc.cn/?/mirai/mirai-core-qqandroid/mirai-core-qqandroid-$newest.mp4",getContent("mirai-core-qqandroid-jvm-$newest.jar")) //.addTask("https://raw.githubusercontent.com/mamoe/mirai-repo/master/shadow/mirai-core-qqandroid/mirai-core-qqandroid-$newest.jar", getContent("mirai-core-qqandroid-jvm-$newest.jar")) } diff --git a/mirai-console-wrapper/src/main/kotlin/net/mamoe/mirai/console/wrapper/WrapperMain.kt b/mirai-console-wrapper/src/main/kotlin/net/mamoe/mirai/console/wrapper/WrapperMain.kt index 7a1b9d195..d866635ac 100644 --- a/mirai-console-wrapper/src/main/kotlin/net/mamoe/mirai/console/wrapper/WrapperMain.kt +++ b/mirai-console-wrapper/src/main/kotlin/net/mamoe/mirai/console/wrapper/WrapperMain.kt @@ -100,7 +100,7 @@ object WrapperMain { println("Please select Console Type") println("请选择 Console 版本") println("=> Pure : pure console") - println("=> Graphical : [Not Supported Yet] graphical UI except unix") + println("=> Graphical : graphical UI except unix") println("=> Terminal : [Not Supported Yet] console in unix") val scanner = Scanner(System.`in`) while (type == null){ @@ -149,6 +149,12 @@ object WrapperMain { ).getMethod("load", String::class.java, String::class.java) .invoke(null, CoreUpdater.getCurrentVersion(), ConsoleUpdater.getCurrentVersion()) } + CONSOLE_GRAPHICAL -> { + loader.loadClass( + "net.mamoe.mirai.console.graphical.MiraiConsoleGraphicalLoader" + ).getMethod("load", String::class.java, String::class.java) + .invoke(null, CoreUpdater.getCurrentVersion(), ConsoleUpdater.getCurrentVersion()) + } } } } diff --git a/mirai-console/build.gradle.kts b/mirai-console/build.gradle.kts index 61f7331b5..8acb30ded 100644 --- a/mirai-console/build.gradle.kts +++ b/mirai-console/build.gradle.kts @@ -30,6 +30,12 @@ dependencies { implementation(group = "org.yaml", name = "snakeyaml", version = "1.25") implementation(group = "com.moandjiezana.toml", name = "toml4j", version = "0.7.2") implementation(kotlin("stdlib-jdk8")) + + + testApi(ktor("client-cio", Versions.Kotlin.ktor)) + testApi(ktor("client-core", Versions.Kotlin.ktor)) + testApi(ktor("network", Versions.Kotlin.ktor)) + testApi("org.jsoup:jsoup:1.12.1") } val miraiConsoleVersion: String by project.ext diff --git a/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsole.kt b/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsole.kt index c0f988fb9..d14b4c812 100644 --- a/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsole.kt +++ b/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsole.kt @@ -18,7 +18,6 @@ import net.mamoe.mirai.console.command.DefaultCommands import net.mamoe.mirai.console.plugins.PluginManager import net.mamoe.mirai.console.utils.MiraiConsoleUI import net.mamoe.mirai.utils.SimpleLogger.LogPriority -import net.mamoe.mirai.utils.cryptor.ECDH import net.mamoe.mirai.utils.io.encodeToString import java.io.ByteArrayOutputStream import java.io.PrintStream @@ -83,13 +82,6 @@ object MiraiConsole { logger("Mirai为开源项目,请自觉遵守开源项目协议") logger("Powered by Mamoe Technologies and contributors") - /* 加载ECDH */ - try { - ECDH() - } catch (ignored: Exception) { - } - //Security.removeProvider("BC") - /* 依次启用功能 */ DefaultCommands() PluginManager.loadPlugins() From eb1a15de76d6dbcf719f23c670235a3c6e76d5cc Mon Sep 17 00:00:00 2001 From: "jiahua.liu" Date: Sun, 29 Mar 2020 18:14:08 +0800 Subject: [PATCH 5/6] fix Vcs --- build.gradle | 4 ++-- buildSrc/src/main/kotlin/versions.kt | 7 ++++--- gradle.properties | 20 ------------------- mirai-console-graphical/build.gradle.kts | 9 ++++----- mirai-console-terminal/build.gradle.kts | 2 +- .../mirai/console/wrapper/ConsoleUpdater.kt | 11 ++++++++-- mirai-console/build.gradle.kts | 5 ++--- 7 files changed, 22 insertions(+), 36 deletions(-) diff --git a/build.gradle b/build.gradle index a2c036fd6..19dbd5669 100644 --- a/build.gradle +++ b/build.gradle @@ -11,8 +11,8 @@ buildscript { dependencies { classpath 'com.github.jengelman.gradle.plugins:shadow:5.2.0' - classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlinVersion" - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" + classpath "org.jetbrains.kotlin:kotlin-serialization:1.4-M1" + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4-M1" classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' // don't use any other. } } diff --git a/buildSrc/src/main/kotlin/versions.kt b/buildSrc/src/main/kotlin/versions.kt index 3dd3ae4c1..91af9fb53 100644 --- a/buildSrc/src/main/kotlin/versions.kt +++ b/buildSrc/src/main/kotlin/versions.kt @@ -11,9 +11,10 @@ import org.gradle.kotlin.dsl.DependencyHandlerScope object Versions { object Mirai { - const val core = "0.30.0" - const val console = "0.3.6" - const val consoleWrapper = "0.1.3" + const val core = "0.31.0" + const val console = "0.3.7" + const val consoleGraphical = "0.0.2" + const val consoleWrapper = "0.2.0" } object Kotlin { diff --git a/gradle.properties b/gradle.properties index 7b1c7df83..6f6711e1f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,22 +1,2 @@ # style guide kotlin.code.style=official -# config -miraiVersion=0.31.0 -miraiConsoleVersion=0.3.8 -miraiConsoleWrapperVersion=0.1.4 -miraiConsoleGraphicalVersion = 0.0.2 -kotlin.incremental.multiplatform=true -kotlin.parallel.tasks.in.project=true -# kotlin -kotlinVersion=1.4-M1 -# kotlin libraries -serializationVersion=0.20.0-1.4-M1 -coroutinesVersion=1.3.5-1.4-M1 -atomicFuVersion=0.14.2-1.4-M1 -kotlinXIoVersion=0.1.16 -coroutinesIoVersion=0.1.16 -# utility -ktorVersion=1.3.2-1.4-M1 -klockVersion=1.7.0 -# gradle plugin -protobufJavaVersion=3.10.0 diff --git a/mirai-console-graphical/build.gradle.kts b/mirai-console-graphical/build.gradle.kts index 89080c27f..918dd49e0 100644 --- a/mirai-console-graphical/build.gradle.kts +++ b/mirai-console-graphical/build.gradle.kts @@ -18,7 +18,6 @@ javafx { apply(plugin = "com.github.johnrengelman.shadow") -version = Versions.Mirai.console /* tasks.withType() { @@ -28,8 +27,7 @@ tasks.withType() { } */ -val miraiConsoleGraphicalVersion: String by project.ext -version = miraiConsoleGraphicalVersion +version = Versions.Mirai.console description = "Console Graphical Version with plugin support for mirai" bintray { @@ -67,7 +65,7 @@ fun kotlinx(id: String, version: String) = "org.jetbrains.kotlinx:kotlinx-$id:$v fun ktor(id: String, version: String) = "io.ktor:ktor-$id:$version" -val miraiVersion: String by rootProject.ext +val miraiVersion = Versions.Mirai.core dependencies { implementation("net.mamoe:mirai-core-jvm:$miraiVersion") @@ -91,6 +89,7 @@ val sourcesJar by tasks.registering(Jar::class) { from(sourceSets.main.get().allSource) } + publishing { /* repositories { @@ -105,7 +104,7 @@ publishing { groupId = rootProject.group.toString() artifactId = "mirai-console-graphical" - version = miraiConsoleGraphicalVersion + version = Versions.Mirai.consoleGraphical pom.withXml { val root = asNode() diff --git a/mirai-console-terminal/build.gradle.kts b/mirai-console-terminal/build.gradle.kts index cb2da1d3f..87777c0c0 100644 --- a/mirai-console-terminal/build.gradle.kts +++ b/mirai-console-terminal/build.gradle.kts @@ -31,7 +31,7 @@ fun kotlinx(id: String, version: String) = "org.jetbrains.kotlinx:kotlinx-$id:$v fun ktor(id: String, version: String) = "io.ktor:ktor-$id:$version" -val miraiVersion: String by rootProject.ext +val miraiVersion = Versions.Mirai.core dependencies { implementation("net.mamoe:mirai-core-jvm:$miraiVersion") diff --git a/mirai-console-wrapper/src/main/kotlin/net/mamoe/mirai/console/wrapper/ConsoleUpdater.kt b/mirai-console-wrapper/src/main/kotlin/net/mamoe/mirai/console/wrapper/ConsoleUpdater.kt index 71ad74dac..5d846d864 100644 --- a/mirai-console-wrapper/src/main/kotlin/net/mamoe/mirai/console/wrapper/ConsoleUpdater.kt +++ b/mirai-console-wrapper/src/main/kotlin/net/mamoe/mirai/console/wrapper/ConsoleUpdater.kt @@ -38,7 +38,14 @@ internal object ConsoleUpdater { if (file.name.contains("mirai-console")) { when (consoleType) { CONSOLE_PURE -> { - return file + if(!file.name.contains("graphical")) { + return file + } + } + CONSOLE_GRAPHICAL -> { + if(file.name.contains("graphical")) { + return file + } } } } @@ -108,7 +115,7 @@ internal object ConsoleUpdater { return if (consoleType == CONSOLE_PURE) { "mirai-console" } else { - "mirai-console-$consoleType" + "mirai-console-${consoleType.toLowerCase()}" } } diff --git a/mirai-console/build.gradle.kts b/mirai-console/build.gradle.kts index 8acb30ded..0250509f7 100644 --- a/mirai-console/build.gradle.kts +++ b/mirai-console/build.gradle.kts @@ -38,8 +38,7 @@ dependencies { testApi("org.jsoup:jsoup:1.12.1") } -val miraiConsoleVersion: String by project.ext -version = miraiConsoleVersion +version = Versions.Mirai.console description = "Console with plugin support for mirai" bintray { @@ -82,7 +81,7 @@ publishing { groupId = rootProject.group.toString() artifactId = "mirai-console" - version = miraiConsoleVersion + version = version pom.withXml { val root = asNode() From f6c508883f1eb72de4b086ef66f3a202f61fdbf7 Mon Sep 17 00:00:00 2001 From: PeratX <1215714524@qq.com> Date: Sun, 29 Mar 2020 18:38:28 +0800 Subject: [PATCH 6/6] Wrapper: update native window --- .../mirai/console/wrapper/MiraiDownloader.kt | 1 - .../mirai/console/wrapper/WrapperMain.kt | 86 +++++++++---------- 2 files changed, 40 insertions(+), 47 deletions(-) diff --git a/mirai-console-wrapper/src/main/kotlin/net/mamoe/mirai/console/wrapper/MiraiDownloader.kt b/mirai-console-wrapper/src/main/kotlin/net/mamoe/mirai/console/wrapper/MiraiDownloader.kt index 4676acd35..cffbc2611 100644 --- a/mirai-console-wrapper/src/main/kotlin/net/mamoe/mirai/console/wrapper/MiraiDownloader.kt +++ b/mirai-console-wrapper/src/main/kotlin/net/mamoe/mirai/console/wrapper/MiraiDownloader.kt @@ -161,7 +161,6 @@ class MiraiDownloaderProgressBarInUI(): MiraiDownloadProgressBar{ } override fun complete() { - TODO("Not yet implemented") } } diff --git a/mirai-console-wrapper/src/main/kotlin/net/mamoe/mirai/console/wrapper/WrapperMain.kt b/mirai-console-wrapper/src/main/kotlin/net/mamoe/mirai/console/wrapper/WrapperMain.kt index d866635ac..c8a38311d 100644 --- a/mirai-console-wrapper/src/main/kotlin/net/mamoe/mirai/console/wrapper/WrapperMain.kt +++ b/mirai-console-wrapper/src/main/kotlin/net/mamoe/mirai/console/wrapper/WrapperMain.kt @@ -7,17 +7,16 @@ * https://github.com/mamoe/mirai/blob/master/LICENSE */ @file:Suppress("EXPERIMENTAL_API_USAGE") + package net.mamoe.mirai.console.wrapper import kotlinx.coroutines.* -import java.awt.Frame -import java.awt.Panel import java.awt.TextArea -import java.awt.Toolkit import java.io.File -import java.lang.StringBuilder import java.net.URLClassLoader import java.util.* +import javax.swing.JFrame +import javax.swing.JPanel val contentPath by lazy { @@ -31,8 +30,8 @@ val contentPath by lazy { object WrapperMain { internal var uiBarOutput = StringBuilder() private val uilog = StringBuilder() - internal fun uiLog(any: Any?){ - if(any!=null) { + internal fun uiLog(any: Any?) { + if (any != null) { uilog.append(any) } } @@ -40,33 +39,27 @@ object WrapperMain { @JvmStatic fun main(args: Array) { gc() - if(args.contains("native") || args.contains("-native")){ - - val f = Frame("Mirai-Console Version Check") + if (args.contains("native") || args.contains("-native")) { + val f = JFrame("Mirai-Console Version Check") + f.setSize(500, 200) + f.setLocationRelativeTo(null) f.isResizable = false - val srcSize= Toolkit.getDefaultToolkit().screenSize - val width = 300 - val height = 200 - - val p = Panel() - val textArea = TextArea() - textArea.isEditable = false - p.add(textArea) - p.isVisible = true - - f.setLocation((srcSize.width-width)/2, (srcSize.height-height)/2) - f.setSize(width, height) + val p = JPanel() f.add(p) + val textArea = TextArea() + p.add(textArea) + textArea.isEditable = false + f.isVisible = true uiLog("正在进行版本检查\n") var uiOpen = true GlobalScope.launch { - while (isActive && uiOpen){ + while (isActive && uiOpen) { delay(16)//60 fps - withContext(Dispatchers.Main){ + withContext(Dispatchers.Main) { textArea.text = uilog.toString() + "\n" + uiBarOutput.toString() } } @@ -85,27 +78,27 @@ object WrapperMain { } start(CONSOLE_GRAPHICAL) - }else{ + } else { preStartInNonNative() } } - private fun preStartInNonNative(){ + private fun preStartInNonNative() { println("You are running Mirai-Console-Wrapper under " + System.getProperty("user.dir")) var type = WrapperProperties.determineConsoleType(WrapperProperties.content) - if(type!=null){ + if (type != null) { println("Starting Mirai Console $type, reset by clear /content/") - }else{ + } else { println("Please select Console Type") println("请选择 Console 版本") println("=> Pure : pure console") println("=> Graphical : graphical UI except unix") println("=> Terminal : [Not Supported Yet] console in unix") val scanner = Scanner(System.`in`) - while (type == null){ - var input = scanner.next() - input = input.toUpperCase()[0] + input.toLowerCase().substring(1) + while (type == null) { + var input = scanner.next() + input = input.toUpperCase()[0] + input.toLowerCase().substring(1) println("Selecting $input") type = WrapperProperties.determineConsoleType(input) } @@ -133,7 +126,7 @@ object WrapperMain { start(type) } - private fun start(type: String){ + private fun start(type: String) { val loader = MiraiClassLoader( CoreUpdater.getProtocolLib()!!, ConsoleUpdater.getFile()!!, @@ -149,7 +142,7 @@ object WrapperMain { ).getMethod("load", String::class.java, String::class.java) .invoke(null, CoreUpdater.getCurrentVersion(), ConsoleUpdater.getCurrentVersion()) } - CONSOLE_GRAPHICAL -> { + CONSOLE_GRAPHICAL -> { loader.loadClass( "net.mamoe.mirai.console.graphical.MiraiConsoleGraphicalLoader" ).getMethod("load", String::class.java, String::class.java) @@ -160,21 +153,22 @@ object WrapperMain { } - private class MiraiClassLoader( protocol: File, console: File, parent: ClassLoader? -): URLClassLoader(arrayOf( - protocol.toURI().toURL(), - console.toURI().toURL() -), parent) +) : URLClassLoader( + arrayOf( + protocol.toURI().toURL(), + console.toURI().toURL() + ), parent +) -private object WrapperProperties{ - val contentFile by lazy{ +private object WrapperProperties { + val contentFile by lazy { File(contentPath.absolutePath + "/.wrapper.txt").also { - if(!it.exists())it.createNewFile() + if (!it.exists()) it.createNewFile() } } @@ -185,19 +179,19 @@ private object WrapperProperties{ fun determineConsoleType( type: String - ):String?{ - if(type == CONSOLE_PURE || type == CONSOLE_GRAPHICAL || type == CONSOLE_TERMINAL){ + ): String? { + if (type == CONSOLE_PURE || type == CONSOLE_GRAPHICAL || type == CONSOLE_TERMINAL) { return type } return null } } -private fun gc(){ - GlobalScope.launch{ +private fun gc() { + GlobalScope.launch { while (true) { - delay(1000*60*5) + delay(1000 * 60 * 5) System.gc() } } -} \ No newline at end of file +}