GithubHelp home page GithubHelp logo

Comments (6)

hluk avatar hluk commented on September 15, 2024 1

This is not a bug, since it was never the intended behavior for the synchronization (which is meant only to sync items in specific tabs).

I've created a command that would help with the clipboard synchronization: Top Item to Clipboard (see README.md for details on how to add the command)

Let me know how that works.

from copyq.

ylluminate avatar ylluminate commented on September 15, 2024

Thank you very much for the explanation. I was obviously not aware of that and this does seem to work. I now only need to figure out why the CopyQ tab is not being updated until I activate/click CopyQ. I suspect that SyncThing is waiting for local filesystem access to retrieve vs the source system pushing an update to initiate the transfer since it's based on file node activity.

from copyq.

ylluminate avatar ylluminate commented on September 15, 2024

@hluk I've noticed a side effect of this new functionality that I'm not sure how to deal with. I use Clop to optimize images automatically, which is very useful, but I've found that with this functionality enabled now with CopyQ it will strip out some of the clip/pasteboard contents on macOS and only allow the textual file location to be available and not the image itself.

As far as I understand it, macOS has multiple encodings that can be available per paste/clip and subsequently some of this data is somehow stripped out by this action.

Additionally, I really like Pastebot and use it on macOS systems, but its synchronization mechanism via iCloud is horrible. The reason I've turned to CopyQ is to facilitate clipboard sharing between both various macOS, Windows and Linux systems I use regularly. I would still like to use Pasteboard, but what I have noticed is that also now enabling this action causes multiple copies of entries to frequently show up in Pasteboard, which I think is an evidence of being related to the issue that Clop is also facing.

Do you perceive of a way to improve this situation or to revise the command script to overcome this / these problem(s)?

Nevermind, this and various permutations still didn't work:
EDIT: I may have figured out a solution, please let me know what you think. The following implements consideration for MIME types in the command:

[Command]
Command="
    // This script ensures all MIME types are preserved when syncing the top clipboard item,
    // particularly useful for maintaining rich data like images processed by Clop.

    // Preserve the original onItemsAdded function
    var onItemsAdded_ = onItemsAdded;
    onItemsAdded = function() {
        // Call the original function to maintain existing behavior
        onItemsAdded_();

        // Early return if we're not in the clipboard tab
        if (selectedTab() !== config('clipboard_tab')) return;

        var sel = ItemSelection().current();
        const topItemIndex = sel.rows().indexOf(0);
        
        // Early return if there's no top item
        if (topItemIndex === -1) return;

        const item = sel.itemAtIndex(topItemIndex);
        var mimeData = {};
        
        // Get all MIME types for the item
        var mimeTypes = itemMimeTypes(topItemIndex);
        
        // Build the mimeData object
        mimeTypes.forEach(function(mimeType) {
            // Only copy non-empty data to avoid unnecessary empty fields
            var data = item[mimeType];
            if (data && data.length > 0) {
                mimeData[mimeType] = data;
            }
        });

        // Only perform the copy operation if we have data to copy
        if (Object.keys(mimeData).length > 0) {
            copy(mimeData);
        } else {
            // Not sure if this will do anything, but anyway:
            print('Warning: No valid data found in top clipboard item');
        }
    }"
Icon=
IsScript=true
Name=Enhanced Top Item to Clipboard with MIME Types

Seems that somehow we have to consider MIME type data, but not sure how to do that in context of CopyQ and macOS' pasteboard.

from copyq.

hluk avatar hluk commented on September 15, 2024

Not sure if it would help, but you can also override onItemsChanged so that the clipboard changes when the first item changes:

[Command]
Command="
    var onItemsAdded_ = onItemsAdded;
    onItemsAdded = function() {
        onItemsAdded_();
        syncClipboard();
    }

    var onItemsChanged_ = onItemsChanged;
    onItemsChanged = function() {
        onItemsChanged_();
        syncClipboard();
    }

    function syncClipboard() {
        if (selectedTab() != config('clipboard_tab'))
            return;

        var sel = ItemSelection().current(); 
        const i = sel.rows().indexOf(0);
        if (i == -1)
            return;

        const item = sel.itemAtIndex(i);
        copy(mimeItems, pack(item));
    }"
Icon=
IsScript=true
Name=Top Item to Clipboard

from copyq.

hluk avatar hluk commented on September 15, 2024

One downside is that the refresh of synchronized tabs is delayed (optimized so it does not happen unnecessarily) and is triggered mainly when the tab is displayed again. This would postpone adding new items and synchronizing the clipboard.

from copyq.

hluk avatar hluk commented on September 15, 2024

I will drop the Top Item to Clipboard command from the command repository since it is very unreliable due to the sync-refresh delay.

An alternative could be to write clipboard content to a special file to the shared folder whenever the clipboard changes, and monitor the file (regularly or with a utility).

from copyq.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.