From 6d9003ff3d45f574cb085858764ce6e845a7f955 Mon Sep 17 00:00:00 2001 From: Jens Lody Date: Wed, 28 Dec 2022 17:43:05 +0100 Subject: [PATCH] Update for Soup3 and split from official owm on ego. Signed-off-by: Jens Lody --- Makefile.am | 2 +- configure.ac | 2 +- data/Makefile.am | 2 +- data/metadata.json.in | 2 +- src/Makefile.am | 2 +- src/extension.js | 36 ++++++++++++++++++++---------------- src/prefs.js | 35 +++++++++++++++++++++-------------- 7 files changed, 46 insertions(+), 35 deletions(-) diff --git a/Makefile.am b/Makefile.am index e5be101..f300255 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,7 +2,7 @@ ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS} SUBDIRS = src data po -uuid = "openweather-extension@jenslody.de" +uuid = "my-openweather-extension@jenslody.de" localprefix = $(HOME)/.local/share/gnome-shell/extensions diff --git a/configure.ac b/configure.ac index 5f6c315..de64ebb 100644 --- a/configure.ac +++ b/configure.ac @@ -46,7 +46,7 @@ AC_ARG_WITH([local-install], AC_SUBST(use_local_install) AM_CONDITIONAL(LOCAL_INSTALL, test "x${use_local_install}" == "xyes") -extensiontopdir=${datadir}/gnome-shell/extensions/openweather-extension@jenslody.de +extensiontopdir=${datadir}/gnome-shell/extensions/my-openweather-extension@jenslody.de dnl This is beyond ugly. Suggestions accepted. if test "x${use_local_install}" == "xyes"; then diff --git a/data/Makefile.am b/data/Makefile.am index 590e149..75b4386 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -3,7 +3,7 @@ extensionurl = https://gitlab.com/jenslody/gnome-shell-extension-openweather # Change these to modify how installation is performed topextensiondir = $(datadir)/gnome-shell/extensions -uuid = openweather-extension@jenslody.de +uuid = my-openweather-extension@jenslody.de extensiondir = $(topextensiondir)/$(uuid) diff --git a/data/metadata.json.in b/data/metadata.json.in index 6caf37c..b209830 100644 --- a/data/metadata.json.in +++ b/data/metadata.json.in @@ -2,7 +2,7 @@ "uuid": "@uuid@", "name": "OpenWeather", "description": "Weather extension to display weather information from https://openweathermap.org/ or https://darksky.net for almost all locations in the world.\nFor openweathermap.org, you can either use the extensions default-key or register at https://openweathermap.org/appid and set the appropriate switch in the preferences dialog to \"off\".\nFor Dark Sky you have to register at https://darksky.net/dev/register and get a personal API-key.\n\nSince version 29 this extensions uses coordinates to store the locations and makes the names editable to support multiple weather-providers!\nIf you update from versions prior to 29 to 29 or greater (with darksky.net - support) you have to recreate your locations.", -"shell-version": [ "40" ], +"shell-version": [ "40", "41", "42", "43" ], "localedir": "@LOCALEDIR@", "url": "@url@", "version": "@version@" diff --git a/src/Makefile.am b/src/Makefile.am index 675e37b..8070050 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,7 +1,7 @@ # Change these to modify how installation is performed topextensiondir = $(datadir)/gnome-shell/extensions -uuid = openweather-extension@jenslody.de +uuid = my-openweather-extension@jenslody.de extensiondir = $(topextensiondir)/$(uuid) diff --git a/src/extension.js b/src/extension.js index 4c9b21b..29b98a9 100644 --- a/src/extension.js +++ b/src/extension.js @@ -45,7 +45,7 @@ const OpenweathermapOrg = Me.imports.openweathermap_org; const { Clutter, Gio, Gtk, GLib, GObject, Soup, St } = imports.gi; - +const ByteArray = imports.byteArray; const Gettext = imports.gettext.domain('gnome-shell-extension-openweather'); const Lang = imports.lang; @@ -965,14 +965,10 @@ class OpenweatherMenuButton extends PanelMenu.Button { _onPreferencesActivate() { this.menu.actor.hide(); - if (typeof ExtensionUtils.openPrefs === 'function') { - ExtensionUtils.openPrefs(); - } else { - Util.spawn([ - "gnome-shell-extension-prefs", - Me.uuid - ]); - } + Util.spawn([ + "gnome-shell-extension-prefs", + Me.uuid + ]); return 0; } @@ -1119,22 +1115,30 @@ class OpenweatherMenuButton extends PanelMenu.Button { // abort previous requests. _httpSession.abort(); } + let _paramsHash = Soup.form_encode_hash(params); + let _message = Soup.Message.new_from_encoded_form('GET', url, _paramsHash); - let message = Soup.form_request_new_from_hash('GET', url, params); + _httpSession.send_and_read_async(_message, GLib.PRIORITY_DEFAULT, null, (_httpSession, _message) => { - _httpSession.queue_message(message, Lang.bind(this, function(_httpSession, message) { + let _jsonString = _httpSession.send_and_read_finish(_message).get_data(); + if (_jsonString instanceof Uint8Array) { + _jsonString = ByteArray.toString(_jsonString); + } try { - if (!message.response_body.data) { + if (!_jsonString) { fun.call(this, 0); return; } - let jp = JSON.parse(message.response_body.data); + let jp = JSON.parse(_jsonString); fun.call(this, jp); - } catch (e) { + return 0; + } + catch (e) { + _httpSession.abort(); fun.call(this, 0); - return; + return 0; } - })); + }); return; } diff --git a/src/prefs.js b/src/prefs.js index c710300..57b58ab 100644 --- a/src/prefs.js +++ b/src/prefs.js @@ -29,12 +29,13 @@ * . * */ -const Gtk = imports.gi.Gtk; -const Gdk = imports.gi.Gdk; -const GObject = imports.gi.GObject; +const { + Gtk, Gdk, GLib, GObject, Soup +} = imports.gi; +const ByteArray = imports.byteArray; + const Gettext = imports.gettext.domain('gnome-shell-extension-openweather'); const _ = Gettext.gettext; -const Soup = imports.gi.Soup; const Lang = imports.lang; const Mainloop = imports.mainloop; @@ -667,7 +668,8 @@ const WeatherPrefsWidget = new GObject.Class({ let here = this; - let message = Soup.form_request_new_from_hash('GET', url, params); + let _paramsHash = Soup.form_encode_hash(params); + let _message = Soup.Message.new_from_encoded_form('GET', url, _paramsHash); if (this.asyncSession === undefined) this.asyncSession = {}; @@ -678,21 +680,26 @@ const WeatherPrefsWidget = new GObject.Class({ } this.asyncSession[id] = 1; - _httpSession.queue_message(message, function(_httpSession, message) { - here.asyncSession[id] = 0; - if (!message.response_body.data) { - fun.call(here, 0); - return 0; + _httpSession.send_and_read_async(_message, GLib.PRIORITY_DEFAULT, null, (_httpSession, _message) => { + let _jsonString = _httpSession.send_and_read_finish(_message).get_data(); + if (_jsonString instanceof Uint8Array) { + _jsonString = ByteArray.toString(_jsonString); } - + here.asyncSession[id] = 0; try { - let jp = JSON.parse(message.response_body.data); + if (!_jsonString) { + fun.call(here, 0); + return; + } + let jp = JSON.parse(_jsonString); fun.call(here, jp); - } catch (e) { + return 0; + } + catch (e) { + _httpSession.abort(); fun.call(here, 0); return 0; } - return 0; }); },