Skip to content

Commit

Permalink
✨ Added clip plugin to support converting strings to URLs (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
guiyanakuang authored Feb 26, 2024
1 parent 59d74db commit dfa30d8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.clipevery.clip.ClipboardService
import com.clipevery.clip.DesktopTransferableConsumer
import com.clipevery.clip.TransferableConsumer
import com.clipevery.clip.getDesktopClipboardService
import com.clipevery.clip.plugin.ConvertUrlPlugin
import com.clipevery.clip.plugin.ImageHtmlCombinePlugin
import com.clipevery.clip.plugin.MultiImagePlugin
import com.clipevery.clip.plugin.SortPlugin
Expand Down Expand Up @@ -129,7 +130,9 @@ object Dependencies {
ImageItemService(),
TextItemService(),
UrlItemService()
), listOf(UrlTextCombinePlugin,
), listOf(
UrlTextCombinePlugin,
ConvertUrlPlugin,
ImageHtmlCombinePlugin,
MultiImagePlugin,
SortPlugin
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.clipevery.clip.plugin

import com.clipevery.clip.ClipPlugin
import com.clipevery.clip.item.TextClipItem
import com.clipevery.clip.item.UrlClipItem
import com.clipevery.dao.clip.ClipAppearItem
import java.net.MalformedURLException
import java.net.URL

object ConvertUrlPlugin: ClipPlugin {
override fun pluginProcess(clipAppearItems: List<ClipAppearItem>): List<ClipAppearItem> {
return clipAppearItems.map {
if (it is TextClipItem && isUrl(it.text)) {
UrlClipItem().apply {
this.identifier = it.identifier
this.url = it.text
this.md5 = it.md5
}
} else {
it
}
}
}

private fun isUrl(string: String): Boolean {
try {
URL(string)
return true
} catch (e: MalformedURLException) {
return false
}
}
}

0 comments on commit dfa30d8

Please sign in to comment.