appFavorites: Use AppStream for renamed apps if possible
The map for renamed .desktop IDs introduced in commit cceac0d8fb
has been growing ever bigger. In the meantime, a similar mapping was
added to AppStream, as well as the ability for apps to provide that
data themselves. It seems silly to duplicate those mappings, and
AppStreams provide-mechanism is clearly more flexible, so start
using it with the goal of dropping our own hard-coded mapping at
one point.
https://bugzilla.gnome.org/show_bug.cgi?id=784588
This commit is contained in:
parent
d9a1434ae9
commit
901a089b45
@ -1,5 +1,6 @@
|
||||
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
||||
|
||||
const AppStream = imports.gi.AppStreamGlib;
|
||||
const Shell = imports.gi.Shell;
|
||||
const Lang = imports.lang;
|
||||
const Signals = imports.signals;
|
||||
@ -52,6 +53,13 @@ var AppFavorites = new Lang.Class({
|
||||
FAVORITE_APPS_KEY: 'favorite-apps',
|
||||
|
||||
_init() {
|
||||
let loadFlags = AppStream.StoreLoadFlags.APP_INFO_SYSTEM |
|
||||
AppStream.StoreLoadFlags.APP_INFO_USER |
|
||||
AppStream.StoreLoadFlags.APPDATA |
|
||||
AppStream.StoreLoadFlags.DESKTOP;
|
||||
this._appDataStore = new AppStream.Store();
|
||||
this._appDataStore.load(loadFlags, null);
|
||||
|
||||
this._favorites = {};
|
||||
global.settings.connect('changed::' + this.FAVORITE_APPS_KEY, this._onFavsChanged.bind(this));
|
||||
this.reload();
|
||||
@ -69,12 +77,23 @@ var AppFavorites = new Lang.Class({
|
||||
// Map old desktop file names to the current ones
|
||||
let updated = false;
|
||||
ids = ids.map(id => {
|
||||
let newId = RENAMED_DESKTOP_IDS[id];
|
||||
let appData = this._appDataStore.get_app_by_id_with_fallbacks(id) ||
|
||||
this._appDataStore.get_app_by_provide(AppStream.ProvideKind.ID, id);
|
||||
let newId = appData != null ? appData.get_id() : undefined;
|
||||
if (newId !== undefined &&
|
||||
newId !== id &&
|
||||
appSys.lookup_app(newId) != null) {
|
||||
updated = true;
|
||||
return newId;
|
||||
}
|
||||
|
||||
newId = RENAMED_DESKTOP_IDS[id];
|
||||
if (newId !== undefined &&
|
||||
appSys.lookup_app(newId) != null) {
|
||||
updated = true;
|
||||
return newId;
|
||||
}
|
||||
|
||||
return id;
|
||||
});
|
||||
// ... and write back the updated desktop file names
|
||||
|
Loading…
Reference in New Issue
Block a user