Skip to content

Commit

Permalink
Version 41 (#170)
Browse files Browse the repository at this point in the history
* full Czech translation #14
* add last updated time to menu #172
* improve date handling
* fix handling of non-latin path names #170
* fix menu thumbnails blanking on hover
  • Loading branch information
neffo authored Aug 14, 2022
1 parent 8a2ba88 commit 95504a2
Show file tree
Hide file tree
Showing 7 changed files with 289 additions and 163 deletions.
43 changes: 33 additions & 10 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,17 @@ const getActorCompat = (obj) =>
Convenience.currentVersionGreaterEqual('3.33') ? obj : obj.actor;

function log(msg) {
if (bingWallpaperIndicator == null || bingWallpaperIndicator._settings.get_boolean('debug-logging'))
if (bingWallpaperIndicator && bingWallpaperIndicator._settings.get_boolean('debug-logging'))
print('BingWallpaper extension: ' + msg); // disable to keep the noise down in journal
}

// pinched from here https://github.com/Odyseus/CinnamonTools (/extensions/MultiTranslatorExtension/js_modules/utils.js)
function soupPrinter(aLog, aLevel = null, aDirection = null, aData = null) {
if (aLevel && aDirection && aData) {
log('Soup: '+String(aData));
}
}

function notifyError(msg) {
Main.notifyError("BingWallpaper extension error", msg);
}
Expand Down Expand Up @@ -100,14 +107,15 @@ class BingWallpaperIndicator extends PanelMenu.Button {
this.selected_image = "current";
this.clipboard = new BWClipboard.BWClipboard();
this.imageIndex = null;
this.logger = null;
blur = new Blur.Blur();
blur.blur_strength = 30;
blur.blur_brightness = 0.55;

// take a variety of actions when the gsettings values are modified by prefs
this._settings = ExtensionUtils.getSettings(Utils.BING_SCHEMA);

this.httpSession = new Soup.Session();
this._initSoup();

getActorCompat(this).visible = !this._settings.get_boolean('hide');

Expand All @@ -132,7 +140,7 @@ class BingWallpaperIndicator extends PanelMenu.Button {
this.swallpaperItem = new PopupMenu.PopupMenuItem(_("Set lock screen image"));
this.refreshItem = new PopupMenu.PopupMenuItem(_("Refresh Now"));
this.settingsItem = new PopupMenu.PopupMenuItem(_("Settings"));
this.thumbnailItem = new PopupMenu.PopupBaseMenuItem();
this.thumbnailItem = new PopupMenu.PopupBaseMenuItem({ style_class: 'wp-thumbnail-image'});
this.menu.addMenuItem(this.refreshItem);
this.menu.addMenuItem(this.refreshDueItem);
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
Expand Down Expand Up @@ -204,6 +212,17 @@ class BingWallpaperIndicator extends PanelMenu.Button {
}
}

// create soup Session, set proxy resolver and hook up the logger
_initSoup() {
this.httpSession = new Soup.Session();
if (this._settings.get_boolean('debug-logging')) {
this.logger = Soup.Logger.new(Soup.LoggerLogLevel.HEADERS, -1);
this.logger.attach(this.httpSession);
this.logger.set_printer(soupPrinter);
}
Soup.Session.prototype.add_feature.call(this.httpSession, new Soup.ProxyResolverDefault()); // unclear if this is necessary
}

// listen for configuration changes
_setConnections() {
this._settings.connect('changed::hide', () => {
Expand Down Expand Up @@ -243,7 +262,10 @@ class BingWallpaperIndicator extends PanelMenu.Button {
this.dwallpaperItem.setSensitive(!this._updatePending && this.filename != "");
this.swallpaperItem.setSensitive(!this._updatePending && this.filename != "");
this.titleItem.setSensitive(!this._updatePending && this.imageinfolink != "");
this.refreshduetext = _("Next refresh") + ": " + (this.refreshdue ? this.refreshdue.format("%X") : '-') + " (" + Utils.friendly_time_diff(this.refreshdue) + ")";
let maxlongdate = Utils.getMaxLongDate(this._settings);
this.refreshduetext =
_("Next refresh") + ": " + (this.refreshdue ? this.refreshdue.format("%X") : '-') + " (" + Utils.friendly_time_diff(this.refreshdue) + "), " +
_("Last updated") + ": " + (maxlongdate? this._localeDate(maxlongdate, true) : '-');
this.refreshDueItem.label.set_text(this.refreshduetext);
}

Expand Down Expand Up @@ -312,7 +334,7 @@ class BingWallpaperIndicator extends PanelMenu.Button {
// set a timer on when the current image is going to expire
_restartTimeoutFromLongDate(longdate) {
// all bing times are in UTC (+0)
let refreshDue = Utils.dateFromLongDate(longdate, 86400);
let refreshDue = Utils.dateFromLongDate(longdate, 86400).to_local();
let now = GLib.DateTime.new_now_local();
let difference = refreshDue.difference(now) / 1000000;
log('Next refresh due ' + difference + ' seconds from now');
Expand All @@ -323,10 +345,10 @@ class BingWallpaperIndicator extends PanelMenu.Button {
this._restartTimeout(difference);
}

// convert shortdate format into human friendly format
_localeDate(shortdate) {
let date = Utils.dateFromShortDate(shortdate);
return date.format('%Y-%m-%d'); // ISO 8601 - https://xkcd.com/1179/
// convert longdate format into human friendly format
_localeDate(longdate, include_time = false) {
let date = Utils.dateFromLongDate(longdate, 300); // date at update
return date.to_local().format('%Y-%m-%d' + (include_time? ' %X' : '')); // ISO 8601 - https://xkcd.com/1179/
}

// set menu text in lieu of a notification/popup
Expand Down Expand Up @@ -473,6 +495,7 @@ class BingWallpaperIndicator extends PanelMenu.Button {
this._updatePending = true;
this._restartTimeout();
let market = this._settings.get_string('market');
//this._initSoup(); // get new session, incase we aren't detecting proxy changes
// create an http message
let url = BingImageURL + (market != 'auto' ? market : '');
let request = Soup.Message.new('GET', url);
Expand Down Expand Up @@ -566,7 +589,7 @@ class BingWallpaperIndicator extends PanelMenu.Button {
// set notifications icon
let source = new MessageTray.Source('Bing Wallpaper', 'preferences-desktop-wallpaper-symbolic');
Main.messageTray.add(source);
let msg = _('Bing Wallpaper of the Day for') + ' ' + this._localeDate(image.startdate);
let msg = _('Bing Wallpaper of the Day for') + ' ' + this._localeDate(image.longstartdate);
let details = Utils.getImageTitle(image);
let notification = new MessageTray.Notification(source, msg, details);
notification.setTransient(this._settings.get_boolean('transient'));
Expand Down
30 changes: 17 additions & 13 deletions locale/BingWallpaper.pot
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ msgstr ""
msgid "Enable desktop notifications"
msgstr ""

#: ui/Settings.ui.h:4 ui/Settings4.ui.h:5 extension.js:131
#: ui/Settings.ui.h:4 ui/Settings4.ui.h:5 extension.js:139
msgid "Set background image"
msgstr ""

Expand Down Expand Up @@ -46,7 +46,7 @@ msgstr ""
msgid "Bing locale"
msgstr ""

#: ui/Settings.ui.h:13 ui/Settings4.ui.h:12 extension.js:134
#: ui/Settings.ui.h:13 ui/Settings4.ui.h:12 extension.js:142
msgid "Settings"
msgstr ""

Expand Down Expand Up @@ -248,47 +248,51 @@ msgstr ""
msgid "Load image gallery"
msgstr ""

#: extension.js:119
#: extension.js:127
msgid "<No refresh scheduled>"
msgstr ""

#: extension.js:121 extension.js:123 extension.js:126
#: extension.js:129 extension.js:131 extension.js:134
msgid "Awaiting refresh..."
msgstr ""

#: extension.js:128
#: extension.js:136
msgid "Copy image to clipboard"
msgstr ""

#: extension.js:129
#: extension.js:137
msgid "Copy image URL to clipboard"
msgstr ""

#: extension.js:130
#: extension.js:138
msgid "Open image folder"
msgstr ""

#: extension.js:132
#: extension.js:140
msgid "Set lock screen image"
msgstr ""

#: extension.js:133
#: extension.js:141
msgid "Refresh Now"
msgstr ""

#: extension.js:246
#: extension.js:267
msgid "Next refresh"
msgstr ""

#: extension.js:569 extension.js:599
#: extension.js:268
msgid "Last updated"
msgstr ""

#: extension.js:592 extension.js:622
msgid "Bing Wallpaper of the Day for"
msgstr ""

#: extension.js:626
#: extension.js:649
msgid "No wallpaper available"
msgstr ""

#: extension.js:627
#: extension.js:650
msgid "No picture for today."
msgstr ""

Expand Down
Binary file modified locale/cs/LC_MESSAGES/BingWallpaper.mo
Binary file not shown.
Loading

0 comments on commit 95504a2

Please sign in to comment.