Theming/Emacs: adjust search logic (fixes #1543)

This commit is contained in:
Lysec
2026-01-25 11:20:49 +01:00
parent 69414b818c
commit 4352b65da6
3 changed files with 89 additions and 27 deletions
+65 -1
View File
@@ -34,6 +34,9 @@ Singleton {
// Code client auto-detection
property var availableCodeClients: []
// Emacs client auto-detection
property var availableEmacsClients: []
// Signal emitted when all checks are complete
signal checksCompleted
@@ -181,6 +184,66 @@ Singleton {
stderr: StdioCollector {}
}
// Function to detect Emacs client by checking config directories
function detectEmacsClient() {
// Build shell script to check each client
var scriptParts = ["available_clients=\"\";"];
for (var i = 0; i < TemplateRegistry.emacsClients.length; i++) {
var client = TemplateRegistry.emacsClients[i];
var clientName = client.name;
var configPath = client.path;
// Check if the config directory exists
scriptParts.push("if [ -d \"$HOME" + configPath.substring(1) + "\" ]; then available_clients=\"$available_clients " + clientName + "\"; fi;");
}
scriptParts.push("echo \"$available_clients\"");
// Use a Process to check directory existence for all clients
emacsDetector.command = ["sh", "-c", scriptParts.join(" ")];
emacsDetector.running = true;
}
// Process to detect Emacs client directories
Process {
id: emacsDetector
running: false
onExited: function (exitCode) {
availableEmacsClients = [];
if (exitCode === 0) {
var detectedClients = stdout.text.trim().split(/\s+/).filter(function (client) {
return client.length > 0;
});
if (detectedClients.length > 0) {
// Build list of available clients
for (var i = 0; i < detectedClients.length; i++) {
var clientName = detectedClients[i];
for (var j = 0; j < TemplateRegistry.emacsClients.length; j++) {
var client = TemplateRegistry.emacsClients[j];
if (client.name === clientName) {
availableEmacsClients.push(client);
break;
}
}
}
Logger.d("ProgramChecker", "Detected Emacs clients:", detectedClients.join(", "));
}
}
if (availableEmacsClients.length === 0) {
Logger.d("ProgramChecker", "No Emacs clients detected");
}
}
stdout: StdioCollector {}
stderr: StdioCollector {}
}
// Internal tracking
property int completedChecks: 0
property int totalChecks: Object.keys(programsToCheck).length
@@ -204,9 +267,10 @@ Singleton {
// Check next program or emit completion signal
if (root.completedChecks >= root.totalChecks) {
// Run Discord and Code client detection after all checks are complete
// Run Discord, Code and Emacs client detection after all checks are complete
root.detectDiscordClient();
root.detectCodeClient();
root.detectEmacsClient();
root.checksCompleted();
} else {
root.checkNextProgram();
+7 -16
View File
@@ -253,23 +253,14 @@ Singleton {
}
});
}
} else if (app.id === "emacs" && app.checkDoomFirst) {
} else if (app.id === "emacs") {
if (isTemplateEnabled("emacs")) {
const doomPathTemplate = app.outputs[0].path; // ~/.config/doom/themes/noctalia-theme.el
const standardPathTemplate = app.outputs[1].path; // ~/.emacs.d/themes/noctalia-theme.el
const doomPath = doomPathTemplate.replace("~", homeDir);
const standardPath = standardPathTemplate.replace("~", homeDir);
const doomConfigDir = `${homeDir}/.config/doom`;
const doomDir = doomPath.substring(0, doomPath.lastIndexOf('/'));
lines.push(`\n[templates.emacs]`);
lines.push(`input_path = "${Quickshell.shellDir}/Assets/Templates/${app.input}"`);
lines.push(`output_path = "${standardPath}"`);
// Move to doom if doom exists, then remove empty .emacs.d/themes and .emacs.d directories
// Check directories are empty before removing
const postHook = `sh -c 'if [ -d "${doomConfigDir}" ] && [ -f "${standardPath}" ]; then mkdir -p "${doomDir}" && mv "${standardPath}" "${doomPath}" && rmdir "${homeDir}/.emacs.d/themes" 2>/dev/null && rmdir "${homeDir}/.emacs.d" 2>/dev/null || true; fi'`;
const postHookEsc = escapeTomlString(postHook);
lines.push(`post_hook = "${postHookEsc}"`);
ProgramCheckerService.availableEmacsClients.forEach(client => {
lines.push(`\n[templates.emacs_${client.name}]`);
lines.push(`input_path = "${Quickshell.shellDir}/Assets/Templates/${app.input}"`);
const expandedPath = client.path.replace("~", homeDir) + "/themes/noctalia-theme.el";
lines.push(`output_path = "${expandedPath}"`);
});
}
} else {
// Handle regular apps
+17 -10
View File
@@ -294,16 +294,7 @@ Singleton {
"id": "emacs",
"name": "Emacs",
"category": "editor",
"input": "emacs.el",
"outputs": [
{
"path": "~/.config/doom/themes/noctalia-theme.el"
},
{
"path": "~/.emacs.d/themes/noctalia-theme.el"
}
],
"checkDoomFirst": true
"input": "emacs.el"
},
{
"id": "niri",
@@ -470,6 +461,22 @@ Singleton {
Logger.d("TemplateRegistry", "User templates config written to:", userConfigPath);
}
// Extract Emacs clients for ProgramCheckerService compatibility
readonly property var emacsClients: [
{
"name": "doom",
"path": "~/.config/doom"
},
{
"name": "modern",
"path": "~/.config/emacs"
},
{
"name": "traditional",
"path": "~/.emacs.d"
}
]
// Process for checking if user templates file exists
Process {
id: fileCheckProcess