mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-26 14:32:52 -05:00
Initial qmlformat
This commit is contained in:
@@ -1,180 +1,181 @@
|
||||
pragma Singleton
|
||||
pragma ComponentBehavior: Bound
|
||||
|
||||
import Qt.labs.platform
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
import Qt.labs.platform
|
||||
import qs.Services
|
||||
|
||||
Singleton {
|
||||
// This dependency forces re-evaluation when colorUpdateTrigger changes
|
||||
// Just check if matugen is available
|
||||
|
||||
id: root
|
||||
|
||||
/* ──────────────── basic state ──────────────── */
|
||||
signal colorsUpdated()
|
||||
|
||||
readonly property string _homeUrl: StandardPaths.writableLocation(StandardPaths.HomeLocation)
|
||||
readonly property string homeDir: _homeUrl.startsWith("file://")
|
||||
? _homeUrl.substring(7)
|
||||
: _homeUrl
|
||||
readonly property string homeDir: _homeUrl.startsWith("file://") ? _homeUrl.substring(7) : _homeUrl
|
||||
readonly property string wallpaperPath: homeDir + "/quickshell/current_wallpaper"
|
||||
readonly property string notifyPath: homeDir + "/quickshell/wallpaper_changed"
|
||||
property bool matugenAvailable: false
|
||||
property string matugenJson: ""
|
||||
property var matugenColors: ({
|
||||
})
|
||||
property bool extractionRequested: false
|
||||
property int colorUpdateTrigger: 0 // Force property re-evaluation
|
||||
// ──────────────── wallpaper change monitor ────────────────
|
||||
property string lastWallpaperTimestamp: ""
|
||||
// ──────────────── color properties (MD3) ────────────────
|
||||
property color primary: getMatugenColor("primary", "#42a5f5")
|
||||
property color secondary: getMatugenColor("secondary", "#8ab4f8")
|
||||
property color tertiary: getMatugenColor("tertiary", "#bb86fc")
|
||||
property color tertiaryContainer: getMatugenColor("tertiary_container", "#3700b3")
|
||||
property color error: getMatugenColor("error", "#cf6679")
|
||||
property color inversePrimary: getMatugenColor("inverse_primary", "#6200ea")
|
||||
// backgrounds
|
||||
property color bg: getMatugenColor("background", "#1a1c1e")
|
||||
property color surface: getMatugenColor("surface", "#1a1c1e")
|
||||
property color surfaceContainer: getMatugenColor("surface_container", "#1e2023")
|
||||
property color surfaceContainerHigh: getMatugenColor("surface_container_high", "#292b2f")
|
||||
property color surfaceVariant: getMatugenColor("surface_variant", "#44464f")
|
||||
// text
|
||||
property color surfaceText: getMatugenColor("on_background", "#e3e8ef")
|
||||
property color primaryText: getMatugenColor("on_primary", "#ffffff")
|
||||
property color surfaceVariantText: getMatugenColor("on_surface_variant", "#c4c7c5")
|
||||
// containers & misc
|
||||
property color primaryContainer: getMatugenColor("primary_container", "#1976d2")
|
||||
property color surfaceTint: getMatugenColor("surface_tint", "#8ab4f8")
|
||||
property color outline: getMatugenColor("outline", "#8e918f")
|
||||
// legacy aliases
|
||||
property color accentHi: primary
|
||||
property color accentLo: secondary
|
||||
|
||||
property bool matugenAvailable: false
|
||||
property string matugenJson: ""
|
||||
property var matugenColors: ({})
|
||||
property bool extractionRequested: false
|
||||
property int colorUpdateTrigger: 0 // Force property re-evaluation
|
||||
// ──────────────── basic state ────────────────
|
||||
signal colorsUpdated()
|
||||
|
||||
Component.onCompleted: {
|
||||
console.log("Colors.qml → home =", homeDir)
|
||||
// Don't automatically run color extraction - only when requested
|
||||
matugenCheck.running = true // Just check if matugen is available
|
||||
|
||||
// Connect to Theme light mode changes to update colors
|
||||
if (typeof Theme !== "undefined") {
|
||||
Theme.isLightModeChanged.connect(root.onLightModeChanged)
|
||||
}
|
||||
}
|
||||
|
||||
function onLightModeChanged() {
|
||||
// Force color properties to update when light mode changes
|
||||
if (matugenColors && Object.keys(matugenColors).length > 0) {
|
||||
console.log("Light mode changed - updating dynamic colors")
|
||||
colorUpdateTrigger++ // This will trigger re-evaluation of all color properties
|
||||
colorsUpdated()
|
||||
console.log("Light mode changed - updating dynamic colors");
|
||||
colorUpdateTrigger++; // This will trigger re-evaluation of all color properties
|
||||
colorsUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
/* ──────────────── availability checks ──────────────── */
|
||||
Process {
|
||||
id: matugenCheck
|
||||
command: ["which", "matugen"]
|
||||
onExited: (code) => {
|
||||
matugenAvailable = (code === 0)
|
||||
console.log("Matugen in PATH:", matugenAvailable)
|
||||
|
||||
if (!matugenAvailable) {
|
||||
console.warn("Matugen missing → dynamic theme disabled")
|
||||
ToastService.wallpaperErrorStatus = "matugen_missing"
|
||||
ToastService.showWarning("matugen not found - dynamic theming disabled")
|
||||
return
|
||||
}
|
||||
|
||||
// If extraction was requested, continue the process
|
||||
if (extractionRequested) {
|
||||
console.log("Continuing with color extraction")
|
||||
fileChecker.running = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Process {
|
||||
id: fileChecker // exists & readable?
|
||||
command: ["test", "-r", wallpaperPath]
|
||||
onExited: (code) => {
|
||||
if (code === 0) {
|
||||
matugenProcess.running = true
|
||||
} else {
|
||||
console.error("code", code)
|
||||
console.error("Wallpaper not found:", wallpaperPath)
|
||||
ToastService.wallpaperErrorStatus = "error"
|
||||
ToastService.showError("Wallpaper processing failed")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ──────────────── matugen invocation ──────────────── */
|
||||
Process {
|
||||
id: matugenProcess
|
||||
command: ["matugen", "-v", "image", wallpaperPath, "--json", "hex"]
|
||||
|
||||
/* ── grab stdout as a stream ── */
|
||||
stdout: StdioCollector {
|
||||
id: matugenCollector
|
||||
onStreamFinished: {
|
||||
const out = matugenCollector.text
|
||||
if (!out.length) {
|
||||
console.error("matugen produced zero bytes\nstderr:", matugenProcess.stderr)
|
||||
ToastService.wallpaperErrorStatus = "error"
|
||||
ToastService.showError("Wallpaper processing failed")
|
||||
return
|
||||
}
|
||||
try {
|
||||
root.matugenJson = out
|
||||
root.matugenColors = JSON.parse(out)
|
||||
root.colorsUpdated()
|
||||
ToastService.clearWallpaperError()
|
||||
ToastService.showInfo("Dynamic theme colors updated")
|
||||
} catch (e) {
|
||||
console.error("JSON parse failed:", e)
|
||||
ToastService.wallpaperErrorStatus = "error"
|
||||
ToastService.showError("Wallpaper processing failed")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* grab stderr too, so we can print it above */
|
||||
stderr: StdioCollector { id: matugenErr }
|
||||
}
|
||||
|
||||
/* ──────────────── wallpaper change monitor ──────────────── */
|
||||
property string lastWallpaperTimestamp: ""
|
||||
|
||||
|
||||
/* ──────────────── public helper ──────────────── */
|
||||
// ──────────────── public helper ────────────────
|
||||
function extractColors() {
|
||||
console.log("Colors.extractColors() called, matugenAvailable:", matugenAvailable)
|
||||
extractionRequested = true
|
||||
console.log("Colors.extractColors() called, matugenAvailable:", matugenAvailable);
|
||||
extractionRequested = true;
|
||||
if (matugenAvailable)
|
||||
fileChecker.running = true
|
||||
fileChecker.running = true;
|
||||
else
|
||||
matugenCheck.running = true
|
||||
matugenCheck.running = true;
|
||||
}
|
||||
|
||||
function getMatugenColor(path, fallback) {
|
||||
// Include colorUpdateTrigger in the function to make properties reactive to changes
|
||||
colorUpdateTrigger // This dependency forces re-evaluation when colorUpdateTrigger changes
|
||||
|
||||
colorUpdateTrigger;
|
||||
// Use light or dark colors based on Theme.isLightMode
|
||||
const colorMode = (typeof Theme !== "undefined" && Theme.isLightMode) ? "light" : "dark"
|
||||
let cur = matugenColors?.colors?.[colorMode]
|
||||
const colorMode = (typeof Theme !== "undefined" && Theme.isLightMode) ? "light" : "dark";
|
||||
let cur = matugenColors && matugenColors.colors && matugenColors.colors[colorMode];
|
||||
for (const part of path.split(".")) {
|
||||
if (!cur || typeof cur !== "object" || !(part in cur))
|
||||
return fallback
|
||||
cur = cur[part]
|
||||
return fallback;
|
||||
|
||||
cur = cur[part];
|
||||
}
|
||||
return cur || fallback
|
||||
return cur || fallback;
|
||||
}
|
||||
|
||||
/* ──────────────── color properties (MD3) ──────────────── */
|
||||
property color primary: getMatugenColor("primary", "#42a5f5")
|
||||
property color secondary: getMatugenColor("secondary", "#8ab4f8")
|
||||
property color tertiary: getMatugenColor("tertiary", "#bb86fc")
|
||||
property color tertiaryContainer: getMatugenColor("tertiary_container", "#3700b3")
|
||||
property color error: getMatugenColor("error", "#cf6679")
|
||||
property color inversePrimary: getMatugenColor("inverse_primary", "#6200ea")
|
||||
|
||||
/* backgrounds */
|
||||
property color bg: getMatugenColor("background", "#1a1c1e")
|
||||
property color surface: getMatugenColor("surface", "#1a1c1e")
|
||||
property color surfaceContainer: getMatugenColor("surface_container", "#1e2023")
|
||||
property color surfaceContainerHigh: getMatugenColor("surface_container_high", "#292b2f")
|
||||
property color surfaceVariant: getMatugenColor("surface_variant", "#44464f")
|
||||
|
||||
/* text */
|
||||
property color surfaceText: getMatugenColor("on_background", "#e3e8ef")
|
||||
property color primaryText: getMatugenColor("on_primary", "#ffffff")
|
||||
property color surfaceVariantText: getMatugenColor("on_surface_variant", "#c4c7c5")
|
||||
|
||||
/* containers & misc */
|
||||
property color primaryContainer: getMatugenColor("primary_container", "#1976d2")
|
||||
property color surfaceTint: getMatugenColor("surface_tint", "#8ab4f8")
|
||||
property color outline: getMatugenColor("outline", "#8e918f")
|
||||
|
||||
/* legacy aliases */
|
||||
property color accentHi: primary
|
||||
property color accentLo: secondary
|
||||
|
||||
function isColorDark(c) {
|
||||
return (0.299 * c.r + 0.587 * c.g + 0.114 * c.b) < 0.5
|
||||
return (0.299 * c.r + 0.587 * c.g + 0.114 * c.b) < 0.5;
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
console.log("Colors.qml → home =", homeDir);
|
||||
// Don't automatically run color extraction - only when requested
|
||||
matugenCheck.running = true;
|
||||
// Connect to Theme light mode changes to update colors
|
||||
if (typeof Theme !== "undefined")
|
||||
Theme.isLightModeChanged.connect(root.onLightModeChanged);
|
||||
|
||||
}
|
||||
|
||||
// ──────────────── availability checks ────────────────
|
||||
Process {
|
||||
id: matugenCheck
|
||||
|
||||
command: ["which", "matugen"]
|
||||
onExited: (code) => {
|
||||
matugenAvailable = (code === 0);
|
||||
console.log("Matugen in PATH:", matugenAvailable);
|
||||
if (!matugenAvailable) {
|
||||
console.warn("Matugen missing → dynamic theme disabled");
|
||||
ToastService.wallpaperErrorStatus = "matugen_missing";
|
||||
ToastService.showWarning("matugen not found - dynamic theming disabled");
|
||||
return ;
|
||||
}
|
||||
// If extraction was requested, continue the process
|
||||
if (extractionRequested) {
|
||||
console.log("Continuing with color extraction");
|
||||
fileChecker.running = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Process {
|
||||
id: fileChecker // exists & readable?
|
||||
|
||||
command: ["test", "-r", wallpaperPath]
|
||||
onExited: (code) => {
|
||||
if (code === 0) {
|
||||
matugenProcess.running = true;
|
||||
} else {
|
||||
console.error("code", code);
|
||||
console.error("Wallpaper not found:", wallpaperPath);
|
||||
ToastService.wallpaperErrorStatus = "error";
|
||||
ToastService.showError("Wallpaper processing failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ──────────────── matugen invocation ────────────────
|
||||
Process {
|
||||
id: matugenProcess
|
||||
|
||||
command: ["matugen", "-v", "image", wallpaperPath, "--json", "hex"]
|
||||
|
||||
// ── grab stdout as a stream ──
|
||||
stdout: StdioCollector {
|
||||
id: matugenCollector
|
||||
|
||||
onStreamFinished: {
|
||||
const out = matugenCollector.text;
|
||||
if (!out.length) {
|
||||
console.error("matugen produced zero bytes\nstderr:", matugenProcess.stderr);
|
||||
ToastService.wallpaperErrorStatus = "error";
|
||||
ToastService.showError("Wallpaper Processing Failed");
|
||||
return ;
|
||||
}
|
||||
try {
|
||||
root.matugenJson = out;
|
||||
root.matugenColors = JSON.parse(out);
|
||||
root.colorsUpdated();
|
||||
ToastService.clearWallpaperError();
|
||||
ToastService.showInfo("Loaded Dynamic Theme Colors");
|
||||
} catch (e) {
|
||||
console.error("JSON parse failed:", e);
|
||||
ToastService.wallpaperErrorStatus = "error";
|
||||
ToastService.showError("Wallpaper Processing Failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// grab stderr too, so we can print it above
|
||||
stderr: StdioCollector {
|
||||
id: matugenErr
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
551
Common/Prefs.qml
551
Common/Prefs.qml
@@ -1,321 +1,314 @@
|
||||
pragma Singleton
|
||||
import QtQuick
|
||||
pragma ComponentBehavior: Bound
|
||||
|
||||
import QtCore
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
|
||||
Singleton {
|
||||
// "auto", "wifi", "ethernet"
|
||||
// Alphabetical tiebreaker
|
||||
|
||||
id: root
|
||||
|
||||
|
||||
property int themeIndex: 0
|
||||
property bool themeIsDynamic: false
|
||||
property bool isLightMode: false
|
||||
property real topBarTransparency: 0.75
|
||||
property real popupTransparency: 0.92
|
||||
property var recentlyUsedApps: []
|
||||
|
||||
// New global preferences
|
||||
property bool use24HourClock: true
|
||||
property bool useFahrenheit: false
|
||||
property bool nightModeEnabled: false
|
||||
property string profileImage: ""
|
||||
property string weatherLocationOverride: "New York, NY"
|
||||
|
||||
// Widget visibility preferences for TopBar
|
||||
property bool showFocusedWindow: true
|
||||
property bool showWeather: true
|
||||
property bool showWeather: true
|
||||
property bool showMusic: true
|
||||
property bool showClipboard: true
|
||||
property bool showSystemResources: true
|
||||
property bool showSystemTray: true
|
||||
|
||||
// View mode preferences for launchers
|
||||
property string appLauncherViewMode: "list"
|
||||
property string spotlightLauncherViewMode: "list"
|
||||
|
||||
// Network preference
|
||||
property string networkPreference: "auto" // "auto", "wifi", "ethernet"
|
||||
|
||||
|
||||
Component.onCompleted: loadSettings()
|
||||
|
||||
// Monitor system resources preference changes to control service monitoring
|
||||
onShowSystemResourcesChanged: {
|
||||
console.log("Prefs: System resources monitoring", showSystemResources ? "enabled" : "disabled")
|
||||
// Control SystemMonitorService based on whether system monitor widgets are visible
|
||||
if (typeof SystemMonitorService !== 'undefined') {
|
||||
SystemMonitorService.enableTopBarMonitoring(showSystemResources)
|
||||
property string networkPreference: "auto"
|
||||
|
||||
function loadSettings() {
|
||||
parseSettings(settingsFile.text());
|
||||
}
|
||||
|
||||
function parseSettings(content) {
|
||||
try {
|
||||
if (content && content.trim()) {
|
||||
var settings = JSON.parse(content);
|
||||
themeIndex = settings.themeIndex !== undefined ? settings.themeIndex : 0;
|
||||
themeIsDynamic = settings.themeIsDynamic !== undefined ? settings.themeIsDynamic : false;
|
||||
isLightMode = settings.isLightMode !== undefined ? settings.isLightMode : false;
|
||||
topBarTransparency = settings.topBarTransparency !== undefined ? (settings.topBarTransparency > 1 ? settings.topBarTransparency / 100 : settings.topBarTransparency) : 0.75;
|
||||
popupTransparency = settings.popupTransparency !== undefined ? (settings.popupTransparency > 1 ? settings.popupTransparency / 100 : settings.popupTransparency) : 0.92;
|
||||
recentlyUsedApps = settings.recentlyUsedApps || [];
|
||||
use24HourClock = settings.use24HourClock !== undefined ? settings.use24HourClock : true;
|
||||
useFahrenheit = settings.useFahrenheit !== undefined ? settings.useFahrenheit : false;
|
||||
nightModeEnabled = settings.nightModeEnabled !== undefined ? settings.nightModeEnabled : false;
|
||||
profileImage = settings.profileImage !== undefined ? settings.profileImage : "";
|
||||
weatherLocationOverride = settings.weatherLocationOverride !== undefined ? settings.weatherLocationOverride : "New York, NY";
|
||||
showFocusedWindow = settings.showFocusedWindow !== undefined ? settings.showFocusedWindow : true;
|
||||
showWeather = settings.showWeather !== undefined ? settings.showWeather : true;
|
||||
showMusic = settings.showMusic !== undefined ? settings.showMusic : true;
|
||||
showClipboard = settings.showClipboard !== undefined ? settings.showClipboard : true;
|
||||
showSystemResources = settings.showSystemResources !== undefined ? settings.showSystemResources : true;
|
||||
showSystemTray = settings.showSystemTray !== undefined ? settings.showSystemTray : true;
|
||||
appLauncherViewMode = settings.appLauncherViewMode !== undefined ? settings.appLauncherViewMode : "list";
|
||||
spotlightLauncherViewMode = settings.spotlightLauncherViewMode !== undefined ? settings.spotlightLauncherViewMode : "list";
|
||||
networkPreference = settings.networkPreference !== undefined ? settings.networkPreference : "auto";
|
||||
console.log("Loaded settings - themeIndex:", themeIndex, "isDynamic:", themeIsDynamic, "lightMode:", isLightMode, "transparency:", topBarTransparency, "recentApps:", recentlyUsedApps.length);
|
||||
applyStoredTheme();
|
||||
} else {
|
||||
console.log("Settings file is empty - applying default theme");
|
||||
applyStoredTheme();
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("Could not parse settings, using defaults:", e);
|
||||
applyStoredTheme();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function saveSettings() {
|
||||
settingsFile.setText(JSON.stringify({
|
||||
"themeIndex": themeIndex,
|
||||
"themeIsDynamic": themeIsDynamic,
|
||||
"isLightMode": isLightMode,
|
||||
"topBarTransparency": topBarTransparency,
|
||||
"popupTransparency": popupTransparency,
|
||||
"recentlyUsedApps": recentlyUsedApps,
|
||||
"use24HourClock": use24HourClock,
|
||||
"useFahrenheit": useFahrenheit,
|
||||
"nightModeEnabled": nightModeEnabled,
|
||||
"profileImage": profileImage,
|
||||
"weatherLocationOverride": weatherLocationOverride,
|
||||
"showFocusedWindow": showFocusedWindow,
|
||||
"showWeather": showWeather,
|
||||
"showMusic": showMusic,
|
||||
"showClipboard": showClipboard,
|
||||
"showSystemResources": showSystemResources,
|
||||
"showSystemTray": showSystemTray,
|
||||
"appLauncherViewMode": appLauncherViewMode,
|
||||
"spotlightLauncherViewMode": spotlightLauncherViewMode,
|
||||
"networkPreference": networkPreference
|
||||
}, null, 2));
|
||||
console.log("Saving settings - themeIndex:", themeIndex, "isDynamic:", themeIsDynamic, "lightMode:", isLightMode, "transparency:", topBarTransparency, "recentApps:", recentlyUsedApps.length);
|
||||
}
|
||||
|
||||
function applyStoredTheme() {
|
||||
console.log("Applying stored theme:", themeIndex, themeIsDynamic, "lightMode:", isLightMode);
|
||||
if (typeof Theme !== "undefined") {
|
||||
Theme.isLightMode = isLightMode;
|
||||
Theme.switchTheme(themeIndex, themeIsDynamic, false);
|
||||
} else {
|
||||
Qt.callLater(() => {
|
||||
if (typeof Theme !== "undefined") {
|
||||
Theme.isLightMode = isLightMode;
|
||||
Theme.switchTheme(themeIndex, themeIsDynamic, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function setTheme(index, isDynamic) {
|
||||
console.log("Prefs setTheme called - themeIndex:", index, "isDynamic:", isDynamic);
|
||||
themeIndex = index;
|
||||
themeIsDynamic = isDynamic;
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
function setLightMode(lightMode) {
|
||||
console.log("Prefs setLightMode called - isLightMode:", lightMode);
|
||||
isLightMode = lightMode;
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
function setTopBarTransparency(transparency) {
|
||||
console.log("Prefs setTopBarTransparency called - topBarTransparency:", transparency);
|
||||
topBarTransparency = transparency;
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
function setPopupTransparency(transparency) {
|
||||
console.log("Prefs setPopupTransparency called - popupTransparency:", transparency);
|
||||
popupTransparency = transparency;
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
function addRecentApp(app) {
|
||||
if (!app)
|
||||
return ;
|
||||
|
||||
var execProp = app.execString || app.exec || "";
|
||||
if (!execProp)
|
||||
return ;
|
||||
|
||||
var existingIndex = -1;
|
||||
for (var i = 0; i < recentlyUsedApps.length; i++) {
|
||||
if (recentlyUsedApps[i].exec === execProp) {
|
||||
existingIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (existingIndex >= 0) {
|
||||
// App exists, increment usage count
|
||||
recentlyUsedApps[existingIndex].usageCount = (recentlyUsedApps[existingIndex].usageCount || 1) + 1;
|
||||
recentlyUsedApps[existingIndex].lastUsed = Date.now();
|
||||
} else {
|
||||
// New app, create entry
|
||||
var appData = {
|
||||
"name": app.name || "",
|
||||
"exec": execProp,
|
||||
"icon": app.icon || "application-x-executable",
|
||||
"comment": app.comment || "",
|
||||
"usageCount": 1,
|
||||
"lastUsed": Date.now()
|
||||
};
|
||||
recentlyUsedApps.push(appData);
|
||||
}
|
||||
// Sort by usage count (descending), then alphabetically by name
|
||||
var sortedApps = recentlyUsedApps.sort(function(a, b) {
|
||||
if (a.usageCount !== b.usageCount)
|
||||
return b.usageCount - a.usageCount;
|
||||
|
||||
// Higher usage count first
|
||||
return a.name.localeCompare(b.name);
|
||||
});
|
||||
// Limit to 10 apps
|
||||
if (sortedApps.length > 10)
|
||||
sortedApps = sortedApps.slice(0, 10);
|
||||
|
||||
// Reassign to trigger property change signal
|
||||
recentlyUsedApps = sortedApps;
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
function getRecentApps() {
|
||||
return recentlyUsedApps;
|
||||
}
|
||||
|
||||
// New preference setters
|
||||
function setClockFormat(use24Hour) {
|
||||
console.log("Prefs setClockFormat called - use24HourClock:", use24Hour);
|
||||
use24HourClock = use24Hour;
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
function setTemperatureUnit(fahrenheit) {
|
||||
console.log("Prefs setTemperatureUnit called - useFahrenheit:", fahrenheit);
|
||||
useFahrenheit = fahrenheit;
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
function setNightModeEnabled(enabled) {
|
||||
console.log("Prefs setNightModeEnabled called - nightModeEnabled:", enabled);
|
||||
nightModeEnabled = enabled;
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
function setProfileImage(imageUrl) {
|
||||
console.log("Prefs setProfileImage called - profileImage:", imageUrl);
|
||||
profileImage = imageUrl;
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
// Widget visibility setters
|
||||
function setShowFocusedWindow(enabled) {
|
||||
console.log("Prefs setShowFocusedWindow called - showFocusedWindow:", enabled);
|
||||
showFocusedWindow = enabled;
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
function setShowWeather(enabled) {
|
||||
console.log("Prefs setShowWeather called - showWeather:", enabled);
|
||||
showWeather = enabled;
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
function setShowMusic(enabled) {
|
||||
console.log("Prefs setShowMusic called - showMusic:", enabled);
|
||||
showMusic = enabled;
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
function setShowClipboard(enabled) {
|
||||
console.log("Prefs setShowClipboard called - showClipboard:", enabled);
|
||||
showClipboard = enabled;
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
function setShowSystemResources(enabled) {
|
||||
console.log("Prefs setShowSystemResources called - showSystemResources:", enabled);
|
||||
showSystemResources = enabled;
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
function setShowSystemTray(enabled) {
|
||||
console.log("Prefs setShowSystemTray called - showSystemTray:", enabled);
|
||||
showSystemTray = enabled;
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
// View mode setters
|
||||
function setAppLauncherViewMode(mode) {
|
||||
console.log("Prefs setAppLauncherViewMode called - appLauncherViewMode:", mode);
|
||||
appLauncherViewMode = mode;
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
function setSpotlightLauncherViewMode(mode) {
|
||||
console.log("Prefs setSpotlightLauncherViewMode called - spotlightLauncherViewMode:", mode);
|
||||
spotlightLauncherViewMode = mode;
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
// Weather location override setter
|
||||
function setWeatherLocationOverride(location) {
|
||||
console.log("Prefs setWeatherLocationOverride called - weatherLocationOverride:", location);
|
||||
weatherLocationOverride = location;
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
// Network preference setter
|
||||
function setNetworkPreference(preference) {
|
||||
console.log("Prefs setNetworkPreference called - networkPreference:", preference);
|
||||
networkPreference = preference;
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
Component.onCompleted: loadSettings()
|
||||
// Monitor system resources preference changes to control service monitoring
|
||||
onShowSystemResourcesChanged: {
|
||||
console.log("Prefs: System resources monitoring", showSystemResources ? "enabled" : "disabled");
|
||||
// Control SystemMonitorService based on whether system monitor widgets are visible
|
||||
if (typeof SystemMonitorService !== 'undefined')
|
||||
SystemMonitorService.enableTopBarMonitoring(showSystemResources);
|
||||
|
||||
}
|
||||
|
||||
FileView {
|
||||
id: settingsFile
|
||||
|
||||
path: StandardPaths.writableLocation(StandardPaths.ConfigLocation) + "/DankMaterialShell/settings.json"
|
||||
blockLoading: true
|
||||
blockWrites: true
|
||||
watchChanges: true
|
||||
|
||||
onLoaded: {
|
||||
console.log("Settings file loaded successfully")
|
||||
parseSettings(settingsFile.text())
|
||||
console.log("Settings file loaded successfully");
|
||||
parseSettings(settingsFile.text());
|
||||
}
|
||||
|
||||
onLoadFailed: (error) => {
|
||||
console.log("Settings file not found, using defaults. Error:", error)
|
||||
applyStoredTheme()
|
||||
console.log("Settings file not found, using defaults. Error:", error);
|
||||
applyStoredTheme();
|
||||
}
|
||||
}
|
||||
|
||||
function loadSettings() {
|
||||
parseSettings(settingsFile.text())
|
||||
}
|
||||
|
||||
function parseSettings(content) {
|
||||
try {
|
||||
if (content && content.trim()) {
|
||||
var settings = JSON.parse(content)
|
||||
themeIndex = settings.themeIndex !== undefined ? settings.themeIndex : 0
|
||||
themeIsDynamic = settings.themeIsDynamic !== undefined ? settings.themeIsDynamic : false
|
||||
isLightMode = settings.isLightMode !== undefined ? settings.isLightMode : false
|
||||
topBarTransparency = settings.topBarTransparency !== undefined ?
|
||||
(settings.topBarTransparency > 1 ? settings.topBarTransparency / 100.0 : settings.topBarTransparency) : 0.75
|
||||
popupTransparency = settings.popupTransparency !== undefined ?
|
||||
(settings.popupTransparency > 1 ? settings.popupTransparency / 100.0 : settings.popupTransparency) : 0.92
|
||||
recentlyUsedApps = settings.recentlyUsedApps || []
|
||||
use24HourClock = settings.use24HourClock !== undefined ? settings.use24HourClock : true
|
||||
useFahrenheit = settings.useFahrenheit !== undefined ? settings.useFahrenheit : false
|
||||
nightModeEnabled = settings.nightModeEnabled !== undefined ? settings.nightModeEnabled : false
|
||||
profileImage = settings.profileImage !== undefined ? settings.profileImage : ""
|
||||
weatherLocationOverride = settings.weatherLocationOverride !== undefined ? settings.weatherLocationOverride : "New York, NY"
|
||||
showFocusedWindow = settings.showFocusedWindow !== undefined ? settings.showFocusedWindow : true
|
||||
showWeather = settings.showWeather !== undefined ? settings.showWeather : true
|
||||
showMusic = settings.showMusic !== undefined ? settings.showMusic : true
|
||||
showClipboard = settings.showClipboard !== undefined ? settings.showClipboard : true
|
||||
showSystemResources = settings.showSystemResources !== undefined ? settings.showSystemResources : true
|
||||
showSystemTray = settings.showSystemTray !== undefined ? settings.showSystemTray : true
|
||||
appLauncherViewMode = settings.appLauncherViewMode !== undefined ? settings.appLauncherViewMode : "list"
|
||||
spotlightLauncherViewMode = settings.spotlightLauncherViewMode !== undefined ? settings.spotlightLauncherViewMode : "list"
|
||||
networkPreference = settings.networkPreference !== undefined ? settings.networkPreference : "auto"
|
||||
console.log("Loaded settings - themeIndex:", themeIndex, "isDynamic:", themeIsDynamic, "lightMode:", isLightMode, "transparency:", topBarTransparency, "recentApps:", recentlyUsedApps.length)
|
||||
|
||||
applyStoredTheme()
|
||||
} else {
|
||||
console.log("Settings file is empty - applying default theme")
|
||||
applyStoredTheme()
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("Could not parse settings, using defaults:", e)
|
||||
applyStoredTheme()
|
||||
}
|
||||
}
|
||||
|
||||
function saveSettings() {
|
||||
settingsFile.setText(JSON.stringify({
|
||||
themeIndex,
|
||||
themeIsDynamic,
|
||||
isLightMode,
|
||||
topBarTransparency,
|
||||
popupTransparency,
|
||||
recentlyUsedApps,
|
||||
use24HourClock,
|
||||
useFahrenheit,
|
||||
nightModeEnabled,
|
||||
profileImage,
|
||||
weatherLocationOverride,
|
||||
showFocusedWindow,
|
||||
showWeather,
|
||||
showMusic,
|
||||
showClipboard,
|
||||
showSystemResources,
|
||||
showSystemTray,
|
||||
appLauncherViewMode,
|
||||
spotlightLauncherViewMode,
|
||||
networkPreference
|
||||
}, null, 2))
|
||||
console.log("Saving settings - themeIndex:", themeIndex, "isDynamic:", themeIsDynamic, "lightMode:", isLightMode, "transparency:", topBarTransparency, "recentApps:", recentlyUsedApps.length)
|
||||
}
|
||||
|
||||
function applyStoredTheme() {
|
||||
console.log("Applying stored theme:", themeIndex, themeIsDynamic, "lightMode:", isLightMode)
|
||||
|
||||
if (typeof Theme !== "undefined") {
|
||||
Theme.isLightMode = isLightMode
|
||||
Theme.switchTheme(themeIndex, themeIsDynamic, false)
|
||||
} else {
|
||||
Qt.callLater(() => {
|
||||
if (typeof Theme !== "undefined") {
|
||||
Theme.isLightMode = isLightMode
|
||||
Theme.switchTheme(themeIndex, themeIsDynamic, false)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function setTheme(index, isDynamic) {
|
||||
console.log("Prefs setTheme called - themeIndex:", index, "isDynamic:", isDynamic)
|
||||
themeIndex = index
|
||||
themeIsDynamic = isDynamic
|
||||
saveSettings()
|
||||
}
|
||||
|
||||
function setLightMode(lightMode) {
|
||||
console.log("Prefs setLightMode called - isLightMode:", lightMode)
|
||||
isLightMode = lightMode
|
||||
saveSettings()
|
||||
}
|
||||
|
||||
function setTopBarTransparency(transparency) {
|
||||
console.log("Prefs setTopBarTransparency called - topBarTransparency:", transparency)
|
||||
topBarTransparency = transparency
|
||||
saveSettings()
|
||||
}
|
||||
|
||||
function setPopupTransparency(transparency) {
|
||||
console.log("Prefs setPopupTransparency called - popupTransparency:", transparency)
|
||||
popupTransparency = transparency
|
||||
saveSettings()
|
||||
}
|
||||
|
||||
function addRecentApp(app) {
|
||||
if (!app) return
|
||||
|
||||
var execProp = app.execString || app.exec || ""
|
||||
if (!execProp) return
|
||||
|
||||
var existingIndex = -1
|
||||
for (var i = 0; i < recentlyUsedApps.length; i++) {
|
||||
if (recentlyUsedApps[i].exec === execProp) {
|
||||
existingIndex = i
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (existingIndex >= 0) {
|
||||
// App exists, increment usage count
|
||||
recentlyUsedApps[existingIndex].usageCount = (recentlyUsedApps[existingIndex].usageCount || 1) + 1
|
||||
recentlyUsedApps[existingIndex].lastUsed = Date.now()
|
||||
} else {
|
||||
// New app, create entry
|
||||
var appData = {
|
||||
name: app.name || "",
|
||||
exec: execProp,
|
||||
icon: app.icon || "application-x-executable",
|
||||
comment: app.comment || "",
|
||||
usageCount: 1,
|
||||
lastUsed: Date.now()
|
||||
}
|
||||
recentlyUsedApps.push(appData)
|
||||
}
|
||||
|
||||
// Sort by usage count (descending), then alphabetically by name
|
||||
var sortedApps = recentlyUsedApps.sort(function(a, b) {
|
||||
if (a.usageCount !== b.usageCount) {
|
||||
return b.usageCount - a.usageCount // Higher usage count first
|
||||
}
|
||||
return a.name.localeCompare(b.name) // Alphabetical tiebreaker
|
||||
})
|
||||
|
||||
// Limit to 10 apps
|
||||
if (sortedApps.length > 10) {
|
||||
sortedApps = sortedApps.slice(0, 10)
|
||||
}
|
||||
|
||||
// Reassign to trigger property change signal
|
||||
recentlyUsedApps = sortedApps
|
||||
|
||||
saveSettings()
|
||||
}
|
||||
|
||||
function getRecentApps() {
|
||||
return recentlyUsedApps
|
||||
}
|
||||
|
||||
// New preference setters
|
||||
function setClockFormat(use24Hour) {
|
||||
console.log("Prefs setClockFormat called - use24HourClock:", use24Hour)
|
||||
use24HourClock = use24Hour
|
||||
saveSettings()
|
||||
}
|
||||
|
||||
function setTemperatureUnit(fahrenheit) {
|
||||
console.log("Prefs setTemperatureUnit called - useFahrenheit:", fahrenheit)
|
||||
useFahrenheit = fahrenheit
|
||||
saveSettings()
|
||||
}
|
||||
|
||||
function setNightModeEnabled(enabled) {
|
||||
console.log("Prefs setNightModeEnabled called - nightModeEnabled:", enabled)
|
||||
nightModeEnabled = enabled
|
||||
saveSettings()
|
||||
}
|
||||
|
||||
function setProfileImage(imageUrl) {
|
||||
console.log("Prefs setProfileImage called - profileImage:", imageUrl)
|
||||
profileImage = imageUrl
|
||||
saveSettings()
|
||||
}
|
||||
|
||||
// Widget visibility setters
|
||||
function setShowFocusedWindow(enabled) {
|
||||
console.log("Prefs setShowFocusedWindow called - showFocusedWindow:", enabled)
|
||||
showFocusedWindow = enabled
|
||||
saveSettings()
|
||||
}
|
||||
|
||||
function setShowWeather(enabled) {
|
||||
console.log("Prefs setShowWeather called - showWeather:", enabled)
|
||||
showWeather = enabled
|
||||
saveSettings()
|
||||
}
|
||||
|
||||
function setShowMusic(enabled) {
|
||||
console.log("Prefs setShowMusic called - showMusic:", enabled)
|
||||
showMusic = enabled
|
||||
saveSettings()
|
||||
}
|
||||
|
||||
function setShowClipboard(enabled) {
|
||||
console.log("Prefs setShowClipboard called - showClipboard:", enabled)
|
||||
showClipboard = enabled
|
||||
saveSettings()
|
||||
}
|
||||
|
||||
function setShowSystemResources(enabled) {
|
||||
console.log("Prefs setShowSystemResources called - showSystemResources:", enabled)
|
||||
showSystemResources = enabled
|
||||
saveSettings()
|
||||
}
|
||||
|
||||
function setShowSystemTray(enabled) {
|
||||
console.log("Prefs setShowSystemTray called - showSystemTray:", enabled)
|
||||
showSystemTray = enabled
|
||||
saveSettings()
|
||||
}
|
||||
|
||||
// View mode setters
|
||||
function setAppLauncherViewMode(mode) {
|
||||
console.log("Prefs setAppLauncherViewMode called - appLauncherViewMode:", mode)
|
||||
appLauncherViewMode = mode
|
||||
saveSettings()
|
||||
}
|
||||
|
||||
function setSpotlightLauncherViewMode(mode) {
|
||||
console.log("Prefs setSpotlightLauncherViewMode called - spotlightLauncherViewMode:", mode)
|
||||
spotlightLauncherViewMode = mode
|
||||
saveSettings()
|
||||
}
|
||||
|
||||
// Weather location override setter
|
||||
function setWeatherLocationOverride(location) {
|
||||
console.log("Prefs setWeatherLocationOverride called - weatherLocationOverride:", location)
|
||||
weatherLocationOverride = location
|
||||
saveSettings()
|
||||
}
|
||||
|
||||
// Network preference setter
|
||||
function setNetworkPreference(preference) {
|
||||
console.log("Prefs setNetworkPreference called - networkPreference:", preference)
|
||||
networkPreference = preference
|
||||
saveSettings()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
pragma Singleton
|
||||
pragma ComponentBehavior: Bound
|
||||
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
|
||||
Reference in New Issue
Block a user