Skip to content

Commit cffee0f

Browse files
committed
matugen: make check codition an array
1 parent f08e2ef commit cffee0f

File tree

4 files changed

+143
-120
lines changed

4 files changed

+143
-120
lines changed

core/internal/matugen/matugen.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -234,61 +234,61 @@ output_path = '%s'
234234
if !opts.ShouldSkipTemplate("gtk") {
235235
switch opts.Mode {
236236
case "light":
237-
appendConfig(opts, cfgFile, "skip", "gtk3-light.toml")
237+
appendConfig(opts, cfgFile, nil, "gtk3-light.toml")
238238
default:
239-
appendConfig(opts, cfgFile, "skip", "gtk3-dark.toml")
239+
appendConfig(opts, cfgFile, nil, "gtk3-dark.toml")
240240
}
241241
}
242242

243243
if !opts.ShouldSkipTemplate("niri") {
244-
appendConfig(opts, cfgFile, "niri", "niri.toml")
244+
appendConfig(opts, cfgFile, []string{"niri"}, "niri.toml")
245245
}
246246
if !opts.ShouldSkipTemplate("qt5ct") {
247-
appendConfig(opts, cfgFile, "qt5ct", "qt5ct.toml")
247+
appendConfig(opts, cfgFile, []string{"qt5ct"}, "qt5ct.toml")
248248
}
249249
if !opts.ShouldSkipTemplate("qt6ct") {
250-
appendConfig(opts, cfgFile, "qt6ct", "qt6ct.toml")
250+
appendConfig(opts, cfgFile, []string{"qt6ct"}, "qt6ct.toml")
251251
}
252252
if !opts.ShouldSkipTemplate("firefox") {
253-
appendConfig(opts, cfgFile, "firefox", "firefox.toml")
253+
appendConfig(opts, cfgFile, []string{"firefox"}, "firefox.toml")
254254
}
255255
if !opts.ShouldSkipTemplate("pywalfox") {
256-
appendConfig(opts, cfgFile, "pywalfox", "pywalfox.toml")
256+
appendConfig(opts, cfgFile, []string{"pywalfox"}, "pywalfox.toml")
257257
}
258258
if !opts.ShouldSkipTemplate("zenbrowser") {
259-
appendConfig(opts, cfgFile, "zen", "zenbrowser.toml")
259+
appendConfig(opts, cfgFile, []string{"zen", "zen-browser"}, "zenbrowser.toml")
260260
}
261261
if !opts.ShouldSkipTemplate("vesktop") {
262-
appendConfig(opts, cfgFile, "vesktop", "vesktop.toml")
262+
appendConfig(opts, cfgFile, []string{"vesktop"}, "vesktop.toml")
263263
}
264264
if !opts.ShouldSkipTemplate("equibop") {
265-
appendConfig(opts, cfgFile, "equibop", "equibop.toml")
265+
appendConfig(opts, cfgFile, []string{"equibop"}, "equibop.toml")
266266
}
267267
if !opts.ShouldSkipTemplate("ghostty") {
268-
appendTerminalConfig(opts, cfgFile, tmpDir, "ghostty", "ghostty.toml")
268+
appendTerminalConfig(opts, cfgFile, tmpDir, []string{"ghostty"}, "ghostty.toml")
269269
}
270270
if !opts.ShouldSkipTemplate("kitty") {
271-
appendTerminalConfig(opts, cfgFile, tmpDir, "kitty", "kitty.toml")
271+
appendTerminalConfig(opts, cfgFile, tmpDir, []string{"kitty"}, "kitty.toml")
272272
}
273273
if !opts.ShouldSkipTemplate("foot") {
274-
appendTerminalConfig(opts, cfgFile, tmpDir, "foot", "foot.toml")
274+
appendTerminalConfig(opts, cfgFile, tmpDir, []string{"foot"}, "foot.toml")
275275
}
276276
if !opts.ShouldSkipTemplate("alacritty") {
277-
appendTerminalConfig(opts, cfgFile, tmpDir, "alacritty", "alacritty.toml")
277+
appendTerminalConfig(opts, cfgFile, tmpDir, []string{"alacritty"}, "alacritty.toml")
278278
}
279279
if !opts.ShouldSkipTemplate("wezterm") {
280-
appendTerminalConfig(opts, cfgFile, tmpDir, "wezterm", "wezterm.toml")
280+
appendTerminalConfig(opts, cfgFile, tmpDir, []string{"wezterm"}, "wezterm.toml")
281281
}
282282
if !opts.ShouldSkipTemplate("nvim") {
283-
appendTerminalConfig(opts, cfgFile, tmpDir, "nvim", "neovim.toml")
283+
appendTerminalConfig(opts, cfgFile, tmpDir, []string{"nvim"}, "neovim.toml")
284284
}
285285

286286
if !opts.ShouldSkipTemplate("dgop") {
287-
appendConfig(opts, cfgFile, "dgop", "dgop.toml")
287+
appendConfig(opts, cfgFile, []string{"dgop"}, "dgop.toml")
288288
}
289289

290290
if !opts.ShouldSkipTemplate("kcolorscheme") {
291-
appendConfig(opts, cfgFile, "skip", "kcolorscheme.toml")
291+
appendConfig(opts, cfgFile, nil, "kcolorscheme.toml")
292292
}
293293

294294
if !opts.ShouldSkipTemplate("vscode") {
@@ -326,12 +326,12 @@ output_path = '%s'
326326
return nil
327327
}
328328

329-
func appendConfig(opts *Options, cfgFile *os.File, checkCmd, fileName string) {
329+
func appendConfig(opts *Options, cfgFile *os.File, checkCmd []string, fileName string) {
330330
configPath := filepath.Join(opts.ShellDir, "matugen", "configs", fileName)
331331
if _, err := os.Stat(configPath); err != nil {
332332
return
333333
}
334-
if checkCmd != "skip" && !utils.CommandExists(checkCmd) {
334+
if !utils.AnyCommandExists(checkCmd...) {
335335
return
336336
}
337337
data, err := os.ReadFile(configPath)
@@ -342,12 +342,12 @@ func appendConfig(opts *Options, cfgFile *os.File, checkCmd, fileName string) {
342342
cfgFile.WriteString("\n")
343343
}
344344

345-
func appendTerminalConfig(opts *Options, cfgFile *os.File, tmpDir, checkCmd, fileName string) {
345+
func appendTerminalConfig(opts *Options, cfgFile *os.File, tmpDir string, checkCmd []string, fileName string) {
346346
configPath := filepath.Join(opts.ShellDir, "matugen", "configs", fileName)
347347
if _, err := os.Stat(configPath); err != nil {
348348
return
349349
}
350-
if checkCmd != "skip" && !utils.CommandExists(checkCmd) {
350+
if !utils.AnyCommandExists(checkCmd...) {
351351
return
352352
}
353353
data, err := os.ReadFile(configPath)

core/internal/utils/exec.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,12 @@ func CommandExists(cmd string) bool {
66
_, err := exec.LookPath(cmd)
77
return err == nil
88
}
9+
10+
func AnyCommandExists(cmds ...string) bool {
11+
for _, cmd := range cmds {
12+
if CommandExists(cmd) {
13+
return true
14+
}
15+
}
16+
return false
17+
}

quickshell/Common/SessionData.qml

Lines changed: 86 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Singleton {
1515

1616
readonly property bool isGreeterMode: Quickshell.env("DMS_RUN_GREETER") === "1" || Quickshell.env("DMS_RUN_GREETER") === "true"
1717
property bool hasTriedDefaultSession: false
18+
property bool _parseError: false
1819
readonly property string _stateUrl: StandardPaths.writableLocation(StandardPaths.GenericStateLocation)
1920
readonly property string _stateDir: Paths.strip(_stateUrl)
2021

@@ -108,96 +109,98 @@ Singleton {
108109
}
109110

110111
function parseSettings(content) {
112+
_parseError = false;
111113
try {
112-
if (content && content.trim()) {
113-
var settings = JSON.parse(content);
114-
isLightMode = settings.isLightMode !== undefined ? settings.isLightMode : false;
115-
116-
if (settings.wallpaperPath && settings.wallpaperPath.startsWith("we:")) {
117-
console.warn("WallpaperEngine wallpaper detected, resetting wallpaper");
118-
wallpaperPath = "";
119-
Quickshell.execDetached(["notify-send", "-u", "critical", "-a", "DMS", "-i", "dialog-warning", "WallpaperEngine Support Moved", "WallpaperEngine support has been moved to a plugin. Please enable the Linux Wallpaper Engine plugin in Settings → Plugins to continue using WallpaperEngine."]);
120-
} else {
121-
wallpaperPath = settings.wallpaperPath !== undefined ? settings.wallpaperPath : "";
122-
}
123-
perMonitorWallpaper = settings.perMonitorWallpaper !== undefined ? settings.perMonitorWallpaper : false;
124-
monitorWallpapers = settings.monitorWallpapers !== undefined ? settings.monitorWallpapers : {};
125-
perModeWallpaper = settings.perModeWallpaper !== undefined ? settings.perModeWallpaper : false;
126-
wallpaperPathLight = settings.wallpaperPathLight !== undefined ? settings.wallpaperPathLight : "";
127-
wallpaperPathDark = settings.wallpaperPathDark !== undefined ? settings.wallpaperPathDark : "";
128-
monitorWallpapersLight = settings.monitorWallpapersLight !== undefined ? settings.monitorWallpapersLight : {};
129-
monitorWallpapersDark = settings.monitorWallpapersDark !== undefined ? settings.monitorWallpapersDark : {};
130-
brightnessExponentialDevices = settings.brightnessExponentialDevices !== undefined ? settings.brightnessExponentialDevices : (settings.brightnessLogarithmicDevices || {});
131-
brightnessUserSetValues = settings.brightnessUserSetValues !== undefined ? settings.brightnessUserSetValues : {};
132-
brightnessExponentValues = settings.brightnessExponentValues !== undefined ? settings.brightnessExponentValues : {};
133-
doNotDisturb = settings.doNotDisturb !== undefined ? settings.doNotDisturb : false;
134-
nightModeEnabled = settings.nightModeEnabled !== undefined ? settings.nightModeEnabled : false;
135-
nightModeTemperature = settings.nightModeTemperature !== undefined ? settings.nightModeTemperature : 4500;
136-
nightModeHighTemperature = settings.nightModeHighTemperature !== undefined ? settings.nightModeHighTemperature : 6500;
137-
nightModeAutoEnabled = settings.nightModeAutoEnabled !== undefined ? settings.nightModeAutoEnabled : false;
138-
nightModeAutoMode = settings.nightModeAutoMode !== undefined ? settings.nightModeAutoMode : "time";
139-
if (settings.nightModeStartTime !== undefined) {
140-
const parts = settings.nightModeStartTime.split(":");
141-
nightModeStartHour = parseInt(parts[0]) || 18;
142-
nightModeStartMinute = parseInt(parts[1]) || 0;
143-
} else {
144-
nightModeStartHour = settings.nightModeStartHour !== undefined ? settings.nightModeStartHour : 18;
145-
nightModeStartMinute = settings.nightModeStartMinute !== undefined ? settings.nightModeStartMinute : 0;
146-
}
147-
if (settings.nightModeEndTime !== undefined) {
148-
const parts = settings.nightModeEndTime.split(":");
149-
nightModeEndHour = parseInt(parts[0]) || 6;
150-
nightModeEndMinute = parseInt(parts[1]) || 0;
151-
} else {
152-
nightModeEndHour = settings.nightModeEndHour !== undefined ? settings.nightModeEndHour : 6;
153-
nightModeEndMinute = settings.nightModeEndMinute !== undefined ? settings.nightModeEndMinute : 0;
154-
}
155-
latitude = settings.latitude !== undefined ? settings.latitude : 0.0;
156-
longitude = settings.longitude !== undefined ? settings.longitude : 0.0;
157-
nightModeUseIPLocation = settings.nightModeUseIPLocation !== undefined ? settings.nightModeUseIPLocation : false;
158-
nightModeLocationProvider = settings.nightModeLocationProvider !== undefined ? settings.nightModeLocationProvider : "";
159-
pinnedApps = settings.pinnedApps !== undefined ? settings.pinnedApps : [];
160-
hiddenTrayIds = settings.hiddenTrayIds !== undefined ? settings.hiddenTrayIds : [];
161-
selectedGpuIndex = settings.selectedGpuIndex !== undefined ? settings.selectedGpuIndex : 0;
162-
nvidiaGpuTempEnabled = settings.nvidiaGpuTempEnabled !== undefined ? settings.nvidiaGpuTempEnabled : false;
163-
nonNvidiaGpuTempEnabled = settings.nonNvidiaGpuTempEnabled !== undefined ? settings.nonNvidiaGpuTempEnabled : false;
164-
enabledGpuPciIds = settings.enabledGpuPciIds !== undefined ? settings.enabledGpuPciIds : [];
165-
wifiDeviceOverride = settings.wifiDeviceOverride !== undefined ? settings.wifiDeviceOverride : "";
166-
weatherHourlyDetailed = settings.weatherHourlyDetailed !== undefined ? settings.weatherHourlyDetailed : true;
167-
wallpaperCyclingEnabled = settings.wallpaperCyclingEnabled !== undefined ? settings.wallpaperCyclingEnabled : false;
168-
wallpaperCyclingMode = settings.wallpaperCyclingMode !== undefined ? settings.wallpaperCyclingMode : "interval";
169-
wallpaperCyclingInterval = settings.wallpaperCyclingInterval !== undefined ? settings.wallpaperCyclingInterval : 300;
170-
wallpaperCyclingTime = settings.wallpaperCyclingTime !== undefined ? settings.wallpaperCyclingTime : "06:00";
171-
monitorCyclingSettings = settings.monitorCyclingSettings !== undefined ? settings.monitorCyclingSettings : {};
172-
lastBrightnessDevice = settings.lastBrightnessDevice !== undefined ? settings.lastBrightnessDevice : "";
173-
launchPrefix = settings.launchPrefix !== undefined ? settings.launchPrefix : "";
174-
wallpaperTransition = settings.wallpaperTransition !== undefined ? settings.wallpaperTransition : "fade";
175-
includedTransitions = settings.includedTransitions !== undefined ? settings.includedTransitions : availableWallpaperTransitions.filter(t => t !== "none");
176-
recentColors = settings.recentColors !== undefined ? settings.recentColors : [];
177-
showThirdPartyPlugins = settings.showThirdPartyPlugins !== undefined ? settings.showThirdPartyPlugins : false;
178-
179-
if (settings.configVersion === undefined) {
180-
migrateFromUndefinedToV1(settings);
181-
saveSettings();
182-
} else if (settings.configVersion === sessionConfigVersion) {
183-
cleanupUnusedKeys();
184-
}
114+
if (!content || !content.trim())
115+
return;
116+
var settings = JSON.parse(content);
117+
isLightMode = settings.isLightMode !== undefined ? settings.isLightMode : false;
185118

186-
if (!isGreeterMode) {
187-
if (typeof Theme !== "undefined") {
188-
Theme.generateSystemThemesFromCurrentTheme();
189-
}
190-
}
119+
if (settings.wallpaperPath && settings.wallpaperPath.startsWith("we:")) {
120+
console.warn("WallpaperEngine wallpaper detected, resetting wallpaper");
121+
wallpaperPath = "";
122+
Quickshell.execDetached(["notify-send", "-u", "critical", "-a", "DMS", "-i", "dialog-warning", "WallpaperEngine Support Moved", "WallpaperEngine support has been moved to a plugin. Please enable the Linux Wallpaper Engine plugin in Settings → Plugins to continue using WallpaperEngine."]);
123+
} else {
124+
wallpaperPath = settings.wallpaperPath !== undefined ? settings.wallpaperPath : "";
125+
}
126+
perMonitorWallpaper = settings.perMonitorWallpaper !== undefined ? settings.perMonitorWallpaper : false;
127+
monitorWallpapers = settings.monitorWallpapers !== undefined ? settings.monitorWallpapers : {};
128+
perModeWallpaper = settings.perModeWallpaper !== undefined ? settings.perModeWallpaper : false;
129+
wallpaperPathLight = settings.wallpaperPathLight !== undefined ? settings.wallpaperPathLight : "";
130+
wallpaperPathDark = settings.wallpaperPathDark !== undefined ? settings.wallpaperPathDark : "";
131+
monitorWallpapersLight = settings.monitorWallpapersLight !== undefined ? settings.monitorWallpapersLight : {};
132+
monitorWallpapersDark = settings.monitorWallpapersDark !== undefined ? settings.monitorWallpapersDark : {};
133+
brightnessExponentialDevices = settings.brightnessExponentialDevices !== undefined ? settings.brightnessExponentialDevices : (settings.brightnessLogarithmicDevices || {});
134+
brightnessUserSetValues = settings.brightnessUserSetValues !== undefined ? settings.brightnessUserSetValues : {};
135+
brightnessExponentValues = settings.brightnessExponentValues !== undefined ? settings.brightnessExponentValues : {};
136+
doNotDisturb = settings.doNotDisturb !== undefined ? settings.doNotDisturb : false;
137+
nightModeEnabled = settings.nightModeEnabled !== undefined ? settings.nightModeEnabled : false;
138+
nightModeTemperature = settings.nightModeTemperature !== undefined ? settings.nightModeTemperature : 4500;
139+
nightModeHighTemperature = settings.nightModeHighTemperature !== undefined ? settings.nightModeHighTemperature : 6500;
140+
nightModeAutoEnabled = settings.nightModeAutoEnabled !== undefined ? settings.nightModeAutoEnabled : false;
141+
nightModeAutoMode = settings.nightModeAutoMode !== undefined ? settings.nightModeAutoMode : "time";
142+
if (settings.nightModeStartTime !== undefined) {
143+
const parts = settings.nightModeStartTime.split(":");
144+
nightModeStartHour = parseInt(parts[0]) || 18;
145+
nightModeStartMinute = parseInt(parts[1]) || 0;
146+
} else {
147+
nightModeStartHour = settings.nightModeStartHour !== undefined ? settings.nightModeStartHour : 18;
148+
nightModeStartMinute = settings.nightModeStartMinute !== undefined ? settings.nightModeStartMinute : 0;
149+
}
150+
if (settings.nightModeEndTime !== undefined) {
151+
const parts = settings.nightModeEndTime.split(":");
152+
nightModeEndHour = parseInt(parts[0]) || 6;
153+
nightModeEndMinute = parseInt(parts[1]) || 0;
154+
} else {
155+
nightModeEndHour = settings.nightModeEndHour !== undefined ? settings.nightModeEndHour : 6;
156+
nightModeEndMinute = settings.nightModeEndMinute !== undefined ? settings.nightModeEndMinute : 0;
157+
}
158+
latitude = settings.latitude !== undefined ? settings.latitude : 0.0;
159+
longitude = settings.longitude !== undefined ? settings.longitude : 0.0;
160+
nightModeUseIPLocation = settings.nightModeUseIPLocation !== undefined ? settings.nightModeUseIPLocation : false;
161+
nightModeLocationProvider = settings.nightModeLocationProvider !== undefined ? settings.nightModeLocationProvider : "";
162+
pinnedApps = settings.pinnedApps !== undefined ? settings.pinnedApps : [];
163+
hiddenTrayIds = settings.hiddenTrayIds !== undefined ? settings.hiddenTrayIds : [];
164+
selectedGpuIndex = settings.selectedGpuIndex !== undefined ? settings.selectedGpuIndex : 0;
165+
nvidiaGpuTempEnabled = settings.nvidiaGpuTempEnabled !== undefined ? settings.nvidiaGpuTempEnabled : false;
166+
nonNvidiaGpuTempEnabled = settings.nonNvidiaGpuTempEnabled !== undefined ? settings.nonNvidiaGpuTempEnabled : false;
167+
enabledGpuPciIds = settings.enabledGpuPciIds !== undefined ? settings.enabledGpuPciIds : [];
168+
wifiDeviceOverride = settings.wifiDeviceOverride !== undefined ? settings.wifiDeviceOverride : "";
169+
weatherHourlyDetailed = settings.weatherHourlyDetailed !== undefined ? settings.weatherHourlyDetailed : true;
170+
wallpaperCyclingEnabled = settings.wallpaperCyclingEnabled !== undefined ? settings.wallpaperCyclingEnabled : false;
171+
wallpaperCyclingMode = settings.wallpaperCyclingMode !== undefined ? settings.wallpaperCyclingMode : "interval";
172+
wallpaperCyclingInterval = settings.wallpaperCyclingInterval !== undefined ? settings.wallpaperCyclingInterval : 300;
173+
wallpaperCyclingTime = settings.wallpaperCyclingTime !== undefined ? settings.wallpaperCyclingTime : "06:00";
174+
monitorCyclingSettings = settings.monitorCyclingSettings !== undefined ? settings.monitorCyclingSettings : {};
175+
lastBrightnessDevice = settings.lastBrightnessDevice !== undefined ? settings.lastBrightnessDevice : "";
176+
launchPrefix = settings.launchPrefix !== undefined ? settings.launchPrefix : "";
177+
wallpaperTransition = settings.wallpaperTransition !== undefined ? settings.wallpaperTransition : "fade";
178+
includedTransitions = settings.includedTransitions !== undefined ? settings.includedTransitions : availableWallpaperTransitions.filter(t => t !== "none");
179+
recentColors = settings.recentColors !== undefined ? settings.recentColors : [];
180+
showThirdPartyPlugins = settings.showThirdPartyPlugins !== undefined ? settings.showThirdPartyPlugins : false;
181+
182+
if (settings.configVersion === undefined) {
183+
migrateFromUndefinedToV1(settings);
184+
saveSettings();
185+
} else if (settings.configVersion === sessionConfigVersion) {
186+
cleanupUnusedKeys();
187+
}
191188

192-
if (typeof WallpaperCyclingService !== "undefined") {
193-
WallpaperCyclingService.updateCyclingState();
194-
}
189+
if (!isGreeterMode && typeof Theme !== "undefined") {
190+
Theme.generateSystemThemesFromCurrentTheme();
191+
}
192+
193+
if (typeof WallpaperCyclingService !== "undefined") {
194+
WallpaperCyclingService.updateCyclingState();
195195
}
196-
} catch (e) {}
196+
} catch (e) {
197+
_parseError = true;
198+
console.error("SessionData: Failed to parse session.json - file will not be overwritten. Error:", e.message);
199+
}
197200
}
198201

199202
function saveSettings() {
200-
if (isGreeterMode)
203+
if (isGreeterMode || _parseError)
201204
return;
202205
settingsFile.setText(JSON.stringify({
203206
"isLightMode": isLightMode,

0 commit comments

Comments
 (0)