Skip to content

Commit f372914

Browse files
authored
Use XDG_CONFIG_HOME to primarily store spices configs in (#11182)
Code prioritizes new path but it will still fall back to old path if config file only exists there
1 parent c098674 commit f372914

File tree

6 files changed

+56
-30
lines changed

6 files changed

+56
-30
lines changed

files/usr/share/cinnamon/cinnamon-settings/bin/Spices.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424

2525
home = os.path.expanduser("~")
2626
locale_inst = '%s/.local/share/locale' % home
27-
settings_dir = '%s/.cinnamon/configs/' % home
27+
settings_dir = os.path.join(GLib.get_user_config_dir(), 'cinnamon', 'spices')
28+
old_settings_dir = '%s/.cinnamon/configs/' % home
2829

2930
URL_SPICES_HOME = "https://cinnamon-spices.linuxmint.com"
3031
URL_MAP = {
@@ -701,6 +702,8 @@ def _uninstall(self, job):
701702
# Uninstall settings file, if any
702703
if (os.path.exists(os.path.join(settings_dir, uuid))):
703704
shutil.rmtree(os.path.join(settings_dir, uuid))
705+
if (os.path.exists(os.path.join(old_settings_dir, uuid))):
706+
shutil.rmtree(os.path.join(old_settings_dir, uuid))
704707
shutil.rmtree(os.path.join(self.install_folder, uuid))
705708
except Exception as detail:
706709
self.errorMessage(_("A problem occurred while removing %s.") % job['uuid'], str(detail))

files/usr/share/cinnamon/cinnamon-settings/xlet-settings.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,18 @@
1717
import json
1818
import importlib.util
1919
import traceback
20+
from pathlib import Path
2021

2122
from JsonSettingsWidgets import *
2223
from ExtensionCore import find_extension_subdir
23-
from gi.repository import Gtk, Gio, XApp
24+
from gi.repository import Gtk, Gio, XApp, GLib
2425

2526
# i18n
2627
gettext.install("cinnamon", "/usr/share/locale")
2728

2829
home = os.path.expanduser("~")
30+
settings_dir = os.path.join(GLib.get_user_config_dir(), 'cinnamon', 'spices')
31+
old_settings_dir = '%s/.cinnamon/configs/' % home
2932

3033
translations = {}
3134

@@ -283,9 +286,12 @@ def check_sizing(widget, data=None):
283286

284287
def load_instances(self):
285288
self.instance_info = []
286-
path = "%s/.cinnamon/configs/%s" % (home, self.uuid)
289+
path = Path(os.path.join(settings_dir, self.uuid))
290+
old_path = Path("%s/.cinnamon/configs/%s" % (home, self.uuid))
287291
instances = 0
288-
dir_items = sorted(os.listdir(path))
292+
new_items = os.listdir(path) if path.exists() else []
293+
old_items = os.listdir(old_path) if old_path.exists() else []
294+
dir_items = sorted(new_items + old_items)
289295
try:
290296
multi_instance = int(self.xlet_meta["max-instances"]) != 1
291297
except (KeyError, ValueError):
@@ -317,7 +323,7 @@ def load_instances(self):
317323
if not instance_exists:
318324
continue
319325

320-
settings = JSONSettingsHandler(os.path.join(path, item), self.notify_dbus)
326+
settings = JSONSettingsHandler(os.path.join(path if item in new_items else old_path, item), self.notify_dbus)
321327
settings.instance_id = instance_id
322328
instance_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
323329
self.instance_stack.add_named(instance_box, instance_id)

js/ui/appletManager.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -346,17 +346,20 @@ function removeAppletFromPanels(appletDefinition, deleteConfig, changed = false)
346346
}
347347

348348
function _removeAppletConfigFile(uuid, instanceId) {
349-
let config_path = (GLib.get_home_dir() + "/" +
350-
".cinnamon" + "/" +
351-
"configs" + "/" +
352-
uuid + "/" +
353-
instanceId + ".json");
354-
let file = Gio.File.new_for_path(config_path);
355-
if (file.query_exists(null)) {
356-
try {
357-
file.delete(null);
358-
} catch (e) {
359-
global.logError("Problem removing applet config file during cleanup. UUID is " + uuid + " and filename is " + config_path);
349+
let config_paths = [
350+
[GLib.get_home_dir(), ".cinnamon", "configs", uuid, instanceId + ".json"].join("/"),
351+
[GLib.get_user_config_dir(), "cinnamon", "spices", uuid, instanceId + ".json"].join("/")
352+
];
353+
354+
for (let i = 0; i < config_paths.length; i++) {
355+
const config_path = array[i];
356+
let file = Gio.File.new_for_path(config_path);
357+
if (file.query_exists(null)) {
358+
try {
359+
file.delete(null);
360+
} catch (e) {
361+
global.logError("Problem removing applet config file during cleanup. UUID is " + uuid + " and filename is " + config_path);
362+
}
360363
}
361364
}
362365
}

js/ui/deskletManager.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -276,17 +276,20 @@ function _unloadDesklet(deskletDefinition, deleteConfig) {
276276
}
277277

278278
function _removeDeskletConfigFile(uuid, instanceId) {
279-
let config_path = (GLib.get_home_dir() + "/" +
280-
".cinnamon" + "/" +
281-
"configs" + "/" +
282-
uuid + "/" +
283-
instanceId + ".json");
284-
let file = Gio.File.new_for_path(config_path);
285-
if (file.query_exists(null)) {
286-
try {
287-
file.delete(null);
288-
} catch (e) {
289-
global.logError("Problem removing desklet config file during cleanup. UUID is " + uuid + " and filename is " + config_path);
279+
let config_paths = [
280+
[GLib.get_home_dir(), ".cinnamon", "configs", uuid, instanceId + ".json"].join("/"),
281+
[GLib.get_user_config_dir(), "cinnamon", "spices", uuid, instanceId + ".json"].join("/")
282+
];
283+
284+
for (let i = 0; i < config_paths.length; i++) {
285+
const config_path = array[i];
286+
let file = Gio.File.new_for_path(config_path);
287+
if (file.query_exists(null)) {
288+
try {
289+
file.delete(null);
290+
} catch (e) {
291+
global.logError("Problem removing desklet config file during cleanup. UUID is " + uuid + " and filename is " + config_path);
292+
}
290293
}
291294
}
292295
}

js/ui/settings.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,10 +689,21 @@ XletSettingsBase.prototype = {
689689
},
690690

691691
_ensureSettingsFiles: function() {
692-
let configPath = [GLib.get_home_dir(), ".cinnamon", "configs", this.uuid].join("/");
692+
let configPath = [GLib.get_user_config_dir(), "cinnamon", "spices", this.uuid].join("/");
693693
let configDir = Gio.file_new_for_path(configPath);
694694
if (!configDir.query_exists(null)) configDir.make_directory_with_parents(null);
695-
this.file = configDir.get_child(this.instanceId + ".json");
695+
696+
let configFile = configDir.get_child(this.instanceId + ".json")
697+
698+
let oldConfigDir = Gio.file_new_for_path([GLib.get_home_dir(), ".cinnamon", "configs", this.uuid].join("/"));
699+
let oldConfigFile = oldConfigDir.get_child(this.instanceId + ".json");
700+
701+
// We only use the config under the old path if it's the only one for backwards compatibility
702+
if (oldConfigFile.query_exists(null) && !configFile.query_exists(null))
703+
this.file = oldConfigFile;
704+
else
705+
this.file = configFile;
706+
696707
this.monitor = this.file.monitor_file(Gio.FileMonitorFlags.NONE, null);
697708

698709
// If the settings have already been installed previously we need to check if the schema

python3/cinnamon/harvester.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def debug(msg):
7171

7272
home = os.path.expanduser("~")
7373
locale_inst = '%s/.local/share/locale' % home
74-
settings_dir = '%s/.cinnamon/configs/' % home
74+
settings_dir = os.path.join(GLib.get_user_config_dir(), 'cinnamon', 'spices')
7575

7676
activity_logger = logger.ActivityLogger()
7777

0 commit comments

Comments
 (0)