summaryrefslogtreecommitdiff
path: root/raveos-hyprland-theme/theme-data/dms/Common/CacheUtils.qml
blob: 1f03f0e3d80c43ee3b7cf65effcb2d5bd0142b0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
pragma Singleton
pragma ComponentBehavior: Bound
import Quickshell

Singleton {
    id: root

    // Clear all image cache
    function clearImageCache() {
        Quickshell.execDetached(["rm", "-rf", Paths.stringify(Paths.imagecache)]);
        Paths.mkdir(Paths.imagecache);
    }

    // Clear cache older than specified minutes
    function clearOldCache(ageInMinutes) {
        Quickshell.execDetached(["find", Paths.stringify(Paths.imagecache), "-name", "*.png", "-mmin", `+${ageInMinutes}`, "-delete"]);
    }

    // Clear cache for specific size
    function clearCacheForSize(size) {
        Quickshell.execDetached(["find", Paths.stringify(Paths.imagecache), "-name", `*@${size}x${size}.png`, "-delete"]);
    }

    // Get cache size in MB
    function getCacheSize(callback) {
        var process = Qt.createQmlObject(`
                                         import Quickshell.Io
                                         Process {
                                         command: ["du", "-sm", "${Paths.stringify(Paths.imagecache)}"]
                                         running: true
                                         stdout: StdioCollector {
                                         onStreamFinished: {
                                         var sizeMB = parseInt(text.split("\\t")[0]) || 0
                                         callback(sizeMB)
                                         }
                                         }
                                         }
                                         `, root);
    }
}