Skip to content

Adding create shortcut option in GNOME launcher

Tommimon requested to merge Tommimon/desktop-icons:shortcuts-support into master

New Feature Description

Currently, in gnome if you open the application launcher and right click one app you see the line 'Add to Favourites' and if you click it automatically adds the app to favourites bar.

I think would be useful the same thing but for Desktop: a new line 'Add to Desktop' that adds the app to the desktop, this can be achieved creating a copy of the original .desktop file of the app and pasting it on Desktop.

I discussed this new feature in the issue #210

Problem of this approach

As discussed in the issue with some apps the path to execute in the .desktop file contains the app version, so it changes every time you update and if you use a copy of the .desktop file your shortcut would be broken every time you update that app.

Solution

To solve this problem the shortcut maker sets the new metadata 'metadata::shortcut-of' with the original file path.

In your Desktop if you right click a file with 'metadata::shortcut-of' it is recognised as a shortcut, and a new option 'Refresh shortcut' appears.

'Refresh shortcut' recreates and replaces the shortcut using the path stored in 'metadata::shortcut-of'.

If your link broke for the previous reasons you can fix it in two clicks.

Why add this to 'Desktop Icons'?

At the beginning I thought making a separate extension but since I ended up coping 'Desktop Icons' functions as _onAllowDisallowLaunchingClicked() I think the best thing is to add this to 'Desktop Icons' and directly use those functions.

The reason is not only avoiding coping the functions but also ensure it would work if the functions of 'Desktop Icons' are changed.

shortcutManager.js

ShortcutManager

All this class does is adding and removing the new option from the app context menu

  • Checks for 'show-add-desktop' setting
  • tries to add the new option near "Add to Favorites"
  • if can't find it, add the new option on the bottom
  • disable() resets menu to the original one

ShortcutMaker

Use this class any time someone wants to make a shortcut, the same instance can create more shortcuts. makeShortcut(appPath) performs following actions:

  • Calculate copy destination
  • Copy file
  • Set 'metadata::shortcut-of' because this makes it a shortcut for us
  • Allow launching

Other files

extension.js

  • New var shortcutManagerInstance to save a ShortcutManager instance
  • Creating and enabling the instance in enable()
  • Disabling it in disable()

fileItem.js:

  • Added property _shortcutOf used to refresh the shortcut
  • Edited _onAllowDisallowLaunchingClicked() to permit setting a specific value. Using this feature when creating a shortcut
  • Added _onRefreshShortcutClicked() which recreates the shortcut using _shortcutOf
  • New option 'Refresh shortcut' in context menu calls _onRefreshShortcutClicked(), appears only if it is a shortcut.

prefs.js

  • Removed what I think was a useless ; (correct me if I'm wrong)
  • Added Switcher to trigger 'Add to desktop' feature

org.gnome.shell.extensions.desktop-icons.gschema.xml:

  • Added option to enable and disable the 'Add to desktop' feature

Translation

I tried to make my strings translatable but (since I never done it and I don't know how to test it) I don't know if I'm doing it right.

Please review all translation related things.

Merge request reports