1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-28 07:22:50 -05:00

meta cleanup and refactors

This commit is contained in:
bbedward
2025-07-18 11:40:17 -04:00
parent 06607fa25e
commit 3a3f18c298
30 changed files with 473 additions and 783 deletions

View File

@@ -10,73 +10,44 @@ import "../Common/fuzzysort.js" as Fuzzy
Singleton {
id: root
property list<DesktopEntry> applications: []
property var applicationsByName: ({})
property var applicationsByExec: ({})
property bool ready: false
property list<DesktopEntry> applications: Array.from(DesktopEntries.applications.values)
.filter(app => !app.noDisplay)
.sort((a, b) => a.name.localeCompare(b.name))
property var preppedApps: []
Component.onCompleted: {
loadApplications()
}
Connections {
target: DesktopEntries
function onApplicationsChanged() {
console.log("AppSearchService: DesktopEntries applicationsChanged signal received")
console.log("AppSearchService: Current applications count before reload:", applications.length)
loadApplications()
property var applicationsByName: {
var byName = {}
for (var i = 0; i < applications.length; i++) {
var app = applications[i]
byName[app.name.toLowerCase()] = app
}
return byName
}
function loadApplications() {
Qt.callLater(function() {
var allApps = Array.from(DesktopEntries.applications.values)
applications = allApps
.filter(app => !app.noDisplay)
.sort((a, b) => a.name.localeCompare(b.name))
var byName = {}
var byExec = {}
for (var i = 0; i < applications.length; i++) {
var app = applications[i]
byName[app.name.toLowerCase()] = app
var execProp = app.execString || ""
var cleanExec = execProp ? execProp.replace(/%[fFuU]/g, "").trim() : ""
if (cleanExec) {
byExec[cleanExec] = app
}
property var applicationsByExec: {
var byExec = {}
for (var i = 0; i < applications.length; i++) {
var app = applications[i]
var execProp = app.execString || ""
var cleanExec = execProp ? execProp.replace(/%[fFuU]/g, "").trim() : ""
if (cleanExec) {
byExec[cleanExec] = app
}
applicationsByName = byName
applicationsByExec = byExec
preppedApps = applications.map(app => ({
name: Fuzzy.prepare(app.name || ""),
comment: Fuzzy.prepare(app.comment || ""),
entry: app
}))
ready = true
console.log("AppSearchService: Loaded", applications.length, "applications")
console.log("AppSearchService: Prepared", preppedApps.length, "apps for fuzzy search")
console.log("AppSearchService: Ready status:", ready)
})
}
return byExec
}
property var preppedApps: applications.map(app => ({
name: Fuzzy.prepare(app.name || ""),
comment: Fuzzy.prepare(app.comment || ""),
entry: app
}))
function searchApplications(query) {
if (!query || query.length === 0) {
return applications
}
if (!ready || preppedApps.length === 0) {
if (preppedApps.length === 0) {
return []
}
@@ -167,18 +138,4 @@ Singleton {
})
}
function launchApp(app) {
if (!app) {
console.warn("AppSearchService: Cannot launch app, app is null")
return false
}
if (typeof app.execute === "function") {
app.execute()
return true
}
console.warn("AppSearchService: Cannot launch app, no execute method")
return false
}
}

View File

@@ -8,108 +8,55 @@ import Quickshell.Io
Singleton {
id: root
property list<var> ddcMonitors: []
readonly property list<Monitor> monitors: variants.instances
property bool brightnessAvailable: laptopBacklightAvailable || ddcMonitors.length > 0
property bool brightnessAvailable: laptopBacklightAvailable || ddcAvailable
property bool laptopBacklightAvailable: false
property bool ddcAvailable: false
property int brightnessLevel: 75
property int laptopBrightnessLevel: 75
function getMonitorForScreen(screen: ShellScreen): var {
return monitors.find(function(m) { return m.modelData === screen; });
}
property var debounceTimer: Timer {
id: debounceTimer
interval: 50
repeat: false
property int pendingValue: 0
onTriggered: {
const focusedMonitor = monitors.find(function(m) { return m.modelData === Quickshell.screens[0]; });
if (focusedMonitor) {
focusedMonitor.setBrightness(pendingValue / 100);
}
}
}
property var laptopDebounceTimer: Timer {
id: laptopDebounceTimer
interval: 50
repeat: false
property int pendingValue: 0
onTriggered: {
laptopBrightnessProcess.command = ["brightnessctl", "set", pendingValue + "%"];
laptopBrightnessProcess.running = true;
}
}
property int maxBrightness: 100
property int currentRawBrightness: 0
function setBrightness(percentage) {
if (root.laptopBacklightAvailable) {
// Use laptop backlight control
root.laptopBrightnessLevel = percentage;
laptopDebounceTimer.pendingValue = percentage;
laptopDebounceTimer.restart();
} else {
// Use external monitor control
root.brightnessLevel = percentage;
debounceTimer.pendingValue = percentage;
debounceTimer.restart();
}
}
function increaseBrightness(): void {
if (root.laptopBacklightAvailable) {
setBrightness(Math.min(100, root.laptopBrightnessLevel + 10));
} else {
const focusedMonitor = monitors.find(function(m) { return m.modelData === Quickshell.screens[0]; });
if (focusedMonitor)
focusedMonitor.setBrightness(focusedMonitor.brightness + 0.1);
}
}
function decreaseBrightness(): void {
if (root.laptopBacklightAvailable) {
setBrightness(Math.max(1, root.laptopBrightnessLevel - 10));
} else {
const focusedMonitor = monitors.find(function(m) { return m.modelData === Quickshell.screens[0]; });
if (focusedMonitor)
focusedMonitor.setBrightness(focusedMonitor.brightness - 0.1);
}
}
onMonitorsChanged: {
ddcMonitors = [];
if (root.brightnessAvailable) {
ddcProc.running = true;
}
brightnessLevel = Math.max(1, Math.min(100, percentage));
// Update brightness level from laptop or first monitor
if (root.laptopBacklightAvailable) {
// Laptop brightness is already set by laptopBrightnessInitProcess
} else if (monitors.length > 0) {
root.brightnessLevel = Math.round(monitors[0].brightness * 100);
if (laptopBacklightAvailable) {
laptopBrightnessProcess.command = ["brightnessctl", "set", brightnessLevel + "%"];
laptopBrightnessProcess.running = true;
} else if (ddcAvailable) {
console.log("Setting DDC brightness to:", brightnessLevel);
Quickshell.execDetached(["ddcutil", "setvcp", "10", brightnessLevel.toString()]);
}
}
function increaseBrightness() {
setBrightness(brightnessLevel + 10);
}
function decreaseBrightness() {
setBrightness(brightnessLevel - 10);
}
Component.onCompleted: {
ddcAvailabilityChecker.running = true;
laptopBacklightChecker.running = true;
}
Variants {
id: variants
model: Quickshell.screens
Monitor {}
onLaptopBacklightAvailableChanged: {
if (laptopBacklightAvailable) {
laptopBrightnessInitProcess.running = true;
}
}
onDdcAvailableChanged: {
if (ddcAvailable) {
ddcBrightnessInitProcess.running = true;
}
}
Process {
id: ddcAvailabilityChecker
command: ["which", "ddcutil"]
onExited: function(exitCode) {
root.brightnessAvailable = (exitCode === 0);
if (root.brightnessAvailable) {
ddcProc.running = true;
}
ddcAvailable = (exitCode === 0);
}
}
@@ -117,10 +64,7 @@ Singleton {
id: laptopBacklightChecker
command: ["brightnessctl", "--list"]
onExited: function(exitCode) {
root.laptopBacklightAvailable = (exitCode === 0);
if (root.laptopBacklightAvailable) {
laptopBrightnessInitProcess.running = true;
}
laptopBacklightAvailable = (exitCode === 0);
}
}
@@ -129,10 +73,7 @@ Singleton {
running: false
onExited: function(exitCode) {
if (exitCode === 0) {
// Update was successful
root.brightnessLevel = root.laptopBrightnessLevel;
} else {
if (exitCode !== 0) {
console.warn("Failed to set laptop brightness, exit code:", exitCode);
}
}
@@ -146,9 +87,8 @@ Singleton {
stdout: StdioCollector {
onStreamFinished: {
if (text.trim()) {
// Get max brightness to calculate percentage
currentRawBrightness = parseInt(text.trim());
laptopMaxBrightnessProcess.running = true;
root.laptopBrightnessLevel = parseInt(text.trim());
}
}
}
@@ -168,10 +108,8 @@ Singleton {
stdout: StdioCollector {
onStreamFinished: {
if (text.trim()) {
const maxBrightness = parseInt(text.trim());
const currentPercentage = Math.round((root.laptopBrightnessLevel / maxBrightness) * 100);
root.laptopBrightnessLevel = currentPercentage;
root.brightnessLevel = currentPercentage;
maxBrightness = parseInt(text.trim());
brightnessLevel = Math.round((currentRawBrightness / maxBrightness) * 100);
}
}
}
@@ -184,86 +122,28 @@ Singleton {
}
Process {
id: ddcProc
command: ["ddcutil", "detect", "--brief"]
id: ddcBrightnessInitProcess
command: ["ddcutil", "getvcp", "10", "--brief"]
running: false
stdout: StdioCollector {
onStreamFinished: {
if (text.trim()) {
root.ddcMonitors = text.trim().split("\n\n").filter(function(d) { return d.startsWith("Display "); }).map(function(d) { return ({
model: d.match(/Monitor:.*:(.*):.*/)?.[1] || "Unknown",
busNum: d.match(/I2C bus:[ ]*\/dev\/i2c-([0-9]+)/)?.[1] || "0"
}); });
} else {
root.ddcMonitors = [];
}
}
}
onExited: function(exitCode) {
if (exitCode !== 0) {
root.ddcMonitors = [];
}
}
}
component Monitor: QtObject {
id: monitor
required property ShellScreen modelData
readonly property bool isDdc: root.ddcMonitors.some(function(m) { return m.model === modelData.model; })
readonly property string busNum: root.ddcMonitors.find(function(m) { return m.model === modelData.model; })?.busNum ?? ""
property real brightness: 0.75
readonly property Process initProc: Process {
stdout: StdioCollector {
onStreamFinished: {
if (text.trim()) {
const parts = text.trim().split(" ");
if (parts.length >= 5) {
const current = parseInt(parts[3]) || 75;
const max = parseInt(parts[4]) || 100;
monitor.brightness = current / max;
root.brightnessLevel = Math.round(monitor.brightness * 100);
}
const parts = text.trim().split(" ");
if (parts.length >= 5) {
const current = parseInt(parts[3]) || 75;
const max = parseInt(parts[4]) || 100;
brightnessLevel = Math.round((current / max) * 100);
}
}
}
onExited: function(exitCode) {
if (exitCode !== 0) {
monitor.brightness = 0.75;
root.brightnessLevel = 75;
}
}
}
function setBrightness(value: real): void {
value = Math.max(0, Math.min(1, value));
const rounded = Math.round(value * 100);
if (Math.round(brightness * 100) === rounded)
return;
brightness = value;
root.brightnessLevel = rounded;
if (isDdc && busNum) {
Quickshell.execDetached(["ddcutil", "-b", busNum, "setvcp", "10", rounded.toString()]);
onExited: function(exitCode) {
if (exitCode !== 0) {
console.warn("Failed to get DDC brightness, exit code:", exitCode);
brightnessLevel = 75;
}
}
onBusNumChanged: {
if (isDdc && busNum) {
initProc.command = ["ddcutil", "-b", busNum, "getvcp", "10", "--brief"];
initProc.running = true;
}
}
Component.onCompleted: {
Qt.callLater(function() {
if (isDdc && busNum) {
initProc.command = ["ddcutil", "-b", busNum, "getvcp", "10", "--brief"];
initProc.running = true;
}
});
}
}
}

View File

@@ -39,11 +39,9 @@ Singleton {
function loadEvents(startDate, endDate) {
if (!root.khalAvailable) {
console.warn("CalendarService: khal not available, skipping event loading");
return ;
}
if (eventsProcess.running) {
console.log("CalendarService: Event loading already in progress, skipping...");
return ;
}
// Store last requested date range for refresh timer
@@ -71,24 +69,9 @@ Singleton {
// Initialize on component completion
Component.onCompleted: {
console.log("CalendarService: Component completed, initializing...");
checkKhalAvailability();
}
// Periodic refresh timer
Timer {
id: refreshTimer
interval: 60000
running: root.khalAvailable
repeat: true
onTriggered: {
if (lastStartDate && lastEndDate)
loadEvents(lastStartDate, lastEndDate);
}
}
// Process for checking khal configuration
Process {
id: khalCheckProcess
@@ -97,17 +80,10 @@ Singleton {
running: false
onExited: (exitCode) => {
root.khalAvailable = (exitCode === 0);
if (exitCode !== 0) {
console.warn("CalendarService: khal not configured (exit code:", exitCode, ")");
} else {
console.log("CalendarService: khal configured and available");
// Load current month events when khal becomes available
if (exitCode === 0) {
loadCurrentMonth();
}
}
onStarted: {
console.log("CalendarService: Checking khal configuration...");
}
}
// Process for loading events
@@ -123,7 +99,6 @@ Singleton {
root.isLoading = false;
if (exitCode !== 0) {
root.lastError = "Failed to load events (exit code: " + exitCode + ")";
console.warn("CalendarService:", root.lastError);
return ;
}
try {
@@ -249,19 +224,14 @@ Singleton {
}
root.eventsByDate = newEventsByDate;
root.lastError = "";
console.log("CalendarService: Loaded events for", Object.keys(newEventsByDate).length, "days");
} catch (error) {
root.lastError = "Failed to parse events JSON: " + error.toString();
console.error("CalendarService:", root.lastError);
root.eventsByDate = {
};
}
// Reset for next run
eventsProcess.rawOutput = "";
}
onStarted: {
console.log("CalendarService: Loading events from", Qt.formatDate(requestStartDate, "yyyy-MM-dd"), "to", Qt.formatDate(requestEndDate, "yyyy-MM-dd"));
}
stdout: SplitParser {
splitMarker: "\n"

View File

@@ -1,19 +0,0 @@
pragma Singleton
pragma ComponentBehavior: Bound
import QtQuick
import Quickshell
Singleton {
id: root
signal showAppLauncher()
signal hideAppLauncher()
signal toggleAppLauncher()
signal showSpotlight()
signal hideSpotlight()
signal toggleSpotlight()
signal showClipboardHistory()
signal hideClipboardHistory()
signal toggleClipboardHistory()
}

View File

@@ -139,7 +139,6 @@ Singleton {
if (preferenceComplete) {
root.changingPreference = false
root.targetPreference = ""
preferenceTimeoutTimer.stop()
console.log("Network preference change completed successfully")
}
}
@@ -379,26 +378,8 @@ Singleton {
}
function delayedRefreshNetworkStatus() {
console.log("Delayed network status refresh...")
refreshTimer.start()
}
Timer {
id: refreshTimer
interval: 1000
onTriggered: {
refreshNetworkStatus()
}
}
Timer {
id: preferenceTimeoutTimer
interval: 15000 // 15 seconds timeout
onTriggered: {
console.log("Network preference change timeout - resetting changingPreference state")
root.changingPreference = false
root.targetPreference = ""
}
console.log("Refreshing network status immediately...")
refreshNetworkStatus()
}
function setNetworkPreference(preference) {
@@ -406,7 +387,6 @@ Singleton {
root.userPreference = preference
root.changingPreference = true
root.targetPreference = preference
preferenceTimeoutTimer.start()
Prefs.setNetworkPreference(preference)
if (preference === "wifi") {

View File

@@ -99,23 +99,13 @@ Singleton {
onExited: (exitCode) => {
if (exitCode !== 0 && root.niriAvailable) {
console.warn("NiriWorkspaceService: Event stream exited with code", exitCode, "restarting in 2 seconds")
restartTimer.start()
}
}
}
// Restart timer for event stream
Timer {
id: restartTimer
interval: 2000
onTriggered: {
if (root.niriAvailable) {
console.warn("NiriWorkspaceService: Event stream exited with code", exitCode, "restarting immediately")
eventStreamProcess.running = true
}
}
}
function handleNiriEvent(event) {
if (event.WorkspacesChanged) {
handleWorkspacesChanged(event.WorkspacesChanged)
@@ -173,6 +163,9 @@ Singleton {
currentOutput = activatedWs.output || ""
updateCurrentOutputWorkspaces()
// Force property change notifications
allWorkspacesChanged()
} else {
focusedWorkspaceIndex = 0
}

View File

@@ -333,31 +333,6 @@ Singleton {
console.log("ProcessMonitorService: Initialization complete");
}
Timer {
id: testTimer
interval: 3000
running: false
repeat: false
onTriggered: {
console.log("ProcessMonitorService: Starting test monitoring...");
enableMonitoring(true);
stopTestTimer.start();
}
}
Timer {
id: stopTestTimer
interval: 8000
running: false
repeat: false
onTriggered: {
console.log("ProcessMonitorService: Stopping test monitoring...");
enableMonitoring(false);
}
}
Process {
id: systemInfoProcess

View File

@@ -24,7 +24,6 @@ Singleton {
property string kernelVersion: ""
property string distribution: ""
property string hostname: ""
property string uptime: ""
property string scheduler: ""
property string architecture: ""
property string loadAverage: ""
@@ -61,7 +60,6 @@ Singleton {
kernelInfoProcess.running = true;
distributionProcess.running = true;
hostnameProcess.running = true;
uptimeProcess.running = true;
schedulerProcess.running = true;
architectureProcess.running = true;
loadAverageProcess.running = true;
@@ -319,26 +317,6 @@ Singleton {
}
Process {
id: uptimeProcess
command: ["bash", "-c", "uptime -p | sed 's/up //'"]
running: false
onExited: (exitCode) => {
if (exitCode !== 0)
console.warn("Uptime check failed with exit code:", exitCode);
}
stdout: StdioCollector {
onStreamFinished: {
if (text.trim())
root.uptime = text.trim();
}
}
}
Process {
id: schedulerProcess
@@ -546,55 +524,27 @@ Singleton {
}
Timer {
id: cpuTimer
id: basicStatsTimer
interval: root.cpuUpdateInterval
interval: 5000
running: root.enabledForTopBar || root.enabledForDetailedView
repeat: true
onTriggered: {
if (root.enabledForTopBar || root.enabledForDetailedView) {
cpuUsageProcess.running = true;
cpuFrequencyProcess.running = true;
}
cpuUsageProcess.running = true;
cpuFrequencyProcess.running = true;
memoryUsageProcess.running = true;
}
}
Timer {
id: memoryTimer
id: detailedStatsTimer
interval: root.memoryUpdateInterval
running: root.enabledForTopBar || root.enabledForDetailedView
repeat: true
onTriggered: {
if (root.enabledForTopBar || root.enabledForDetailedView)
memoryUsageProcess.running = true;
}
}
Timer {
id: temperatureTimer
interval: root.temperatureUpdateInterval
interval: 15000
running: root.enabledForDetailedView
repeat: true
onTriggered: {
if (root.enabledForDetailedView)
temperatureProcess.running = true;
}
}
Timer {
id: systemInfoTimer
interval: root.systemInfoUpdateInterval
running: root.enabledForDetailedView
repeat: true
onTriggered: {
if (root.enabledForDetailedView)
updateSystemInfo();
temperatureProcess.running = true;
updateSystemInfo();
}
}

View File

@@ -44,7 +44,7 @@ Singleton {
currentLevel = levelInfo;
toastTimer.stop();
if (toastQueue.length > 0)
queueTimer.start();
processQueue();
}
@@ -56,7 +56,7 @@ Singleton {
currentMessage = toast.message;
currentLevel = toast.level;
toastVisible = true;
toastTimer.interval = toast.level === levelError ? 8000 : toast.level === levelWarn ? 6000 : 5000;
toastTimer.interval = toast.level === levelError ? 5000 : toast.level === levelWarn ? 4000 : 3000;
toastTimer.start();
}
@@ -73,13 +73,5 @@ Singleton {
onTriggered: hideToast()
}
Timer {
id: queueTimer
interval: 500
running: false
repeat: false
onTriggered: processQueue()
}
}

View File

@@ -36,17 +36,6 @@ Singleton {
Component.onCompleted: {
getUserInfo();
getUptime();
// Update uptime every minute
uptimeTimer.start();
}
Timer {
id: uptimeTimer
interval: 60000 // 1 minute
running: false
repeat: true
onTriggered: getUptime()
}
// Get username and full name
@@ -96,7 +85,6 @@ Singleton {
stdout: StdioCollector {
onStreamFinished: {
root.uptime = text.trim() || "Unknown";
console.log("UserInfoService: Uptime updated -", root.uptime);
}
}

View File

@@ -23,11 +23,9 @@ Singleton {
return ;
root.isScanning = true;
console.log("Starting WiFi scan...");
wifiScanner.running = true;
savedWifiScanner.running = true;
currentWifiInfo.running = true;
// Fallback timer in case no networks are found
fallbackTimer.start();
}
@@ -133,7 +131,6 @@ Singleton {
}
function updateCurrentWifiInfo() {
console.log("Updating current WiFi info...");
currentWifiInfo.running = true;
}
@@ -254,7 +251,6 @@ Singleton {
interval: 5000
onTriggered: {
root.isScanning = false;
console.log("WiFi scan timeout - no networks found");
}
}
@@ -274,11 +270,7 @@ Singleton {
interval: 20000
running: root.autoRefreshEnabled
repeat: true
onTriggered: {
if (root.autoRefreshEnabled)
root.scanWifi();
}
onTriggered: root.scanWifi()
}
}