-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Turning off listening to the pasteboard does not turn it on again (#…
- Loading branch information
1 parent
fa5973f
commit af935d7
Showing
8 changed files
with
91 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
composeApp/src/desktopMain/kotlin/com/clipevery/clip/AbstractClipboardService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.clipevery.clip | ||
|
||
import com.clipevery.dao.clip.ClipData | ||
import java.awt.datatransfer.Clipboard | ||
import java.awt.datatransfer.Transferable | ||
|
||
abstract class AbstractClipboardService : ClipboardService { | ||
|
||
abstract var ownerTransferable: Transferable? | ||
|
||
abstract val systemClipboard: Clipboard | ||
|
||
abstract val clipConsumer: TransferableConsumer | ||
|
||
abstract val clipProducer: TransferableProducer | ||
|
||
fun isValidContents(contents: Transferable?): Boolean { | ||
return contents != null && contents.transferDataFlavors.isNotEmpty() | ||
} | ||
|
||
fun getClipboardContentsBySafe(): Transferable? { | ||
return try { | ||
systemClipboard.getContents(null) | ||
} catch (e: Exception) { | ||
logger.error(e) { "getContentsBySafe error" } | ||
null | ||
} | ||
} | ||
|
||
override suspend fun tryWriteClipboard( | ||
clipData: ClipData, | ||
localOnly: Boolean, | ||
filterFile: Boolean, | ||
) { | ||
try { | ||
clipProducer.produce(clipData, localOnly, filterFile)?.let { | ||
ownerTransferable = it | ||
owner = true | ||
systemClipboard.setContents(ownerTransferable, this) | ||
} | ||
} catch (e: Exception) { | ||
logger.error(e) { "tryWriteClipboard error" } | ||
} | ||
} | ||
|
||
override suspend fun tryWriteRemoteClipboard(clipData: ClipData) { | ||
clipDao.releaseRemoteClipData(clipData) { storeClipData, filterFile -> | ||
clipboardChannel.trySend { tryWriteClipboard(storeClipData, localOnly = true, filterFile = filterFile) } | ||
} | ||
} | ||
|
||
override suspend fun tryWriteRemoteClipboardWithFile(clipData: ClipData) { | ||
clipDao.releaseRemoteClipDataWithFile(clipData.id) { storeClipData -> | ||
clipboardChannel.trySend { tryWriteClipboard(storeClipData, localOnly = true, filterFile = false) } | ||
} | ||
} | ||
|
||
override suspend fun clearRemoteClipboard(clipData: ClipData) { | ||
clipDao.markDeleteClipData(clipData.id) | ||
} | ||
|
||
@Synchronized | ||
override fun toggle() { | ||
val enableClipboardListening = configManager.config.enableClipboardListening | ||
if (enableClipboardListening) { | ||
stop() | ||
} else { | ||
start() | ||
} | ||
configManager.updateConfig { it.copy(enableClipboardListening = !enableClipboardListening) } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters