mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-06-25 04:25:22 -04:00
fix: gate mango matugen and Cosmic config sync on active session
This commit is contained in:
@@ -557,6 +557,8 @@ func detectRunningWM() string {
|
|||||||
return "Hyprland"
|
return "Hyprland"
|
||||||
case os.Getenv("NIRI_SOCKET") != "":
|
case os.Getenv("NIRI_SOCKET") != "":
|
||||||
return "niri"
|
return "niri"
|
||||||
|
case os.Getenv("MANGO_INSTANCE_SIGNATURE") != "":
|
||||||
|
return "MangoWC"
|
||||||
case os.Getenv("MIRACLESOCK") != "":
|
case os.Getenv("MIRACLESOCK") != "":
|
||||||
return "Miracle WM"
|
return "Miracle WM"
|
||||||
case os.Getenv("XDG_CURRENT_DESKTOP") != "":
|
case os.Getenv("XDG_CURRENT_DESKTOP") != "":
|
||||||
|
|||||||
@@ -47,13 +47,14 @@ type TemplateDef struct {
|
|||||||
ConfigFile string
|
ConfigFile string
|
||||||
Kind TemplateKind
|
Kind TemplateKind
|
||||||
RunUnconditionally bool
|
RunUnconditionally bool
|
||||||
|
RequiredEnv string
|
||||||
}
|
}
|
||||||
|
|
||||||
var templateRegistry = []TemplateDef{
|
var templateRegistry = []TemplateDef{
|
||||||
{ID: "gtk", Kind: TemplateKindGTK, RunUnconditionally: true},
|
{ID: "gtk", Kind: TemplateKindGTK, RunUnconditionally: true},
|
||||||
{ID: "niri", Commands: []string{"niri"}, ConfigFile: "niri.toml"},
|
{ID: "niri", Commands: []string{"niri"}, ConfigFile: "niri.toml"},
|
||||||
{ID: "hyprland", Commands: []string{"Hyprland"}, ConfigFile: "hyprland.toml"},
|
{ID: "hyprland", Commands: []string{"Hyprland"}, ConfigFile: "hyprland.toml"},
|
||||||
{ID: "mangowc", Commands: []string{"mango"}, ConfigFile: "mangowc.toml"},
|
{ID: "mangowc", Commands: []string{"mango"}, ConfigFile: "mangowc.toml", RequiredEnv: "MANGO_INSTANCE_SIGNATURE"},
|
||||||
{ID: "qt5ct", Commands: []string{"qt5ct"}, ConfigFile: "qt5ct.toml"},
|
{ID: "qt5ct", Commands: []string{"qt5ct"}, ConfigFile: "qt5ct.toml"},
|
||||||
{ID: "qt6ct", Commands: []string{"qt6ct"}, ConfigFile: "qt6ct.toml"},
|
{ID: "qt6ct", Commands: []string{"qt6ct"}, ConfigFile: "qt6ct.toml"},
|
||||||
{ID: "firefox", Commands: []string{"firefox"}, ConfigFile: "firefox.toml"},
|
{ID: "firefox", Commands: []string{"firefox"}, ConfigFile: "firefox.toml"},
|
||||||
@@ -356,6 +357,9 @@ output_path = '%s'
|
|||||||
if opts.ShouldSkipTemplate(tmpl.ID) {
|
if opts.ShouldSkipTemplate(tmpl.ID) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if !templateSessionActive(tmpl) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
switch tmpl.Kind {
|
switch tmpl.Kind {
|
||||||
case TemplateKindGTK:
|
case TemplateKindGTK:
|
||||||
@@ -489,6 +493,18 @@ func appendTerminalConfig(opts *Options, cfgFile *os.File, tmpDir string, checkC
|
|||||||
cfgFile.WriteString("\n")
|
cfgFile.WriteString("\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func templateSessionActive(tmpl TemplateDef) bool {
|
||||||
|
if tmpl.RequiredEnv == "" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
socket := os.Getenv(tmpl.RequiredEnv)
|
||||||
|
if socket == "" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
_, err := os.Stat(socket)
|
||||||
|
return err == nil
|
||||||
|
}
|
||||||
|
|
||||||
func appExists(checker utils.AppChecker, checkCmd []string, checkFlatpaks []string) bool {
|
func appExists(checker utils.AppChecker, checkCmd []string, checkFlatpaks []string) bool {
|
||||||
// Both nil is treated as "skip check" / unconditionally run
|
// Both nil is treated as "skip check" / unconditionally run
|
||||||
if checkCmd == nil && checkFlatpaks == nil {
|
if checkCmd == nil && checkFlatpaks == nil {
|
||||||
@@ -951,7 +967,7 @@ func CheckTemplates(checker utils.AppChecker) []TemplateCheck {
|
|||||||
case tmpl.Kind == TemplateKindEmacs:
|
case tmpl.Kind == TemplateKindEmacs:
|
||||||
detected = appExists(checker, tmpl.Commands, tmpl.Flatpaks) && utils.EmacsConfigDir() != ""
|
detected = appExists(checker, tmpl.Commands, tmpl.Flatpaks) && utils.EmacsConfigDir() != ""
|
||||||
default:
|
default:
|
||||||
detected = appExists(checker, tmpl.Commands, tmpl.Flatpaks)
|
detected = appExists(checker, tmpl.Commands, tmpl.Flatpaks) && templateSessionActive(tmpl)
|
||||||
}
|
}
|
||||||
|
|
||||||
checks = append(checks, TemplateCheck{ID: tmpl.ID, Detected: detected})
|
checks = append(checks, TemplateCheck{ID: tmpl.ID, Detected: detected})
|
||||||
|
|||||||
@@ -441,3 +441,49 @@ func TestBuildMergedConfigColorsOnly(t *testing.T) {
|
|||||||
assert.NotContains(t, content, "[templates.gtk]")
|
assert.NotContains(t, content, "[templates.gtk]")
|
||||||
assert.False(t, strings.Contains(content, "output_path = 'CONFIG_DIR/"), "colors-only config should not emit app template outputs")
|
assert.False(t, strings.Contains(content, "output_path = 'CONFIG_DIR/"), "colors-only config should not emit app template outputs")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBuildMergedConfigSkipsMangowcWithoutActiveSession(t *testing.T) {
|
||||||
|
t.Setenv("MANGO_INSTANCE_SIGNATURE", "")
|
||||||
|
|
||||||
|
tempDir := t.TempDir()
|
||||||
|
shellDir := filepath.Join(tempDir, "shell")
|
||||||
|
configsDir := filepath.Join(shellDir, "matugen", "configs")
|
||||||
|
if err := os.MkdirAll(configsDir, 0o755); err != nil {
|
||||||
|
t.Fatalf("failed to create configs dir: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := os.WriteFile(filepath.Join(configsDir, "base.toml"), []byte("[config]\n"), 0o644); err != nil {
|
||||||
|
t.Fatalf("failed to write base config: %v", err)
|
||||||
|
}
|
||||||
|
mangowcConfig := "[templates.dmsmango]\ninput_path = 'in'\noutput_path = 'out'\n"
|
||||||
|
if err := os.WriteFile(filepath.Join(configsDir, "mangowc.toml"), []byte(mangowcConfig), 0o644); err != nil {
|
||||||
|
t.Fatalf("failed to write mangowc config: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
cfgFile, err := os.CreateTemp(tempDir, "merged-*.toml")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create temp config: %v", err)
|
||||||
|
}
|
||||||
|
defer os.Remove(cfgFile.Name())
|
||||||
|
defer cfgFile.Close()
|
||||||
|
|
||||||
|
opts := &Options{
|
||||||
|
ShellDir: shellDir,
|
||||||
|
ConfigDir: filepath.Join(tempDir, "config"),
|
||||||
|
StateDir: filepath.Join(tempDir, "state"),
|
||||||
|
SkipTemplates: "gtk,niri,hyprland,qt5ct,qt6ct,firefox,pywalfox,zenbrowser,vesktop,vencord,equibop,ghostty,kitty,foot,alacritty,wezterm,nvim,dgop,kcolorscheme,vscode,emacs,zed",
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := buildMergedConfig(opts, cfgFile, filepath.Join(tempDir, "templates")); err != nil {
|
||||||
|
t.Fatalf("buildMergedConfig failed: %v", err)
|
||||||
|
}
|
||||||
|
if err := cfgFile.Close(); err != nil {
|
||||||
|
t.Fatalf("failed to close merged config: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
output, err := os.ReadFile(cfgFile.Name())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to read merged config: %v", err)
|
||||||
|
}
|
||||||
|
assert.NotContains(t, string(output), "[templates.dmsmango]")
|
||||||
|
}
|
||||||
|
|||||||
@@ -1372,7 +1372,14 @@ Singleton {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function cosmicIntegrationAvailable() {
|
||||||
|
const desktop = (Quickshell.env("XDG_CURRENT_DESKTOP") || "").toUpperCase();
|
||||||
|
return desktop.includes("COSMIC");
|
||||||
|
}
|
||||||
|
|
||||||
function updateCosmicIconTheme() {
|
function updateCosmicIconTheme() {
|
||||||
|
if (!cosmicIntegrationAvailable())
|
||||||
|
return;
|
||||||
const resolved = resolveIconTheme();
|
const resolved = resolveIconTheme();
|
||||||
let cosmicThemeName = (resolved === "System Default") ? systemDefaultIconTheme : resolved;
|
let cosmicThemeName = (resolved === "System Default") ? systemDefaultIconTheme : resolved;
|
||||||
if (!cosmicThemeName || cosmicThemeName === "System Default") {
|
if (!cosmicThemeName || cosmicThemeName === "System Default") {
|
||||||
@@ -1403,6 +1410,8 @@ Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function updateCosmicThemeMode(isLightMode) {
|
function updateCosmicThemeMode(isLightMode) {
|
||||||
|
if (!cosmicIntegrationAvailable())
|
||||||
|
return;
|
||||||
const isDark = isLightMode ? "false" : "true";
|
const isDark = isLightMode ? "false" : "true";
|
||||||
const script = `mkdir -p ${_configDir}/cosmic/com.system76.CosmicTheme.Mode/v1
|
const script = `mkdir -p ${_configDir}/cosmic/com.system76.CosmicTheme.Mode/v1
|
||||||
printf '%s\\n' ${isDark} > ${_configDir}/cosmic/com.system76.CosmicTheme.Mode/v1/is_dark 2>/dev/null || true`;
|
printf '%s\\n' ${isDark} > ${_configDir}/cosmic/com.system76.CosmicTheme.Mode/v1/is_dark 2>/dev/null || true`;
|
||||||
|
|||||||
@@ -414,6 +414,8 @@ Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function reloadConfig(showToast, suppressWatch) {
|
function reloadConfig(showToast, suppressWatch) {
|
||||||
|
if (!CompositorService.isMango || !root.available)
|
||||||
|
return;
|
||||||
const shouldShowToast = showToast !== false;
|
const shouldShowToast = showToast !== false;
|
||||||
const shouldSuppressWatch = suppressWatch !== false;
|
const shouldSuppressWatch = suppressWatch !== false;
|
||||||
if (shouldSuppressWatch)
|
if (shouldSuppressWatch)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
[templates.dmsmango]
|
[templates.dmsmango]
|
||||||
input_path = 'SHELL_DIR/matugen/templates/mango-colors.conf'
|
input_path = 'SHELL_DIR/matugen/templates/mango-colors.conf'
|
||||||
output_path = 'CONFIG_DIR/mango/dms/colors.conf'
|
output_path = 'CONFIG_DIR/mango/dms/colors.conf'
|
||||||
post_hook = 'sh -c "mmsg dispatch reload_config 2>&1 || true"'
|
post_hook = 'sh -c "[ -n \"$MANGO_INSTANCE_SIGNATURE\" ] && mmsg dispatch reload_config || true"'
|
||||||
|
|||||||
Reference in New Issue
Block a user