BWClipboard.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. // Bing Wallpaper GNOME extension
  2. // Copyright (C) 2017-2023 Michael Carroll
  3. // This extension is free software: you can redistribute it and/or modify
  4. // it under the terms of the GNU Lesser General Public License as published by
  5. // the Free Software Foundation, either version 3 of the License, or
  6. // (at your option) any later version.
  7. // See the GNU General Public License, version 3 or later for details.
  8. import St from 'gi://St';
  9. import Gio from 'gi://Gio';
  10. const CLIPBOARD_TYPE = St.ClipboardType.CLIPBOARD;
  11. export default class BWClipboard {
  12. constructor() {
  13. this.clipboard = St.Clipboard.get_default();
  14. }
  15. setImage(filename) {
  16. try {
  17. let file = Gio.File.new_for_path(filename);
  18. let [success, image_data] = file.load_contents(null);
  19. //log('error: '+success);
  20. if (success)
  21. this.clipboard.set_content(CLIPBOARD_TYPE, 'image/jpeg', image_data);
  22. } catch (err) {
  23. log('unable to set clipboard to data in '+filename);
  24. }
  25. }
  26. setText(text) {
  27. this.clipboard.set_text(CLIPBOARD_TYPE, text);
  28. }
  29. };