launcher overhaul
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import Quickshell
|
||||
import "../scripts/fzf.js" as Fzf
|
||||
import "../scripts/fuzzysort.js" as Fuzzy
|
||||
import QtQuick
|
||||
|
||||
Singleton {
|
||||
required property list<QtObject> list
|
||||
property string key: "name"
|
||||
property bool useFuzzy: false
|
||||
property var extraOpts: ({})
|
||||
|
||||
// Extra stuff for fuzzy
|
||||
property list<string> keys: [key]
|
||||
property list<real> weights: [1]
|
||||
|
||||
readonly property var fzf: useFuzzy ? [] : new Fzf.Finder(list, Object.assign({
|
||||
selector
|
||||
}, extraOpts))
|
||||
readonly property list<var> fuzzyPrepped: useFuzzy ? list.map(e => {
|
||||
const obj = {
|
||||
_item: e
|
||||
};
|
||||
for (const k of keys)
|
||||
obj[k] = Fuzzy.prepare(e[k]);
|
||||
return obj;
|
||||
}) : []
|
||||
|
||||
function transformSearch(search: string): string {
|
||||
return search;
|
||||
}
|
||||
|
||||
function selector(item: var): string {
|
||||
// Only for fzf
|
||||
return item[key];
|
||||
}
|
||||
|
||||
function query(search: string): list<var> {
|
||||
search = transformSearch(search);
|
||||
if (!search)
|
||||
return [...list];
|
||||
|
||||
if (useFuzzy)
|
||||
return Fuzzy.go(search, fuzzyPrepped, Object.assign({
|
||||
all: true,
|
||||
keys,
|
||||
scoreFn: r => weights.reduce((a, w, i) => a + r[i].score * w, 0)
|
||||
}, extraOpts)).map(r => r.obj._item);
|
||||
|
||||
return fzf.find(search).sort((a, b) => {
|
||||
if (a.score === b.score)
|
||||
return selector(a.item).trim().length - selector(b.item).trim().length;
|
||||
return b.score - a.score;
|
||||
}).map(r => r.item);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
pragma Singleton
|
||||
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
import ZShell.Models
|
||||
import qs.Config
|
||||
import qs.Modules
|
||||
import qs.Helpers
|
||||
import qs.Paths
|
||||
|
||||
Searcher {
|
||||
id: root
|
||||
|
||||
property bool showPreview: false
|
||||
readonly property string current: showPreview ? previewPath : actualCurrent
|
||||
property string previewPath
|
||||
property string actualCurrent: WallpaperPath.currentWallpaperPath
|
||||
|
||||
function setWallpaper(path: string): void {
|
||||
actualCurrent = path;
|
||||
WallpaperPath.currentWallpaperPath = path;
|
||||
Quickshell.execDetached(["sh", "-c", `python3 ${Quickshell.shellPath("scripts/LockScreenBg.py")} --input_image=${root.actualCurrent} --output_path=${Paths.state}/lockscreen_bg.png`]);
|
||||
}
|
||||
|
||||
function preview(path: string): void {
|
||||
previewPath = path;
|
||||
showPreview = true;
|
||||
}
|
||||
|
||||
function stopPreview(): void {
|
||||
showPreview = false;
|
||||
Quickshell.execDetached(["sh", "-c", `python3 ${Quickshell.shellPath("scripts/SchemeColorGen.py")} --path=${root.actualCurrent} --thumbnail=${Paths.cache}/imagecache/thumbnail.jpg --output=${Paths.state}/scheme.json --scheme=${Config.colors.schemeType}`]);
|
||||
}
|
||||
|
||||
list: wallpapers.entries
|
||||
key: "relativePath"
|
||||
useFuzzy: true
|
||||
extraOpts: useFuzzy ? ({}) : ({
|
||||
forward: false
|
||||
})
|
||||
|
||||
FileSystemModel {
|
||||
id: wallpapers
|
||||
|
||||
recursive: true
|
||||
path: Config.general.wallpaperPath
|
||||
filter: FileSystemModel.Images
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user