first
This commit is contained in:
14
BingWallpaper@sonichy/README.md
Executable file
14
BingWallpaper@sonichy/README.md
Executable file
@@ -0,0 +1,14 @@
|
||||
# BingWallpaper_GNOME
|
||||
Change wallpaper of GNOME with Bing wallpaper on one click.
|
||||
|
||||
## Changelog
|
||||
### V1.0 (2025-04-26)
|
||||
Get Bing wallpaper API, parse image url, download image, set GNOME wallpaper.
|
||||
|
||||
## Reference
|
||||
[guide](https://gjs.guide/extensions/development/creating.html)
|
||||
[Soup](https://libsoup.gnome.org/libsoup-3.0/index.html)
|
||||
[bing-wallpaper-gnome-extension](https://github.com/neffo/bing-wallpaper-gnome-extension)
|
||||
|
||||
## Debug
|
||||
dbus-run-session -- gnome-shell --nested --wayland
|
||||
81
BingWallpaper@sonichy/bing-symbolic.svg
Normal file
81
BingWallpaper@sonichy/bing-symbolic.svg
Normal file
@@ -0,0 +1,81 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
width="128"
|
||||
height="128"
|
||||
id="svg2"
|
||||
version="1.1"
|
||||
inkscape:version="0.91 r13725"
|
||||
sodipodi:docname="bing.svg"
|
||||
inkscape:export-filename="/home/giulio/Scaricati/bing.svg.png"
|
||||
inkscape:export-xdpi="90"
|
||||
inkscape:export-ydpi="90">
|
||||
<defs
|
||||
id="defs4" />
|
||||
<sodipodi:namedview
|
||||
id="base"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="0.28574218"
|
||||
inkscape:cx="360.85355"
|
||||
inkscape:cy="487.41923"
|
||||
inkscape:document-units="px"
|
||||
inkscape:current-layer="layer1"
|
||||
showgrid="false"
|
||||
fit-margin-left="0"
|
||||
fit-margin-bottom="0"
|
||||
fit-margin-top="0"
|
||||
fit-margin-right="0"
|
||||
inkscape:window-width="1307"
|
||||
inkscape:window-height="704"
|
||||
inkscape:window-x="59"
|
||||
inkscape:window-y="27"
|
||||
inkscape:window-maximized="1">
|
||||
<inkscape:grid
|
||||
type="xygrid"
|
||||
id="grid2996"
|
||||
empspacing="5"
|
||||
visible="true"
|
||||
enabled="true"
|
||||
snapvisiblegridlinesonly="true"
|
||||
originx="226.45871"
|
||||
originy="5.9950575"
|
||||
spacingx="1.0666667"
|
||||
spacingy="1.0666667" />
|
||||
</sodipodi:namedview>
|
||||
<metadata
|
||||
id="metadata7">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title></dc:title>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1"
|
||||
transform="translate(226.45871,-1000.5147)">
|
||||
<path
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1.06666672"
|
||||
d="m -207.22508,1000.5147 25.56889,8.995 0,90.0025 36.01496,-20.7906 -17.65737,-8.2848 -11.13975,-27.7264 56.74602,19.9359 0,28.9836 -63.94928,36.8848 -25.58347,-14.2309 z"
|
||||
id="path2998"
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="ccccccccccc" />
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.4 KiB |
79
BingWallpaper@sonichy/extension.js
Executable file
79
BingWallpaper@sonichy/extension.js
Executable file
@@ -0,0 +1,79 @@
|
||||
import GLib from "gi://GLib";
|
||||
import Gio from 'gi://Gio';
|
||||
import St from 'gi://St';
|
||||
import Soup from 'gi://Soup';
|
||||
|
||||
import { Extension } from 'resource:///org/gnome/shell/extensions/extension.js';
|
||||
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
|
||||
import * as PanelMenu from 'resource:///org/gnome/shell/ui/panelMenu.js';
|
||||
import * as PopupMenu from 'resource:///org/gnome/shell/ui/popupMenu.js';
|
||||
|
||||
export var schema = 'org.gnome.desktop.background';
|
||||
export var imagePath = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_PICTURES) + '/BingWallpaper';
|
||||
|
||||
export default class BingWallpaperExtension extends Extension {
|
||||
enable() {
|
||||
this._indicator = new PanelMenu.Button(0.0, this.metadata.name, false);
|
||||
|
||||
let gicon = Gio.icon_new_for_string(this.dir.get_path() + '/bing-symbolic.svg');
|
||||
const icon = new St.Icon({
|
||||
gicon: gicon,
|
||||
style_class: 'system-status-icon'
|
||||
});
|
||||
this._indicator.add_child(icon);
|
||||
//this._indicator.connect('pressed', () => this.getWallpaper());
|
||||
|
||||
Main.panel.addToStatusArea(this.uuid, this._indicator);
|
||||
|
||||
const menu_browse = new PopupMenu.PopupImageMenuItem('Browse', 'folder-directory-symbolic', {});
|
||||
menu_browse.connect('activate', () => {});
|
||||
this._indicator.menu.addMenuItem(menu_browse);
|
||||
|
||||
this.menu_update = new PopupMenu.PopupImageMenuItem('Update', 'info-symbolic', {});
|
||||
this.menu_update.connect('activate', () => this.getWallpaper());
|
||||
this._indicator.menu.addMenuItem(this.menu_update);
|
||||
}
|
||||
|
||||
disable() {
|
||||
this._indicator?.destroy();
|
||||
this._indicator = null;
|
||||
}
|
||||
|
||||
getWallpaper() {
|
||||
console.log('BingWallpaper menu pressed!');
|
||||
let gsettings = new Gio.Settings({ schema: schema });
|
||||
//let uri = gsettings.get_string('picture-uri');
|
||||
//console.log(schema + ': ' + uri);
|
||||
var url = 'http://cn.bing.com/HPImageArchive.aspx';
|
||||
let params = { format: 'js', idx: '0' , n: '1' } ;
|
||||
let httpSession = new Soup.Session();
|
||||
let request = Soup.Message.new_from_encoded_form('GET', url, Soup.form_encode_hash(params));
|
||||
httpSession.send_and_read_async(request, GLib.PRIORITY_DEFAULT, null, (httpSession, message) => {
|
||||
const decoder = new TextDecoder();
|
||||
var data = decoder.decode(httpSession.send_and_read_finish(message).get_data());
|
||||
console.log(data);
|
||||
var json = JSON.parse(data);
|
||||
let imgUrl = "http://www.bing.com" + json.images[0].url;
|
||||
var filename = json.images[0].enddate + '_' + json.images[0].urlbase.replace('/th?id=OHR.', '') + '.jpg';
|
||||
this.menu_update.label.text = json.images[0].copyright;
|
||||
//console.log(imgUrl);
|
||||
//console.log(filename);
|
||||
var filepath = imagePath + '/' + filename;
|
||||
//console.log(filepath);
|
||||
let file = Gio.file_new_for_path(filepath);
|
||||
let request = Soup.Message.new('GET', imgUrl);
|
||||
httpSession.send_and_read_async(request, GLib.PRIORITY_DEFAULT, null, (httpSession, message) => {
|
||||
data = httpSession.send_and_read_finish(message).get_data();
|
||||
file.replace_contents_bytes_async(data, null, false, Gio.FileCreateFlags.REPLACE_DESTINATION, null, (file, res) => {
|
||||
let uri = 'file://' + filepath;
|
||||
//console.log(uri);
|
||||
gsettings.set_string('picture-uri', uri);
|
||||
gsettings.set_string('picture-uri-dark', uri);
|
||||
Gio.Settings.sync();
|
||||
gsettings.apply();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
9
BingWallpaper@sonichy/metadata.json
Executable file
9
BingWallpaper@sonichy/metadata.json
Executable file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"uuid": "BingWallpaper@sonichy",
|
||||
"name": "Bing Wallpaper",
|
||||
"description": "Change wallpaper of GNOME with Bing wallpaper on one click.",
|
||||
"author": "sonichy",
|
||||
"version": "1.0",
|
||||
"shell-version": [ "45", "46", "47", "48" ],
|
||||
"url": "https://github.com/sonichy/GNOME_extension"
|
||||
}
|
||||
Reference in New Issue
Block a user