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