2011-09-28 09:16:26 -04:00
|
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2019-01-31 09:07:06 -05:00
|
|
|
|
/* exported getAppFavorites */
|
2009-10-15 19:28:29 -04:00
|
|
|
|
|
|
|
|
|
const Shell = imports.gi.Shell;
|
2020-03-31 05:33:18 -04:00
|
|
|
|
const ParentalControlsManager = imports.misc.parentalControlsManager;
|
2009-10-15 19:28:29 -04:00
|
|
|
|
const Signals = imports.signals;
|
|
|
|
|
|
2010-02-08 17:50:50 -05:00
|
|
|
|
const Main = imports.ui.main;
|
2009-10-15 19:28:29 -04:00
|
|
|
|
|
2017-03-16 13:41:09 -04:00
|
|
|
|
// In alphabetical order
|
2014-07-22 08:16:48 -04:00
|
|
|
|
const RENAMED_DESKTOP_IDS = {
|
|
|
|
|
'baobab.desktop': 'org.gnome.baobab.desktop',
|
|
|
|
|
'cheese.desktop': 'org.gnome.Cheese.desktop',
|
|
|
|
|
'dconf-editor.desktop': 'ca.desrt.dconf-editor.desktop',
|
2017-08-30 22:14:49 -04:00
|
|
|
|
'empathy.desktop': 'org.gnome.Empathy.desktop',
|
2020-05-01 18:12:50 -04:00
|
|
|
|
'eog.desktop': 'org.gnome.eog.desktop',
|
2016-12-09 13:39:12 -05:00
|
|
|
|
'epiphany.desktop': 'org.gnome.Epiphany.desktop',
|
2018-04-10 10:38:26 -04:00
|
|
|
|
'evolution.desktop': 'org.gnome.Evolution.desktop',
|
2014-07-22 08:16:48 -04:00
|
|
|
|
'file-roller.desktop': 'org.gnome.FileRoller.desktop',
|
2019-04-11 15:48:21 -04:00
|
|
|
|
'five-or-more.desktop': 'org.gnome.five-or-more.desktop',
|
|
|
|
|
'four-in-a-row.desktop': 'org.gnome.Four-in-a-row.desktop',
|
2016-12-12 19:47:27 -05:00
|
|
|
|
'gcalctool.desktop': 'org.gnome.Calculator.desktop',
|
2016-12-02 04:52:22 -05:00
|
|
|
|
'geary.desktop': 'org.gnome.Geary.desktop',
|
2014-07-22 08:16:48 -04:00
|
|
|
|
'gedit.desktop': 'org.gnome.gedit.desktop',
|
2019-04-11 15:48:21 -04:00
|
|
|
|
'glchess.desktop': 'org.gnome.Chess.desktop',
|
|
|
|
|
'glines.desktop': 'org.gnome.five-or-more.desktop',
|
|
|
|
|
'gnect.desktop': 'org.gnome.Four-in-a-row.desktop',
|
2016-02-12 21:02:57 -05:00
|
|
|
|
'gnibbles.desktop': 'org.gnome.Nibbles.desktop',
|
2019-04-11 15:48:21 -04:00
|
|
|
|
'gnobots2.desktop': 'org.gnome.Robots.desktop',
|
2014-09-16 10:51:03 -04:00
|
|
|
|
'gnome-boxes.desktop': 'org.gnome.Boxes.desktop',
|
2016-12-12 19:47:27 -05:00
|
|
|
|
'gnome-calculator.desktop': 'org.gnome.Calculator.desktop',
|
2019-04-11 15:48:21 -04:00
|
|
|
|
'gnome-chess.desktop': 'org.gnome.Chess.desktop',
|
2017-02-06 02:40:43 -05:00
|
|
|
|
'gnome-clocks.desktop': 'org.gnome.clocks.desktop',
|
2014-08-29 07:21:58 -04:00
|
|
|
|
'gnome-contacts.desktop': 'org.gnome.Contacts.desktop',
|
2014-07-22 08:16:48 -04:00
|
|
|
|
'gnome-documents.desktop': 'org.gnome.Documents.desktop',
|
|
|
|
|
'gnome-font-viewer.desktop': 'org.gnome.font-viewer.desktop',
|
2019-04-11 15:48:21 -04:00
|
|
|
|
'gnome-klotski.desktop': 'org.gnome.Klotski.desktop',
|
2016-02-12 21:02:57 -05:00
|
|
|
|
'gnome-nibbles.desktop': 'org.gnome.Nibbles.desktop',
|
2019-01-15 10:31:13 -05:00
|
|
|
|
'gnome-mahjongg.desktop': 'org.gnome.Mahjongg.desktop',
|
2019-04-11 15:48:21 -04:00
|
|
|
|
'gnome-mines.desktop': 'org.gnome.Mines.desktop',
|
2017-03-16 13:41:09 -04:00
|
|
|
|
'gnome-music.desktop': 'org.gnome.Music.desktop',
|
2014-07-22 08:16:48 -04:00
|
|
|
|
'gnome-photos.desktop': 'org.gnome.Photos.desktop',
|
2019-04-11 15:48:21 -04:00
|
|
|
|
'gnome-robots.desktop': 'org.gnome.Robots.desktop',
|
2014-07-22 08:16:48 -04:00
|
|
|
|
'gnome-screenshot.desktop': 'org.gnome.Screenshot.desktop',
|
|
|
|
|
'gnome-software.desktop': 'org.gnome.Software.desktop',
|
2015-03-04 12:31:05 -05:00
|
|
|
|
'gnome-terminal.desktop': 'org.gnome.Terminal.desktop',
|
2019-04-11 15:48:21 -04:00
|
|
|
|
'gnome-tetravex.desktop': 'org.gnome.Tetravex.desktop',
|
2018-04-05 22:06:15 -04:00
|
|
|
|
'gnome-tweaks.desktop': 'org.gnome.tweaks.desktop',
|
2019-01-31 10:39:50 -05:00
|
|
|
|
'gnome-weather.desktop': 'org.gnome.Weather.desktop',
|
2019-04-11 15:48:21 -04:00
|
|
|
|
'gnomine.desktop': 'org.gnome.Mines.desktop',
|
|
|
|
|
'gnotravex.desktop': 'org.gnome.Tetravex.desktop',
|
|
|
|
|
'gnotski.desktop': 'org.gnome.Klotski.desktop',
|
|
|
|
|
'gtali.desktop': 'org.gnome.Tali.desktop',
|
2019-02-13 07:12:24 -05:00
|
|
|
|
'iagno.desktop': 'org.gnome.Reversi.desktop',
|
2014-07-22 08:16:48 -04:00
|
|
|
|
'nautilus.desktop': 'org.gnome.Nautilus.desktop',
|
2019-02-13 07:17:54 -05:00
|
|
|
|
'org.gnome.gnome-2048.desktop': 'org.gnome.TwentyFortyEight.desktop',
|
2019-02-13 07:23:47 -05:00
|
|
|
|
'org.gnome.taquin.desktop': 'org.gnome.Taquin.desktop',
|
2019-01-31 10:39:50 -05:00
|
|
|
|
'org.gnome.Weather.Application.desktop': 'org.gnome.Weather.desktop',
|
2014-07-22 08:16:48 -04:00
|
|
|
|
'polari.desktop': 'org.gnome.Polari.desktop',
|
2019-12-20 08:59:53 -05:00
|
|
|
|
'seahorse.desktop': 'org.gnome.seahorse.Application.desktop',
|
2019-10-18 09:28:26 -04:00
|
|
|
|
'shotwell.desktop': 'org.gnome.Shotwell.desktop',
|
2019-04-11 15:48:21 -04:00
|
|
|
|
'tali.desktop': 'org.gnome.Tali.desktop',
|
2014-08-29 07:21:58 -04:00
|
|
|
|
'totem.desktop': 'org.gnome.Totem.desktop',
|
2018-10-04 11:54:01 -04:00
|
|
|
|
'evince.desktop': 'org.gnome.Evince.desktop',
|
2014-07-22 08:16:48 -04:00
|
|
|
|
};
|
|
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
|
class AppFavorites {
|
|
|
|
|
constructor() {
|
2020-03-31 05:33:18 -04:00
|
|
|
|
// Filter the apps through the user’s parental controls.
|
|
|
|
|
this._parentalControlsManager = ParentalControlsManager.getDefault();
|
|
|
|
|
this._parentalControlsManager.connect('app-filter-changed', () => {
|
|
|
|
|
this.reload();
|
|
|
|
|
this.emit('changed');
|
|
|
|
|
});
|
|
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
|
this.FAVORITE_APPS_KEY = 'favorite-apps';
|
2009-10-15 19:28:29 -04:00
|
|
|
|
this._favorites = {};
|
2022-02-07 09:14:06 -05:00
|
|
|
|
global.settings.connect(`changed::${this.FAVORITE_APPS_KEY}`, this._onFavsChanged.bind(this));
|
2013-08-27 08:00:26 -04:00
|
|
|
|
this.reload();
|
2017-10-30 21:19:44 -04:00
|
|
|
|
}
|
2009-10-15 19:28:29 -04:00
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
|
_onFavsChanged() {
|
2013-08-27 08:00:26 -04:00
|
|
|
|
this.reload();
|
2009-10-15 19:28:29 -04:00
|
|
|
|
this.emit('changed');
|
2017-10-30 21:19:44 -04:00
|
|
|
|
}
|
2009-10-15 19:28:29 -04:00
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
|
reload() {
|
2010-05-05 17:05:42 -04:00
|
|
|
|
let ids = global.settings.get_strv(this.FAVORITE_APPS_KEY);
|
2015-03-04 13:01:32 -05:00
|
|
|
|
let appSys = Shell.AppSystem.get_default();
|
2014-07-22 08:16:48 -04:00
|
|
|
|
|
|
|
|
|
// Map old desktop file names to the current ones
|
|
|
|
|
let updated = false;
|
2017-10-30 20:38:18 -04:00
|
|
|
|
ids = ids.map(id => {
|
2014-07-22 08:16:48 -04:00
|
|
|
|
let newId = RENAMED_DESKTOP_IDS[id];
|
2015-03-04 13:01:32 -05:00
|
|
|
|
if (newId !== undefined &&
|
|
|
|
|
appSys.lookup_app(newId) != null) {
|
2014-07-22 08:16:48 -04:00
|
|
|
|
updated = true;
|
|
|
|
|
return newId;
|
|
|
|
|
}
|
|
|
|
|
return id;
|
|
|
|
|
});
|
|
|
|
|
// ... and write back the updated desktop file names
|
|
|
|
|
if (updated)
|
|
|
|
|
global.settings.set_strv(this.FAVORITE_APPS_KEY, ids);
|
|
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
|
let apps = ids.map(id => appSys.lookup_app(id))
|
2020-03-31 05:33:18 -04:00
|
|
|
|
.filter(app => app !== null && this._parentalControlsManager.shouldShowApp(app.app_info));
|
2009-10-15 19:28:29 -04:00
|
|
|
|
this._favorites = {};
|
|
|
|
|
for (let i = 0; i < apps.length; i++) {
|
|
|
|
|
let app = apps[i];
|
|
|
|
|
this._favorites[app.get_id()] = app;
|
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
|
}
|
2009-10-15 19:28:29 -04:00
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
|
_getIds() {
|
2009-10-15 19:28:29 -04:00
|
|
|
|
let ret = [];
|
|
|
|
|
for (let id in this._favorites)
|
|
|
|
|
ret.push(id);
|
|
|
|
|
return ret;
|
2017-10-30 21:19:44 -04:00
|
|
|
|
}
|
2009-10-15 19:28:29 -04:00
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
|
getFavoriteMap() {
|
2009-10-15 19:28:29 -04:00
|
|
|
|
return this._favorites;
|
2017-10-30 21:19:44 -04:00
|
|
|
|
}
|
2009-10-15 19:28:29 -04:00
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
|
getFavorites() {
|
2009-10-15 19:28:29 -04:00
|
|
|
|
let ret = [];
|
|
|
|
|
for (let id in this._favorites)
|
|
|
|
|
ret.push(this._favorites[id]);
|
|
|
|
|
return ret;
|
2017-10-30 21:19:44 -04:00
|
|
|
|
}
|
2009-10-15 19:28:29 -04:00
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
|
isFavorite(appId) {
|
2009-10-15 19:28:29 -04:00
|
|
|
|
return appId in this._favorites;
|
2017-10-30 21:19:44 -04:00
|
|
|
|
}
|
2009-10-15 19:28:29 -04:00
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
|
_addFavorite(appId, pos) {
|
2009-10-15 19:28:29 -04:00
|
|
|
|
if (appId in this._favorites)
|
2010-02-08 17:50:50 -05:00
|
|
|
|
return false;
|
|
|
|
|
|
Kill off ShellAppInfo, move into ShellApp
This dramatically thins down and sanitizes the application code.
The ShellAppSystem changes in a number of ways:
* Preferences are special cased more explicitly; they aren't apps,
they're shortcuts for an app), and we don't have many of them, so
don't need e.g. the optimizations in ShellAppSystem for searching.
* get_app() changes to lookup_app() and returns null if an app isn't
found. The semantics where it tried to find the .desktop file
if we didn't know about it were just broken; I am pretty sure no
caller needs this, and if they do we'll fix them.
* ShellAppSystem maintains two indexes on apps (by desktop file id
and by GMenuTreeEntry), but is no longer in the business of
dealing with GMenuTree as far as hierarchy and categories go. That
is moved up into js/ui/appDisplay.js. Actually, it flattens both
apps and settings.
Also, ShellWindowTracker is now the sole reference-owner for
window-backed apps. We still do the weird "window:0x1234beef" id
for these apps, but a reference is not stored in ShellAppSystem.
The js/ui/appDisplay.js code is rewritten, and sucks a lot less.
Variable names are clearer:
_apps -> _appIcons
_filterApp -> _visibleApps
_filters -> _categoryBox
Similarly for function names. We no longer call (for every app) a
recursive lookup in GMenuTree to see if it's in a particular section
on every category switch; it's all cached.
NOTE - this intentionally reverts the incremental loading code from
commit 7813c5b93f6bcde8c4beae286e82bfc472b2b656. It's fast enough
here without that.
https://bugzilla.gnome.org/show_bug.cgi?id=648149
2011-04-21 13:35:01 -04:00
|
|
|
|
let app = Shell.AppSystem.get_default().lookup_app(appId);
|
2010-02-08 17:50:50 -05:00
|
|
|
|
|
2009-10-15 19:28:29 -04:00
|
|
|
|
if (!app)
|
2010-02-08 17:50:50 -05:00
|
|
|
|
return false;
|
|
|
|
|
|
2020-03-31 05:33:18 -04:00
|
|
|
|
if (!this._parentalControlsManager.shouldShowApp(app.app_info))
|
|
|
|
|
return false;
|
|
|
|
|
|
2009-10-15 19:28:29 -04:00
|
|
|
|
let ids = this._getIds();
|
2010-11-07 20:51:02 -05:00
|
|
|
|
if (pos == -1)
|
|
|
|
|
ids.push(appId);
|
|
|
|
|
else
|
|
|
|
|
ids.splice(pos, 0, appId);
|
2010-05-05 17:05:42 -04:00
|
|
|
|
global.settings.set_strv(this.FAVORITE_APPS_KEY, ids);
|
2010-02-08 17:50:50 -05:00
|
|
|
|
return true;
|
2017-10-30 21:19:44 -04:00
|
|
|
|
}
|
2009-10-15 19:28:29 -04:00
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
|
addFavoriteAtPos(appId, pos) {
|
2010-11-07 20:51:02 -05:00
|
|
|
|
if (!this._addFavorite(appId, pos))
|
2009-10-15 19:28:29 -04:00
|
|
|
|
return;
|
2010-02-08 17:50:50 -05:00
|
|
|
|
|
Kill off ShellAppInfo, move into ShellApp
This dramatically thins down and sanitizes the application code.
The ShellAppSystem changes in a number of ways:
* Preferences are special cased more explicitly; they aren't apps,
they're shortcuts for an app), and we don't have many of them, so
don't need e.g. the optimizations in ShellAppSystem for searching.
* get_app() changes to lookup_app() and returns null if an app isn't
found. The semantics where it tried to find the .desktop file
if we didn't know about it were just broken; I am pretty sure no
caller needs this, and if they do we'll fix them.
* ShellAppSystem maintains two indexes on apps (by desktop file id
and by GMenuTreeEntry), but is no longer in the business of
dealing with GMenuTree as far as hierarchy and categories go. That
is moved up into js/ui/appDisplay.js. Actually, it flattens both
apps and settings.
Also, ShellWindowTracker is now the sole reference-owner for
window-backed apps. We still do the weird "window:0x1234beef" id
for these apps, but a reference is not stored in ShellAppSystem.
The js/ui/appDisplay.js code is rewritten, and sucks a lot less.
Variable names are clearer:
_apps -> _appIcons
_filterApp -> _visibleApps
_filters -> _categoryBox
Similarly for function names. We no longer call (for every app) a
recursive lookup in GMenuTree to see if it's in a particular section
on every category switch; it's all cached.
NOTE - this intentionally reverts the incremental loading code from
commit 7813c5b93f6bcde8c4beae286e82bfc472b2b656. It's fast enough
here without that.
https://bugzilla.gnome.org/show_bug.cgi?id=648149
2011-04-21 13:35:01 -04:00
|
|
|
|
let app = Shell.AppSystem.get_default().lookup_app(appId);
|
2010-02-08 17:50:50 -05:00
|
|
|
|
|
2022-01-29 12:07:25 -05:00
|
|
|
|
let msg = _('%s has been pinned to the dash.').format(app.get_name());
|
2019-02-12 09:02:09 -05:00
|
|
|
|
Main.overview.setMessage(msg, {
|
|
|
|
|
forFeedback: true,
|
|
|
|
|
undoCallback: () => this._removeFavorite(appId),
|
|
|
|
|
});
|
2017-10-30 21:19:44 -04:00
|
|
|
|
}
|
2010-02-08 17:50:50 -05:00
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
|
addFavorite(appId) {
|
2010-11-07 20:51:02 -05:00
|
|
|
|
this.addFavoriteAtPos(appId, -1);
|
2017-10-30 21:19:44 -04:00
|
|
|
|
}
|
2010-11-07 20:51:02 -05:00
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
|
moveFavoriteToPos(appId, pos) {
|
2010-11-07 20:51:02 -05:00
|
|
|
|
this._removeFavorite(appId);
|
|
|
|
|
this._addFavorite(appId, pos);
|
2017-10-30 21:19:44 -04:00
|
|
|
|
}
|
2010-11-07 20:51:02 -05:00
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
|
_removeFavorite(appId) {
|
2019-01-29 16:43:41 -05:00
|
|
|
|
if (!(appId in this._favorites))
|
2010-02-08 17:50:50 -05:00
|
|
|
|
return false;
|
|
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
|
let ids = this._getIds().filter(id => id != appId);
|
2010-05-05 17:05:42 -04:00
|
|
|
|
global.settings.set_strv(this.FAVORITE_APPS_KEY, ids);
|
2010-02-08 17:50:50 -05:00
|
|
|
|
return true;
|
2017-10-30 21:19:44 -04:00
|
|
|
|
}
|
2010-02-08 17:50:50 -05:00
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
|
removeFavorite(appId) {
|
2010-11-07 20:51:02 -05:00
|
|
|
|
let ids = this._getIds();
|
|
|
|
|
let pos = ids.indexOf(appId);
|
|
|
|
|
|
2010-07-13 21:32:41 -04:00
|
|
|
|
let app = this._favorites[appId];
|
2010-02-08 17:50:50 -05:00
|
|
|
|
if (!this._removeFavorite(appId))
|
|
|
|
|
return;
|
|
|
|
|
|
2022-01-29 12:07:25 -05:00
|
|
|
|
let msg = _('%s has been unpinned from the dash.').format(app.get_name());
|
2019-02-12 09:02:09 -05:00
|
|
|
|
Main.overview.setMessage(msg, {
|
|
|
|
|
forFeedback: true,
|
|
|
|
|
undoCallback: () => this._addFavorite(appId, pos),
|
|
|
|
|
});
|
2009-10-15 19:28:29 -04:00
|
|
|
|
}
|
2019-01-28 20:18:52 -05:00
|
|
|
|
}
|
2009-10-15 19:28:29 -04:00
|
|
|
|
Signals.addSignalMethods(AppFavorites.prototype);
|
|
|
|
|
|
|
|
|
|
var appFavoritesInstance = null;
|
|
|
|
|
function getAppFavorites() {
|
|
|
|
|
if (appFavoritesInstance == null)
|
|
|
|
|
appFavoritesInstance = new AppFavorites();
|
|
|
|
|
return appFavoritesInstance;
|
|
|
|
|
}
|