From 869b0f477d469f37004bf7ef141c3c46944044d0 Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Sun, 20 Nov 2022 20:21:37 +1000 Subject: [PATCH] Version 16 (#37) * initial gnome 43+ support, add CodeQL * fix lint errors and warnings, and metadata * SessionAsync is deprecated * wrap some first run errors --- .eslintrc.yml | 3 +- .github/workflows/codeql-analysis.yml | 74 ++++++++++++++++ convenience.js | 2 +- extension.js | 121 +++++++++++++++++++------- locale/GoogleEarthWallpaper.pot | 62 ++++++------- metadata.json | 6 +- prefs.js | 24 ++--- utils.js | 45 ++++++---- 8 files changed, 242 insertions(+), 95 deletions(-) create mode 100644 .github/workflows/codeql-analysis.yml diff --git a/.eslintrc.yml b/.eslintrc.yml index 62e05d3..7a8b204 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -197,7 +197,8 @@ rules: prefer-arrow-callback: 'off' prefer-const: 'off' prefer-destructuring: 'off' - prefer-named-capture-group: error + prefer-named-capture-group: 'warn' + no-cond-assign: 'warn' prefer-numeric-literals: error prefer-object-spread: error prefer-promise-reject-errors: error diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 0000000..6c96ed6 --- /dev/null +++ b/.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}}" diff --git a/convenience.js b/convenience.js index 3d17f01..a170f5d 100644 --- a/convenience.js +++ b/convenience.js @@ -63,7 +63,7 @@ function versionSmaller(a, b) { } function currentVersion() { - return ''+Config.PACKAGE_VERSION.replace(/(alpha|beta)/,'0'); + return String(Config.PACKAGE_VERSION.replace(/(alpha|beta|rc)/,'0')); } function currentVersionEqual(v) { diff --git a/extension.js b/extension.js index 5d62c43..13e5caf 100644 --- a/extension.js +++ b/extension.js @@ -12,6 +12,7 @@ const {St, Soup, Gio, GLib, Clutter, GObject} = imports.gi; const {main, panelMenu, popupMenu, messageTray} = imports.ui; const Util = imports.misc.util; +const ByteArray = imports.byteArray; const ExtensionUtils = imports.misc.extensionUtils; const Me = ExtensionUtils.getCurrentExtension(); @@ -23,11 +24,9 @@ const Gettext = imports.gettext.domain('GoogleEarthWallpaper'); const _ = Gettext.gettext; const GEjsonURL = "https://www.gstatic.com/prettyearth/assets/data/v3/"; // previously was v2 -const GEURL = "https://earth.google.com"; const IndicatorName = "GEWallpaperIndicator"; const TIMEOUT_SECONDS = 24 * 3600; // FIXME: this should use the end data from the json data const TIMEOUT_SECONDS_ON_HTTP_ERROR = 4 * 3600; // retry in one hour if there is a http error -const ICON = "pin"; const providerNames = ['Google Earth', 'Google Maps', 'Bing Maps', 'OpenStreetMap' , 'GNOME Maps']; let googleearthWallpaperIndicator=null; @@ -82,21 +81,18 @@ class GEWallpaperIndicator extends panelMenu.Button { this.link = "https://earthview.withgoogle.com/"; this.imageid = 0; this.refreshdue = 0; // UNIX timestamp when next refresh is due - this.httpSession = new Soup.SessionAsync(); - Soup.Session.prototype.add_feature.call(this.httpSession, new Soup.ProxyResolverDefault()); + this.httpSession = null; + + // create libSoup session for http requests + this._initSoup(); this._settings.connect('changed::hide', () => { getActorCompat(this).visible = !this._settings.get_boolean('hide'); }); getActorCompat(this).visible = !this._settings.get_boolean('hide'); - - this._settings.connect('changed::map-link-provider', this._updateProviderLink.bind(this)); - this._settings.connect('changed::notify', this._notifyCurrentImage.bind(this)); getActorCompat(this).add_child(this.icon); this._setIcon(); - // watch for indicator icon settings changes - this._settings.connect('changed::icon', this._setIcon.bind(this)); this.refreshDueItem = new popupMenu.PopupMenuItem(_("")); this.descriptionItem = new popupMenu.PopupMenuItem(_("Text Location")); @@ -107,6 +103,8 @@ class GEWallpaperIndicator extends panelMenu.Button { this.swallpaperItem = new popupMenu.PopupMenuItem(_("Set lockscreen image now")); this.refreshItem = new popupMenu.PopupMenuItem(_("Refresh Now")); this.settingsItem = new popupMenu.PopupMenuItem(_("Extension settings")); + + // force word wrapping for potentially long menu items this._wrapLabelItem(this.descriptionItem); this._wrapLabelItem(this.copyrightItem); @@ -130,16 +128,12 @@ class GEWallpaperIndicator extends panelMenu.Button { this.descriptionItem.setSensitive(false); this.copyrightItem.setSensitive(false); this.locationItem.setSensitive(false); - - this.extLinkItem.connect('activate', this._open_link.bind(this)); - this.dwallpaperItem.connect('activate', this._setDesktopBackground.bind(this)); + if (!Convenience.currentVersionGreaterEqual("3.36")) { // lockscreen and desktop wallpaper are the same in GNOME 3.36+ this.swallpaperItem.connect('activate', this._setLockscreenBackground.bind(this)); this.menu.addMenuItem(this.swallpaperItem); } this.menu.addMenuItem(new popupMenu.PopupSeparatorMenuItem()); - this.refreshItem.connect('activate', this._refresh.bind(this)); - this.settingsItem.connect('activate', this._openPrefs.bind(this)); this.menu.addMenuItem(new popupMenu.PopupMenuItem(_("On refresh:"), {reactive : false} )); this.menu.addMenuItem(this.wallpaperToggle); if (!Convenience.currentVersionGreaterEqual("3.36")) { // lockscreen and desktop wallpaper are the same in GNOME 3.36+ @@ -147,10 +141,12 @@ class GEWallpaperIndicator extends panelMenu.Button { } this.menu.addMenuItem(this.notifyToggle); this.menu.addMenuItem(new popupMenu.PopupSeparatorMenuItem()); - this.menu.addMenuItem(this.settingsItem); - - getActorCompat(this).connect('button-press-event', this._updateMenu.bind(this)); + this.menu.addMenuItem(this.settingsItem); + + // connect menu items and settings changes to functions + this._setMenuConnections(); + // persistance of notification interval if (this._settings.get_int('next-refresh') > 0 ) { this._restorePreviousState(); } @@ -160,6 +156,33 @@ class GEWallpaperIndicator extends panelMenu.Button { } } + // create soup Session + _initSoup() { + this.httpSession = new Soup.Session(); + this.httpSession.user_agent = 'User-Agent: Mozilla/5.0 (GNOME Shell/' + imports.misc.config.PACKAGE_VERSION + '; Linux; +https://github.com/neffo/earth-view-wallpaper-gnome-extension ) Google Earth Wallpaper Gnome Extension/' + Me.metadata.version; + + } + + _setMenuConnections() { + // update link to map of location + this._settings.connect('changed::map-link-provider', this._updateProviderLink.bind(this)); + + // on notification toggle change immediately create a notification + this._settings.connect('changed::notify', this._notifyCurrentImage.bind(this)); + + // watch for indicator icon settings changes (including hiding indicator) + this._settings.connect('changed::icon', this._setIcon.bind(this)); + + // connect menu items clicks to functions + this.extLinkItem.connect('activate', this._open_link.bind(this)); + this.dwallpaperItem.connect('activate', this._setDesktopBackground.bind(this)); + this.refreshItem.connect('activate', this._refresh.bind(this)); + this.settingsItem.connect('activate', this._openPrefs.bind(this)); + + // update menu when user clicks button + getActorCompat(this).connect('button-press-event', this._updateMenu.bind(this)); + } + _open_link () { Util.spawn(["xdg-open", this.link]); } @@ -201,9 +224,9 @@ class GEWallpaperIndicator extends panelMenu.Button { // update menu text this.refreshDueItem.label.set_text(_('Next refresh')+': '+this.refreshdue.format('%X')+' ('+Utils.friendly_time_diff(this.refreshdue)+')'); this.locationItem.label.set_text(Utils.friendly_coordinates(this.lat, this.lon)); - this.descriptionItem.label.set_text(this.explanation); - this.copyrightItem.label.set_text(this.copyright); - this.extLinkItem.label.set_text(this.provider_text); + this.descriptionItem.label.set_text(this._ifString(this.explanation)); + this.copyrightItem.label.set_text(this._ifString(this.copyright)); + this.extLinkItem.label.set_text(this._ifString(this.provider_text)); } _notifyCurrentImage() { @@ -287,6 +310,9 @@ class GEWallpaperIndicator extends panelMenu.Button { return widget; } + _ifString(check) { + return (typeof check === 'string' || check instanceof String)?check:''; + } _restartTimeout(seconds = null) { if (this._timeout) @@ -308,29 +334,50 @@ class GEWallpaperIndicator extends panelMenu.Button { this._restartTimeout(300); // in case of a timeout this.refreshDueItem.label.set_text(_('Fetching...')); + // pick random image to fetch log('locations count: '+Images.imageids.length); - // create an http message let imgindex = GLib.random_int_range(0,Images.imageids.length); + + // create an http message let url = GEjsonURL+Images.imageids[imgindex]+'.json'; log("fetching: " + url); let request = Soup.Message.new('GET', url); + request.request_headers.append('Accept', 'application/json'); // queue the http request - this.httpSession.queue_message(request, this._http_process_message.bind(this)); + if (Soup.MAJOR_VERSION >= 3) { // soup3 changes this significantly + try { + this.httpSession.send_and_read_async(request, GLib.PRIORITY_DEFAULT, null, this._http_process_message.bind(this)); + } + catch(error) { + log('unable to send libsoup json message '+error); + } + } + else { + try { + this.httpSession.queue_message(request, this._http_process_message.bind(this)); + } + catch(error) { + log('unable to send libsoup json message '+error); + } + } } _http_process_message(httpSession, message) { - if (message.status_code == 200) { - log("Datatype: "+message.response_headers.get_content_type()); - let data = message.response_body.data; + try { + let data; + if (Soup.MAJOR_VERSION >= 3) { + data = ByteArray.toString(this.httpSession.send_and_read_finish(message).get_data()); + } + else { + log("Datatype: "+message.response_headers.get_content_type()); + data = message.response_body.data; + } log("Recieved "+data.length+" bytes"); this._parseData(data); - } 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); + } + catch (error) { + log("Network error occured: "+error); this._updatePending = false; this._restartTimeout(TIMEOUT_SECONDS_ON_HTTP_ERROR); } @@ -342,13 +389,14 @@ class GEWallpaperIndicator extends panelMenu.Button { if (imagejson.id != '') { this.title = _("Google Earth Wallpaper"); let location = ""; + if ('geocode' in imagejson) { //location = imagejson.geocode.administrative_area_level_1 +', '+imagejson.geocode.country; location = Object.values(imagejson.geocode).join(", "); } else { location = [imagejson.region,imagejson.country].filter(Boolean).join(', '); } - let coordinates = Utils.friendly_coordinates(imagejson.lat,imagejson.lng); + this.explanation = location.trim(); // + '\n'+ coordinates; this.copyright = imagejson.attribution; this.lat = imagejson.lat; @@ -359,6 +407,7 @@ class GEWallpaperIndicator extends panelMenu.Button { let GEWallpaperDir = this._settings.get_string('download-folder'); let userPicturesDir = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_PICTURES); // XDG pictures directory + if (GEWallpaperDir == '') { GEWallpaperDir = userPicturesDir + "/GoogleEarthWallpaper/"; this._settings.set_string('download-folder',GEWallpaperDir); @@ -386,6 +435,7 @@ class GEWallpaperIndicator extends panelMenu.Button { this._setBackground(); this._updatePending = false; } + this._settings.set_string('image-details',[ this.explanation.replace(/\|/gm, ''), // just incase (see below) this.copyright.replace(/\|/gm, '&'), // i think copyright info uses | instead of & @@ -393,12 +443,15 @@ class GEWallpaperIndicator extends panelMenu.Button { this.lon.toString(), this.zoom.toString()].join('|')); this._settings.set_int('image-id',imagejson.id); - } else { + } + else { + log('refresh failed, no valid image returned'); this.title = _("No wallpaper available"); this.explanation = _("Something went wrong..."); this.filename = ""; this._updatePending = false; } + this._updateMenu(); this._notifyCurrentImage(); this._restartTimeout(this._settings.get_int('refresh-interval')); @@ -407,7 +460,9 @@ class GEWallpaperIndicator extends panelMenu.Button { _delete_previous(to_delete) { if (to_delete == '') return; + let deletepictures = this._settings.get_boolean('delete-previous'); + if (deletepictures) { let oldfile = Gio.file_new_for_path(to_delete); if (oldfile.query_exists(null)) { diff --git a/locale/GoogleEarthWallpaper.pot b/locale/GoogleEarthWallpaper.pot index 933a2de..66dddb9 100644 --- a/locale/GoogleEarthWallpaper.pot +++ b/locale/GoogleEarthWallpaper.pot @@ -34,7 +34,7 @@ msgstr "" msgid "Provider used to view wallpaper location and context" msgstr "" -#: ui/Settings.ui.h:10 ui/Settings4.ui.h:9 extension.js:114 +#: ui/Settings.ui.h:10 ui/Settings4.ui.h:9 extension.js:112 msgid "Set background image" msgstr "" @@ -87,7 +87,7 @@ msgid "" "photo from a selection of curated locations." msgstr "" -#: ui/Settings.ui.h:23 ui/Settings4.ui.h:23 extension.js:173 extension.js:343 +#: ui/Settings.ui.h:23 ui/Settings4.ui.h:23 extension.js:196 extension.js:387 msgid "Google Earth Wallpaper" msgstr "" @@ -107,114 +107,114 @@ msgstr "" msgid "Select how the image is rendered on desktop" msgstr "" -#: extension.js:101 +#: extension.js:97 msgid "" msgstr "" -#: extension.js:102 +#: extension.js:98 msgid "Text Location" msgstr "" -#: extension.js:103 +#: extension.js:99 msgid "Geo Location" msgstr "" -#: extension.js:104 +#: extension.js:100 msgid "External Link" msgstr "" -#: extension.js:105 +#: extension.js:101 msgid "Copyright" msgstr "" -#: extension.js:106 +#: extension.js:102 msgid "Set background image now" msgstr "" -#: extension.js:107 +#: extension.js:103 msgid "Set lockscreen image now" msgstr "" -#: extension.js:108 +#: extension.js:104 msgid "Refresh Now" msgstr "" -#: extension.js:109 +#: extension.js:105 msgid "Extension settings" msgstr "" -#: extension.js:115 +#: extension.js:113 msgid "Set lockscreen image" msgstr "" -#: extension.js:116 +#: extension.js:114 msgid "Send notification" msgstr "" -#: extension.js:143 +#: extension.js:137 msgid "On refresh:" msgstr "" -#: extension.js:202 +#: extension.js:225 msgid "Next refresh" msgstr "" -#: extension.js:254 +#: extension.js:277 msgid "View in " msgstr "" -#: extension.js:309 +#: extension.js:332 msgid "Fetching..." msgstr "" -#: extension.js:397 +#: extension.js:446 msgid "No wallpaper available" msgstr "" -#: extension.js:398 +#: extension.js:447 msgid "Something went wrong..." msgstr "" -#: prefs.js:27 +#: prefs.js:23 msgid "5 m" msgstr "" -#: prefs.js:27 +#: prefs.js:23 msgid "10 m" msgstr "" -#: prefs.js:27 +#: prefs.js:23 msgid "30 m" msgstr "" -#: prefs.js:27 +#: prefs.js:23 msgid "60 m" msgstr "" -#: prefs.js:27 +#: prefs.js:23 msgid "90 m" msgstr "" -#: prefs.js:27 +#: prefs.js:23 msgid "daily" msgstr "" -#: prefs.js:105 +#: prefs.js:112 msgid "Select folder" msgstr "" -#: utils.js:35 utils.js:38 +#: utils.js:36 utils.js:39 msgid "minutes" msgstr "" -#: utils.js:41 +#: utils.js:42 msgid "days" msgstr "" -#: utils.js:44 +#: utils.js:45 msgid "hours" msgstr "" -#: utils.js:71 -msgid "No change log found for this release" +#: utils.js:83 +msgid "Error fetching change log: " msgstr "" diff --git a/metadata.json b/metadata.json index f666abc..ae931e8 100644 --- a/metadata.json +++ b/metadata.json @@ -1,10 +1,10 @@ { "uuid": "GoogleEarthWallpaper@neffo.github.com", - "shell-version": ["3.36", "3.38", "40", "41", "42"], + "shell-version": ["3.36", "3.38", "40", "41", "42", "43"], "name": "Google Earth Wallpaper", "settings-schema": "org.gnome.shell.extensions.googleearthwallpaper", - "description": "Lightweight GNOME shell extension to sets your wallpaper to a random photo from the curated Google Earth collection (2604 photos).\n\n*Disclaimer*: this extension is unofficial and not affiliated with Google in any way. Images are protected by copyright and are licensed only for use as wallpapers.\n\nSee also my other extension, Bing Wallpaper Changer (https://github.com/neffo/bing-wallpaper-gnome-extension).\n\nFeatures:\n* Fetches a random Google Earth wallpaper and sets as both lock screen and desktop wallpaper\n* User selectable refresh intervals (default is once per day)\n* View location on Google Maps, Bing Maps, Gnome Maps, OpenStreetMaps\n* German, Dutch and Chinese translations\n\nPlease report any bugs or suggestions to extension GitHub page below.", - "version": "15", + "description": "Sets your wallpaper to a random photo from the curated Google Earth collection (2604 photos).\n\n*Disclaimer*: this extension is unofficial and not affiliated with Google in any way. Images are protected by copyright and are licensed only for use as wallpapers.\n\nSee also my other extension, Bing Wallpaper Changer (https://github.com/neffo/bing-wallpaper-gnome-extension).\n\nFeatures:\n* Fetches a random Google Earth wallpaper and sets as both lock screen and desktop wallpaper\n* User selectable refresh intervals (default is once per day)\n* View location on Google Maps, Bing Maps, Gnome Maps, OpenStreetMaps\n* German, Dutch and Chinese translations\n\nPlease report any bugs or suggestions to extension GitHub page below.", + "version": "16", "url": "https://github.com/neffo/earth-view-wallpaper-gnome-extension", "gettext-domain": "GoogleEarthWallpaper" } diff --git a/prefs.js b/prefs.js index 77432db..12de926 100644 --- a/prefs.js +++ b/prefs.js @@ -9,7 +9,7 @@ /*global imports, log*/ imports.gi.versions.Soup = '2.4'; -const {Gtk, Gio, GLib, Soup} = imports.gi; +const {Gtk, Gio, GLib, Soup, Gdk} = imports.gi; const ExtensionUtils = imports.misc.extensionUtils; const Me = ExtensionUtils.getCurrentExtension(); const Utils = Me.imports.utils; @@ -19,11 +19,6 @@ const Gettext = imports.gettext.domain('GoogleEarthWallpaper'); const _ = Gettext.gettext; const Images = Me.imports.images; -let settings; -let desktop_settings; -let httpSession = null; -let provider = new Gtk.CssProvider(); - const intervals = [ 300, 600, 1800, 3600, 4800, 86400 ]; const interval_names = [ _("5 m"), _("10 m"), _("30 m"), _("60 m"), _("90 m"), _("daily")]; @@ -36,7 +31,12 @@ function init() { ExtensionUtils.initTranslations("GoogleEarthWallpaper"); } -function buildPrefsWidget(){ +function buildPrefsWidget() { + // formerly globals + let settings; + let desktop_settings; + let httpSession = null; + let provider = new Gtk.CssProvider(); // Prepare labels and controls settings = ExtensionUtils.getSettings(Utils.schema); desktop_settings = ExtensionUtils.getSettings(Utils.DESKTOP_SCHEMA); @@ -102,6 +102,7 @@ function buildPrefsWidget(){ if (Gtk.get_major_version() == 4) { fileChooserBtn.set_label(settings.get_string('download-folder')); + fileChooserBtn.connect('clicked', function(widget) { let parent = widget.get_root(); fileChooser.set_transient_for(parent); @@ -111,6 +112,7 @@ function buildPrefsWidget(){ fileChooser.set_accept_label(_('Select folder')); fileChooser.show(); }); + fileChooser.connect('response', function(widget, response) { if (response !== Gtk.ResponseType.ACCEPT) { return; @@ -122,6 +124,7 @@ function buildPrefsWidget(){ Utils.moveImagesToNewFolder(settings, oldPath, fileURI); settings.set_string('download-folder', fileURI); }); + folderButton.connect('clicked', function() { ge_tryspawn(["xdg-open", settings.get_string('download-folder')]); log('open_background_folder '+settings.get_string('download-folder')); @@ -134,6 +137,7 @@ function buildPrefsWidget(){ fileChooser.connect('file-set', function(widget) { settings.set_string('download-folder', widget.get_filename()); }); + folderButton.connect('button-press-event', function() { ge_tryspawn(["xdg-open", settings.get_string('download-folder')]); log('open_background_folder '+settings.get_string('download-folder')); @@ -141,7 +145,6 @@ function buildPrefsWidget(){ } settings.bind('delete-previous', deleteSwitch, 'active', Gio.SettingsBindFlags.DEFAULT); - intervals.forEach(function (interval, index) { // add intervals to dropdown list (aka a GtkComboText) refreshSpin.append(interval.toString(), interval_names[index]); }); @@ -195,7 +198,7 @@ function buildPrefsWidget(){ return box; } -function validate_interval() { +function validate_interval(settings) { let interval = settings.get_string('refresh-interval'); if (interval == "" || interval.indexOf(intervals) == -1) // if not a valid interval settings.reset('refresh-interval'); @@ -204,7 +207,8 @@ function validate_interval() { function ge_tryspawn(argv) { try { GLib.spawn_async(null, argv, null, GLib.SpawnFlags.SEARCH_PATH | GLib.SpawnFlags.DO_NOT_REAP_CHILD, null); - } catch (err) { + } + catch (err) { log("Unable to open: "+argv[0]+" error: "+err); } } diff --git a/utils.js b/utils.js index 294b339..21fbb7e 100644 --- a/utils.js +++ b/utils.js @@ -13,6 +13,7 @@ const ExtensionUtils = imports.misc.extensionUtils; const Me = imports.misc.extensionUtils.getCurrentExtension(); const Gettext = imports.gettext.domain('BingWallpaper'); const _ = Gettext.gettext; +const ByteArray = imports.byteArray; var icon_list = ['pin', 'globe','official']; var icon_list_filename = ['pin-symbolic', 'globe-symbolic', 'official']; @@ -57,20 +58,30 @@ function fetch_change_log(version, label, httpSession) { // create an http message let url = gitreleaseurl + "v" + version; let request = Soup.Message.new('GET', url); - httpSession.user_agent = 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:'+version+') Google Earth Wallpaper Gnome Extension'; - log("Fetching "+url); - // queue the http request - httpSession.queue_message(request, function (httpSession, message) { - if (message.status_code == 200) { - let data = message.response_body.data; - let text = JSON.parse(data).body; - label.set_label(text); - } - else { - log("Change log not found: " + message.status_code + "\n" + message.response_body.data); - label.set_label(_("No change log found for this release") + ": " + message.status_code); - } - }); + httpSession.user_agent = 'User-Agent: Mozilla/5.0 (X11; GNOME Shell/' + imports.misc.config.PACKAGE_VERSION + '; Linux x86_64; +https://github.com/neffo/earth-view-wallpaper-gnome-extension ) Google Earth Wallpaper Gnome Extension/' + Me.metadata.version; + + // queue the http request + log("Fetching "+url); + try { + if (Soup.MAJOR_VERSION >= 3) { + httpSession.send_and_read_async(request, GLib.PRIORITY_DEFAULT, null, (httpSession, message) => { + let data = ByteArray.toString(httpSession.send_and_read_finish(message).get_data()); + let text = JSON.parse(data).body; + label.set_label(text); + }); + } + else { + httpSession.queue_message(request, (httpSession, message) => { + let data = message.response_body.data; + let text = JSON.parse(data).body; + label.set_label(text); + }); + } + } + catch (error) { + log("Error fetching change log: " + error); + label.set_label(_("Error fetching change log: "+error)); + } } function validate_icon(settings, icon_image = null) { @@ -115,7 +126,9 @@ function moveImagesToNewFolder(settings, oldPath, newPath) { log('file: ' + slash(oldPath) + filename + ' -> ' + slash(newPath) + filename); let cur = Gio.file_new_for_path(slash(oldPath) + filename); let dest = Gio.file_new_for_path(slash(newPath) + filename); - cur.move(dest, Gio.FileCopyFlags.OVERWRITE, null, function () { log ('...moved'); }); + cur.move(dest, Gio.FileCopyFlags.OVERWRITE, null, () => { + log ('...moved'); + }); } } // correct filenames for GNOME backgrounds @@ -129,7 +142,7 @@ function dirname(path) { function slash(path) { if (!path.endsWith('/')) - return path += '/'; + return path+'/'; return path; }