From cbe3d8af77ec98bc3752c0daf95ab16a292e086d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=A2=81=E5=85=B8=E5=85=B8?= <413153189@qq.com>
Date: Sat, 23 Dec 2023 15:33:04 +0800
Subject: [PATCH 1/5] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=96=B0=E7=89=88?=
=?UTF-8?q?=E6=9C=AC=E6=A3=80=E6=B5=8B=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 23 ++--
.../tools/DartPluginVersionCheck.kt | 113 ++++++++++--------
.../itbug/fluttercheckversionx/util/Util.kt | 29 +++++
.../fluttercheckversionx/util/YamlExtends.kt | 18 ++-
.../messages/pluginBundle_en.properties | 2 +-
5 files changed, 120 insertions(+), 65 deletions(-)
diff --git a/README.md b/README.md
index b08cb1c9..e61316b1 100644
--- a/README.md
+++ b/README.md
@@ -1,14 +1,15 @@
-# Fluttercheckversionx
+
+
FlutterX
+
+
-
-
-Flutter development assistant, Dio monitoring, variable type display, generation of asset file dictionary, beautification of Dart documents and other tools, documents are under preparation
-
-Download Url : [Fluttercheckversionx](https://plugins.jetbrains.com/plugin/18986-fluttercheckversionx)
-
-
- dio tool window tutorial [See More>](https://github.com/mdddj/dd_flutter_idea_plugin/blob/master/dio.md)
+Flutter development assistant, Dio monitoring, variable type display, generation of asset file dictionary,
+beautification of Dart documents and other tools, documents are under preparation
- [x] Dart document beautification
- [x] Flutter plug-in version detection update
@@ -21,11 +22,8 @@ Download Url : [Fluttercheckversionx](https://plugins.jetbrains.com/plugin/18986
More tools in development...
-
# Screenshot
-
-
@@ -37,4 +35,5 @@ More tools in development...
### 打赏
+
![IMG_1839](https://user-images.githubusercontent.com/29020213/169472413-8dad4bf8-a2bb-4eda-bfda-c05b95877b78.JPG)
diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/tools/DartPluginVersionCheck.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/tools/DartPluginVersionCheck.kt
index cd62ce76..cd2811ea 100644
--- a/src/main/kotlin/shop/itbug/fluttercheckversionx/tools/DartPluginVersionCheck.kt
+++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/tools/DartPluginVersionCheck.kt
@@ -4,63 +4,79 @@ import com.intellij.codeInsight.intention.IntentionAction
import com.intellij.lang.annotation.AnnotationHolder
import com.intellij.lang.annotation.ExternalAnnotator
import com.intellij.lang.annotation.HighlightSeverity
-import com.intellij.openapi.application.runReadAction
import com.intellij.openapi.editor.Editor
+import com.intellij.openapi.project.DumbAware
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.psi.PsiRecursiveElementWalkingVisitor
+import kotlinx.coroutines.Deferred
+import kotlinx.coroutines.async
+import kotlinx.coroutines.awaitAll
+import kotlinx.coroutines.runBlocking
import shop.itbug.fluttercheckversionx.cache.DartPluginIgnoreConfig
import shop.itbug.fluttercheckversionx.i18n.PluginBundle
import shop.itbug.fluttercheckversionx.model.PubVersionDataModel
import shop.itbug.fluttercheckversionx.util.*
-///插件版本检查
-class DartPluginVersionCheck : ExternalAnnotator>() {
+/**
+ * 插件新版本检测
+ */
+class DartPluginVersionCheck : ExternalAnnotator>(),
+ DumbAware {
- data class Input(val file: PsiFile,val element: List)
- data class Problem(val textRange: TextRange,val model : PubVersionDataModel,val element: PsiElement)
+ data class Input(val file: PsiFile, val element: List)
+ data class PackageInfo(val element: PsiElement, val packageInfo: DartPluginVersionName)
+ data class Problem(val textRange: TextRange, val model: PubVersionDataModel, val element: PsiElement)
override fun collectInformation(file: PsiFile): Input {
- val elements = mutableListOf()
- file.originalElement.accept(object : PsiRecursiveElementWalkingVisitor(){
+ val elements = mutableListOf()
+ file.originalElement.accept(object : PsiRecursiveElementWalkingVisitor() {
override fun visitElement(element: PsiElement) {
val ext = YamlExtends(element)
- if(ext.isDartPluginElement() && DartPluginIgnoreConfig.getInstance(file.project).isIg(ext.getDartPluginNameAndVersion()?.name?:"").not()){
- elements.add(element)
+ val info = ext.getDartPluginNameAndVersion()
+ val igSetting = DartPluginIgnoreConfig.getInstance(file.project)
+ if (ext.isDartPluginElement() && igSetting.isIg(info?.name ?: "").not()) {
+ if (info != null) {
+ elements.add(PackageInfo(element, info))
+ }
}
super.visitElement(element)
}
})
- return Input(file,elements)
+ return Input(file, elements)
}
-
-
-
//执行长时间操作
override fun doAnnotate(collectedInfo: Input?): List {
val arr = mutableListOf()
collectedInfo?.let {
- val pluginElements = it.element //插件列表
- pluginElements.forEach { ele ->
- val ext = YamlExtends(ele)
- var plugin : DartPluginVersionName? = null
- runReadAction {
- plugin = ext.getDartPluginNameAndVersion()
+ val infos: List = runBlocking {
+ val tasks = it.element.map { info ->
+ val pluginName = info.packageInfo.name
+ val r: Deferred = async {
+ return@async ApiService.getPluginDetail(pluginName)
+ }
+ return@map r
}
- if(plugin!=null){
- val model = ApiService.getPluginDetail(plugin!!.name)
- if(model != null && model.judge(plugin!!.version){}.not()){
- //有新版本
- arr.add(Problem(ele.lastChild.textRange,model,ele))
+ return@runBlocking tasks.awaitAll()
+ }
+ it.element.forEach { info ->
+ val packageName = info.packageInfo.name
+ val find: PubVersionDataModel? = infos.find { detail -> detail?.name == packageName }
+ find?.let { model ->
+ run {
+ if (model.judge(info.packageInfo.version) {}.not()) {
+ arr.add(Problem(info.element.lastChild.textRange, model, info.element)) //有新版本
+ }
}
}
-
}
+
}
+
return arr
}
@@ -68,38 +84,39 @@ class DartPluginVersionCheck : ExternalAnnotator?, holder: AnnotationHolder) {
annotationResult?.forEach {
- holder.newAnnotation(HighlightSeverity.WARNING,"${PluginBundle.get("version.tip.1")}:${it.model.lastVersion}")
- .newFix(object : IntentionAction {
- val fixText = PluginBundle.get("version.tip.3") + it.model.lastVersion
- var available = true
- override fun startInWriteAction(): Boolean {
- return true
- }
+ holder.newAnnotation(
+ HighlightSeverity.WARNING, "${PluginBundle.get("version.tip.1")}:${it.model.lastVersion}"
+ ).newFix(object : IntentionAction {
+ val fixText = PluginBundle.get("version.tip.3") + it.model.lastVersion
+ var available = true
+ override fun startInWriteAction(): Boolean {
+ return true
+ }
- override fun getFamilyName(): String {
- return fixText
- }
+ override fun getFamilyName(): String {
+ return fixText
+ }
- override fun getText(): String {
- return fixText
- }
+ override fun getText(): String {
+ return fixText
+ }
- override fun isAvailable(project: Project, editor: Editor?, file: PsiFile?): Boolean {
- return available
- }
+ override fun isAvailable(project: Project, editor: Editor?, file: PsiFile?): Boolean {
+ return available
+ }
- override fun invoke(project: Project, editor: Editor?, file: PsiFile?) {
- MyPsiElementUtil.modifyPsiElementText(it.element.lastChild,it.model.lastVersion)
- available = false
- project.restartPubFileAnalyzer();
- }
+ override fun invoke(project: Project, editor: Editor?, file: PsiFile?) {
+ MyPsiElementUtil.modifyPsiElementText(it.element.lastChild, it.model.lastVersion)
+ available = false
+ project.restartPubFileAnalyzer();
+ }
- }).registerFix().range(it.element.lastChild).needsUpdateOnTyping().create()
+ }).registerFix().range(it.element.lastChild).needsUpdateOnTyping().create()
}
}
-}
\ No newline at end of file
+}
diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/util/Util.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/util/Util.kt
index d1f85864..39db2e36 100644
--- a/src/main/kotlin/shop/itbug/fluttercheckversionx/util/Util.kt
+++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/util/Util.kt
@@ -22,6 +22,10 @@ import java.net.NetworkInterface
import java.net.SocketException
import java.text.ParseException
import java.text.SimpleDateFormat
+import java.time.Duration
+import java.time.LocalDateTime
+import java.time.ZoneOffset
+import java.time.format.DateTimeFormatter
import java.util.*
import java.util.regex.Matcher
import java.util.regex.Pattern
@@ -92,6 +96,31 @@ class Util {
}
+ ///格式化 dart 版本时间
+ fun getDateFormat(dateString: String): String {
+
+ // 解析日期时间字符串
+ val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSSSSZ")
+ val dateTime = LocalDateTime.parse(dateString, formatter)
+
+ // 获取当前时间
+ val now = LocalDateTime.now(ZoneOffset.UTC)
+
+ // 计算时间差
+ val duration = Duration.between(dateTime, now)
+
+ // 转换成“几天前”、“几小时前”的格式
+ val days = duration.toDays()
+ val hours = duration.toHours() % 24
+
+ return when {
+ days > 0 -> "$days 天前"
+ hours > 0 -> "$hours 小时前"
+ else -> dateString
+ }
+ }
+
+
fun removeSpecialCharacters(string: String): String {
var str1: String = CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, string)
diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/util/YamlExtends.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/util/YamlExtends.kt
index d01e9fd5..ee6e4111 100644
--- a/src/main/kotlin/shop/itbug/fluttercheckversionx/util/YamlExtends.kt
+++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/util/YamlExtends.kt
@@ -7,17 +7,27 @@ import org.jetbrains.yaml.psi.impl.YAMLBlockMappingImpl
import org.jetbrains.yaml.psi.impl.YAMLKeyValueImpl
-data class DartPluginVersionName(val name: String,val version: String)
+///插件版本是不是 dev
+fun DartPluginVersionName.isDev(): Boolean {
+ return version.contains("dev")
+}
+
+data class DartPluginVersionName(val name: String, val version: String)
+
/**
* yaml工具类
*/
class YamlExtends(val element: PsiElement) {
///判断是不是dart plugin 节点
- fun isDartPluginElement(): Boolean {
- if (element is YAMLKeyValueImpl && element.parent is YAMLBlockMappingImpl && element.parent.parent is YAMLKeyValueImpl && PsiTreeUtil.findChildOfType(element,YAMLBlockMappingImpl::class.java)==null) {
+ fun isDartPluginElement(): Boolean {
+ if (element is YAMLKeyValueImpl && element.parent is YAMLBlockMappingImpl && element.parent.parent is YAMLKeyValueImpl && PsiTreeUtil.findChildOfType(
+ element,
+ YAMLBlockMappingImpl::class.java
+ ) == null
+ ) {
val root = element.parent.parent as YAMLKeyValueImpl
- if (root.firstChild is LeafPsiElement ) {
+ if (root.firstChild is LeafPsiElement) {
val temp = root.firstChild.text
if (temp == "dependencies" || temp == "dependency_overrides" || temp == "dev_dependencies") {
return true
diff --git a/src/main/resources/messages/pluginBundle_en.properties b/src/main/resources/messages/pluginBundle_en.properties
index b659b8a2..925515ac 100644
--- a/src/main/resources/messages/pluginBundle_en.properties
+++ b/src/main/resources/messages/pluginBundle_en.properties
@@ -57,7 +57,7 @@ dio.toolbar.post.params=View Post request body
bugs=Comments&bug feedback
replace.with=Replace with
nav.to=Navigate to
-version.tip.1=This plug-in has a new version
+version.tip.1=This package has a new version
version.tip.2=Update time
clean.cache=Clean cache
search.pub.plugin=Search pub.dev plug-in
From fdb0bc9d46c05eaee2010a2b425c107ac1fa9c9d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=A2=81=E5=85=B8=E5=85=B8?= <413153189@qq.com>
Date: Sat, 30 Dec 2023 15:12:10 +0800
Subject: [PATCH 2/5] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=96=B0=E7=89=88?=
=?UTF-8?q?=E6=9C=AC=E6=A3=80=E6=B5=8B=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
build.gradle.kts | 2 --
.../shop/itbug/fluttercheckversionx/setting/AppConfig.kt | 9 ++++++++-
.../fluttercheckversionx/tools/DartPluginVersionCheck.kt | 4 +---
3 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/build.gradle.kts b/build.gradle.kts
index d79a302d..642cb58d 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -42,8 +42,6 @@ if (ideaType == "IU" && ideaVersion == "2023.3") {
intellij {
-
-
version.set(ideaVersion)
type.set(ideaType)
plugins.set(pluginList)
diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/setting/AppConfig.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/setting/AppConfig.kt
index edab7108..521417dc 100644
--- a/src/main/kotlin/shop/itbug/fluttercheckversionx/setting/AppConfig.kt
+++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/setting/AppConfig.kt
@@ -4,6 +4,7 @@ import com.intellij.openapi.Disposable
import com.intellij.openapi.options.Configurable
import com.intellij.openapi.options.SearchableConfigurable
import com.intellij.openapi.ui.DialogPanel
+import com.intellij.openapi.util.Disposer
import com.intellij.ui.components.JBTabbedPane
import shop.itbug.fluttercheckversionx.config.DioListingUiConfig
import shop.itbug.fluttercheckversionx.config.DoxListeningSetting
@@ -82,4 +83,10 @@ class AppConfig : Configurable, Disposable, SearchableConfigurable {
override fun dispose() {
}
-}
\ No newline at end of file
+
+
+ override fun disposeUIResources() {
+ Disposer.dispose(this)
+ super.disposeUIResources()
+ }
+}
diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/tools/DartPluginVersionCheck.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/tools/DartPluginVersionCheck.kt
index cd2811ea..d6280acd 100644
--- a/src/main/kotlin/shop/itbug/fluttercheckversionx/tools/DartPluginVersionCheck.kt
+++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/tools/DartPluginVersionCheck.kt
@@ -5,7 +5,6 @@ import com.intellij.lang.annotation.AnnotationHolder
import com.intellij.lang.annotation.ExternalAnnotator
import com.intellij.lang.annotation.HighlightSeverity
import com.intellij.openapi.editor.Editor
-import com.intellij.openapi.project.DumbAware
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiElement
@@ -24,8 +23,7 @@ import shop.itbug.fluttercheckversionx.util.*
/**
* 插件新版本检测
*/
-class DartPluginVersionCheck : ExternalAnnotator>(),
- DumbAware {
+class DartPluginVersionCheck : ExternalAnnotator>() {
data class Input(val file: PsiFile, val element: List)
data class PackageInfo(val element: PsiElement, val packageInfo: DartPluginVersionName)
From 2969a29a9f4132b5739f220df02ae18870231d60 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=A2=81=E5=85=B8=E5=85=B8?= <413153189@qq.com>
Date: Fri, 5 Jan 2024 15:31:41 +0800
Subject: [PATCH 3/5] .
---
gradle.properties | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gradle.properties b/gradle.properties
index 8bef377c..4787e5f4 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -2,7 +2,7 @@ kotlin.stdlib.default.dependency=true
kotlin.incremental.useClasspathSnapshot=false
kotlin.experimental.tryK2=true
kapt.use.k2=true
-pluginVersion=4.0.0
+pluginVersion=4.0.1
#===============================> 223 AS release version : https://plugins.jetbrains.com/docs/intellij/android-studio-releases-list.html
#===============================> 正式版本最新 Giraffe
#dartVersion=223.8977
From a8ac0e2195f9c9ba8fd811594a92c0f1d3dfa405 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=A2=81=E5=85=B8=E5=85=B8?= <413153189@qq.com>
Date: Sat, 6 Jan 2024 11:48:11 +0800
Subject: [PATCH 4/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8Ddev,bate=E7=89=88?=
=?UTF-8?q?=E6=9C=AC=E6=A3=80=E6=9F=A5=E4=B8=8D=E5=87=86=E7=A1=AE=E7=9A=84?=
=?UTF-8?q?=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
build.gradle.kts | 5 +
.../model/PubVersionDataModel.kt | 92 +++++++++++------
.../services/ServiceCreate.kt | 7 +-
.../tools/DartPluginVersionCheck.kt | 20 ++--
.../fluttercheckversionx/util/ApiService.kt | 7 +-
.../fluttercheckversionx/util/YamlExtends.kt | 31 +++++-
src/test/kotlin/DartPluginVersionTest.kt | 98 +++++++++++++++++++
7 files changed, 213 insertions(+), 47 deletions(-)
create mode 100644 src/test/kotlin/DartPluginVersionTest.kt
diff --git a/build.gradle.kts b/build.gradle.kts
index 642cb58d..f7f67928 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -65,6 +65,7 @@ dependencies {
implementation("com.alibaba.fastjson2:fastjson2-kotlin:latest.release")
implementation("com.google.code.gson:gson:latest.release")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:latest.release")
+ testImplementation(kotlin("test"))
}
@@ -132,6 +133,10 @@ tasks {
verifyPluginConfiguration {
}
+
+ test {
+ useJUnitPlatform()
+ }
}
diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/model/PubVersionDataModel.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/model/PubVersionDataModel.kt
index dd2eaf1c..8b2bada4 100644
--- a/src/main/kotlin/shop/itbug/fluttercheckversionx/model/PubVersionDataModel.kt
+++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/model/PubVersionDataModel.kt
@@ -1,26 +1,48 @@
package shop.itbug.fluttercheckversionx.model
-data class PubVersionDataModel(
- val name: String,
- val latest: Latest,
- val versions: List
-) {
- val lastVersion get() = '^' + latest.version
+import shop.itbug.fluttercheckversionx.util.*
- /**
- * 判断版本是否为最新版本.将传入的[version]和[latest.version]进行比如,如果不是最新版则执行[apply]函数
- * [apply] 函数回调一个最新版本
- * @return true 已经是最新版本 false 不是最新版本
- */
- fun judge(version: String, apply: (lastVersionString: String) -> Unit) : Boolean {
- if (lastVersion != version) {
- apply.invoke(lastVersion)
- return false
- }
- return true
+
+private fun handleCaret(v: String?): String? {
+ if (v == null) {
+ return null
+ }
+ return if (v.startsWith("^")) {
+ v // 如果以^开头,则原样返回
+ } else {
+ "^$v" // 如果不是,则在最前面加上^返回
+ }
+}
+
+///判断一个插件是否有新的版本
+/// @return true 有新版本
+fun PubVersionDataModel.hasNewVersion(model: DartPluginVersionName): Boolean {
+ return when (model.versionType) {
+ DartVersionType.Dev -> lastDevVersion?.finalVersionText?.equals(model.finalVersionText)?.not() ?: false
+ DartVersionType.Beta -> lastBetaVersion?.finalVersionText?.equals(model.finalVersionText)?.not() ?: false
+ DartVersionType.Base -> (latest.version.removePrefix("^") == model.finalVersionText).not()
+ }
+}
+
+
+///返回最新的一个版本号,带^号
+fun PubVersionDataModel.getLastVersionText(model: DartPluginVersionName): String? {
+ if (!hasNewVersion(model)) {
+ return null
+ }
+ val v = when (model.versionType) {
+ DartVersionType.Dev -> lastDevVersion?.finalVersionText
+ DartVersionType.Beta -> lastBetaVersion?.finalVersionText
+ DartVersionType.Base -> latest.version.removePrefix("^")
}
+ return handleCaret(v)
+}
+data class PubVersionDataModel(
+ val name: String, val latest: Latest, val versions: List
+) {
+
/**
* 获取最新版本的最后更新时间
*
@@ -28,8 +50,8 @@ data class PubVersionDataModel(
private fun getLastUpdateTime(): String {
var timeString = latest.published
val toCharArray = timeString.toCharArray()
- val tChat = toCharArray.get(10)
- if (tChat.equals('T')) {
+ val tChat = toCharArray[10]
+ if (tChat == 'T') {
timeString = timeString.replace("T", " ")
}
val dotIndex = timeString.lastIndexOf(".")
@@ -41,22 +63,30 @@ data class PubVersionDataModel(
}
data class Latest(
- val version: String,
- val pubspec: LatestPubspec,
- val archiveURL: String,
- val published: String
+ val version: String, val pubspec: Pubspec, val archiveURL: String, val published: String
)
-data class LatestPubspec(
- val name: String,
- val version: String,
- val homepage: String,
- val description: String
+data class Pubspec(
+ val name: String, val version: String, val homepage: String, val description: String
)
+val Pubspec.dartPluginModel get() = DartPluginVersionName(name, version)
+
data class Version(
- val version: String,
- val archiveURL: String,
- val published: String
+ val version: String, val published: String, val pubspec: Pubspec
)
+
+val Version.finalVersionText get() = version.removePrefix("^")
+val Version.dartPluginModel get() = pubspec.dartPluginModel
+
+val PubVersionDataModel.devVersionList: List get() = versions.filter { it.dartPluginModel.isDev() }
+val PubVersionDataModel.betaVersionList: List get() = versions.filter { it.dartPluginModel.isBeta() }
+
+//最新的dev版本
+val PubVersionDataModel.lastDevVersion get() = devVersionList.lastOrNull()
+
+//最新的beta版本
+val PubVersionDataModel.lastBetaVersion get() = betaVersionList.lastOrNull()
+
+
diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/services/ServiceCreate.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/services/ServiceCreate.kt
index 6efe2f61..43001001 100644
--- a/src/main/kotlin/shop/itbug/fluttercheckversionx/services/ServiceCreate.kt
+++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/services/ServiceCreate.kt
@@ -7,7 +7,6 @@ import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import shop.itbug.fluttercheckversionx.services.Env.Dev
import shop.itbug.fluttercheckversionx.services.Env.Pro
-import shop.itbug.fluttercheckversionx.util.CredentialUtil
//当前环境
val currentEnv = Dev
@@ -35,9 +34,9 @@ open class ApiServiceCreate(var host: String) {
private val client = OkHttpClient.Builder()
.addInterceptor { chain ->
var request = chain.request()
- CredentialUtil.token?.apply {
- request = request.newBuilder().addHeader("Authorization", this).build()
- }
+// CredentialUtil.token?.apply {
+// request = request.newBuilder().addHeader("Authorization", this).build()
+// }
chain.proceed(request)
}
.build()
diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/tools/DartPluginVersionCheck.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/tools/DartPluginVersionCheck.kt
index d6280acd..8a804bad 100644
--- a/src/main/kotlin/shop/itbug/fluttercheckversionx/tools/DartPluginVersionCheck.kt
+++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/tools/DartPluginVersionCheck.kt
@@ -17,6 +17,7 @@ import kotlinx.coroutines.runBlocking
import shop.itbug.fluttercheckversionx.cache.DartPluginIgnoreConfig
import shop.itbug.fluttercheckversionx.i18n.PluginBundle
import shop.itbug.fluttercheckversionx.model.PubVersionDataModel
+import shop.itbug.fluttercheckversionx.model.getLastVersionText
import shop.itbug.fluttercheckversionx.util.*
@@ -27,7 +28,12 @@ class DartPluginVersionCheck : ExternalAnnotator)
data class PackageInfo(val element: PsiElement, val packageInfo: DartPluginVersionName)
- data class Problem(val textRange: TextRange, val model: PubVersionDataModel, val element: PsiElement)
+ data class Problem(
+ val textRange: TextRange,
+ val model: PubVersionDataModel,
+ val element: PsiElement,
+ val lastVersion: String
+ )
override fun collectInformation(file: PsiFile): Input {
val elements = mutableListOf()
@@ -66,8 +72,10 @@ class DartPluginVersionCheck : ExternalAnnotator detail?.name == packageName }
find?.let { model ->
run {
- if (model.judge(info.packageInfo.version) {}.not()) {
- arr.add(Problem(info.element.lastChild.textRange, model, info.element)) //有新版本
+
+ val versionText = model.getLastVersionText(info.packageInfo)
+ if (versionText != null) {
+ arr.add(Problem(info.element.lastChild.textRange, model, info.element, versionText)) //有新版本
}
}
}
@@ -83,9 +91,9 @@ class DartPluginVersionCheck : ExternalAnnotator().callPluginDetails(name).execute().body()
- } catch (_: Exception) {}
+ } catch (e: Exception) {
+ log.warn("获取插件失败:${e.localizedMessage}")
+ e.printStackTrace()
+ }
return null
}
}
\ No newline at end of file
diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/util/YamlExtends.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/util/YamlExtends.kt
index ee6e4111..64791e12 100644
--- a/src/main/kotlin/shop/itbug/fluttercheckversionx/util/YamlExtends.kt
+++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/util/YamlExtends.kt
@@ -7,12 +7,34 @@ import org.jetbrains.yaml.psi.impl.YAMLBlockMappingImpl
import org.jetbrains.yaml.psi.impl.YAMLKeyValueImpl
+private val devPattern = Regex("""\bdev\b""")
+private val betaPattern = Regex("""\bbeta\b""")
+
+
+enum class DartVersionType {
+ Dev, Beta, Base
+}
+
+
///插件版本是不是 dev
-fun DartPluginVersionName.isDev(): Boolean {
- return version.contains("dev")
+fun DartPluginVersionName.isDev(): Boolean = devPattern.containsMatchIn(version)
+fun DartPluginVersionName.isBeta(): Boolean = betaPattern.containsMatchIn(version)
+
+///版本类型
+val DartPluginVersionName.versionType: DartVersionType
+ get() = when {
+ isBeta() -> DartVersionType.Beta
+ isDev() -> DartVersionType.Dev
+ else -> DartVersionType.Base
+ }
+val DartPluginVersionName.finalVersionText get() = version.removePrefix("^")
+
+class DartPluginVersionName(val name: String, val version: String) {
+ override fun toString(): String {
+ return "插件名:$name,版本:$version,插件类型:$versionType"
+ }
}
-data class DartPluginVersionName(val name: String, val version: String)
/**
* yaml工具类
@@ -22,8 +44,7 @@ class YamlExtends(val element: PsiElement) {
///判断是不是dart plugin 节点
fun isDartPluginElement(): Boolean {
if (element is YAMLKeyValueImpl && element.parent is YAMLBlockMappingImpl && element.parent.parent is YAMLKeyValueImpl && PsiTreeUtil.findChildOfType(
- element,
- YAMLBlockMappingImpl::class.java
+ element, YAMLBlockMappingImpl::class.java
) == null
) {
val root = element.parent.parent as YAMLKeyValueImpl
diff --git a/src/test/kotlin/DartPluginVersionTest.kt b/src/test/kotlin/DartPluginVersionTest.kt
new file mode 100644
index 00000000..258b7927
--- /dev/null
+++ b/src/test/kotlin/DartPluginVersionTest.kt
@@ -0,0 +1,98 @@
+import shop.itbug.fluttercheckversionx.model.PubVersionDataModel
+import shop.itbug.fluttercheckversionx.model.getLastVersionText
+import shop.itbug.fluttercheckversionx.model.hasNewVersion
+import shop.itbug.fluttercheckversionx.model.lastDevVersion
+import shop.itbug.fluttercheckversionx.util.ApiService
+import shop.itbug.fluttercheckversionx.util.DartPluginVersionName
+import shop.itbug.fluttercheckversionx.util.isBeta
+import shop.itbug.fluttercheckversionx.util.isDev
+import kotlin.test.Test
+import kotlin.test.assertEquals
+
+class DartPluginVersionTest {
+
+ @Test
+ fun testVersion(): Unit {
+ val isarDev = DartPluginVersionName(name = "isar", version = "^4.0.0-dev.14")
+ val hiveDev = DartPluginVersionName(name = "hive", version = "4.0.0-dev.2")
+ val graphqlBeta = DartPluginVersionName(name = "graphql_flutter", version = "^5.2.0-beta.6")
+ val graphqlBeta2 = DartPluginVersionName(name = "graphql_flutter", version = "5.2.0-beta.12")
+ val ddJsUtil = DartPluginVersionName(name = "dd_js_util", version = "^3.5.2")
+ assertEquals(true, isarDev.isDev())
+ assertEquals(true, hiveDev.isDev())
+ assertEquals(false, isarDev.isBeta())
+ assertEquals(false, hiveDev.isBeta())
+ assertEquals(true, graphqlBeta.isBeta())
+ assertEquals(false, graphqlBeta.isDev())
+ assertEquals(true, graphqlBeta2.isBeta())
+ assertEquals(false, graphqlBeta2.isDev())
+ assertEquals(false, ddJsUtil.isBeta())
+ assertEquals(false, ddJsUtil.isDev())
+ }
+
+
+ ///dev测试
+ @Test
+ fun lastVersionTest(): Unit {
+
+
+ /// dev 测试
+
+ val pluginName = "wechat_assets_picker";
+ val model: PubVersionDataModel? = ApiService.getPluginDetail(pluginName)
+ model?.let {
+ assertEquals("8.8.1+1", it.latest.version)
+ assertEquals("9.0.0-dev.2", it.lastDevVersion?.version)
+
+
+ val testVersion = DartPluginVersionName(pluginName, "^9.0.0-dev.2")
+
+ val testVersion2 = DartPluginVersionName(pluginName, "^9.0.0-dev.1")
+
+ val testVersion3 = DartPluginVersionName(pluginName, "9.0.0-dev.1")
+
+
+
+ assertEquals(false, it.hasNewVersion(testVersion))
+ assertEquals(true, it.hasNewVersion(testVersion2))
+
+ assertEquals("^9.0.0-dev.2", it.getLastVersionText(testVersion2))
+ assertEquals("^9.0.0-dev.2", it.getLastVersionText(testVersion3))
+
+ }
+
+ }
+
+
+ ///基本测试
+ @Test
+ fun lastVersionTest2(): Unit {
+
+
+ /// dev 测试
+
+ val pluginName = "dd_js_util";
+ val model: PubVersionDataModel? = ApiService.getPluginDetail(pluginName)
+ model?.let {
+ assertEquals("5.1.6", it.latest.version)
+ assertEquals(null, it.lastDevVersion?.version)
+
+
+ val testVersion = DartPluginVersionName(pluginName, "^9.0.0-dev.2")
+
+ val testVersion2 = DartPluginVersionName(pluginName, "^9.0.0-dev.1")
+
+ val testVersion3 = DartPluginVersionName(pluginName, "5.1.5")
+
+
+
+ assertEquals(false, it.hasNewVersion(testVersion))
+ assertEquals(false, it.hasNewVersion(testVersion2))
+
+ assertEquals("^5.1.6", it.getLastVersionText(testVersion3))
+
+ }
+
+ }
+
+}
\ No newline at end of file
From 43ecf50c0dd17d87e21ca1c0e2d05fbcba86a598 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=A2=81=E5=85=B8=E5=85=B8?= <413153189@qq.com>
Date: Sat, 6 Jan 2024 16:38:50 +0800
Subject: [PATCH 5/5] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=87=E6=A1=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
dio.md | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/dio.md b/dio.md
index 3ee72ba9..07fa6720 100644
--- a/dio.md
+++ b/dio.md
@@ -1,11 +1,12 @@
# Use of dio window
+[中文文档(使用谷歌浏览器打开)](https://flutterx.itbug.shop/starter.html)
+
You can listen to the API requests of the Flutter plug-in dio in this window. There is no need to use the print function
to print the logs related to dio
![image](https://user-images.githubusercontent.com/29020213/216746543-fb9ea063-3250-4d53-b3ef-0aeba89fc871.png)
-
## 1.Installation dependency
Add a dependency in the `pubspec. yaml` under the root directory of your Flutter Project
@@ -34,12 +35,11 @@ void main() {
}
```
->
+>
> InitHost can automatically recognize your local IP address
->
+>
> ![image](https://user-images.githubusercontent.com/29020213/216746356-58ca9a3b-0df0-41c3-b319-d38945694727.png)
-
| Attribute | Introduce |
|----------------------------|----------------------------------------------------|
| initHost | IP address of your development tool computer |