Skip to content

Commit

Permalink
[email protected]: Add force refresh menu (#6718)
Browse files Browse the repository at this point in the history
  • Loading branch information
nabetaro authored Jan 7, 2025
1 parent d8d12f7 commit feba0da
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions [email protected]/files/[email protected]/applet.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const Mainloop = imports.mainloop;
const Lang = imports.lang;
const PopupMenu = imports.ui.popupMenu;
const St = imports.gi.St;

const logging = false;

Expand Down Expand Up @@ -45,6 +47,12 @@ BingWallpaperApplet.prototype = {
this.wallpaperPath = `${this.wallpaperDir}/BingWallpaper.jpg`;
this.metaDataPath = `${this.wallpaperDir}/meta.json`;

let refreshBg = new PopupMenu.PopupIconMenuItem(_("Refresh Now"), "view-refresh", St.IconType.SYMBOLIC);
refreshBg.connect('activate', Lang.bind(this, function() {
this._downloadMetaData()
}));
this._applet_context_menu.addMenuItem(refreshBg);

// Begin refresh loop
this._refresh();
},
Expand Down Expand Up @@ -140,7 +148,7 @@ BingWallpaperApplet.prototype = {

_downloadMetaData: function () {
const process_result = data => {

// Write to meta data file
let gFile = Gio.file_new_for_path(this.metaDataPath);
let fStream = gFile.replace(null, false, Gio.FileCreateFlags.NONE, null);
Expand All @@ -157,7 +165,7 @@ BingWallpaperApplet.prototype = {
this._downloadImage();

};

// Retrieve json metadata, either from local file or remote
let request = Soup.Message.new('GET', `${bingHost}${bingRequestPath}`);
if (Soup.MAJOR_VERSION === 2) {
Expand All @@ -168,7 +176,7 @@ BingWallpaperApplet.prototype = {
log(`Failed to acquire image metadata (${message.status_code})`);
this._setTimeout(60) // Try again
}

});
} else { //version 3
_httpSession.send_and_read_async(request, Soup.MessagePriority.NORMAL, null, (_httpSession, message) => {
Expand Down

0 comments on commit feba0da

Please sign in to comment.