extensionDownloader: Make checkForUpdates() check for updates
Currently the method installs updates instead of merely checking for them (or it would do, if it actually worked). This is not just surprising considering the method name, the whole idea of live updates is problematic and will not work properly more often than not: - imports are cached, so any local modules will stay at their original version until a shell restart - GTypes cannot be unregistered So change the method to only download available updates, and set the extensions' hasUpdate state accordingly. https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/945
This commit is contained in:
parent
375d1892bf
commit
9c785ca6b6
@ -1,6 +1,5 @@
|
||||
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
||||
/* exported init, installExtension, uninstallExtension,
|
||||
checkForUpdates, updateExtension */
|
||||
/* exported init, installExtension, uninstallExtension, checkForUpdates */
|
||||
|
||||
const { Clutter, Gio, GLib, GObject, Soup } = imports.gi;
|
||||
|
||||
@ -100,13 +99,9 @@ function gotExtensionZipFile(session, message, uuid, dir, callback, errback) {
|
||||
});
|
||||
}
|
||||
|
||||
function updateExtension(uuid) {
|
||||
// This gets a bit tricky. We want the update to be seamless -
|
||||
// if we have any error during downloading or extracting, we
|
||||
// want to not unload the current version.
|
||||
|
||||
let oldExtensionTmpDir = GLib.Dir.make_tmp('XXXXXX-shell-extension');
|
||||
let newExtensionTmpDir = GLib.Dir.make_tmp('XXXXXX-shell-extension');
|
||||
function downloadExtensionUpdate(uuid) {
|
||||
let dir = Gio.File.new_for_path(
|
||||
GLib.build_filenamev([global.userdatadir, 'extension-updates', uuid]));
|
||||
|
||||
let params = { shell_version: Config.PACKAGE_VERSION };
|
||||
|
||||
@ -114,39 +109,10 @@ function updateExtension(uuid) {
|
||||
let message = Soup.form_request_new_from_hash('GET', url, params);
|
||||
|
||||
_httpSession.queue_message(message, session => {
|
||||
gotExtensionZipFile(session, message, uuid, newExtensionTmpDir, () => {
|
||||
let oldExtension = Main.extensionManager.lookup(uuid);
|
||||
let extensionDir = oldExtension.dir;
|
||||
|
||||
if (!Main.extensionManager.unloadExtension(oldExtension))
|
||||
return;
|
||||
|
||||
FileUtils.recursivelyMoveDir(extensionDir, oldExtensionTmpDir);
|
||||
FileUtils.recursivelyMoveDir(newExtensionTmpDir, extensionDir);
|
||||
|
||||
let extension = null;
|
||||
|
||||
try {
|
||||
extension = Main.extensionManager.createExtensionObject(uuid, extensionDir, ExtensionUtils.ExtensionType.PER_USER);
|
||||
Main.extensionManager.loadExtension(extension);
|
||||
} catch (e) {
|
||||
if (extension)
|
||||
Main.extensionManager.unloadExtension(extension);
|
||||
|
||||
logError(e, 'Error loading extension %s'.format(uuid));
|
||||
|
||||
FileUtils.recursivelyDeleteDir(extensionDir, false);
|
||||
FileUtils.recursivelyMoveDir(oldExtensionTmpDir, extensionDir);
|
||||
|
||||
// Restore what was there before. We can't do much if we
|
||||
// fail here.
|
||||
Main.extensionManager.loadExtension(oldExtension);
|
||||
return;
|
||||
}
|
||||
|
||||
FileUtils.recursivelyDeleteDir(oldExtensionTmpDir, true);
|
||||
gotExtensionZipFile(session, message, uuid, dir, () => {
|
||||
Main.extensionManager.notifyExtensionUpdate(uuid);
|
||||
}, (code, msg) => {
|
||||
log(`Error while updating extension ${uuid}: ${code} (${msg})`);
|
||||
log(`Error while downloading update for extension ${uuid}: ${code} (${msg})`);
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -172,7 +138,7 @@ function checkForUpdates() {
|
||||
if (operation == 'blacklist')
|
||||
uninstallExtension(uuid);
|
||||
else if (operation == 'upgrade' || operation == 'downgrade')
|
||||
updateExtension(uuid);
|
||||
downloadExtensionUpdate(uuid);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user