mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
launcher: app usage recording moved to ShellState singleton
This commit is contained in:
@@ -90,6 +90,46 @@ Singleton {
|
||||
}
|
||||
}
|
||||
|
||||
// Launcher app usage tracking (separate file, survives panel destruction)
|
||||
FileView {
|
||||
id: launcherUsageFile
|
||||
path: Settings.cacheDir ? Settings.cacheDir + "launcher_app_usage.json" : ""
|
||||
printErrors: false
|
||||
watchChanges: false
|
||||
|
||||
onLoadFailed: function (error) {
|
||||
if (error.toString().includes("No such file") || error === 2) {
|
||||
writeAdapter();
|
||||
}
|
||||
}
|
||||
|
||||
JsonAdapter {
|
||||
id: launcherUsageAdapter
|
||||
property var counts: ({})
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: launcherUsageSaveTimer
|
||||
interval: 500
|
||||
onTriggered: launcherUsageFile.writeAdapter()
|
||||
}
|
||||
|
||||
function getLauncherUsageCount(key) {
|
||||
const m = launcherUsageAdapter.counts;
|
||||
if (!m)
|
||||
return 0;
|
||||
const v = m[key];
|
||||
return typeof v === 'number' && isFinite(v) ? v : 0;
|
||||
}
|
||||
|
||||
function recordLauncherUsage(key) {
|
||||
let counts = Object.assign({}, launcherUsageAdapter.counts || {});
|
||||
counts[key] = getLauncherUsageCount(key) + 1;
|
||||
launcherUsageAdapter.counts = counts;
|
||||
launcherUsageSaveTimer.restart();
|
||||
}
|
||||
|
||||
// Debounced save timer
|
||||
Timer {
|
||||
id: saveTimer
|
||||
|
||||
Reference in New Issue
Block a user