Skip to content

Commit 844493a

Browse files
authored
fix: use XDG_DATA_HOME to store custom launchers, also fix launcher desklet (#11185)
Changes: * use XDG_DATA_HOME/cinnamon/panel-launchers folder to save launcher configs, with a fallback to the old path in .cinnamon * Remove launcher desklet's right click->Add new launcher because it is broken and new instances can be added from the desklets settings anyway * Make sure associated custom launchers are removed when the desklet is removed * When adding a custom launcher for the desklet name is not needed (it's greyed out) but without it it cannot be added. Fixed
1 parent f372914 commit 844493a

File tree

4 files changed

+52
-29
lines changed

4 files changed

+52
-29
lines changed

files/usr/share/cinnamon/applets/[email protected]/applet.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ const SignalManager = imports.misc.signalManager;
2020
const PANEL_EDIT_MODE_KEY = 'panel-edit-mode';
2121
const PANEL_LAUNCHERS_KEY = 'panel-launchers';
2222

23-
const CUSTOM_LAUNCHERS_PATH = GLib.get_home_dir() + '/.cinnamon/panel-launchers';
23+
const CUSTOM_LAUNCHERS_PATH = GLib.get_user_data_dir() + "/cinnamon/panel-launchers/";
24+
const OLD_CUSTOM_LAUNCHERS_PATH = GLib.get_home_dir() + '/.cinnamon/panel-launchers/';
2425

2526
let pressLauncher = null;
2627

@@ -578,7 +579,11 @@ class CinnamonPanelLaunchersApplet extends Applet.Applet {
578579
let app = appSys.lookup_app(path);
579580
let appinfo = null;
580581
if (!app) {
581-
appinfo = CMenu.DesktopAppInfo.new_from_filename(CUSTOM_LAUNCHERS_PATH+"/"+path);
582+
appinfo = CMenu.DesktopAppInfo.new_from_filename(CUSTOM_LAUNCHERS_PATH + path);
583+
// Fallback to old launcher folder
584+
if (!appinfo) {
585+
appinfo = CMenu.DesktopAppInfo.new_from_filename(OLD_CUSTOM_LAUNCHERS_PATH + path);
586+
}
582587
if (!appinfo) {
583588
global.logWarning(`Failed to add launcher from path: ${path}`);
584589
return null;
@@ -641,8 +646,10 @@ class CinnamonPanelLaunchersApplet extends Applet.Applet {
641646
}
642647
if (delete_file) {
643648
let appid = launcher.getId();
644-
let file = Gio.file_new_for_path(CUSTOM_LAUNCHERS_PATH+"/"+appid);
649+
let file = Gio.file_new_for_path(CUSTOM_LAUNCHERS_PATH + appid);
645650
if (file.query_exists(null)) file.delete(null);
651+
let old_file = Gio.file_new_for_path(OLD_CUSTOM_LAUNCHERS_PATH + appid);
652+
if (old_file.query_exists(null)) old_file.delete(null);
646653
}
647654

648655
this.sync_settings_proxy_to_settings();

files/usr/share/cinnamon/cinnamon-desktop-editor/cinnamon-desktop-editor.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626

2727
#_ = gettext.gettext # bug !!! _ is already defined by gettext.install!
2828
home = os.path.expanduser("~")
29-
PANEL_LAUNCHER_PATH = os.path.join(home, ".cinnamon", "panel-launchers")
29+
PANEL_LAUNCHER_PATH = os.path.join(GLib.get_user_data_dir(), "cinnamon", "panel-launchers")
30+
OLD_PANEL_LAUNCHER_PATH = os.path.join(home, ".cinnamon", "panel-launchers")
3031

3132
EXTENSIONS = (".png", ".xpm", ".svg")
3233

@@ -270,8 +271,10 @@ def check_custom_path(self):
270271
i = 1
271272
while True:
272273
name = os.path.join(PANEL_LAUNCHER_PATH, 'cinnamon-custom-launcher-' + str(i) + '.desktop')
274+
old_name = os.path.join(OLD_PANEL_LAUNCHER_PATH, 'cinnamon-custom-launcher-' + str(i) + '.desktop')
273275
file = Gio.file_parse_name(name)
274-
if not file.query_exists(None):
276+
old_file = Gio.file_parse_name(old_name)
277+
if not file.query_exists(None) and not old_file.query_exists(None):
275278
break
276279
i += 1
277280
self.item_path = name
@@ -395,7 +398,8 @@ def get_desktop_path(self):
395398
self.search_menu_sys()
396399
if self.orig_file is None:
397400
panel_launchers = glob.glob(os.path.join(PANEL_LAUNCHER_PATH, "*.desktop"))
398-
for launcher in panel_launchers:
401+
old_panel_launchers = glob.glob(os.path.join(OLD_PANEL_LAUNCHER_PATH, "*.desktop"))
402+
for launcher in (panel_launchers + old_panel_launchers):
399403
if os.path.split(launcher)[1] == self.desktop_file:
400404
self.orig_file = launcher
401405

files/usr/share/cinnamon/desklets/[email protected]/desklet.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ const Desklet = imports.ui.desklet;
1111
const PopupMenu = imports.ui.popupMenu;
1212
const Util = imports.misc.util;
1313

14-
const CUSTOM_LAUNCHERS_PATH = GLib.get_home_dir() + '/.cinnamon/panel-launchers/';
14+
const CUSTOM_LAUNCHERS_PATH = GLib.get_user_data_dir() + "/cinnamon/panel-launchers/";
15+
const OLD_CUSTOM_LAUNCHERS_PATH = GLib.get_home_dir() + '/.cinnamon/panel-launchers/';
1516

1617
const ICON_SIZE = 48;
1718
const ANIM_ICON_SIZE = 40;
@@ -25,9 +26,6 @@ class CinnamonLauncherDesklet extends Desklet.Desklet {
2526
this._removing = false;
2627

2728
this._menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
28-
this._menu.addAction(_('Add new launcher'), function() {
29-
Util.spawnCommandLine('/usr/share/cinnamon/desklets/[email protected]/editorDialog.py');
30-
});
3129
this._menu.addAction(
3230
_('Edit launcher'),
3331
Lang.bind(this, function() {
@@ -51,6 +49,10 @@ class CinnamonLauncherDesklet extends Desklet.Desklet {
5149
if (!app) {
5250
app = CMenu.DesktopAppInfo.new_from_filename(CUSTOM_LAUNCHERS_PATH + desktopFile);
5351
}
52+
// Fallback to old launcher folder
53+
if (!app) {
54+
app = CMenu.DesktopAppInfo.new_from_filename(OLD_CUSTOM_LAUNCHERS_PATH + desktopFile);
55+
}
5456
return app;
5557
}
5658
}
@@ -84,8 +86,15 @@ class CinnamonLauncherDesklet extends Desklet.Desklet {
8486
}
8587
}
8688
if (found) {
87-
settingsList.splice(i, 1);
89+
let item = settingsList.splice(i, 1);
8890
this._launcherSettings.set_strv('launcher-list', settingsList);
91+
92+
// We try to remove custom launchers if they exist
93+
let fileName = item[0].split(':')[1];
94+
let file = Gio.file_new_for_path(CUSTOM_LAUNCHERS_PATH + fileName);
95+
if (file.query_exists(null)) file.delete(null);
96+
let old_file = Gio.file_new_for_path(OLD_CUSTOM_LAUNCHERS_PATH + fileName);
97+
if (old_file.query_exists(null)) old_file.delete(null);
8998
}
9099

91100
this._launcherSettings.disconnect(this._settingsSignalId);

files/usr/share/cinnamon/desklets/[email protected]/editorDialog.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66

77
import gi
88
gi.require_version('Gtk', '3.0')
9-
from gi.repository import Gtk, Gio
9+
from gi.repository import Gtk, Gio, GLib
1010

1111
SCHEMAS = "org.cinnamon.desklets.launcher"
1212
LAUNCHER_KEY = "launcher-list"
1313

1414
HOME_DIR = os.path.expanduser("~")+"/"
15-
CUSTOM_LAUNCHERS_PATH = HOME_DIR + ".cinnamon/panel-launchers/"
15+
CUSTOM_LAUNCHERS_PATH = os.path.join(GLib.get_user_data_dir(), "cinnamon", "panel-launchers")
16+
OLD_CUSTOM_LAUNCHERS_PATH = HOME_DIR + ".cinnamon/panel-launchers/"
1617
EDITOR_DIALOG_UI_PATH = "/usr/share/cinnamon/desklets/[email protected]/editorDialog.ui"
1718

1819
class EditorDialog:
@@ -110,10 +111,9 @@ def on_edit_close_clicked(self, widget):
110111
self.dialog.destroy()
111112

112113
def on_edit_ok_clicked(self, widget):
113-
if not self.name_entry.get_text():
114-
return None
115-
116114
if (self.launcher_type == "Application"):
115+
if not self.name_entry.get_text():
116+
return None
117117
launcher_name = self.name_entry.get_text() + ".desktop"
118118
elif (self.launcher_type == "Custom Application"):
119119
launcher_name = self.write_custom_application()
@@ -144,24 +144,23 @@ def on_edit_ok_clicked(self, widget):
144144

145145
self.dialog.destroy()
146146

147-
def get_custom_id(self):
148-
i = 1
147+
def get_custom_path(self):
149148
directory = Gio.file_new_for_path(CUSTOM_LAUNCHERS_PATH)
150149
if not directory.query_exists(None):
151150
directory.make_directory_with_parents(None)
152151

153-
fileRec = Gio.file_parse_name(CUSTOM_LAUNCHERS_PATH + 'cinnamon-custom-launcher-' + str(i) + '.desktop')
154-
while fileRec.query_exists(None):
155-
i = i + 1
156-
fileRec = Gio.file_parse_name(CUSTOM_LAUNCHERS_PATH + 'cinnamon-custom-launcher-' + str(i) + '.desktop')
152+
i = 1
153+
while True:
154+
name = 'cinnamon-custom-launcher-' + str(i) + '.desktop'
155+
path = os.path.join(CUSTOM_LAUNCHERS_PATH, name)
156+
oldPath = os.path.join(OLD_CUSTOM_LAUNCHERS_PATH, name)
157+
if not os.path.exists(path) and not os.path.exists(oldPath):
158+
return (name, path)
157159

158-
return i
160+
i = i + 1
159161

160162
def write_custom_application(self):
161-
i = self.get_custom_id()
162-
163-
file_name = "cinnamon-custom-launcher-" + str(i) + ".desktop"
164-
file_path = CUSTOM_LAUNCHERS_PATH + file_name
163+
file_name, file_path = self.get_custom_path()
165164

166165
title = self.title_entry.get_text()
167166
command = self.command_entry.get_text()
@@ -184,8 +183,12 @@ def __init__(self, file_name):
184183
self.title = None
185184
self.command = None
186185

187-
if (os.path.exists(CUSTOM_LAUNCHERS_PATH + file_name)):
188-
self._path = CUSTOM_LAUNCHERS_PATH + file_name
186+
custom_path = os.path.join(CUSTOM_LAUNCHERS_PATH, file_name)
187+
old_custom_path = os.path.join(OLD_CUSTOM_LAUNCHERS_PATH, file_name)
188+
if (os.path.exists(custom_path)):
189+
self._path = custom_path
190+
elif (os.path.exists(old_custom_path)):
191+
self._path = old_custom_path
189192
elif (os.path.exists("/usr/share/applications/" + file_name)):
190193
self._path = "/usr/share/applications/" + file_name
191194

0 commit comments

Comments
 (0)