1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2025-12-07 05:55:37 -05:00

Code cleanups and some keyboard navigation on AppLauncher

This commit is contained in:
bbedward
2025-07-12 22:47:39 -04:00
parent f843d4dc7b
commit 44f6f3ca1a
8 changed files with 99 additions and 202 deletions

View File

@@ -1,105 +0,0 @@
import QtQuick
import QtCore
import Quickshell
import Quickshell.Io
pragma Singleton
pragma ComponentBehavior: Bound
Singleton {
id: root
property string configDir: StandardPaths.writableLocation(StandardPaths.ConfigLocation) + "/DankMaterialShell"
property string recentAppsFile: configDir + "/recentApps.json"
property int maxRecentApps: 10
property var recentApps: []
// Create config directory on startup
Process {
id: mkdirProcess
command: ["mkdir", "-p", root.configDir]
running: true
onExited: {
loadRecentApps()
}
}
FileView {
id: recentAppsFileView
path: root.recentAppsFile
onTextChanged: {
if (text && text.length > 0) {
try {
var data = JSON.parse(text)
if (Array.isArray(data)) {
root.recentApps = data
}
} catch (e) {
console.log("PreferencesService: Invalid recent apps format")
root.recentApps = []
}
}
}
}
function loadRecentApps() {
// FileView will automatically load and trigger onTextChanged
if (!recentAppsFileView.text || recentAppsFileView.text.length === 0) {
recentApps = []
}
}
function saveRecentApps() {
var jsonData = JSON.stringify(recentApps, null, 2)
var process = Qt.createQmlObject('
import Quickshell.Io
Process {
command: ["sh", "-c", "echo \'' + jsonData.replace(/'/g, "'\"'\"'") + '\' > \'' + root.recentAppsFile + '\'"]
running: true
onExited: {
if (exitCode !== 0) {
console.warn("Failed to save recent apps:", exitCode)
}
destroy()
}
}
', root)
}
function addRecentApp(app) {
if (!app) return
var execProp = app.execString || ""
if (!execProp) return
// Create a minimal app object to store
var appData = {
name: app.name,
exec: execProp,
icon: app.icon || "application-x-executable",
comment: app.comment || ""
}
// Remove existing entry if present
recentApps = recentApps.filter(a => a.exec !== execProp)
// Add to front
recentApps.unshift(appData)
// Limit size
if (recentApps.length > maxRecentApps) {
recentApps = recentApps.slice(0, maxRecentApps)
}
saveRecentApps()
}
function getRecentApps() {
return recentApps
}
function clearRecentApps() {
recentApps = []
saveRecentApps()
}
}

View File

@@ -9,7 +9,6 @@ singleton BrightnessService 1.0 BrightnessService.qml
singleton BatteryService 1.0 BatteryService.qml
singleton SystemMonitorService 1.0 SystemMonitorService.qml
singleton AppSearchService 1.0 AppSearchService.qml
singleton PreferencesService 1.0 PreferencesService.qml
singleton LauncherService 1.0 LauncherService.qml
singleton NiriWorkspaceService 1.0 NiriWorkspaceService.qml
singleton CalendarService 1.0 CalendarService.qml