Compare commits

...

3 Commits

Author SHA1 Message Date
Florian Müllner
3f5f4d8a44 Load app data store asynchronously 2018-07-09 17:33:37 +02:00
Florian Müllner
1f21516021 appFavorites: Remove mappings provided by AppStream
Drop any mapping that have been in AppStream long enough that we
can assume their presence. In the long term, we should be able to
remove our own mappings entirely ...

https://bugzilla.gnome.org/show_bug.cgi?id=784588
2018-07-09 17:33:37 +02:00
Florian Müllner
901a089b45 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
2018-07-09 17:32:29 +02:00

View File

@ -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;
@ -8,42 +9,16 @@ const Main = imports.ui.main;
// In alphabetical order
const RENAMED_DESKTOP_IDS = {
'baobab.desktop': 'org.gnome.baobab.desktop',
'cheese.desktop': 'org.gnome.Cheese.desktop',
'dconf-editor.desktop': 'ca.desrt.dconf-editor.desktop',
'empathy.desktop': 'org.gnome.Empathy.desktop',
'epiphany.desktop': 'org.gnome.Epiphany.desktop',
'evolution.desktop': 'org.gnome.Evolution.desktop',
'file-roller.desktop': 'org.gnome.FileRoller.desktop',
'gcalctool.desktop': 'org.gnome.Calculator.desktop',
'geary.desktop': 'org.gnome.Geary.desktop',
'gedit.desktop': 'org.gnome.gedit.desktop',
'glchess.desktop': 'gnome-chess.desktop',
'glines.desktop': 'five-or-more.desktop',
'gnect.desktop': 'four-in-a-row.desktop',
'gnibbles.desktop': 'org.gnome.Nibbles.desktop',
'gnobots2.desktop': 'gnome-robots.desktop',
'gnome-boxes.desktop': 'org.gnome.Boxes.desktop',
'gnome-calculator.desktop': 'org.gnome.Calculator.desktop',
'gnome-clocks.desktop': 'org.gnome.clocks.desktop',
'gnome-contacts.desktop': 'org.gnome.Contacts.desktop',
'gnome-documents.desktop': 'org.gnome.Documents.desktop',
'gnome-font-viewer.desktop': 'org.gnome.font-viewer.desktop',
'gnome-nibbles.desktop': 'org.gnome.Nibbles.desktop',
'gnome-music.desktop': 'org.gnome.Music.desktop',
'gnome-photos.desktop': 'org.gnome.Photos.desktop',
'gnome-screenshot.desktop': 'org.gnome.Screenshot.desktop',
'gnome-software.desktop': 'org.gnome.Software.desktop',
'gnome-terminal.desktop': 'org.gnome.Terminal.desktop',
'gnome-tweaks.desktop': 'org.gnome.tweaks.desktop',
'gnome-weather.desktop': 'org.gnome.Weather.Application.desktop',
'gnomine.desktop': 'gnome-mines.desktop',
'gnotravex.desktop': 'gnome-tetravex.desktop',
'gnotski.desktop': 'gnome-klotski.desktop',
'gtali.desktop': 'tali.desktop',
'nautilus.desktop': 'org.gnome.Nautilus.desktop',
'polari.desktop': 'org.gnome.Polari.desktop',
'totem.desktop': 'org.gnome.Totem.desktop',
};
var AppFavorites = new Lang.Class({
@ -52,6 +27,21 @@ 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._appDataReady = false;
this._appDataStore = new AppStream.Store();
this._appDataStore.load_async(loadFlags, null, (store, res) => {
try {
this._appDataReady = store.load_finish(res);
this.reload();
} catch(e) {
log('Failed to load AppData store: ' + e.message);
}
});
this._favorites = {};
global.settings.connect('changed::' + this.FAVORITE_APPS_KEY, this._onFavsChanged.bind(this));
this.reload();
@ -69,12 +59,26 @@ 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 = null;
if (this._appDataReady)
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