mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2025-12-09 23:15:38 -05:00
General code cleanups
This commit is contained in:
@@ -12,28 +12,6 @@ Singleton {
|
||||
|
||||
property var applications: DesktopEntries.applications.values
|
||||
|
||||
property var applicationsByName: {
|
||||
var byName = {}
|
||||
for (var i = 0; i < applications.length; i++) {
|
||||
var app = applications[i]
|
||||
byName[app.name.toLowerCase()] = app
|
||||
}
|
||||
return byName
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
return byExec
|
||||
}
|
||||
|
||||
property var preppedApps: applications.map(app => ({
|
||||
name: Fuzzy.prepare(app.name || ""),
|
||||
comment: Fuzzy.prepare(app.comment || ""),
|
||||
@@ -89,14 +67,7 @@ Singleton {
|
||||
return results.map(r => r.obj.entry)
|
||||
}
|
||||
|
||||
function getAppByName(name) {
|
||||
return applicationsByName[name.toLowerCase()] || null
|
||||
}
|
||||
|
||||
function getAppByExec(exec) {
|
||||
var cleanExec = exec.replace(/%[fFuU]/g, "").trim()
|
||||
return applicationsByExec[cleanExec] || null
|
||||
}
|
||||
|
||||
|
||||
function getCategoriesForApp(app) {
|
||||
if (!app || !app.categories) return []
|
||||
|
||||
@@ -77,35 +77,7 @@ Singleton {
|
||||
return "bluetooth";
|
||||
}
|
||||
|
||||
function getDeviceType(device) {
|
||||
if (!device)
|
||||
return "bluetooth";
|
||||
|
||||
var name = (device.name || device.deviceName || "").toLowerCase();
|
||||
var icon = (device.icon || "").toLowerCase();
|
||||
if (icon.includes("headset") || icon.includes("audio") || name.includes("headphone") || name.includes("airpod") || name.includes("headset") || name.includes("arctis"))
|
||||
return "headset";
|
||||
|
||||
if (icon.includes("mouse") || name.includes("mouse"))
|
||||
return "mouse";
|
||||
|
||||
if (icon.includes("keyboard") || name.includes("keyboard"))
|
||||
return "keyboard";
|
||||
|
||||
if (icon.includes("phone") || name.includes("phone") || name.includes("iphone") || name.includes("android") || name.includes("samsung"))
|
||||
return "phone";
|
||||
|
||||
if (icon.includes("watch") || name.includes("watch"))
|
||||
return "watch";
|
||||
|
||||
if (icon.includes("speaker") || name.includes("speaker"))
|
||||
return "speaker";
|
||||
|
||||
if (icon.includes("display") || name.includes("tv"))
|
||||
return "tv";
|
||||
|
||||
return "bluetooth";
|
||||
}
|
||||
|
||||
function canConnect(device) {
|
||||
if (!device)
|
||||
|
||||
@@ -22,7 +22,7 @@ Singleton {
|
||||
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()]);
|
||||
}
|
||||
}
|
||||
@@ -66,7 +66,7 @@ Singleton {
|
||||
|
||||
onExited: function(exitCode) {
|
||||
if (exitCode !== 0) {
|
||||
console.warn("Failed to set laptop brightness, exit code:", exitCode);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -87,7 +87,7 @@ Singleton {
|
||||
|
||||
onExited: function(exitCode) {
|
||||
if (exitCode !== 0) {
|
||||
console.warn("Failed to get laptop brightness, exit code:", exitCode);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -108,7 +108,7 @@ Singleton {
|
||||
|
||||
onExited: function(exitCode) {
|
||||
if (exitCode !== 0) {
|
||||
console.warn("Failed to get max laptop brightness, exit code:", exitCode);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -133,7 +133,7 @@ Singleton {
|
||||
|
||||
onExited: function(exitCode) {
|
||||
if (exitCode !== 0) {
|
||||
console.warn("Failed to get DDC brightness, exit code:", exitCode);
|
||||
|
||||
brightnessLevel = 75;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,27 +45,18 @@ Singleton {
|
||||
|
||||
function addRef() {
|
||||
refCount++;
|
||||
console.log("NetworkService: addRef, refCount now:", refCount);
|
||||
// Reference counting affects WiFi scanning operations only
|
||||
// Basic network status monitoring always runs
|
||||
}
|
||||
|
||||
function removeRef() {
|
||||
refCount = Math.max(0, refCount - 1);
|
||||
console.log("NetworkService: removeRef, refCount now:", refCount);
|
||||
// Stop intensive WiFi operations when no consumers
|
||||
if (refCount === 0) {
|
||||
autoRefreshTimer.running = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Load saved preference on startup
|
||||
Component.onCompleted: {
|
||||
// Load preference from Prefs system
|
||||
root.userPreference = Prefs.networkPreference
|
||||
console.log("NetworkService: Loaded network preference from Prefs:", root.userPreference)
|
||||
|
||||
// Trigger immediate WiFi info update if WiFi is connected and enabled
|
||||
if (root.networkStatus === "wifi" && root.wifiEnabled) {
|
||||
updateCurrentWifiInfo()
|
||||
}
|
||||
@@ -582,7 +573,7 @@ Singleton {
|
||||
return b.signal - a.signal;
|
||||
});
|
||||
root.wifiNetworks = networks;
|
||||
console.log("Found", networks.length, "WiFi networks");
|
||||
|
||||
// Stop scanning once we have results
|
||||
if (networks.length > 0) {
|
||||
root.isScanning = false;
|
||||
@@ -615,7 +606,7 @@ Singleton {
|
||||
|
||||
}
|
||||
root.savedWifiNetworks = saved;
|
||||
console.log("Found", saved.length, "saved WiFi networks");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -902,14 +893,14 @@ Singleton {
|
||||
|
||||
root.networkInfoDetails = details;
|
||||
root.networkInfoLoading = false;
|
||||
console.log("Network info fetched for:", root.networkInfoSSID);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
onExited: (exitCode) => {
|
||||
root.networkInfoLoading = false;
|
||||
if (exitCode !== 0) {
|
||||
console.log("Failed to fetch network info, exit code:", exitCode);
|
||||
|
||||
root.networkInfoDetails = "Failed to fetch network information";
|
||||
}
|
||||
}
|
||||
@@ -917,7 +908,7 @@ Singleton {
|
||||
stderr: SplitParser {
|
||||
splitMarker: "\\n"
|
||||
onRead: (data) => {
|
||||
console.log("WiFi info stderr:", data);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ Singleton {
|
||||
try {
|
||||
data = JSON.parse(text);
|
||||
} catch (error) {
|
||||
console.error("SysMonitorService: Failed to parse JSON:", error, "Raw text:", text.slice(0, 300));
|
||||
|
||||
isUpdating = false;
|
||||
return;
|
||||
}
|
||||
@@ -535,7 +535,7 @@ printf "}\\n"`
|
||||
running: false
|
||||
onExited: (exitCode) => {
|
||||
if (exitCode !== 0) {
|
||||
console.warn("Unified stats process failed with exit code:", exitCode);
|
||||
|
||||
isUpdating = false;
|
||||
}
|
||||
}
|
||||
@@ -545,7 +545,7 @@ printf "}\\n"`
|
||||
const fullText = text.trim();
|
||||
const lastBraceIndex = fullText.lastIndexOf('}');
|
||||
if (lastBraceIndex === -1) {
|
||||
console.error("SysMonitorService: No JSON object found in output.", fullText);
|
||||
|
||||
isUpdating = false;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ Singleton {
|
||||
running: false
|
||||
onExited: (exitCode) => {
|
||||
if (exitCode !== 0) {
|
||||
console.warn("UserInfoService: Failed to get user info");
|
||||
|
||||
root.username = "User";
|
||||
root.fullName = "User";
|
||||
root.hostname = "System";
|
||||
@@ -55,7 +55,7 @@ Singleton {
|
||||
root.username = parts[0] || "";
|
||||
root.fullName = parts[1] || parts[0] || "";
|
||||
root.hostname = parts[2] || "";
|
||||
console.log("UserInfoService: User info loaded -", root.username, root.fullName, root.hostname);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,7 +70,7 @@ Singleton {
|
||||
running: false
|
||||
onExited: (exitCode) => {
|
||||
if (exitCode !== 0) {
|
||||
console.warn("UserInfoService: Failed to get uptime");
|
||||
|
||||
root.uptime = "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ Singleton {
|
||||
|
||||
function addRef() {
|
||||
refCount++;
|
||||
console.log("WeatherService: addRef, refCount now:", refCount);
|
||||
|
||||
if (refCount === 1 && !weather.available) {
|
||||
// Start fetching when first consumer appears
|
||||
fetchWeather();
|
||||
@@ -109,13 +109,13 @@ Singleton {
|
||||
|
||||
function removeRef() {
|
||||
refCount = Math.max(0, refCount - 1);
|
||||
console.log("WeatherService: removeRef, refCount now:", refCount);
|
||||
|
||||
}
|
||||
|
||||
function fetchWeather() {
|
||||
// Only fetch if someone is consuming the data
|
||||
if (root.refCount === 0) {
|
||||
console.log("WeatherService: Skipping fetch - no consumers");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user