Skip to content

Commit

Permalink
Port to GNOME 45
Browse files Browse the repository at this point in the history
  • Loading branch information
Tommimon committed Sep 26, 2023
1 parent 7934518 commit b62d110
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 35 deletions.
32 changes: 16 additions & 16 deletions extension.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const ShortcutMaker = Me.imports.shortcutMaker;
const AppDisplay = imports.ui.appDisplay;
const GObject = imports.gi.GObject;
import * as ShortcutMaker from './shortcutMaker.js';
import * as AppDisplay from 'resource:///org/gnome/shell/ui/appDisplay.js';
import GObject from 'gi://GObject';
import {Extension} from 'resource:///org/gnome/shell/extensions/extension.js';

// Saves the standard Menu globally to be able to reset it on disable
var oldPopupMenu = null;

function init () {

}
export default class AddToDesktop extends Extension {
init () {
}

function enable () {
if (GObject.type_from_name("Gjs_add-to-desktop_tommimon_github_com_shortcutMaker_CustomIcon") == null) {
oldPopupMenu = AppDisplay.AppIcon.prototype.popupMenu;
ShortcutMaker.editIconClass(oldPopupMenu);
enable () {
if (GObject.type_from_name("Gjs_add-to-desktop_tommimon_github_com_shortcutMaker_CustomIcon") == null) {
oldPopupMenu = AppDisplay.AppIcon.prototype.popupMenu;
ShortcutMaker.editIconClass(oldPopupMenu);
}
}
}

function disable () {
// Reset the menu to the standard one (without new item)
AppDisplay.AppIcon.prototype.popupMenu = oldPopupMenu;
disable () {
// Reset the menu to the standard one (without new item)
AppDisplay.AppIcon.prototype.popupMenu = oldPopupMenu;
}
}
5 changes: 2 additions & 3 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
"description": "An easy way to create desktop app shortcut in gnome",
"name": "Add to Desktop",
"shell-version": [
"42",
"43",
"44"
"45"
],
"url": "https://github.com/Tommimon/add-to-desktop",
"uuid": "add-to-desktop@tommimon.github.com",
"gettext-domain": "add-to-desktop",
"version": 10
}
27 changes: 11 additions & 16 deletions shortcutMaker.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const { Gio, GLib, St, GObject } = imports.gi;
const AppDisplay = imports.ui.appDisplay;
const PopupMenu = imports.ui.popupMenu;
const Gettext = imports.gettext;
const Config = imports.misc.config;
Gettext.textdomain(Config.GETTEXT_PACKAGE); // use 'gnome-shell' as default domain
import Gio from 'gi://Gio';
import GLib from 'gi://GLib';
import St from 'gi://St';
import GObject from 'gi://GObject';
import * as AppDisplay from 'resource:///org/gnome/shell/ui/appDisplay.js';
import * as PopupMenu from 'resource:///org/gnome/shell/ui/popupMenu.js';
import Gettext from 'gettext';
const shell_gettext = Gettext.gettext;
Gettext.bindtextdomain( 'add-to-desktop', Me.dir.get_child('locale').get_path());
import {gettext as _} from 'resource:///org/gnome/shell/extensions/extension.js';

var DEFAULT_AND_UEXEC = 0o00764;

function _(stringIn) {
return Gettext.dgettext('add-to-desktop', stringIn)
}

// edit the icon popupMenu method to add the new item
function editIconClass(oldPopupMenu) {
export function editIconClass(oldPopupMenu) {
AppDisplay.AppIcon.prototype._preAddToDesktopPopupMenu = oldPopupMenu;
AppDisplay.AppIcon.prototype.popupMenu = function(side = St.Side.LEFT) {
let firstCall = !this._menu; // if _menu is not defined is the first call to this function
Expand All @@ -29,7 +24,7 @@ function editIconClass(oldPopupMenu) {
}

function insertAddToDesktopButton(menu) {
let nameArray = ['Add to Favorites', 'Remove from Favorites', 'Pin to Dash', 'Unpin'];
let nameArray = ['Pin to Dash', 'Unpin'];
nameArray.forEach(name => {
nameArray.push(shell_gettext(name)); // look for both english and translated
});
Expand All @@ -47,7 +42,7 @@ function insertAddToDesktopButton(menu) {
}

let label = _('Add to Desktop');
item = new PopupMenu.PopupMenuItem(label);
let item = new PopupMenu.PopupMenuItem(label);
if (pos === -1) {
menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
menu.addMenuItem(item); // add at the end
Expand Down

0 comments on commit b62d110

Please sign in to comment.