Code Monkey home page Code Monkey logo

Comments (22)

Tudmotu avatar Tudmotu commented on May 24, 2024 1

Hi @JPvRiel :) Thanks for this and the other comments!
An in-memory cache shouldn't be hard to implement. After all, it's just a JSON, no matter if in-memory or not. Writing to tmpfs is an interesting idea, and if possible with a non-privileged user, might work. If not, we can store the JSON in memory instead of on file (though this might not persist when extension is reloaded).
This can be an option in the settings.
Any of you like to try implementing this? I'm not sure when will i have time to do that, and would appreciate help :)

from gnome-shell-extension-clipboard-indicator.

 avatar commented on May 24, 2024 1

I think it's very interesting too.

I want to pay attention to something : when you lock the screen of gnome, all extensions are closed and when you open your session again, all extensions are reloaded...so, this solution must delete cache not only after a reboot.

I don't know if it's possible to distinguish reboot and lock/open-the-same-session-again. If it is, it can be good to investigate, if not, the new option will be necessary a hard option (that I will use anyway^^).

from gnome-shell-extension-clipboard-indicator.

Tudmotu avatar Tudmotu commented on May 24, 2024 1

Nice! Awesome job! πŸ˜ƒ
As far as I can see, you figured out everything, and it looks good.

Only issue I see is that in line 166 you use Fields.CACHE_FILE_DISABLE but in line 17 you set the variable name to Fields.DISABLE_CACHE_FILE.
You see the DISABLE part is not in the same place. Maybe fixing that will solve the issue? Please let me know if it doesn't fix it, I will try to help more.

Definitely, writing gnome extensions is one of the most difficult things I ever did 😁 No documentation, clumsy development workflow, errors are hidden in journal, no testing, etc..

Thanks for helping out!
Also, can you please open a PR already? Even if this doesn't fix the issues completely, it's more convenient to look at it through the pull request UI.

from gnome-shell-extension-clipboard-indicator.

Tudmotu avatar Tudmotu commented on May 24, 2024

Thanks for the idea! πŸ˜„
I'm not sure how to do that, though. I mean, I don't know how to listen to the shutdown signal.
Maybe somewhere in https://git.gnome.org/browse/gnome-shell/tree/js/misc

If anyone has any idea, it will be welcomed :)
I'll also look around a bit more.

from gnome-shell-extension-clipboard-indicator.

 avatar commented on May 24, 2024

I've done investigations and finally found this https://github.com/farseerfc/systemd-shutdown-diagnose. It's a really good example.

The idea is to start a service at boot and when the service is stopped (basically shutdown and reboot), a shell script is called. Two files are needed like those that I've started to fill.

/usr/lib/systemd/system/shutdown-clipboard-indicator.service :

[Unit]
Description= A service to execute clear-at-shutdown-clipboard-indicator at shutdown

[Service]
Type=idle
RemainAfterExit=yes
ExecStart=/usr/bin/true
ExecStop=/usr/bin/clear-at-shutdown-clipboard-indicator

[Install]
WantedBy=default.target

/usr/bin/clear-at-shutdown-clipboard-indicator :

#!/bin/bash
/*
* Code here cleaning of history
*/

I hope I don't make mistakes because I don't know how to test it on my pc ("compile" and "make" are still weird for me).

from gnome-shell-extension-clipboard-indicator.

Tudmotu avatar Tudmotu commented on May 24, 2024

Nice idea! πŸ˜ƒ But unfortunately I don't think we can do something like this:

  1. I'm pretty sure GNOME extensions can't add scripts to the systemd path.
  2. Even though systemd is very popular, it is not the only init system out there.

I would guess that there is some way of listening to a "logout" signal using the GNOME shell APIs. For example, seems like we can listen to a "PrepareForSleep" signal via the loginManager module:
https://github.com/GNOME/gnome-shell/blob/master/js/misc/loginManager.js#L32
Or to to the "ConfirmedShutdown/Login/Reboot" signal in the endSessionDialog module:
https://github.com/GNOME/gnome-shell/blob/695bfb96160033be55cfb5ac41c121998f98c328/js/ui/endSessionDialog.js#L57

Both don't give us what we want.

A simple option is to remove history in the .disable() callabck, but that one is called in all sorts of occasions, and I'm not sure when exactly. If it's called on every screen-lock, I think it's not what we're looking for.

from gnome-shell-extension-clipboard-indicator.

 avatar commented on May 24, 2024

I don't know those APIs, sorry.

The other solution is to delete history when the module is initiate at boot, it's could be very simple, no?

from gnome-shell-extension-clipboard-indicator.

JPvRiel avatar JPvRiel commented on May 24, 2024

@freeroot. see #46 (comment) ;-)

Basically, you can have what you've asked for by storing your clipboard history in RAM! A user level systemd unit. Instead of going onto disk (and available at next boot), it's in a tmpfs.

@Tudmotu , I get and agree that systemd isn't the only init system. The above is just a hack until we get around to having an in-memory cache option, which would be more secure than using tmpfs which all apps for the given user can read.

from gnome-shell-extension-clipboard-indicator.

JPvRiel avatar JPvRiel commented on May 24, 2024

@freeroot @Tudmotu I've done the tempfs thing with systemd for the logged in user. See:

#46 (comment)

It does work across shell extension reloads. Nevertheless, it's a work around for now. As commented before, gnome-shell extensions probably don't get to install user level systemd units.

tmpfs is an option, but remember, the X server / Linux desktop security model is really poor and all apps running under the same current user can read that file even if stored in tmpfs, hence I'd like the option of using an in memory json object rather than tmpfs.

from gnome-shell-extension-clipboard-indicator.

thomsh avatar thomsh commented on May 24, 2024

Hi,
Quick and dirty fix on my laptop : a small startup script to put with ln -s the ~/.cache/[email protected] in /dev/shm (tmpfs)
But πŸ‘ for a new option "In memory only"

from gnome-shell-extension-clipboard-indicator.

C0R10L4NU2 avatar C0R10L4NU2 commented on May 24, 2024

Hi,

If this is too difficult to implement, what about an option to clear the clipboard at a certain interval like every day?

from gnome-shell-extension-clipboard-indicator.

Tudmotu avatar Tudmotu commented on May 24, 2024

"In memory" storage should not be too difficult to implement - add a boolean setting, and check its value before writing to the cache file (here).

from gnome-shell-extension-clipboard-indicator.

JPvRiel avatar JPvRiel commented on May 24, 2024

should not be too difficult to implement - add a boolean setting

@Tudmotu gave it a go (my first try at working on a gnome extension, and not proficient with js). I think I got most of my PR ready, but I get stuck with gsettings schema issues of some sort trying to add the option.

This error happens when I try open the settings (prefs.js)

Error: Expected type utf8 for Argument 'key' but got type 'undefined'

This is the line I added (including other needed bits) that triggers the error

SettingsSchema.bind(Fields.CACHE_FILE_DISABLE, this.field_cache_disable, 'active', Gio.SettingsBindFlags.DEFAULT);

I'm not 100% sure how to apply defaults, should 'active' be set as 'inactive'. I gave up googling for docs related to SettingsSchema.bind - closest I could find was g_settings_bind

Hacking around, I even went into gnome-shell-extension-clipboard-indicator/schemas, updated the .xml with

    <key name="cache-disable" type="b">
      <default>false</default>
        <summary>Disable the registry cache file and use memory only</summary>
        <description>
            If true, content is not stored and retrieved from a cache (registry.txt) file. If the extension is reloaded, then your copy paste history is lost. However, if you copy and paste passwords, then this helps avoid writing them to a plaintext file.
        </description>
    </key>

And ran

glib-compile-schemas .

So at this point, I'm getting quite fed up with how hard gnome / dconf make it to add one simple menu item. It's required 5 entries in prefs.js to setup the toggle, the xml schema for dconf, not knowing how or when extensions bother to try use/install the schema for the extension. I did try bundle and install as a zip, no luck.

Any hints please?

https://github.com/JPvRiel/gnome-shell-extension-clipboard-indicator

from gnome-shell-extension-clipboard-indicator.

JPvRiel avatar JPvRiel commented on May 24, 2024

@Tudmotu thanks for helping spot that silly typo - obviously it was invisible to me! Will get to the PR and some santiy testing this weekend.

from gnome-shell-extension-clipboard-indicator.

JPvRiel avatar JPvRiel commented on May 24, 2024

PR #78 submitted. Tested it a bit. An extra tweak might be to delete registry.txt when toggled, but functional for now.

from gnome-shell-extension-clipboard-indicator.

JPvRiel avatar JPvRiel commented on May 24, 2024

@freeroot @Tudmotu this can now be closed? #78 has been merged. Of course, the option isn't on by default (don't want to disrupt other users who have come expect persistent history). You have to go to preferences and disable the file caching.

image

from gnome-shell-extension-clipboard-indicator.

 avatar commented on May 24, 2024

Thanks a lot.

from gnome-shell-extension-clipboard-indicator.

JPvRiel avatar JPvRiel commented on May 24, 2024

Hi there, just a heads up / experience with this clear at boot feature - over and above reboot/shutdown, it also applies (looses history) when:

  1. logging out of gnome sessions,
  2. if gnome crashes and restarts, and
  3. if you suspend and resume.

Not ideal, but I still prefer the security at the cost of reliable/easy clipboard history.

from gnome-shell-extension-clipboard-indicator.

JPvRiel avatar JPvRiel commented on May 24, 2024

Another big annoying issue with using the extension memory I've found is locking and unlocking gnome seems to reload the extension and clear the history... This will need further investigation.

from gnome-shell-extension-clipboard-indicator.

Tudmotu avatar Tudmotu commented on May 24, 2024

All of those situations you are describing are situations where the extensions unload from memory. So for memory-only cache file, this is expected. Not much to do about it. Can think of some other impl, such as tmp-fs that was suggested before. Not sure when is it cleared exactly, but probably not between lock/unlock.

from gnome-shell-extension-clipboard-indicator.

 avatar commented on May 24, 2024

I read somewhere that /tmp is empty at each boot. Maybe using a cache file in this folder can distinguish reboot and relock/relog.

from gnome-shell-extension-clipboard-indicator.

JPvRiel avatar JPvRiel commented on May 24, 2024

Can think of some other impl, such as tmp-fs that was suggested before. Not sure when is it cleared exactly, but probably not between lock/unlock.

Yeah, I considered that, but the "attack surface" is not as ideal. If we use tmpfs, then any process running as the user can read that file, regardless of it being in memory. Using the extension memory was better because there's extra effort/rights needed to get to the data...

I've opened a separate issue for this (given this one is technically closed): #91

from gnome-shell-extension-clipboard-indicator.

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.