Skip to content

Commit

Permalink
✨ Implement realm definition of clip items
Browse files Browse the repository at this point in the history
  • Loading branch information
guiyanakuang committed Feb 15, 2024
1 parent d0e0c98 commit 89db293
Show file tree
Hide file tree
Showing 28 changed files with 432 additions and 262 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ enum class AppFileType {
LOG,
ENCRYPT,
DATA,
IMAGE,
VIDEO,
FILE
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.clipevery.clip.item

import java.io.File
import java.nio.file.Path

interface ClipFile {

fun getFile(): File
fun getFilePath(): Path

fun getExtension(): String
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.clipevery.clip.item

import java.io.File
import java.nio.file.Path

interface ClipFiles {
fun getFiles(): List<File>
fun getFilePaths(): List<Path>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.clipevery.dao.clip

interface ClipDao {

fun getMaxClipId(): Int
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,37 @@ interface PathProvider {
AppFileType.LOG -> clipLogPath.resolve("logs")
AppFileType.ENCRYPT -> clipEncryptPath.resolve("encrypt")
AppFileType.DATA -> clipDataPath.resolve("data")
AppFileType.IMAGE -> clipDataPath.resolve("images")
AppFileType.VIDEO -> clipUserPath.resolve("videos")
AppFileType.FILE -> clipUserPath.resolve("files")
}

if (!path.toFile().exists()) {
path.toFile().mkdirs()
}
autoCreateDir(path)

return fileName?.let {
path.resolve(fileName)
} ?: path
}

fun resolve(basePath: Path,
path: String,
autoCreate: Boolean = true,
isFile: Boolean = false): Path {
val newPath = basePath.resolve(path)
if (isFile) {
autoCreateDir(newPath.parent)
} else {
autoCreateDir(newPath)
}
return newPath
}

private fun autoCreateDir(path: Path) {
if (!path.toFile().exists()) {
path.toFile().mkdirs()
}
}

val clipUserPath: Path

val clipLogPath: Path get() = clipUserPath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ interface OneFilePersist {
fun <T> save(config: T)

fun saveBytes(bytes: ByteArray)

fun delete(): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ import com.clipevery.net.DesktopClipClient
import com.clipevery.net.DesktopClipServer
import com.clipevery.net.DesktopDeviceRefresher
import com.clipevery.net.DeviceRefresher
import com.clipevery.path.getPathProvider
import com.clipevery.path.DesktopPathProvider
import com.clipevery.presist.DesktopFilePersist
import com.clipevery.presist.FilePersist
import com.clipevery.presist.getFilePersist
import com.clipevery.realm.RealmManager
import com.clipevery.signal.DesktopPreKeyStore
import com.clipevery.signal.DesktopSessionStore
Expand All @@ -42,6 +42,7 @@ import com.clipevery.signal.getClipIdentityKeyStoreFactory
import com.clipevery.ui.DesktopThemeDetector
import com.clipevery.ui.ThemeDetector
import com.clipevery.utils.DesktopQRCodeGenerator
import com.clipevery.utils.IDGeneratorFactory
import com.clipevery.utils.QRCodeGenerator
import com.clipevery.utils.TelnetUtils
import org.koin.core.KoinApplication
Expand All @@ -58,18 +59,18 @@ object Dependencies {
val koinApplication: KoinApplication = initKoinApplication()

private fun initKoinApplication(): KoinApplication {
val pathProvider = getPathProvider()
val appModule = module {

// simple component
single<AppInfo> { DesktopAppInfoFactory(get()).createAppInfo() }
single<EndpointInfoFactory> { DesktopEndpointInfoFactory( lazy { get<ClipServer>() }) }
single<FilePersist> { getFilePersist() }
single<FilePersist> { DesktopFilePersist }
single<ConfigManager> { DefaultConfigManager(get<FilePersist>().getPersist("appConfig.json", AppFileType.USER)) }
single<QRCodeGenerator> { DesktopQRCodeGenerator(get(), get()) }
single<IDGeneratorFactory> { IDGeneratorFactory(get()) }

// realm component
single<RealmManager> { RealmManager.createRealmManager(pathProvider = pathProvider) }
single<RealmManager> { RealmManager.createRealmManager(pathProvider = DesktopPathProvider) }
single<SignalDao> { SignalRealm(get<RealmManager>().realm) }
single<SyncRuntimeInfoDao> { SyncRuntimeInfoRealm(get<RealmManager>().realm) }

Expand All @@ -91,7 +92,7 @@ object Dependencies {

// clip component
single<ClipboardService> { getDesktopClipboardService(get()) }
single<TransferableConsumer> { DesktopTransferableConsumer() }
single<TransferableConsumer> { DesktopTransferableConsumer(get()) }

// ui component
single<AppUI> { AppUI(width = 460.dp, height = 710.dp) }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.clipevery.clip

import com.clipevery.app.AppInfo
import com.clipevery.dao.clip.ClipDao

class ClipCollector(
appInfo: AppInfo,
clipDao: ClipDao,
singleClipPlugins: List<SingleClipPlugin>,
multiClipPlugins: List<MultiClipPlugin>
) {
fun needCollectionItem(): Boolean {
TODO("Not yet implemented")
}

fun completeCollect() {
TODO("Not yet implemented")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.clipevery.clip

import java.awt.datatransfer.Transferable

interface ClipItemService {

fun getIdentifiers(): List<String>

fun createClipItem(
clipId: Int,
itemIndex: Int,
hpn: String?,
transferable: Transferable,
clipCollector: ClipCollector
)

// fun createPreClipItem(clipId: Int, itemIndex: Int, identifier: String, itemProvider: DataFlavor, clipCollector: ClipCollector)
}
16 changes: 16 additions & 0 deletions composeApp/src/desktopMain/kotlin/com/clipevery/clip/ClipPlugin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.clipevery.clip

import com.clipevery.dao.clip.ClipAppearItem
import kotlin.reflect.KClass

interface SingleClipPlugin {

fun pluginProcess(clipAppearItems: Map<KClass<ClipItemService>, ClipAppearItem>): Map<KClass<ClipItemService>, ClipAppearItem>

}

interface MultiClipPlugin {

fun pluginProcess(clipAppearItems: List<ClipAppearItem>): List<ClipAppearItem>

}
Loading

0 comments on commit 89db293

Please sign in to comment.