Skip to content

Commit

Permalink
Version 42 (#177)
Browse files Browse the repository at this point in the history
* wrap refresh title #175

* update ru translation #14

* don't change popup-menu-item CSS system wide

* add support for Gnome 43

* support libsoup3 (GNOME 43+, some version of GNOME 42)

* improve useragent string

* clean up errors on first start

* Fix libsoup3 json request

* clean up menu

* setup CodeQL (code scanning)

* small readme cleanups

Co-authored-by: Christopher Snowhill <chris@kode54.net>
  • Loading branch information
neffo and kode54 committed Sep 21, 2022
1 parent 95504a2 commit 98639d5
Show file tree
Hide file tree
Showing 10 changed files with 543 additions and 315 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/codeql-analysis.yml
@@ -0,0 +1,74 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ "master" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "master" ]
schedule:
- cron: '15 1 * * 2'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'javascript' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
16 changes: 8 additions & 8 deletions README.md
@@ -1,15 +1,14 @@
# GNOME Shell extension - Bing Wallpaper

A lightweight extension that brings some color to your desktop by syncing your desktop and lockscreen wallpapers with today's Microsoft Bing image of the day (the image you see when you visit Bing.com). The intention of this extension is to just do what it needs to do and stay out of your way, with a few optional features to improve quality-of-life.
Bring some color to your GNOME desktop by syncing your desktop and lockscreen wallpapers with today's Microsoft Bing image of the day (the image you see when you visit Bing.com) with this extension. The intention of this extension is to just do what it needs to do and stay out of your way, with a few optional features to improve quality-of-life.

![Screenshot](/screenshot/notification.png)
[![Get it on GNOME extensions](/screenshot/get_it_on_gnome_extensions.png)](https://extensions.gnome.org/extension/1262/bing-wallpaper-changer/) [![<3 Sponsor this project on GitHub <3](/screenshot/sponsor.png)](https://github.com/sponsors/neffo)

This extension is based extensively on the NASA APOD extension by [Elinvention](https://github.com/Elinvention)
and inspired by Bing Desktop WallpaperChanger by [Utkarsh Gupta](https://github.com/UtkarshGpta). As featured on [OMG! Ubuntu](https://www.omgubuntu.co.uk/2017/07/bing-wallpaper-changer-gnome-extension). Lockscreen blur code is based on [Pratap-Kumar's extension.](https://github.com/PRATAP-KUMAR/Control_Blur_Effect_On_Lock_Screen)
![Screenshot](/screenshot/notification.png)

Also, check out my related [Google Earth View wallpaper extension](https://github.com/neffo/earth-view-wallpaper-gnome-extension) and the partially-derived [Bing Desktop Wallpaper for Cinnamon](https://github.com/Starcross/bing-wallpaper-cinnamon) by Starcross.
As featured on [OMG! Ubuntu](https://www.omgubuntu.co.uk/2017/07/bing-wallpaper-changer-gnome-extension).

[![Get it on GNOME extensions](/screenshot/get_it_on_gnome_extensions.png)](https://extensions.gnome.org/extension/1262/bing-wallpaper-changer/) [![<3 Sponsor this project on GitHub <3](/screenshot/sponsor.png)](https://github.com/sponsors/neffo)
Also, check out my related [Google Earth View wallpaper extension](https://github.com/neffo/earth-view-wallpaper-gnome-extension) and the partially-derived [Bing Desktop Wallpaper for Cinnamon](https://cinnamon-spices.linuxmint.com/applets/view/320) applet by Starcross.

## Features

Expand All @@ -19,7 +18,7 @@ Also, check out my related [Google Earth View wallpaper extension](https://githu
* Image gallery to view, select and curate stored images
* Optionally delete old images after a week, or you can keep (and curate) them forever
* Override the lockscreen blur
* Language support: English (en), German (de), Dutch (nl), Italian (it), Polish (pl), Chinese (zh_CN), French (fr_FR), Portuguese (pt, pt_BR), Russian (ru_RU), Spanish (es), Korean (ko, ko_KR, ko_KP), Indonesian (id), Catalan (ca), Norwegian Bokmål (nb) & Nynorsk (ni), Swedish (sv), Arabic (ar), Hungarian (hu) and Japanese (ja) - a HUGE thanks to the translators
* Language support: English (en), German (de), Dutch (nl), Italian (it), Polish (pl), Chinese (zh_CN, zh_TW), French (fr_FR), Portuguese (pt, pt_BR), Ukrainian (uk), Russian (ru_RU), Spanish (es), Korean (ko), Indonesian (id), Catalan (ca), Norwegian Bokmål (nb) & Nynorsk (ni), Swedish (sv), Arabic (ar), Hungarian (hu) and Japanese (ja) - a HUGE thanks to the translators
* Image preview in menus & ability to manually set wallpapers individually or copy image to clipboard
* A selection of different theme-aware indicator (tray) icons to choose (or hide it completely)

Expand Down Expand Up @@ -91,7 +90,8 @@ This extension is unofficial and not affiliated with Bing or Microsoft in any wa

## Special Thanks

I'd like to give a special shout out to those who have [contributed code and translations](https://github.com/neffo/bing-wallpaper-gnome-extension/graphs/contributors) as well as everyone who has reported bugs or provided feedback and suggestions for improvements. Also, thanks to Microsoft for this great API and wallpaper collection.
This extension is based on the NASA APOD extension by [Elinvention](https://github.com/Elinvention)
and inspired by Bing Desktop WallpaperChanger by [Utkarsh Gupta](https://github.com/UtkarshGpta). Lockscreen blur code is based on [Pratap-Kumar's extension](https://github.com/PRATAP-KUMAR/Control_Blur_Effect_On_Lock_Screen). I'd like to give a special shout out to those who have [contributed code and translations](https://github.com/neffo/bing-wallpaper-gnome-extension/graphs/contributors) as well as everyone who has reported bugs or provided feedback and suggestions for improvements. Also, thanks to Microsoft for this great API and wallpaper collection.

## License

Expand Down
179 changes: 113 additions & 66 deletions extension.js
@@ -1,12 +1,14 @@
// Bing Wallpaper GNOME extension
// Copyright (C) 2017-2021 Michael Carroll
// Copyright (C) 2017-2022 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.
// Based on GNOME shell extension NASA APOD by Elia Argentieri https://github.com/Elinvention/gnome-shell-extension-nasa-apod

imports.gi.versions.Soup = "2.4";

const {St, Soup, Gio, GObject, GLib, Clutter, Cogl, Gdk} = imports.gi;
const Main = imports.ui.main;
const MessageTray = imports.ui.messageTray;
Expand Down Expand Up @@ -57,13 +59,6 @@ function log(msg) {
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 @@ -125,6 +120,7 @@ class BingWallpaperIndicator extends PanelMenu.Button {
}

this.refreshDueItem = new PopupMenu.PopupMenuItem(_("<No refresh scheduled>"));
this._wrapLabelItem(this.refreshDueItem);
//this.showItem = new PopupMenu.PopupMenuItem(_("Show description"));
this.titleItem = new PopupMenu.PopupMenuItem(_("Awaiting refresh...")); //FIXME: clean this up
this._wrapLabelItem(this.titleItem);
Expand Down Expand Up @@ -212,15 +208,10 @@ class BingWallpaperIndicator extends PanelMenu.Button {
}
}

// create soup Session, set proxy resolver and hook up the logger
// create soup Session
_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
this.httpSession.user_agent = 'User-Agent: Mozilla/5.0 (X11; GNOME Shell/' + imports.misc.config.PACKAGE_VERSION + '; Linux x86_64; +https://github.com/neffo/bing-wallpaper-gnome-extension ) BingWallpaper Gnome Extension/' + Me.metadata.version;
}

// listen for configuration changes
Expand Down Expand Up @@ -264,8 +255,8 @@ class BingWallpaperIndicator extends PanelMenu.Button {
this.titleItem.setSensitive(!this._updatePending && this.imageinfolink != "");
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) : '-');
_("Next refresh") + ": " + (this.refreshdue ? this.refreshdue.format("%Y-%m-%d %X") : '-') + " (" + Utils.friendly_time_diff(this.refreshdue) + ")\n" +
_("Last refresh") + ": " + (maxlongdate? this._localeDate(maxlongdate, true) : '-');
this.refreshDueItem.label.set_text(this.refreshduetext);
}

Expand Down Expand Up @@ -347,8 +338,13 @@ class BingWallpaperIndicator extends PanelMenu.Button {

// 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/
try {
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/
}
catch (e) {
return 'none';
}
}

// set menu text in lieu of a notification/popup
Expand Down Expand Up @@ -494,31 +490,58 @@ class BingWallpaperIndicator extends PanelMenu.Button {
return;
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);
log('fetching: ' + url);
if (Soup.MAJOR_VERSION >= 3) {
let url = BingImageURL;
let params = Utils.BingParams;
params['mkt'] = ( market != 'auto' ? market : '' );

// queue the http request
this.httpSession.queue_message(request, (httpSession, message) => {
if (message.status_code == 200) {
let data = message.response_body.data;
log('Recieved ' + data.length + ' bytes');
this._parseData(data);
if (this.selected_image != 'random')
this._selectImage();
} else if (message.status_code == 403) {
log('Access denied: ' + message.status_code);
this._updatePending = false;
this._restartTimeout(TIMEOUT_SECONDS_ON_HTTP_ERROR);
} else {
log('Network error occured: ' + message.status_code);
this._updatePending = false;
this._restartTimeout(TIMEOUT_SECONDS_ON_HTTP_ERROR);
let request = Soup.Message.new_from_encoded_form('GET', url, Soup.form_encode_hash(params));
request.request_headers.append('Accept', 'application/json');

try {
this.httpSession.send_and_read_async(request, GLib.PRIORITY_DEFAULT, null, (httpSession, message) => {
this._processMessageRefresh(message);
});
}
});
catch(error) {
log('unable to send libsoup json message '+error);
}
}
else {
let url = BingImageURL + '?format=js&idx=0&n=8&mbl=1&mkt=' + (market != 'auto' ? market : '');
let request = Soup.Message.new('GET', url);
request.request_headers.append('Accept', 'application/json');
//log('fetching: ' + message.get_uri().to_string(false));

// queue the http request
try {
this.httpSession.queue_message(request, (httpSession, message) => {
this._processMessageRefresh(message);
});
}
catch (error) {
log('unable to send libsoup json message '+error);
}
}
}

_processMessageRefresh(message) {
try {
let data = (Soup.MAJOR_VERSION >= 3) ?
ByteArray.toString(this.httpSession.send_and_read_finish(message).get_data()): // Soup3
message.response_body.data; // Soup 2
log('Recieved ' + data.length + ' bytes');
this._parseData(data);
if (this.selected_image != 'random')
this._selectImage();
}
catch (error) {
log('Network error occured: ' + error);
this._updatePending = false;
this._restartTimeout(TIMEOUT_SECONDS_ON_HTTP_ERROR);
}
}

// sets a timer for next refresh of Bing metadata
Expand Down Expand Up @@ -708,35 +731,59 @@ class BingWallpaperIndicator extends PanelMenu.Button {
// download and process new image
// FIXME: improve error handling
_downloadImage(url, file) {
log("Downloading " + url + " to " + file.get_uri());
log("Downloading " + url + " to " + file.get_uri());
let request = Soup.Message.new('GET', url);

// queue the http request
this.httpSession.queue_message(request, (httpSession, message) => {
// request completed
this._updatePending = false;
if (message.status_code == 200) {
file.replace_contents_bytes_async(
message.response_body.flatten().get_as_bytes(),
null,
false,
Gio.FileCreateFlags.REPLACE_DESTINATION,
null,
(file, res) => {
try {
file.replace_contents_finish(res);
this._setBackground();
log('Download successful');
} catch(e) {
log('Error writing file: ' + e);
}
}
);
} else {
log('Couldn\'t fetch image from ' + url);
file.delete(null);
try {
if (Soup.MAJOR_VERSION >= 3) {
this.httpSession.send_and_read_async(request, GLib.PRIORITY_DEFAULT, null, (httpSession, message) => {
// request completed
this._updatePending = false;
this._processFileDownload(message, file);
});
}
});
else {
this.httpSession.queue_message(request, (httpSession, message) => {
// request completed
this._updatePending = false;
this._processFileDownload(message, file);
});
}

}
catch (error) {
log('error sending libsoup message '+error);
}
}

_processFileDownload(message, file) {
try {
let data = (Soup.MAJOR_VERSION >= 3) ?
this.httpSession.send_and_read_finish(message).get_data():
message.response_body.flatten().get_as_bytes();

file.replace_contents_bytes_async(
data,
null,
false,
Gio.FileCreateFlags.REPLACE_DESTINATION,
null,
(file, res) => {
try {
file.replace_contents_finish(res);
this._setBackground();
log('Download successful');
}
catch(e) {
log('Error writing file: ' + e);
}
}
);
}
catch (error) {
log('Unable download image '+error);
}
}

// open image in default image view
Expand Down

0 comments on commit 98639d5

Please sign in to comment.