mirror of
https://github.com/TermoraDev/termora.git
synced 2026-01-16 02:12:58 +08:00
chore: improve sync plugin
This commit is contained in:
@@ -8,9 +8,9 @@ import java.util.*
|
||||
abstract class AbstractI18n {
|
||||
private val log get() = getLogger()
|
||||
|
||||
private val substitutor by lazy { StringSubstitutor { key -> getString(key) } }
|
||||
protected val substitutor by lazy { StringSubstitutor { key -> getString(key) } }
|
||||
|
||||
fun getString(key: String, vararg args: Any): String {
|
||||
open fun getString(key: String, vararg args: Any): String {
|
||||
val text = getString(key)
|
||||
if (args.isNotEmpty()) {
|
||||
return MessageFormat.format(text, *args)
|
||||
@@ -19,7 +19,7 @@ abstract class AbstractI18n {
|
||||
}
|
||||
|
||||
|
||||
fun getString(key: String): String {
|
||||
open fun getString(key: String): String {
|
||||
try {
|
||||
return substitutor.replace(getBundle().getString(key))
|
||||
} catch (e: MissingResourceException) {
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
package app.termora
|
||||
|
||||
import app.termora.database.DatabaseManager
|
||||
|
||||
/**
|
||||
* 仅标记
|
||||
*/
|
||||
class DeleteDataManager private constructor() {
|
||||
companion object {
|
||||
fun getInstance(): DeleteDataManager {
|
||||
return ApplicationScope.forApplicationScope().getOrCreate(DeleteDataManager::class) { DeleteDataManager() }
|
||||
}
|
||||
}
|
||||
|
||||
private val data = mutableMapOf<String, DeletedData>()
|
||||
private val database get() = DatabaseManager.getInstance()
|
||||
|
||||
fun removeHost(id: String, deleteDate: Long = System.currentTimeMillis()) {
|
||||
addDeletedData(DeletedData(id, "Host", deleteDate))
|
||||
}
|
||||
|
||||
fun removeKeymap(id: String, deleteDate: Long = System.currentTimeMillis()) {
|
||||
addDeletedData(DeletedData(id, "Keymap", deleteDate))
|
||||
}
|
||||
|
||||
fun removeKeyPair(id: String, deleteDate: Long = System.currentTimeMillis()) {
|
||||
addDeletedData(DeletedData(id, "KeyPair", deleteDate))
|
||||
}
|
||||
|
||||
fun removeKeywordHighlight(id: String, deleteDate: Long = System.currentTimeMillis()) {
|
||||
addDeletedData(DeletedData(id, "KeywordHighlight", deleteDate))
|
||||
}
|
||||
|
||||
fun removeMacro(id: String, deleteDate: Long = System.currentTimeMillis()) {
|
||||
addDeletedData(DeletedData(id, "Macro", deleteDate))
|
||||
}
|
||||
|
||||
fun removeSnippet(id: String, deleteDate: Long = System.currentTimeMillis()) {
|
||||
addDeletedData(DeletedData(id, "Snippet", deleteDate))
|
||||
}
|
||||
|
||||
private fun addDeletedData(deletedData: DeletedData) {
|
||||
if (data.containsKey(deletedData.id)) return
|
||||
data[deletedData.id] = deletedData
|
||||
// TODO database.addDeletedData(deletedData)
|
||||
}
|
||||
|
||||
fun getDeletedData(): List<DeletedData> {
|
||||
if (data.isEmpty()) {
|
||||
// TODO data.putAll(database.getDeletedData().associateBy { it.id })
|
||||
}
|
||||
return data.values.sortedBy { it.deleteDate }
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package app.termora.account
|
||||
|
||||
import app.termora.*
|
||||
import app.termora.Application.ohMyJson
|
||||
import app.termora.database.OwnerType
|
||||
import app.termora.plugin.ExtensionManager
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
@@ -47,6 +48,10 @@ class AccountManager private constructor() : ApplicationRunnerExtension {
|
||||
fun getAccessToken() = account.accessToken
|
||||
fun getRefreshToken() = account.refreshToken
|
||||
fun getOwnerIds() = account.teams.map { it.id }.toMutableList().apply { add(getAccountId()) }.toSet()
|
||||
fun getOwners() =
|
||||
account.teams.map { AccountOwner(it.id, it.name, OwnerType.Team) }
|
||||
.toMutableList().apply { AccountOwner(getAccountId(), getEmail(), OwnerType.User) }
|
||||
.toSet()
|
||||
|
||||
fun isFreePlan(): Boolean {
|
||||
return isLocally() || getSubscription().plan == SubscriptionPlan.Free
|
||||
|
||||
@@ -252,7 +252,7 @@ class DatabaseManager private constructor() : Disposable {
|
||||
source
|
||||
)
|
||||
} else {
|
||||
save(data)
|
||||
save(data, source)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package app.termora.highlight
|
||||
|
||||
import app.termora.Application.ohMyJson
|
||||
import app.termora.ApplicationScope
|
||||
import app.termora.DeleteDataManager
|
||||
import app.termora.TerminalPanelFactory
|
||||
import app.termora.account.AccountOwner
|
||||
import app.termora.database.Data
|
||||
@@ -48,7 +47,6 @@ class KeywordHighlightManager private constructor() {
|
||||
fun removeKeywordHighlight(id: String) {
|
||||
database.delete(id, DataType.KeywordHighlight.name)
|
||||
TerminalPanelFactory.getInstance().repaintAll()
|
||||
DeleteDataManager.getInstance().removeKeywordHighlight(id)
|
||||
|
||||
if (log.isDebugEnabled) {
|
||||
log.debug("Keyword highlighter removed. {}", id)
|
||||
|
||||
@@ -2,7 +2,6 @@ package app.termora.keymgr
|
||||
|
||||
import app.termora.Application.ohMyJson
|
||||
import app.termora.ApplicationScope
|
||||
import app.termora.DeleteDataManager
|
||||
import app.termora.account.AccountOwner
|
||||
import app.termora.database.Data
|
||||
import app.termora.database.DataType
|
||||
@@ -36,7 +35,6 @@ class KeyManager private constructor() {
|
||||
|
||||
fun removeOhKeyPair(id: String) {
|
||||
databaseManager.delete(id, DataType.KeyPair.name)
|
||||
DeleteDataManager.getInstance().removeKeyPair(id)
|
||||
}
|
||||
|
||||
fun getOhKeyPairs(): List<OhKeyPair> {
|
||||
|
||||
@@ -2,7 +2,6 @@ package app.termora.macro
|
||||
|
||||
import app.termora.Application.ohMyJson
|
||||
import app.termora.ApplicationScope
|
||||
import app.termora.DeleteDataManager
|
||||
import app.termora.account.AccountManager
|
||||
import app.termora.database.Data
|
||||
import app.termora.database.DataType
|
||||
@@ -50,7 +49,6 @@ class MacroManager private constructor() {
|
||||
|
||||
fun removeMacro(id: String) {
|
||||
database.delete(id, DataType.Macro.name)
|
||||
DeleteDataManager.getInstance().removeMacro(id)
|
||||
|
||||
if (log.isDebugEnabled) {
|
||||
log.debug("Removed macro $id")
|
||||
|
||||
@@ -2,7 +2,6 @@ package app.termora.snippet
|
||||
|
||||
import app.termora.Application.ohMyJson
|
||||
import app.termora.ApplicationScope
|
||||
import app.termora.DeleteDataManager
|
||||
import app.termora.account.AccountManager
|
||||
import app.termora.assertEventDispatchThread
|
||||
import app.termora.database.Data
|
||||
@@ -45,7 +44,6 @@ class SnippetManager private constructor() {
|
||||
|
||||
fun removeSnippet(id: String) {
|
||||
database.delete(id, DataType.Snippet.name)
|
||||
DeleteDataManager.getInstance().removeSnippet(id)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,6 +6,6 @@ import kotlinx.serialization.Serializable
|
||||
data class Tag(
|
||||
val id: String,
|
||||
val text: String,
|
||||
val createDate: Long = System.currentTimeMillis(),
|
||||
val updateDate: Long = System.currentTimeMillis(),
|
||||
val createDate: Long,
|
||||
val updateDate: Long,
|
||||
)
|
||||
@@ -63,7 +63,14 @@ class TagPanel(accountOwner: AccountOwner) : JPanel(BorderLayout()), Disposable
|
||||
title = I18n.getString("termora.tag"),
|
||||
)
|
||||
if (text.isNullOrBlank().not()) {
|
||||
model.addElement(Tag(id = randomUUID(), text = text))
|
||||
model.addElement(
|
||||
Tag(
|
||||
id = randomUUID(),
|
||||
text = text,
|
||||
createDate = System.currentTimeMillis(),
|
||||
updateDate = System.currentTimeMillis(),
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -70,26 +70,6 @@ termora.settings.terminal.floating-toolbar=Floating Toolbar
|
||||
termora.settings.terminal.auto-close-tab=Auto Close Tab
|
||||
termora.settings.terminal.auto-close-tab-description=Automatically close the tab when the terminal is disconnected normally
|
||||
|
||||
termora.settings.sync=Sync
|
||||
termora.settings.sync.done=Synchronized data successfully
|
||||
termora.settings.sync.export=${termora.keymgr.export}
|
||||
termora.settings.sync.import=${termora.keymgr.import}
|
||||
termora.settings.sync.import.file-too-large=The file is too large
|
||||
termora.settings.sync.import.successful=Import data successfully
|
||||
termora.settings.sync.export-done=The export was successful
|
||||
termora.settings.sync.export-encrypt=Enter password to encrypt file (optional)
|
||||
termora.settings.sync.export-done-open-folder=The export was successful. Do you want to open the folder?
|
||||
termora.settings.sync.range=Range
|
||||
termora.settings.sync.range.keys=My keys
|
||||
termora.settings.sync.range.keyword-highlights=${termora.highlight}
|
||||
termora.settings.sync.last-sync-time=Last sync time
|
||||
termora.settings.sync.gist=Gist
|
||||
termora.settings.sync.token=Token
|
||||
termora.settings.sync.type=Type
|
||||
termora.settings.sync.webdav.help=WebDAV storage address, e.g. https://yourhost/webdav/termora.json
|
||||
termora.settings.sync.policy=Sync Policy
|
||||
termora.settings.sync.policy.manual=Manual
|
||||
termora.settings.sync.policy.on-change=On Change
|
||||
|
||||
termora.settings.about=About
|
||||
termora.settings.about.author=Author
|
||||
|
||||
@@ -81,24 +81,6 @@ termora.settings.terminal.auto-close-tab=自动关闭标签
|
||||
termora.settings.terminal.auto-close-tab-description=当终端正常断开连接时自动关闭标签页
|
||||
|
||||
|
||||
termora.settings.sync=同步
|
||||
termora.settings.sync.export-done=导出成功
|
||||
termora.settings.sync.export-encrypt=输入密码加密文件 (可选)
|
||||
termora.settings.sync.export-done-open-folder=导出成功,是否需要打开所在文件夹?
|
||||
termora.settings.sync.range=范围
|
||||
termora.settings.sync.range.keys=我的密钥
|
||||
termora.settings.sync.last-sync-time=最后同步时间
|
||||
termora.settings.sync.done=同步数据成功
|
||||
termora.settings.sync.import.file-too-large=文件太大
|
||||
termora.settings.sync.import.successful=导入数据成功
|
||||
termora.settings.sync.gist=片段
|
||||
termora.settings.sync.token=令牌
|
||||
termora.settings.sync.type=类型
|
||||
termora.settings.sync.webdav.help=WebDAV 的存储地址,例如:https://yourhost/webdav/termora.json
|
||||
termora.settings.sync.policy=同步策略
|
||||
termora.settings.sync.policy.manual=手动
|
||||
termora.settings.sync.policy.on-change=数据变动时
|
||||
|
||||
termora.settings.about=关于
|
||||
termora.settings.about.author=作者
|
||||
termora.settings.about.source=源代码
|
||||
|
||||
@@ -92,23 +92,6 @@ termora.settings.terminal.floating-toolbar=懸浮工具列
|
||||
termora.settings.terminal.auto-close-tab=自動關閉標籤
|
||||
termora.settings.terminal.auto-close-tab-description=當終端正常斷開連線時自動關閉標籤頁
|
||||
|
||||
termora.settings.sync=同步
|
||||
termora.settings.sync.export-done=匯出成功
|
||||
termora.settings.sync.export-encrypt=輸入密碼加密檔案 (可選)
|
||||
termora.settings.sync.export-done-open-folder=匯出成功,是否需要打開所在資料夾?
|
||||
termora.settings.sync.range=範圍
|
||||
termora.settings.sync.range.keys=我的密鑰
|
||||
termora.settings.sync.last-sync-time=最後同步時間
|
||||
termora.settings.sync.done=同步資料成功
|
||||
termora.settings.sync.import.file-too-large=檔案太大
|
||||
termora.settings.sync.import.successful=導入資料成功
|
||||
termora.settings.sync.gist=片段
|
||||
termora.settings.sync.token=令牌
|
||||
termora.settings.sync.type=類型
|
||||
termora.settings.sync.webdav.help=WebDAV 的儲存位址,例如:https://yourhost/webdav/termora.json
|
||||
termora.settings.sync.policy=同步策略
|
||||
termora.settings.sync.policy.manual=手動
|
||||
termora.settings.sync.policy.on-change=資料變動時
|
||||
|
||||
termora.settings.about=關於
|
||||
termora.settings.about.author=作者
|
||||
|
||||
Reference in New Issue
Block a user