Skip to content

Commit

Permalink
Merge branch 'next'
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
  • Loading branch information
YiiGuxing committed Aug 31, 2023
2 parents b94f8cc + 2728dea commit 7c91087
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Translation Plugin Changelog

## [Unreleased]
- Fixed the problem that the translation engine could not be switched when installing the plugin for the first time.
- Fixed the problem that Alibaba Translate could not parse translations in some cases.
- 修复了首次安装插件时无法切换翻译引擎的问题
- 修复了阿里翻译在某些情况下无法解析翻译的问题

## [3.5.2] (2023/08/16)
- Bug fixes.
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pluginGroup = cn.yiiguxing.plugin.translate
pluginRepositoryUrl = https://github.com/YiiGuxing/TranslationPlugin

# SemVer format -> https://semver.org
pluginMajorVersion = 3.5.2
pluginMajorVersion = 3.5.3
pluginPreReleaseVersion =
pluginBuildMetadata =
autoSnapshotVersion = true
Expand All @@ -32,7 +32,7 @@ platformPlugins = java, org.jetbrains.kotlin, \
kotlin.stdlib.default.dependency = false

# Gradle Releases -> https://github.com/gradle/gradle/releases
gradleVersion = 8.2.1
gradleVersion = 8.3

# Enable Gradle Configuration Cache -> https://docs.gradle.org/current/userguide/configuration_cache.html
org.gradle.configuration-cache = true
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ ideaCompat = "0.0.2"
junit = "4.13.2"

# plugins
kotlin = "1.9.0"
kotlin = "1.9.10"
kover = "0.7.3"
qodana = "0.1.13"
changelog = "2.1.2"
changelog = "2.2.0"
gradleIntelliJPlugin = "1.15.0"

[libraries]
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
22 changes: 11 additions & 11 deletions src/main/kotlin/cn/yiiguxing/plugin/translate/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -167,22 +167,22 @@ class Settings : PersistentStateComponent<Settings> {
override fun getState(): Settings = this

override fun loadState(state: Settings) {
try {
XmlSerializerUtil.copyBean(state, this)
XmlSerializerUtil.copyBean(state, this)

val properties: PropertiesComponent = PropertiesComponent.getInstance()
val dataVersion = properties.getInt(DATA_VERSION_KEY, 0)
val properties: PropertiesComponent = PropertiesComponent.getInstance()
val dataVersion = properties.getInt(DATA_VERSION_KEY, 0)

LOG.d("===== Settings Data Version: $dataVersion =====")
if (dataVersion < CURRENT_DATA_VERSION) {
migrate()
properties.setValue(DATA_VERSION_KEY, CURRENT_DATA_VERSION, 0)
}
} finally {
isInitialized = true
LOG.d("===== Settings Data Version: $dataVersion =====")
if (dataVersion < CURRENT_DATA_VERSION) {
migrate()
properties.setValue(DATA_VERSION_KEY, CURRENT_DATA_VERSION, 0)
}
}

override fun initializeComponent() {
isInitialized = true
}

companion object {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ data class AliTranslation(

override fun toTranslation(): Translation {
check(isSuccessful) { "Cannot convert to Translation: errorCode=${code}" }
check(data.translation.isNotEmpty()) { "Cannot convert to Translation: data.translation = null" }

return Translation(query, data.translation, src, target, listOf(src))
val translation = data.translation.takeIf { it.isNotEmpty() } ?: query
return Translation(query, translation, src, target, listOf(src))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ internal class MicrosoftTranslatorService {
val promise = asyncLatch { latch ->
runAsync {
latch.await(100, TimeUnit.MILLISECONDS)
Http.get(AUTH_URL) { userAgent() }
Http.get(AUTH_URL) {
accept("*/*")
userAgent()
}
}
.onError { LOG.w("Failed to get access token", it) }
.onSuccess(::updateAccessToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class UpdateManager : BaseStartupActivity() {
.createNotification(content, NotificationType.INFORMATION)
.setTitle(title)
.setImportant(true)
.setIcon(TranslationIcons.Logo)
.apply {
setListener(Notifications.UrlOpeningListener(false))
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/cn/yiiguxing/plugin/translate/util/Http.kt
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ object Http {
}

private fun getUserAgent(): String {
val chrome = "Chrome/112.0.0.0"
val edge = "Edg/112.0.1722.39"
val chrome = "Chrome/115.0.0.0"
val edge = "Edg/115.0.1901.203"
val safari = "Safari/537.36"
val systemInfo = "Windows NT ${SystemInfoRt.OS_VERSION}; Win64; x64"
@Suppress("SpellCheckingInspection")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import com.intellij.notification.*
import com.intellij.notification.impl.NotificationFullContent
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.project.Project
import icons.TranslationIcons
import javax.swing.Icon
import javax.swing.event.HyperlinkEvent


Expand All @@ -21,6 +23,11 @@ object Notifications {
private val DEFAULT_NOTIFICATION_CUSTOMIZER: (Notification) -> Unit = { }


private fun getNotificationIcon(type: NotificationType): Icon? = when (type) {
NotificationType.INFORMATION -> TranslationIcons.Logo
else -> null
}

fun showNotification(
title: String,
message: String,
Expand All @@ -32,6 +39,7 @@ object Notifications {
NotificationGroupManager.getInstance()
.getNotificationGroup(groupId)
.createNotification(message, type)
.setIcon(getNotificationIcon(type))
.setTitle(title)
.apply { notificationCustomizer(this) }
.show(project)
Expand All @@ -47,6 +55,7 @@ object Notifications {
) {
val group = NotificationGroupManager.getInstance().getNotificationGroup(groupId)
val notification = FullContentNotification(group.displayId, title, message, type)
notification.setIcon(getNotificationIcon(type))
notificationCustomizer(notification)
notification.show(project)
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/icons/TranslationIcons.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import javax.swing.Icon

object TranslationIcons {

@JvmField
val Logo: Icon = load("/icons/logo.svg")

@JvmField
val Translation: Icon = load("/icons/translation.svg")

Expand Down
9 changes: 9 additions & 0 deletions src/main/resources/icons/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7c91087

Please sign in to comment.