neffo / bing-wallpaper-gnome-extension

GNOME shell extension that syncs your desktop & lock screen wallpaper to Microsoft Bing's Image of the Day.
https://extensions.gnome.org/extension/1262/bing-wallpaper-changer/
GNU General Public License v3.0
299 stars 56 forks source link

[BUG] Not compatible with GNOME 43 #181

Closed scottbeamer closed 2 years ago

scottbeamer commented 2 years ago

I'm running GNOME 43 beta. The final release is out on September 21. Could you update this extension to work with GNOME 43 at your earliest convenience? Thank you.

neffo commented 2 years ago

Similar to #180, this is breaking as GNOME 43 uses Soup 3 (for fetching www data) which is materially different from Soup 2. Thanks for reporting I am currently looking into it.

kflihan commented 2 years ago

Hi, I tried upgrading the soup code to soup-3 and its working for me now, and getting the new images from site. hope this help :)

changes to utils.js

removed this line: var BingImageURL = 'https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=8&mbl=1&mkt=';

adding those lines: var BingImageURL = 'https://www.bing.com/HPImageArchive.aspx'; var BingParams = { format: 'js', idx: '0' , n: '8' , mbl: '1' , mkt: '' } ;

===============

changes to extension.js updated both _refresh & _downloadImage :


    _refresh() {
        if (this._updatePending)
            return;
        this._updatePending = true;
        this._restartTimeout();
        let market = this._settings.get_string('market');
        // create an http message
        let session = new Soup.Session();
        let url = BingImageURL ;
        log('fetching: ' + url);

        let params = Utils.BingParams;
        params['mkt'] = ( market != 'auto' ? market : '' ) ;
        log('-----------params: ' + JSON.stringify(params));

        let message = Soup.Message.new_from_encoded_form(
            'GET',
            url  ,   
            Soup.form_encode_hash(params)
            );

        session.send_and_read_async(
            message,
            GLib.PRIORITY_DEFAULT,
            null,
            (session, result) => {
                if (message.status_code === Soup.Status.OK) {
                    let bytes = session.send_and_read_finish(result);
                    console.log(`bytes: ${bytes}`);

                    let decoder = new TextDecoder('utf-8');
                    let data = decoder.decode(bytes.get_data());

                    console.log(`data: ${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);
                }

            }
        );       

    }

_downloadImage(url, file) {
    let session = new Soup.Session();
    let message = Soup.Message.new(
        'GET',
        url     
        );  
    session.send_and_read_async(
        message,
        GLib.PRIORITY_DEFAULT,
        null,
        (session, result) =>  {
            // request completed
            this._updatePending = false;
            let bytes = session.send_and_read_finish(result);
            console.log(`bytes: ${bytes}`);
            let data = bytes.get_data();
           console.log(`status_code: ${message.status_code}`);
            if (message.status_code == 200) {
                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);
                        }
                    }
                )  ;
            } else {
            log('Couldn\'t fetch image from ' + url);
            file.delete(null);
        }
         });
}
neffo commented 2 years ago

Thanks heaps @kflihan , very helpful. I've implemented some of the above code in #177 (extension version 42). It's not quite as clean as I'm still trying to retain support for GNOME Shell versions < 43. (I also cleaned up your post to help me read it :))

neffo commented 2 years ago

Ok, I have a working version in the test branch 'version 42' now. Very fiddly... the documentation for Soup 3 doesn't reflect what works in GJS. Should be possible to push this before GNOME 43 is released.

kflihan commented 2 years ago

thanks, I'm testing 'version 42' under Fedora 37 Beta (Wayland session), I had to add support to Gnome "43.rc" to metadata.json.

kode54 commented 2 years ago

Attempted testing this on the Gnome 43 which is in the gnome-unstable Arch custom repository, but attempting to refresh the wallpaper locks up that option indefinitely, and disables all of the menu entries normally disabled while the extension is busy. I even turned on debug logging, but I don't know where it's logging to, because version 42 isn't emitting anything into the system journal.

neffo commented 2 years ago

Hmm, I can't test that myself (unless there are ISOs I can boot in a VM, but doesn't look like it). It's possible it's failing that early it's not emitting any messages itself. However GNOME itself should output errors, something like this: image

Can you post a screenshot or so I can better understand? Like what is the menu doing as well? (And thanks for the report @kode54)

kode54 commented 2 years ago
Sep 19 21:05:01 mrgency gnome-shell[1264006]: BingWallpaper extension: next check in 86400 seconds @ local time 2022-09-20 21:05 -0700
Sep 19 21:05:01 mrgency gnome-shell[1264006]: BingWallpaper extension: unable to send libsoup json message ReferenceError: message is not defined
Sep 20 00:49:20 mrgency gnome-shell[1475732]: BingWallpaper extension: next check in 86400 seconds @ local time 2022-09-21 00:49 -0700
Sep 20 00:49:20 mrgency gnome-shell[1475732]: BingWallpaper extension: unable to send libsoup json message ReferenceError: message is not defined

I also get the following if I open the Settings:

Sep 20 00:57:37 mrgency gjs[1497806]: JS WARNING: [/home/chris/.local/share/gnome-shell/extensions/BingWallpaper@ineffable-gmail.com/prefs.js 10]: Requiring Soup but it has 2 versions available; use imports.gi.versions to pick one
Sep 20 00:57:37 mrgency org.gnome.Shell.Extensions[1497806]: BingWallpaper extension: create carousel...
kode54 commented 2 years ago

Oh, I get it. You made a transposition error with the code for libsoup3, and replaced the first parameter to send_and_read_async, which should be request, with message, which is a parameter to the callback you're passing to it for response handling. Oops.

kode54 commented 2 years ago

Oh, never mind, I misread. You forgot to also declare message like the above snippet does for libsoup3.

kode54 commented 2 years ago

There we go, I got it working. Only missed two days worth of wallpapers.

neffo commented 2 years ago

FYI, if you hit the back button, you can download up to a week of Bing wallpapers (if you missed them). And thanks for PR, testing GNOME 43 is a pain as I can use VM on my desktop atm. I didn't realise I broke something.

image