[gnome-shell/wip/fmuellner/appstream-mappings: 3155/3156] appFavorites: Use AppStream for renamed apps if possible
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/wip/fmuellner/appstream-mappings: 3155/3156] appFavorites: Use AppStream for renamed apps if possible
- Date: Fri, 20 Nov 2020 15:23:37 +0000 (UTC)
commit 0b24529d96a0818796d89c637c0664768a26e139
Author: Florian Müllner <fmuellner gnome org>
Date: Wed Jul 5 23:50:05 2017 +0200
appFavorites: Use AppStream for renamed apps if possible
The map for renamed .desktop IDs introduced in commit cceac0d8fbce
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
AppStream's provide-mechanism is clearly more flexible, so use it
to replace our own hard-coded mapping.
js/ui/appFavorites.js | 89 ++++++++++++++++++---------------------------------
1 file changed, 31 insertions(+), 58 deletions(-)
---
diff --git a/js/ui/appFavorites.js b/js/ui/appFavorites.js
index a876727eda..008eaa6fd7 100644
--- a/js/ui/appFavorites.js
+++ b/js/ui/appFavorites.js
@@ -1,71 +1,23 @@
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
/* exported getAppFavorites */
+const AppStream = imports.gi.AppStreamGlib;
+const Gio = imports.gi.Gio;
const Shell = imports.gi.Shell;
const ParentalControlsManager = imports.misc.parentalControlsManager;
const Signals = imports.signals;
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',
- 'eog.desktop': 'org.gnome.eog.desktop',
- 'epiphany.desktop': 'org.gnome.Epiphany.desktop',
- 'evolution.desktop': 'org.gnome.Evolution.desktop',
- 'file-roller.desktop': 'org.gnome.FileRoller.desktop',
- 'five-or-more.desktop': 'org.gnome.five-or-more.desktop',
- 'four-in-a-row.desktop': 'org.gnome.Four-in-a-row.desktop',
- 'gcalctool.desktop': 'org.gnome.Calculator.desktop',
- 'geary.desktop': 'org.gnome.Geary.desktop',
- 'gedit.desktop': 'org.gnome.gedit.desktop',
- 'glchess.desktop': 'org.gnome.Chess.desktop',
- 'glines.desktop': 'org.gnome.five-or-more.desktop',
- 'gnect.desktop': 'org.gnome.Four-in-a-row.desktop',
- 'gnibbles.desktop': 'org.gnome.Nibbles.desktop',
- 'gnobots2.desktop': 'org.gnome.Robots.desktop',
- 'gnome-boxes.desktop': 'org.gnome.Boxes.desktop',
- 'gnome-calculator.desktop': 'org.gnome.Calculator.desktop',
- 'gnome-chess.desktop': 'org.gnome.Chess.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-klotski.desktop': 'org.gnome.Klotski.desktop',
- 'gnome-nibbles.desktop': 'org.gnome.Nibbles.desktop',
- 'gnome-mahjongg.desktop': 'org.gnome.Mahjongg.desktop',
- 'gnome-mines.desktop': 'org.gnome.Mines.desktop',
- 'gnome-music.desktop': 'org.gnome.Music.desktop',
- 'gnome-photos.desktop': 'org.gnome.Photos.desktop',
- 'gnome-robots.desktop': 'org.gnome.Robots.desktop',
- 'gnome-screenshot.desktop': 'org.gnome.Screenshot.desktop',
- 'gnome-software.desktop': 'org.gnome.Software.desktop',
- 'gnome-terminal.desktop': 'org.gnome.Terminal.desktop',
- 'gnome-tetravex.desktop': 'org.gnome.Tetravex.desktop',
- 'gnome-tweaks.desktop': 'org.gnome.tweaks.desktop',
- 'gnome-weather.desktop': 'org.gnome.Weather.desktop',
- 'gnomine.desktop': 'org.gnome.Mines.desktop',
- 'gnotravex.desktop': 'org.gnome.Tetravex.desktop',
- 'gnotski.desktop': 'org.gnome.Klotski.desktop',
- 'gtali.desktop': 'org.gnome.Tali.desktop',
- 'iagno.desktop': 'org.gnome.Reversi.desktop',
- 'nautilus.desktop': 'org.gnome.Nautilus.desktop',
- 'org.gnome.gnome-2048.desktop': 'org.gnome.TwentyFortyEight.desktop',
- 'org.gnome.taquin.desktop': 'org.gnome.Taquin.desktop',
- 'org.gnome.Weather.Application.desktop': 'org.gnome.Weather.desktop',
- 'polari.desktop': 'org.gnome.Polari.desktop',
- 'seahorse.desktop': 'org.gnome.seahorse.Application.desktop',
- 'shotwell.desktop': 'org.gnome.Shotwell.desktop',
- 'tali.desktop': 'org.gnome.Tali.desktop',
- 'totem.desktop': 'org.gnome.Totem.desktop',
- 'evince.desktop': 'org.gnome.Evince.desktop',
-};
+Gio._promisify(AppStream.Store.prototype, 'load_async', 'load_finish');
class AppFavorites {
constructor() {
+ this._appDataStore = new AppStream.Store();
+ this._appDataStore.connect('changed',
+ () => this.reload());
+ this._loadAppDataStore();
+
// Filter the apps through the user’s parental controls.
this._parentalControlsManager = ParentalControlsManager.getDefault();
this._parentalControlsManager.connect('app-filter-changed', () => {
@@ -84,6 +36,22 @@ class AppFavorites {
this.emit('changed');
}
+ async _loadAppDataStore() {
+ try {
+ const loadFlags =
+ AppStream.StoreLoadFlags.APP_INFO_SYSTEM |
+ AppStream.StoreLoadFlags.APP_INFO_USER |
+ AppStream.StoreLoadFlags.FLATPAK_SYSTEM |
+ AppStream.StoreLoadFlags.FLATPAK_USER |
+ AppStream.StoreLoadFlags.APPDATA |
+ AppStream.StoreLoadFlags.DESKTOP;
+ // emits ::changed when successful
+ await this._appDataStore.load_async(loadFlags, null);
+ } catch (e) {
+ log(`Failed to load AppData store: ${e.message}`);
+ }
+ }
+
reload() {
let ids = global.settings.get_strv(this.FAVORITE_APPS_KEY);
let appSys = Shell.AppSystem.get_default();
@@ -91,9 +59,14 @@ class AppFavorites {
// Map old desktop file names to the current ones
let updated = false;
ids = ids.map(id => {
- let newId = RENAMED_DESKTOP_IDS[id];
+ const appData =
+ this._appDataStore.get_app_by_id_with_fallbacks(id) ||
+ this._appDataStore.get_app_by_provide(AppStream.ProvideKind.ID, id);
+
+ const newId = appData?.get_id();
if (newId !== undefined &&
- appSys.lookup_app(newId) != null) {
+ newId !== id &&
+ appSys.lookup_app(newId) !== null) {
updated = true;
return newId;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]